Re: [PATCH v3 10/21] diff-parseopt: convert --stat*

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

 



Nguyễn Thái Ngọc Duy  <pclouds@xxxxxxxxx> writes:

> -static int stat_opt(struct diff_options *options, const char **av)
> +static int diff_opt_stat(const struct option *opt, const char *value, int unset)
>  {
> -	const char *arg = av[0];
> -	char *end;
> +	struct diff_options *options = opt->value;
> ...
> -	switch (*arg) {
> -	case '-':
> -		if (skip_prefix(arg, "-width", &arg)) {
> -			if (*arg == '=')
> -				width = strtoul(arg + 1, &end, 10);
> -			else if (!*arg && !av[1])
> -				die_want_option("--stat-width");
> -			else if (!*arg) {
> -				width = strtoul(av[1], &end, 10);
> -				argcount = 2;
> -			}
> ...
> +	if (!strcmp(opt->long_name, "stat")) {
> +		if (value) {
> +			width = strtoul(value, &end, 10);
> +			if (*end == ',')
> +				name_width = strtoul(end+1, &end, 10);
> +			if (*end == ',')
> +				count = strtoul(end+1, &end, 10);
> +			if (*end)
> +				return error(_("invalid --stat value: %s"), value);
>  		}

It took me a while to recall and figure out what the original is
doing, primarily because the code was designed to handle both
"-$option $arg" and "--$option=$arg".  But thanks to the switch to
parse-options API, this helper no longer has to worry about that,
which is a very big plus.  It only needs to parse what is in value.

Very nice.



[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]

  Powered by Linux