Re: [PATCH v2 13/15] cli: add support for --no- prefixed boolean and keyword flag arguments

Subject: Re: [PATCH v2 13/15] cli: add support for --no- prefixed boolean and keyword flag arguments

Date: Sun, 01 Oct 2017 14:08:25 -0700

To: Jani Nikula, notmuch@notmuchmail.org

Cc: Daniel Kahn Gillmor

From: William Casarin


Jani Nikula <jani@nikula.org> writes:

> @@ -171,11 +186,22 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_
>  	if (! try->name)
>  	    continue;
>  
> -	if (strncmp (arg, try->name, strlen (try->name)) != 0)
> +	char next;
> +	const char *value;
> +	notmuch_bool_t negate = FALSE;
> +
> +	if (strncmp (arg, try->name, strlen (try->name)) == 0) {
> +	    next = arg[strlen (try->name)];
> +	    value = arg + strlen (try->name) + 1;
> +	} else if (negative_arg && (try->opt_bool || try->opt_flags) &&
> +		   strncmp (negative_arg, try->name, strlen (try->name)) == 0) {
> +	    next = negative_arg[strlen (try->name)];
> +	    value = negative_arg + strlen (try->name) + 1;
> +	    /* The argument part of --no-argument matches, negate the result. */
> +	    negate = TRUE;
> +	} else {
>  	    continue;
> -
> -	char next = arg[strlen (try->name)];
> -	const char *value = arg + strlen(try->name) + 1;
> +	}

nit: I see strlen (try->name) computed 6 times here, any reason not to pull
this out into a variable?
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: