summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--subopt-helper.c33
1 files 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<opt>
- 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-<opt>
+ 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