diff options
author | wm4 <wm4@nowhere> | 2012-09-20 03:32:01 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-02-09 00:21:16 +0100 |
commit | 830560979c02b4e06924a813cf9bacb1629d40c9 (patch) | |
tree | c90295bcc2bc77bee2d2a8c13d661d5b20772117 /core/parser-mpcmd.c | |
parent | ae070a6f1eff9f38dcd3ec785dd1f251e3761472 (diff) | |
download | mpv-830560979c02b4e06924a813cf9bacb1629d40c9.tar.bz2 mpv-830560979c02b4e06924a813cf9bacb1629d40c9.tar.xz |
options: change handling of "no-" options
Normally, all flag options can be negated by prepending a "no-", for
example "--no-opt" becomes "--opt=no". Some flag options can't actually
be negated, so add a CONF_TYPE_STORE option type to disallow the "no-"
fallback.
Do the same for choice options. Remove the explicit "no-" prefixed
options, add "no" as choice.
Move the handling of automatic "no-" options from parser-mpcmd.c to
m_config.c, and use it in m_config_set_option/m_config_parse_option.
This makes these options available in the config file. It also
simplifies sub-option parsing, because it doesn't need to handle "no-"
anymore.
Diffstat (limited to 'core/parser-mpcmd.c')
-rw-r--r-- | core/parser-mpcmd.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/core/parser-mpcmd.c b/core/parser-mpcmd.c index bc7499fd83..025c7faf97 100644 --- a/core/parser-mpcmd.c +++ b/core/parser-mpcmd.c @@ -87,32 +87,21 @@ static int split_opt_silent(struct parse_state *p) } } + if (m_config_map_option(p->config, &p->arg, &p->param) == M_OPT_INVALID) + return -2; + p->mp_opt = m_config_get_option(p->config, p->arg); - if (!p->mp_opt) { - // Automagic "no-" arguments: "--no-bla" turns into "--bla=no". - if (!bstr_startswith0(p->arg, "no-")) - return -1; - - struct bstr s = bstr_cut(p->arg, 3); - p->mp_opt = m_config_get_option(p->config, s); - if (!p->mp_opt || p->mp_opt->type != &m_option_type_flag) - return -1; - // Avoid allowing "--no-no-bla". - if (bstr_startswith(bstr0(p->mp_opt->name), bstr0("no-"))) - return -1; - // Flag options never have parameters. - old_syntax = false; - if (p->param.len) - return -2; - p->arg = s; - p->param = bstr0("no"); - } + if (!p->mp_opt) + return -1; - if (bstr_endswith0(p->arg, "-clr")) + if ((p->mp_opt->type->flags & M_OPT_TYPE_OLD_SYNTAX_NO_PARAM) + || p->param.len + || bstr_endswith0(p->arg, "-clr")) + { old_syntax = false; + } - if (old_syntax && !(p->mp_opt->type->flags & M_OPT_TYPE_OLD_SYNTAX_NO_PARAM)) - { + if (old_syntax) { if (p->argc < 1) return -3; p->param = bstr0(p->argv[0]); |