From 7c6188a8eb50175e9e6e776b8830f5374814cae9 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Mon, 23 Jan 2006 21:06:28 +0000 Subject: [PATCH] * flower/include/std-string.hh: Oops, bugfix for --disable-std-string. * flower/include/getopt-long.hh: Use std::string [interface]. Update callers. * stepmake/stepmake/executable-rules.make: Add dependency on module libraries. --- ChangeLog | 10 ++++++ flower/getopt-long.cc | 38 +++++++++++------------ flower/include/getopt-long.hh | 8 +++-- flower/include/std-string.hh | 6 +++- flower/include/string.hh | 4 ++- flower/std-string.cc | 24 +++++++++++++-- flower/string.cc | 41 +++++++++++++++++++------ lily/main.cc | 2 +- stepmake/stepmake/executable-rules.make | 9 +++++- 9 files changed, 104 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4516553dc7..b27db6b3b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-23 Jan Nieuwenhuizen + + * flower/include/std-string.hh: Oops, bugfix for --disable-std-string. + + * flower/include/getopt-long.hh: Use std::string [interface]. + Update callers. + + * stepmake/stepmake/executable-rules.make: Add dependency on + module libraries. + 2006-01-22 Jan Nieuwenhuizen * flower/file-path.cc: diff --git a/flower/getopt-long.cc b/flower/getopt-long.cc index 80db6fa46a..8829c27ee9 100644 --- a/flower/getopt-long.cc +++ b/flower/getopt-long.cc @@ -10,11 +10,9 @@ #include #include -#include using namespace std; #include "config.hh" -#include "string-convert.hh" #if !HAVE_GETTEXT inline char * @@ -88,23 +86,23 @@ Getopt_long::parselong () return found_option_; } -String +Std_string Long_option_init::to_string () const { - String str; + Std_string str; if (shortname_char_) str += "-" + shortname_char_; if (shortname_char_ && longname_str0_) str += ", "; if (longname_str0_) - str += String ("`--") + longname_str0_ + "'"; + str += Std_string ("`--") + longname_str0_ + "'"; return str; } -String +Std_string Long_option_init::str_for_help () const { - String s; + Std_string s; if (shortname_char_) s = "-" + ::to_string (shortname_char_); else @@ -135,7 +133,7 @@ Getopt_long::report (Errorcod c) if (!error_out_) return; - String str = arg_value_char_a_a_[0]; + Std_string str = arg_value_char_a_a_[0]; str += ": "; switch (c) { @@ -149,10 +147,9 @@ Getopt_long::report (Errorcod c) break; case E_UNKNOWNOPTION: str += _f ("unrecognized option: `%s'", - String (argument_index_ - ? String ("-" + String_convert::form_string ("%c", - arg_value_char_a_a_[array_index_][argument_index_])) - : String (arg_value_char_a_a_[array_index_]))); + Std_string (argument_index_ + ? Std_string ("-" + Std_string (1, arg_value_char_a_a_[array_index_][argument_index_])) + : Std_string (arg_value_char_a_a_[array_index_]))); break; case E_ILLEGALARG: str += _f ("invalid argument `%s' to option `%s'", @@ -161,7 +158,7 @@ Getopt_long::report (Errorcod c) default: assert (false); } - fprintf (error_out_, "%s\n", str.to_str0 ()); + fprintf (error_out_, "%s\n", str.c_str ()); exit (2); } @@ -299,22 +296,23 @@ Getopt_long::get_next_arg () const int EXTRA_SPACES = 5; -String +Std_string Long_option_init::table_string (Long_option_init *l) { - String tabstr = ""; + Std_string tabstr = ""; int wid = 0; for (int i = 0; l[i].shortname_char_ || l[i].longname_str0_; i++) - wid = max (wid, l[i].str_for_help ().length ()); + wid = max (wid, int(l[i].str_for_help ().length ())); for (int i = 0; l[i].shortname_char_ || l[i].longname_str0_; i++) { - String s = " " + l[i].str_for_help (); - s += String_convert::char_string (' ', wid - s.length () + EXTRA_SPACES); + Std_string s = " " + l[i].str_for_help (); + s += Std_string (wid - s.length () + EXTRA_SPACES, ' '); - String help_text (gettext (l[i].help_str0_)); - help_text.substitute ("\n", "\n" + String_convert::char_string (' ', wid + EXTRA_SPACES + 2)); + Std_string help_text (gettext (l[i].help_str0_)); + replace_all (help_text, "\n", + "\n" + Std_string (wid + EXTRA_SPACES + 2, ' ')); tabstr += s + help_text + "\n"; } diff --git a/flower/include/getopt-long.hh b/flower/include/getopt-long.hh index c186ce85bb..3e5d7000f8 100644 --- a/flower/include/getopt-long.hh +++ b/flower/include/getopt-long.hh @@ -2,6 +2,8 @@ #define GETOPT_LONG_HH #include + +#include "std-string.hh" using namespace std; #include "string.hh" @@ -21,12 +23,12 @@ struct Long_option_init char const *help_str0_; - String to_string () const; - String str_for_help () const; + Std_string to_string () const; + Std_string str_for_help () const; // NO constructor! static int compare (Long_option_init const &, Long_option_init const &); - static String table_string (Long_option_init *); + static Std_string table_string (Long_option_init *); }; /** C++ for version of long_getopt. For processing GNU style command diff --git a/flower/include/std-string.hh b/flower/include/std-string.hh index 129cf4dfc7..1a505cc79a 100644 --- a/flower/include/std-string.hh +++ b/flower/include/std-string.hh @@ -11,8 +11,9 @@ #if !STD_STRING -#define Std_string +#define Std_string String #define to_std_string to_string +class String; #include "string.hh" #else @@ -48,6 +49,9 @@ namespace std { Std_string to_std_string (char const *format, ...); } +} #endif /* STD_STRING */ + +Std_string &replace_all (Std_string &str, Std_string find, Std_string replace); #endif /* STD_STRING_HH */ diff --git a/flower/include/string.hh b/flower/include/string.hh index bf83b5ba8f..af4ea7932f 100644 --- a/flower/include/string.hh +++ b/flower/include/string.hh @@ -68,11 +68,13 @@ public: /* std::string interface */ char const *c_str () const; bool empty () const; - int size () const; + int String::find (String &s, int pos=0) const; int find (char c) const; int rfind (char c) const; + String replace (int pos, int n, String str); String (String const &, int pos, int n=-1); + String (int n, char c); protected: String_handle strh_; diff --git a/flower/std-string.cc b/flower/std-string.cc index d457d50655..e9cd0d9e5c 100644 --- a/flower/std-string.cc +++ b/flower/std-string.cc @@ -6,11 +6,13 @@ (c) 2006 Jan Nieuwenhuizen */ -#if STD_STRING #include "std-string.hh" +#if STD_STRING + namespace std { - Std_string to_std_string (char c, int n) + Std_string + to_std_string (char c, int n) { /* FIXME, remove this function and use std::string interface for String? This interface is a bit clumsy, almost alway you want @@ -19,4 +21,22 @@ namespace std { } } +#define FIND_FAILED string::npos +#define SIZE_T size_t +#else /* !STD_STRING */ + +#define FIND_FAILED -1 +#define SIZE_T int + #endif /* STD_STRING */ + +Std_string & +replace_all (Std_string &str, Std_string find, Std_string replace) +{ + int len = find.length (); + for (SIZE_T i = str.find (find); i != FIND_FAILED; i = str.find (find, + i + len)) + str = str.replace (i, len, replace); + return str; +} + diff --git a/flower/string.cc b/flower/string.cc index 622ef5917e..7b4620906a 100644 --- a/flower/string.cc +++ b/flower/string.cc @@ -21,6 +21,8 @@ using namespace std; #include "libc-extension.hh" #include "string-convert.hh" +/* std::string conversion helpers */ + #if STD_STRING #include "std-string.hh" @@ -29,22 +31,29 @@ String::String (Std_string const &s) { *this = String (s.c_str ()); } + +String::operator Std_string () const +{ + return Std_string (this->c_str ()); +} + #endif +/* std::string interface */ String::String (String const &s, int pos, int n) { if (n == -1) - n = s.size () - pos; + n = s.length () - pos; if (pos == 0) *this = s.left_string (n); else - *this = s.right_string (s.size () - pos).left_string (n); + *this = s.right_string (s.length () - pos).left_string (n); } -String::operator Std_string () const +String::String (int n, char c) { - return Std_string (this->c_str ()); + *this = String_convert::char_string (c, n); } char const * @@ -60,15 +69,21 @@ String::empty () const } int -String::size () const +String::find (char c) const { - return length (); + return index (c); } int -String::find (char c) const -{ - return index (c); +String::find (String &s, int pos) const +{ + if (!pos) + return index (s); + String f = right_string (length () - pos); + int n = f.index (s); + if (n != -1) + return pos + n; + return -1; } int @@ -77,7 +92,15 @@ String::rfind (char c) const return index_last (c); } +String +String::replace (int pos, int n, String str) +{ + return String (*this, 0, pos) + str + String (*this, pos + n); +} + + +/* String */ #ifdef STRING_DEBUG void *mymemmove (void *dest, void const *src, size_t n); diff --git a/lily/main.cc b/lily/main.cc index 9fa362c6c2..715a83186c 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -254,7 +254,7 @@ LY_DEFINE (ly_usage, "ly:usage", printf ("\n\n"); printf (_ ("Options:").to_str0 ()); printf ("\n"); - printf (Long_option_init::table_string (options_static).to_str0 ()); + printf (Long_option_init::table_string (options_static).c_str ()); printf ("\n"); printf (_f ("Report bugs via %s", "http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs" diff --git a/stepmake/stepmake/executable-rules.make b/stepmake/stepmake/executable-rules.make index 00b9fa8497..f82ab99a72 100644 --- a/stepmake/stepmake/executable-rules.make +++ b/stepmake/stepmake/executable-rules.make @@ -1,4 +1,11 @@ -$(EXECUTABLE): $(outdir)/config.hh $(O_FILES) $(outdir)/version.hh +define MODULE_LIB_template +$(1)/$(outdir)/library.a : + $(MAKE) -C $(1) +endef + +$(foreach a, $(MODULE_LIBS), $(eval $(call MODULE_LIB_template,$(a)))) + +$(EXECUTABLE): $(outdir)/config.hh $(O_FILES) $(outdir)/version.hh $(MODULE_LIBS:%=%/$(outdir)/library.a) $(foreach a, $(MODULE_LIBS), $(MAKE) -C $(a) && ) true $(LD) -o $@ $(O_FILES) $(LOADLIBES) $(ALL_LDFLAGS) -- 2.39.2