1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 08:12:17 +00:00

options: make --no-... options work for OPT_REPLACED too

Do this by automatically adding the option, if the aliased option name
also has a "no-..." variant.

Could be easier by manually adding "no-..." variants to the option list,
but this seems better because you can't just forget it.
This commit is contained in:
wm4 2014-12-11 23:23:50 +01:00
parent 29f28fd948
commit 3dc8f63baa
2 changed files with 24 additions and 9 deletions

View File

@ -372,10 +372,6 @@ static void m_config_add_option(struct m_config *config,
.name = arg->name,
};
if (co.opt->type == &m_option_type_alias ||
co.opt->type == &m_option_type_removed)
co.is_generated = true;
if (arg->offset >= 0) {
if (optstruct)
co.data = (char *)optstruct + arg->offset;
@ -434,6 +430,24 @@ static void m_config_add_option(struct m_config *config,
MP_TARRAY_APPEND(config, config->opts, config->num_opts, co);
add_negation_option(config, &co, parent_name);
if (co.opt->type == &m_option_type_alias) {
co.is_generated = true; // hide it
const char *alias = (const char *)co.opt->priv;
char no_alias[40];
snprintf(no_alias, sizeof(no_alias), "no-%s", alias);
if (m_config_get_co(config, bstr0(no_alias))) {
struct m_option *new = talloc_zero(config, struct m_option);
new->name = talloc_asprintf(config, "no-%s", co.name);
new->priv = talloc_strdup(config, no_alias);
new->type = &m_option_type_alias;
new->offset = -1;
m_config_add_option(config, "", NULL, NULL, new);
}
}
if (co.opt->type == &m_option_type_removed)
co.is_generated = true; // hide it
}
struct m_config_option *m_config_get_co(const struct m_config *config,
@ -453,14 +467,14 @@ struct m_config_option *m_config_get_co(const struct m_config *config,
matches = true;
if (matches) {
if (co->opt->type == &m_option_type_alias) {
const char *new = (const char *)co->opt->priv;
const char *alias = (const char *)co->opt->priv;
if (!co->warning_was_printed) {
MP_WARN(config, "Warning: option %s%s was replaced with "
"%s%s and might be removed in the future.\n",
prefix, co->name, prefix, new);
prefix, co->name, prefix, alias);
co->warning_was_printed = true;
}
return m_config_get_co(config, bstr0(new));
return m_config_get_co(config, bstr0(alias));
} else if (co->opt->type == &m_option_type_removed) {
if (!co->warning_was_printed) {
char *msg = co->opt->priv;

View File

@ -275,7 +275,6 @@ const m_option_t mp_opts[] = {
OPT_STRING("vd", video_decoders, 0),
OPT_FLAG("ad-spdif-dtshd", dtshd, 0),
OPT_FLAG("dtshd", dtshd, 0), // old alias
OPT_CHOICE("hwdec", hwdec_api, 0,
({"no", 0},
@ -305,7 +304,6 @@ const m_option_t mp_opts[] = {
OPT_SUBSTRUCT("demuxer-rawvideo", demux_rawvideo, demux_rawvideo_conf, 0),
OPT_FLAG("demuxer-mkv-subtitle-preroll", mkv_subtitle_preroll, 0),
OPT_FLAG("mkv-subtitle-preroll", mkv_subtitle_preroll, 0), // old alias
OPT_DOUBLE("demuxer-mkv-subtitle-preroll-secs", mkv_subtitle_preroll_secs,
M_OPT_MIN, .min = 0),
OPT_FLAG("demuxer-mkv-probe-video-duration", mkv_probe_duration, 0),
@ -643,6 +641,9 @@ const m_option_t mp_opts[] = {
OPT_REMOVED("no-cache-pause-below", "use --no-cache-pause"),
OPT_REMOVED("volstep", "edit input.conf directly instead"),
OPT_REPLACED("mkv-subtitle-preroll", "demuxer-mkv-subtitle-preroll"),
OPT_REPLACED("dtshd", "ad-spdif-dtshd"),
{0}
};