X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Fgetopt-long.cc;h=458c2374cafb97f785b086c74e10127b6b5ce8ea;hb=9e781b7dc83b60a543ce218aa1a5f139f74c760f;hp=5d8b4259f308e6b32cf02daa8a8667dcca7005ed;hpb=a9d9433bc7b95cb2d4b3d96eefce7a8437c0d44e;p=lilypond.git diff --git a/flower/getopt-long.cc b/flower/getopt-long.cc index 5d8b4259f3..458c2374ca 100644 --- a/flower/getopt-long.cc +++ b/flower/getopt-long.cc @@ -1,7 +1,20 @@ /* - process command line, GNU style. + This file is part of LilyPond, the GNU music typesetter. - this is Copyleft (c) 1996--2009 Han-Wen Nienhuys, + Copyright (C) 1996--2014 Han-Wen Nienhuys, + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "getopt-long.hh" @@ -41,7 +54,7 @@ Getopt_long::parselong () assert (*optnm); char const *endopt = strchr (optnm, '='); - int searchlen = (endopt) ? endopt - optnm : strlen (optnm); + size_t searchlen = (endopt) ? (size_t) (endopt - optnm) : strlen (optnm); found_option_ = 0; for (int i = 0; i < table_len_; i++) @@ -49,10 +62,10 @@ Getopt_long::parselong () char const *ln = option_a_[i].longname_str0_; if (ln && !strncmp (ln, optnm, searchlen)) - { - found_option_ = option_a_ + i; - break; - } + { + found_option_ = option_a_ + i; + break; + } } if (!found_option_) @@ -66,20 +79,20 @@ Getopt_long::parselong () if (found_option_->take_arg_str0_) { if (endopt) - optional_argument_str0_ = endopt +1; // a '=' + optional_argument_str0_ = endopt + 1; // a '=' else - { - optional_argument_str0_ = arg_value_char_a_a_[array_index_]; - array_index_++; - } + { + optional_argument_str0_ = arg_value_char_a_a_[array_index_]; + array_index_++; + } if (!optional_argument_str0_) - report (E_ARGEXPECT); + report (E_ARGEXPECT); } else { optional_argument_str0_ = 0; if (endopt) - report (E_NOARGEXPECT); + report (E_NOARGEXPECT); } return found_option_; @@ -115,9 +128,9 @@ Long_option_init::str_for_help () const if (take_arg_str0_) { if (longname_str0_) - s = s + "="; + s = s + "="; else - s = s + " "; + s = s + " "; s = s + gettext (take_arg_str0_); } @@ -138,21 +151,21 @@ Getopt_long::report (Errorcod c) { case E_ARGEXPECT: str += _f ("option `%s' requires an argument", - found_option_->to_string ()); + found_option_->to_string ()); break; case E_NOARGEXPECT: str += _f ("option `%s' does not allow an argument", - found_option_->to_string ()); + found_option_->to_string ()); break; case E_UNKNOWNOPTION: str += _f ("unrecognized option: `%s'", - string (argument_index_ - ? string ("-" + string (1, 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'", - optional_argument_str0_, found_option_->to_string ()); + optional_argument_str0_, found_option_->to_string ()); break; default: assert (false); @@ -171,8 +184,8 @@ Getopt_long::parseshort () for (int i = 0; i < table_len_; i++) if (option_a_[i].shortname_char_ == c) { - found_option_ = option_a_ + i; - break; + found_option_ = option_a_ + i; + break; } if (!found_option_) @@ -221,21 +234,22 @@ Getopt_long::operator () () if (argument[0] != '-') return 0; - if (argument[1] == '-') {// what to do with "command -- bla" - if (argument[2]) - return parselong (); - else - return 0; - } + if (argument[1] == '-') // what to do with "command -- bla" + { + if (argument[2]) + return parselong (); + else + return 0; + } else { if (argument[ 1 ]) - { - argument_index_ = 1; - return parseshort (); - } + { + argument_index_ = 1; + return parseshort (); + } else - return 0; + return 0; } } @@ -265,7 +279,7 @@ Getopt_long::next () { error_ = E_NOERROR; while (array_index_ < argument_count_ - && !arg_value_char_a_a_[array_index_][argument_index_]) + && !arg_value_char_a_a_[array_index_][argument_index_]) { array_index_++; argument_index_ = 0; @@ -300,9 +314,9 @@ Long_option_init::table_string (Long_option_init *l) { string tabstr = ""; - int wid = 0; + size_t wid = 0; for (int i = 0; l[i].shortname_char_ || l[i].longname_str0_; i++) - wid = max (int(wid), int(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++) { @@ -311,7 +325,7 @@ Long_option_init::table_string (Long_option_init *l) string help_text (gettext (l[i].help_str0_)); replace_all (&help_text, "\n", - "\n" + string (wid + EXTRA_SPACES + 2, ' ')); + "\n" + string (wid + EXTRA_SPACES + 2, ' ')); tabstr += s + help_text + "\n"; } @@ -321,7 +335,7 @@ Long_option_init::table_string (Long_option_init *l) int Long_option_init::compare (Long_option_init const &a, Long_option_init const &b) { - if (a.shortname_char_ && b.shortname_char_ && a.shortname_char_- b.shortname_char_) + if (a.shortname_char_ && b.shortname_char_ && a.shortname_char_ - b.shortname_char_) return a.shortname_char_ - b.shortname_char_; if (b.shortname_char_ && a.longname_str0_)