From fb3d13058fa03e8d1bc33b83328a10a2e0f00cd7 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sun, 6 Nov 2011 09:09:39 +0200 Subject: subopt-helper: support "no-" prefix to negate suboptions Support "no-" prefix to negate boolean suboptions in the subopt helper (used to parse VO etc suboptions). Previously only "no" was supported, unlike toplevel options which gained "no-" support earlier. --- subopt-helper.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/subopt-helper.c b/subopt-helper.c index 5a2f19ea40..bc7a14ba47 100644 --- a/subopt-helper.c +++ b/subopt-helper.c @@ -260,23 +260,24 @@ int subopt_parse( char const * const str, const opt_t * opts ) parse_pos = last - str; } } -} -else if ( substr_len == opt_len+2 ) -{ - if ( opts[idx].type == OPT_ARG_BOOL && // check for no - strncmp( &str[parse_pos], "no", 2 ) == 0 && - strncmp( &str[parse_pos+2], opts[idx].name, opt_len ) == 0 ) - { - /* option was found but negated */ - next = 1; - - /* set arg to false */ - *((int *)(opts[idx].valp)) = 0; - - /* increment position */ - parse_pos += opt_len+2; + } + else if (opts[idx].type == OPT_ARG_BOOL) { + // check for no- + for (char **p = (char *[]){"no-", "no", NULL}; *p; p++) { + if (substr_len == opt_len + strlen(*p) && + !strncmp(str + parse_pos, *p, strlen(*p)) && + !strncmp(str + parse_pos + strlen(*p), opts[idx].name, opt_len)) { + /* option was found but negated */ + next = 1; + + /* set arg to false */ + *((int *)(opts[idx].valp)) = 0; + + parse_pos += opt_len + strlen(*p); + break; + } + } } -} ++idx; // test against next option -- cgit v1.2.3