X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Fgetopt-long.cc;h=2cb537c67b39724afa5d06e57f8697e3e7115277;hb=d43b7e5c861f92010641109733279dc743799ff8;hp=e3850b153c47e47d63ca39807b1a055410f83bc3;hpb=58bcc84c9480dae1b21bc24d8396b91fe19e0131;p=lilypond.git diff --git a/flower/getopt-long.cc b/flower/getopt-long.cc index e3850b153c..2cb537c67b 100644 --- a/flower/getopt-long.cc +++ b/flower/getopt-long.cc @@ -1,7 +1,7 @@ /* process command line, GNU style. - this is Copyleft (c) 1996--2005 Han-Wen Nienhuys, + this is Copyleft (c) 1996--2007 Han-Wen Nienhuys, */ #include "getopt-long.hh" @@ -10,10 +10,8 @@ #include #include -#include - #include "config.hh" -#include "string-convert.hh" +#include "international.hh" #if !HAVE_GETTEXT inline char * @@ -43,16 +41,16 @@ Getopt_long::parselong () assert (*optnm); char const *endopt = strchr (optnm, '='); - int searchlen = (endopt) ? endopt - optnm : strlen (optnm); + int searchlen = (endopt) ? endopt - optnm : strlen (optnm); - found_option_=0; - for (int i=0; i< table_len_; i++) + found_option_ = 0; + for (int i = 0; i < table_len_; i++) { char const *ln = option_a_[i].longname_str0_; if (ln && !strncmp (ln, optnm, searchlen)) { - found_option_ = option_a_+i; + found_option_ = option_a_ + i; break; } } @@ -65,7 +63,6 @@ Getopt_long::parselong () array_index_++; argument_index_ = 0; - if (found_option_->take_arg_str0_) { if (endopt) @@ -77,7 +74,6 @@ Getopt_long::parselong () } if (!optional_argument_str0_) report (E_ARGEXPECT); - } else { @@ -89,23 +85,23 @@ Getopt_long::parselong () return found_option_; } -String +string Long_option_init::to_string () const { - String str; + string str; if (shortname_char_) str += "-" + shortname_char_; if (shortname_char_ && longname_str0_) str += ", "; if (longname_str0_) - str += String ("`--") + longname_str0_ + "'"; + str += string ("`--") + longname_str0_ + "'"; return str; } -String +string Long_option_init::str_for_help () const { - String s; + string s; if (shortname_char_) s = "-" + ::to_string (shortname_char_); else @@ -136,7 +132,7 @@ Getopt_long::report (Errorcod c) if (!error_out_) return; - String str = arg_value_char_a_a_[0]; + string str = arg_value_char_a_a_[0]; str += ": "; switch (c) { @@ -145,15 +141,14 @@ Getopt_long::report (Errorcod c) found_option_->to_string ()); break; case E_NOARGEXPECT: - str += _f ("option `%s' doesn't allow an argument", + str += _f ("option `%s' does not allow an argument", found_option_->to_string ()); 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_]))); + string (argument_index_ + ? string ("-" + string (1, arg_value_char_a_a_[array_index_][argument_index_])) + : string (arg_value_char_a_a_[array_index_]))); break; case E_ILLEGALARG: str += _f ("invalid argument `%s' to option `%s'", @@ -162,7 +157,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); } @@ -203,15 +198,13 @@ Getopt_long::parseshort () array_index_++; } if (!optional_argument_str0_) - { - report (E_ARGEXPECT); - } + report (E_ARGEXPECT); return found_option_; } const Long_option_init * -Getopt_long::operator() () +Getopt_long::operator () () { if (!ok ()) return 0; @@ -223,7 +216,7 @@ Getopt_long::operator() () if (argument_index_) return parseshort (); - const char *argument = arg_value_char_a_a_[array_index_]; + char const *argument = arg_value_char_a_a_[array_index_]; if (argument[0] != '-') return 0; @@ -242,9 +235,7 @@ Getopt_long::operator() () return parseshort (); } else - { - return 0; - } + return 0; } } @@ -258,10 +249,9 @@ Getopt_long::Getopt_long (int c, char **v, Long_option_init *lo) argument_index_ = 0; // reached end of option table? - table_len_ =0; - for (int i = 0; option_a_[i].longname_str0_ ||option_a_[i].shortname_char_; i++) + table_len_ = 0; + for (int i = 0; option_a_[i].longname_str0_ || option_a_[i].shortname_char_; i++) table_len_++; - } bool @@ -298,31 +288,31 @@ Getopt_long::get_next_arg () if (a) { array_index_++; - argument_index_= 0; + argument_index_ = 0; } return a; } const int EXTRA_SPACES = 5; -String +string Long_option_init::table_string (Long_option_init *l) { - String argstr = "ARG"; - String tabstr = ""; + string tabstr = ""; int wid = 0; for (int i = 0; l[i].shortname_char_ || l[i].longname_str0_; i++) - { - wid = wid >? l[i].str_for_help ().length (); - } + wid = max (int(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); + string s = " " + l[i].str_for_help (); + s += string (wid - s.length () + EXTRA_SPACES, ' '); - tabstr += s + gettext (l[i].help_str0_) + "\n"; + string help_text (gettext (l[i].help_str0_)); + replace_all (help_text, "\n", + "\n" + string (wid + EXTRA_SPACES + 2, ' ')); + tabstr += s + help_text + "\n"; } return tabstr;