From e4bc563fd2dcff1059624efb7b948b2886a382ab Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 2 Jul 2017 16:26:41 +0200 Subject: options: change everything again Fucking bullshit. --- options/m_config.c | 29 ++++++++++++++++++++++++++--- options/m_option.c | 33 +++++---------------------------- options/m_option.h | 10 ++++++++-- options/options.c | 21 +++++++++++---------- 4 files changed, 50 insertions(+), 43 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index ea58b5a3dd..604f4a8133 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -566,6 +566,9 @@ 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; } else if (co->opt->type == &m_option_type_removed) { if (!co->warning_was_printed) { char *msg = co->opt->priv; @@ -806,8 +809,13 @@ static struct m_config_option *m_config_mogrify_cli_opt(struct m_config *config, return co; } + // Resolve CLI alias. (We don't allow you to combine them with "--no-".) + co = m_config_get_co_raw(config, *name); + if (co && co->opt->type == &m_option_type_cli_alias) + *name = bstr0((char *)co->opt->priv); + // Might be a suffix "action", like "--vf-add". Expensively check for - // matches. (Also, we don't allow you to combine them with "--no-".) + // 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; @@ -902,8 +910,19 @@ int m_config_set_option_node(struct m_config *config, bstr name, int r; struct m_config_option *co = m_config_get_co(config, name); - if (!co) - return M_OPT_UNKNOWN; + if (!co) { + co = m_config_get_co_raw(config, name); + if (co && co->opt->type == &m_option_type_cli_alias) { + /*bstr old_name = name; + co = m_config_mogrify_cli_opt(config, &name, &(bool){0}, &(int){0}); + */ + name = bstr0((char *)co->opt->priv); + MP_WARN(config, "Setting %.*s via API is deprecated, set %s instead.\n", + BSTR_P(name), co->opt->name); + } else { + return M_OPT_UNKNOWN; + } + } // Do this on an "empty" type to make setting the option strictly overwrite // the old value, as opposed to e.g. appending to lists. @@ -1005,6 +1024,10 @@ void m_config_print_option_list(const struct m_config *config, const char *name) MP_INFO(config, " [file]"); if (opt->flags & M_OPT_FIXED) MP_INFO(config, " [no runtime changes]"); + if (opt->type == &m_option_type_alias) + MP_INFO(config, " for %s", (char *)opt->priv); + if (opt->type == &m_option_type_cli_alias) + MP_INFO(config, " for %s (CLI/config files only)", (char *)opt->priv); MP_INFO(config, "\n"); for (int n = 0; opt->type->actions && opt->type->actions[n].name; n++) { const struct m_option_action *action = &opt->type->actions[n]; diff --git a/options/m_option.c b/options/m_option.c index 9bdabd807e..162d57ee8e 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1213,7 +1213,7 @@ static int parse_str_list_impl(struct mp_log *log, const m_option_t *opt, if (bstr_endswith0(name, "-add")) { op = OP_ADD; - } else if (bstr_endswith0(name, "-add-str")) { + } else if (bstr_endswith0(name, "-append")) { op = OP_ADD_STR; } else if (bstr_endswith0(name, "-pre")) { op = OP_PRE; @@ -1395,33 +1395,7 @@ const m_option_type_t m_option_type_string_list = { .set = str_list_set, .actions = (const struct m_option_action[]){ {"add"}, - {"add-str"}, - {"clr", M_OPT_TYPE_OPTIONAL_PARAM}, - {"del"}, - {"pre"}, - {"set"}, - {0} - }, -}; - -static int parse_str_append_list(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param, void *dst) -{ - return parse_str_list_impl(log, opt, name, param, dst, OP_ADD_STR); -} - -const m_option_type_t m_option_type_string_append_list = { - .name = "String list (append by default)", - .size = sizeof(char **), - .parse = parse_str_append_list, - .print = print_str_list, - .copy = copy_str_list, - .free = free_str_list, - .get = str_list_get, - .set = str_list_set, - .actions = (const struct m_option_action[]){ - {"add"}, - {"add-str"}, + {"append"}, {"clr", M_OPT_TYPE_OPTIONAL_PARAM}, {"del"}, {"pre"}, @@ -3372,6 +3346,9 @@ const m_option_type_t m_option_type_node = { const m_option_type_t m_option_type_alias = { .name = "alias", }; +const m_option_type_t m_option_type_cli_alias = { + .name = "alias", +}; const m_option_type_t m_option_type_removed = { .name = "removed", }; diff --git a/options/m_option.h b/options/m_option.h index dea3956f7f..6935c93594 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -65,6 +65,7 @@ extern const m_option_type_t m_option_type_node; // Used internally by m_config.c extern const m_option_type_t m_option_type_alias; +extern const m_option_type_t m_option_type_cli_alias; extern const m_option_type_t m_option_type_removed; extern const m_option_type_t m_option_type_subconfig; @@ -579,8 +580,8 @@ extern const char m_option_path_separator; #define OPT_KEYVALUELIST(...) \ OPT_GENERAL(char**, __VA_ARGS__, .type = &m_option_type_keyvalue_list) -#define OPT_PATHLIST(...) \ - OPT_GENERAL(char**, __VA_ARGS__, .type = &m_option_type_string_append_list, \ +#define OPT_PATHLIST(...) \ + OPT_GENERAL(char**, __VA_ARGS__, .type = &m_option_type_string_list,\ .priv = (void *)&m_option_path_separator) #define OPT_INT(...) \ @@ -713,6 +714,11 @@ extern const char m_option_path_separator; // Same, with a generic deprecation message. #define OPT_REPLACED(optname, newname) OPT_REPLACED_MSG(optname, newname, "") +// Alias, resolved on the CLI/config file/profile parser level only. +#define OPT_CLI_ALIAS(optname, newname) \ + {.name = optname, .type = &m_option_type_cli_alias, .priv = newname, \ + .flags = M_OPT_NOPROP, .offset = -1} + // "--optname" doesn't exist, but inform the user about a replacement with msg. #define OPT_REMOVED(optname, msg) \ {.name = optname, .type = &m_option_type_removed, .priv = msg, \ diff --git a/options/options.c b/options/options.c index db63efa9d2..2b9a630bc9 100644 --- a/options/options.c +++ b/options/options.c @@ -289,7 +289,8 @@ const m_option_t mp_opts[] = { OPT_STRINGLIST("reset-on-next-file", reset_options, 0), #if HAVE_LUA || HAVE_JAVASCRIPT - OPT_PATHLIST("script", script_files, M_OPT_FIXED), + OPT_PATHLIST("scripts", script_files, M_OPT_FIXED), + OPT_CLI_ALIAS("script", "scripts-append"), OPT_KEYVALUELIST("script-opts", script_opts, 0), OPT_FLAG("load-scripts", auto_load_scripts, 0), #endif @@ -375,7 +376,8 @@ const m_option_t mp_opts[] = { #endif // demuxer.c - select audio/sub file/demuxer - OPT_PATHLIST("audio-file", audio_files, 0), + OPT_PATHLIST("audio-files", audio_files, 0), + OPT_CLI_ALIAS("audio-file", "audio-files-append"), OPT_STRING("demuxer", demuxer_name, 0), OPT_STRING("audio-demuxer", audio_demuxer_name, 0), OPT_STRING("sub-demuxer", sub_demuxer_name, 0), @@ -459,10 +461,12 @@ const m_option_t mp_opts[] = { // ------------------------- subtitles options -------------------- - OPT_PATHLIST("sub-file", sub_name, 0), - OPT_PATHLIST("sub-file-path", sub_paths, 0), - OPT_PATHLIST("audio-file-path", audiofile_paths, 0), - OPT_PATHLIST("external-file", external_files, 0), + OPT_PATHLIST("sub-files", sub_name, 0), + OPT_CLI_ALIAS("sub-file", "sub-files-append"), + OPT_PATHLIST("sub-file-paths", sub_paths, 0), + OPT_PATHLIST("audio-file-paths", audiofile_paths, 0), + OPT_PATHLIST("external-files", external_files, 0), + OPT_CLI_ALIAS("external-file", "external-file-append"), OPT_FLAG("autoload-files", autoload_files, 0), OPT_FLOAT("sub-delay", sub_delay, UPDATE_OSD), OPT_FLOAT("sub-fps", sub_fps, UPDATE_OSD), @@ -832,10 +836,7 @@ const m_option_t mp_opts[] = { OPT_REMOVED("fs-black-out-screens", NULL), OPT_REPLACED_MSG("loop", "loop-playlist", "--loop will be changed to map to" " --loop-file in future releases."), - OPT_REPLACED_MSG("sub-paths", "sub-file-path", - "passing multiple paths works differently now"), - OPT_REPLACED_MSG("audio-file-paths", "audio-file-path", - "passing multiple paths works differently now"), + OPT_REPLACED("sub-paths", "sub-file-paths"), {0} }; -- cgit v1.2.3