* flower/include/getopt-long.hh: Use std::string [interface].
Update callers.
* stepmake/stepmake/executable-rules.make: Add dependency on
module libraries.
+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:
#include <cassert>
#include <cstdlib>
-#include <iostream>
using namespace std;
#include "config.hh"
-#include "string-convert.hh"
#if !HAVE_GETTEXT
inline char *
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
if (!error_out_)
return;
- String str = arg_value_char_a_a_[0];
+ Std_string str = arg_value_char_a_a_[0];
str += ": ";
switch (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'",
default:
assert (false);
}
- fprintf (error_out_, "%s\n", str.to_str0 ());
+ fprintf (error_out_, "%s\n", str.c_str ());
exit (2);
}
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";
}
#define GETOPT_LONG_HH
#include <cstdio>
+
+#include "std-string.hh"
using namespace std;
#include "string.hh"
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
#if !STD_STRING
-#define Std_string
+#define Std_string String
#define to_std_string to_string
+class String;
#include "string.hh"
#else
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 */
/* 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_;
(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
}
}
+#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;
+}
+
#include "libc-extension.hh"
#include "string-convert.hh"
+/* std::string conversion helpers */
+
#if STD_STRING
#include "std-string.hh"
{
*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 *
}
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
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);
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"
-$(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)