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

William Casarin jb55 at jb55.com
Sun Oct 1 14:08:25 PDT 2017


Jani Nikula <jani at 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?


More information about the notmuch mailing list