[PATCH v2 13/15] cli: add support for --no- prefixed boolean and keyword flag arguments
Jani Nikula
jani at nikula.org
Mon Oct 2 08:52:00 PDT 2017
On Sun, 01 Oct 2017, William Casarin <jb55 at jb55.com> wrote:
> 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?
I pretty much thought the change was so controversial that I wouldn't
bother with that kind of fixes until we'd agreed we want this. Other
than that, agreed.
BR,
Jani.
More information about the notmuch
mailing list