]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/getopt-long.cc
* The grand 2005-2006 replace.
[lilypond.git] / flower / getopt-long.cc
index d8d750bf0e8bd83f865fc70de72a1f40f86e842c..80db6fa46a6b7ee80c9326298075a561496c3639 100644 (file)
@@ -1,7 +1,7 @@
 /*
   process command line, GNU style.
 
-  this is Copyleft (c) 1996--2005 Han-Wen Nienhuys, <hanwen@cs.uu.nl>
+  this is Copyleft (c) 1996--2006 Han-Wen Nienhuys, <hanwen@xs4all.nl>
 */
 
 #include "getopt-long.hh"
@@ -11,6 +11,7 @@
 #include <cstdlib>
 
 #include <iostream>
+using namespace std;
 
 #include "config.hh"
 #include "string-convert.hh"
@@ -43,16 +44,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 +66,6 @@ Getopt_long::parselong ()
   array_index_++;
   argument_index_ = 0;
 
-
   if (found_option_->take_arg_str0_)
     {
       if (endopt)
@@ -202,9 +202,7 @@ Getopt_long::parseshort ()
       array_index_++;
     }
   if (!optional_argument_str0_)
-    {
-      report (E_ARGEXPECT);
-    }
+    report (E_ARGEXPECT);
 
   return found_option_;
 }
@@ -222,7 +220,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;
@@ -241,9 +239,7 @@ Getopt_long::operator () ()
          return parseshort ();
        }
       else
-       {
-         return 0;
-       }
+       return 0;
     }
 }
 
@@ -306,21 +302,20 @@ const int EXTRA_SPACES = 5;
 String
 Long_option_init::table_string (Long_option_init *l)
 {
-  String argstr = "ARG";
   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 (wid, 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);
 
-      tabstr += s + gettext (l[i].help_str0_) + "\n";
+      String help_text (gettext (l[i].help_str0_));
+      help_text.substitute ("\n", "\n" + String_convert::char_string (' ', wid + EXTRA_SPACES + 2));
+      tabstr += s + help_text + "\n";
     }
 
   return tabstr;