diff options
author | wm4 <wm4@nowhere> | 2017-09-22 11:31:03 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-09-22 11:31:03 +0200 |
commit | fba927de415d1541b242cc628b3ff3c09cec46bd (patch) | |
tree | 3738ce208036948af4a4d2aae885c126ba8f2360 /options/m_config.c | |
parent | acfd1a1929e9086f7a6bc3d2c05453a64be45f9a (diff) | |
download | mpv-fba927de415d1541b242cc628b3ff3c09cec46bd.tar.bz2 mpv-fba927de415d1541b242cc628b3ff3c09cec46bd.tar.xz |
options: properly handle deprecated options with CLI actions
We want e.g. --opengl-shaders-append=foo to resolve to the new option,
all while printing an option name. --opengl-shader is a similar case.
These options are special, because they apply "actions" on actual
options by specifying a suffix. So the alias/deprecation handling has to
be part of resolving the actual option from prefix and suffix.
Diffstat (limited to 'options/m_config.c')
-rw-r--r-- | options/m_config.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/options/m_config.c b/options/m_config.c index 24f4b83c45..82b6088c12 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -549,8 +549,9 @@ struct m_config_option *m_config_get_co_raw(const struct m_config *config, return NULL; } -struct m_config_option *m_config_get_co(const struct m_config *config, - struct bstr name) +// Like m_config_get_co_raw(), but resolve aliases. +static struct m_config_option *m_config_get_co_any(const struct m_config *config, + struct bstr name) { struct m_config_option *co = m_config_get_co_raw(config, name); if (!co) @@ -571,10 +572,7 @@ struct m_config_option *m_config_get_co(const struct m_config *config, } co->warning_was_printed = true; } - return m_config_get_co(config, bstr0(alias)); - } else if (co->opt->type == &m_option_type_cli_alias) { - // Pretend it does not exist. - return NULL; + return m_config_get_co_any(config, bstr0(alias)); } else if (co->opt->type == &m_option_type_removed) { if (!co->warning_was_printed) { char *msg = co->opt->priv; @@ -599,6 +597,17 @@ struct m_config_option *m_config_get_co(const struct m_config *config, return co; } +struct m_config_option *m_config_get_co(const struct m_config *config, + struct bstr name) +{ + struct m_config_option *co = m_config_get_co_any(config, name); + // CLI aliases should not be real options, and are explicitly handled by + // m_config_set_option_cli(). So petend it does not exist. + if (co && co->opt->type == &m_option_type_cli_alias) + co = NULL; + return co; +} + int m_config_get_co_count(struct m_config *config) { return config->num_opts; @@ -818,7 +827,7 @@ static struct m_config_option *m_config_mogrify_cli_opt(struct m_config *config, } // Resolve CLI alias. (We don't allow you to combine them with "--no-".) - co = m_config_get_co_raw(config, *name); + co = m_config_get_co_any(config, *name); if (co && co->opt->type == &m_option_type_cli_alias) *name = bstr0((char *)co->opt->priv); @@ -826,12 +835,18 @@ static struct m_config_option *m_config_mogrify_cli_opt(struct m_config *config, // matches. (We don't allow you to combine them with "--no-".) for (int n = 0; n < config->num_opts; n++) { co = &config->opts[n]; - const struct m_option_type *type = co->opt->type; struct bstr coname = bstr0(co->name); if (!bstr_startswith(*name, coname)) continue; + // Aliased option + a suffix action, e.g. --opengl-shaders-append + if (co->opt->type == &m_option_type_alias) + co = m_config_get_co_any(config, coname); + if (!co) + continue; + + const struct m_option_type *type = co->opt->type; for (int i = 0; type->actions && type->actions[i].name; i++) { const struct m_option_action *action = &type->actions[i]; bstr suffix = bstr0(action->name); |