Re: [PATCH 02/10] parse-options: clearer reporting of API misuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]