From: Jonathan Nieder Date: Thu, 02 Dec 2010 04:57:07 GMT Subject: Re: [PATCH 02/10] parse-options: clearer reporting of API misuse Message-ID: <20101202045707.GA32125@burratino> In-Reply-To: <20101201232923.GC31815@burratino> Jonathan Nieder wrote: > --- a/parse-options.c > +++ b/parse-options.c > @@ -316,24 +323,12 @@ static void check_typos(const char *arg, const struct option *options) > > static void parse_options_check(const struct option *opts) > { > - int err = 0; > - > for (; opts->type != OPTION_END; opts++) { > if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) && > - (opts->flags & PARSE_OPT_OPTARG)) { > - if (opts->long_name) { > - error("`--%s` uses incompatible flags " > - "LASTARG_DEFAULT and OPTARG", opts->long_name); > - } else { > - error("`-%c` uses incompatible flags " > - "LASTARG_DEFAULT and OPTARG", opts->short_name); > - } > - err |= 1; > - } > + (opts->flags & PARSE_OPT_OPTARG)) > + optbug(opts, "uses incompatible flags " > + "LASTARG_DEFAULT and OPTARG"); > } > - > - if (err) > - exit(129); Hmph, this is simpler but it does not report all errors any more. So it would be better to do: int err = 0; for (; opts->type != OPTION_END; opts++) { if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) && (opts->flags & PARSE_OPT_OPTARG)) err |= optbug(opts, "uses incompatible flags " "LASTARG_DEFAULT and OPTARG"); } if (err) exit(128); Sorry about that.