diff options
author | Uoti Urpala <uau@mplayer2.org> | 2011-11-06 09:09:39 +0200 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2011-11-14 20:24:39 +0200 |
commit | fb3d13058fa03e8d1bc33b83328a10a2e0f00cd7 (patch) | |
tree | ba3728f04499759f441be7d329f2d2484557b0c1 /subopt-helper.c | |
parent | 505f94cef9556a838066964ff1f558437fc458c0 (diff) | |
download | mpv-fb3d13058fa03e8d1bc33b83328a10a2e0f00cd7.tar.bz2 mpv-fb3d13058fa03e8d1bc33b83328a10a2e0f00cd7.tar.xz |
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.
Diffstat (limited to 'subopt-helper.c')
-rw-r--r-- | subopt-helper.c | 33 |
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 |