]> git.donarmstrong.com Git - lilypond.git/commitdiff
* flower/include/std-string.hh: Oops, bugfix for --disable-std-string.
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 23 Jan 2006 21:06:28 +0000 (21:06 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 23 Jan 2006 21:06:28 +0000 (21:06 +0000)
* flower/include/getopt-long.hh: Use std::string [interface].
Update callers.

* stepmake/stepmake/executable-rules.make: Add dependency on
module libraries.

ChangeLog
flower/getopt-long.cc
flower/include/getopt-long.hh
flower/include/std-string.hh
flower/include/string.hh
flower/std-string.cc
flower/string.cc
lily/main.cc
stepmake/stepmake/executable-rules.make

index 4516553dc7915fcdbc22221df9968906c62d29dc..b27db6b3b7b474797441c13dfe5199df837b90eb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2006-01-23  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * 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  <janneke@gnu.org>
 
        * flower/file-path.cc: 
index 80db6fa46a6b7ee80c9326298075a561496c3639..8829c27ee9d069c6c83691e992dbc2a1210438fa 100644 (file)
 #include <cassert>
 #include <cstdlib>
 
-#include <iostream>
 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";
     }
 
index c186ce85bb4906f24bfb4c25c751d3b06ee3774a..3e5d7000f8c8be827fcadb6dc3dd0dc2acafb730 100644 (file)
@@ -2,6 +2,8 @@
 #define GETOPT_LONG_HH
 
 #include <cstdio>
+
+#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
index 129cf4dfc7747eb1b7d445619a92858bcabd74f0..1a505cc79a40ad10175f1e2873859accabf5c2c2 100644 (file)
@@ -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 */
index bf83b5ba8fd6e4482921bea0649d375c98af48a5..af4ea7932fb29fa5d90c41cd99247520d192da66 100644 (file)
@@ -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_;
index d457d50655cbe613f7725ec165d4a7e21be2cb7c..e9cd0d9e5cac08eea88ef7a6f8b0200d57ea746a 100644 (file)
@@ -6,11 +6,13 @@
   (c) 2006  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
-#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;
+}
+
index 622ef5917e1c5954a3f77bcb3d2eabec8356e9a3..7b4620906a595ac07eaf430ec193344788c83989 100644 (file)
@@ -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);
index 9fa362c6c233c1db93791c9a4f6d2ab7189689cb..715a83186c6bda56e0701ac2be3fe3a9a7ee7fbe 100644 (file)
@@ -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"
index 00b9fa84971390769054a070c357e99a81d868e9..f82ab99a72db6a1493e7ec09ecf4b34372da8dce 100644 (file)
@@ -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)