mirror of https://github.com/mpv-player/mpv
options: some simplifications
Remove more stuff that was needed only for legacy suboptions. One user-visible change is that parent-options like --tv are now not visible anymore. They lead to a special error message when used before, but now they're simply not part of the option list anymore.
This commit is contained in:
parent
3203d6003c
commit
4958c1a556
|
@ -344,8 +344,6 @@ error:
|
||||||
|
|
||||||
static void ensure_backup(struct m_config *config, struct m_config_option *co)
|
static void ensure_backup(struct m_config *config, struct m_config_option *co)
|
||||||
{
|
{
|
||||||
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
|
|
||||||
return;
|
|
||||||
if (!co->data)
|
if (!co->data)
|
||||||
return;
|
return;
|
||||||
for (struct m_opt_backup *cur = config->backup_opts; cur; cur = cur->next) {
|
for (struct m_opt_backup *cur = config->backup_opts; cur; cur = cur->next) {
|
||||||
|
@ -553,6 +551,8 @@ static void m_config_add_option(struct m_config *config,
|
||||||
.name = arg->name,
|
.name = arg->name,
|
||||||
.shadow_offset = -1,
|
.shadow_offset = -1,
|
||||||
.group = parent ? parent->group : 0,
|
.group = parent ? parent->group : 0,
|
||||||
|
.default_data = &default_value,
|
||||||
|
.is_hidden = !!arg->deprecation_message,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (arg->offset >= 0) {
|
if (arg->offset >= 0) {
|
||||||
|
@ -560,22 +560,11 @@ static void m_config_add_option(struct m_config *config,
|
||||||
co.data = (char *)optstruct + arg->offset;
|
co.data = (char *)optstruct + arg->offset;
|
||||||
if (optstruct_def)
|
if (optstruct_def)
|
||||||
co.default_data = (char *)optstruct_def + arg->offset;
|
co.default_data = (char *)optstruct_def + arg->offset;
|
||||||
int size = arg->type->size;
|
|
||||||
if (optstruct && size) {
|
|
||||||
// The required alignment is unknown, so go with the minimum C
|
|
||||||
// could require. Slightly wasteful, but not that much.
|
|
||||||
int align = (size - config->shadow_size % size) % size;
|
|
||||||
co.shadow_offset = config->shadow_size + align;
|
|
||||||
config->shadow_size = co.shadow_offset + size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg->defval)
|
if (arg->defval)
|
||||||
co.default_data = arg->defval;
|
co.default_data = arg->defval;
|
||||||
|
|
||||||
if (!co.default_data)
|
|
||||||
co.default_data = &default_value;
|
|
||||||
|
|
||||||
// Fill in the full name
|
// Fill in the full name
|
||||||
if (!co.name[0]) {
|
if (!co.name[0]) {
|
||||||
co.name = parent_name;
|
co.name = parent_name;
|
||||||
|
@ -583,24 +572,28 @@ static void m_config_add_option(struct m_config *config,
|
||||||
co.name = talloc_asprintf(config, "%s-%s", parent_name, co.name);
|
co.name = talloc_asprintf(config, "%s-%s", parent_name, co.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (co.opt->deprecation_message)
|
if (arg->type == &m_option_type_subconfig) {
|
||||||
co.is_hidden = true;
|
|
||||||
|
|
||||||
// Option with children -> add them
|
|
||||||
if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
|
|
||||||
const struct m_sub_options *subopts = arg->priv;
|
const struct m_sub_options *subopts = arg->priv;
|
||||||
add_sub_options(config, &co, subopts);
|
add_sub_options(config, &co, subopts);
|
||||||
} else {
|
} else {
|
||||||
|
int size = arg->type->size;
|
||||||
|
if (optstruct && size) {
|
||||||
|
// The required alignment is unknown, so go with the maximum C
|
||||||
|
// could require. Slightly wasteful, but not that much.
|
||||||
|
int align = (size - config->shadow_size % size) % size;
|
||||||
|
co.shadow_offset = config->shadow_size + align;
|
||||||
|
config->shadow_size = co.shadow_offset + size;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize options
|
// Initialize options
|
||||||
if (co.data && co.default_data)
|
if (co.data && co.default_data)
|
||||||
init_opt_inplace(arg, co.data, co.default_data);
|
init_opt_inplace(arg, co.data, co.default_data);
|
||||||
}
|
|
||||||
|
MP_TARRAY_APPEND(config, config->opts, config->num_opts, co);
|
||||||
|
|
||||||
if (arg->type == &m_option_type_obj_settings_list)
|
if (arg->type == &m_option_type_obj_settings_list)
|
||||||
init_obj_settings_list(config, (const struct m_obj_list *)arg->priv);
|
init_obj_settings_list(config, (const struct m_obj_list *)arg->priv);
|
||||||
|
}
|
||||||
if (arg->name[0]) // no own name -> hidden
|
|
||||||
MP_TARRAY_APPEND(config, config->opts, config->num_opts, co);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct m_config_option *m_config_get_co_raw(const struct m_config *config,
|
struct m_config_option *m_config_get_co_raw(const struct m_config *config,
|
||||||
|
@ -843,16 +836,9 @@ static int m_config_parse_option(struct m_config *config, struct bstr name,
|
||||||
if (bstr_equals0(name, "list-options"))
|
if (bstr_equals0(name, "list-options"))
|
||||||
return list_options(config, bstr0("*"), false);
|
return list_options(config, bstr0("*"), false);
|
||||||
|
|
||||||
// Option with children are a bit different to parse
|
|
||||||
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
|
|
||||||
MP_FATAL(config, "Suboptions (--%.*s=...) have been removed. Use "
|
|
||||||
"flat options instead.\n", BSTR_P(name));
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
union m_option_value val = {0};
|
union m_option_value val = {0};
|
||||||
|
|
||||||
// Some option tpyes are "impure" and work on the existing data.
|
// Some option types are "impure" and work on the existing data.
|
||||||
// (Prime examples: --vf-add, --sub-file)
|
// (Prime examples: --vf-add, --sub-file)
|
||||||
if (co->data)
|
if (co->data)
|
||||||
m_option_copy(co->opt, &val, co->data);
|
m_option_copy(co->opt, &val, co->data);
|
||||||
|
@ -968,8 +954,6 @@ void m_config_print_option_list(const struct m_config *config, const char *name)
|
||||||
for (int i = 0; i < config->num_opts; i++) {
|
for (int i = 0; i < config->num_opts; i++) {
|
||||||
struct m_config_option *co = &sorted[i];
|
struct m_config_option *co = &sorted[i];
|
||||||
const struct m_option *opt = co->opt;
|
const struct m_option *opt = co->opt;
|
||||||
if (opt->type->flags & M_OPT_TYPE_HAS_CHILD)
|
|
||||||
continue;
|
|
||||||
if (co->is_hidden)
|
if (co->is_hidden)
|
||||||
continue;
|
continue;
|
||||||
#if HAVE_FNMATCH
|
#if HAVE_FNMATCH
|
||||||
|
@ -1022,9 +1006,6 @@ char **m_config_list_options(void *ta_parent, const struct m_config *config)
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int i = 0; i < config->num_opts; i++) {
|
for (int i = 0; i < config->num_opts; i++) {
|
||||||
struct m_config_option *co = &config->opts[i];
|
struct m_config_option *co = &config->opts[i];
|
||||||
const struct m_option *opt = co->opt;
|
|
||||||
if (opt->type->flags & M_OPT_TYPE_HAS_CHILD)
|
|
||||||
continue;
|
|
||||||
if (co->is_hidden)
|
if (co->is_hidden)
|
||||||
continue;
|
continue;
|
||||||
// For use with CONF_TYPE_STRING_LIST, it's important not to set list
|
// For use with CONF_TYPE_STRING_LIST, it's important not to set list
|
||||||
|
|
|
@ -1662,10 +1662,7 @@ const m_option_type_t m_option_type_print_fn = {
|
||||||
.parse = parse_print,
|
.parse = parse_print,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////////// Subconfig
|
|
||||||
#undef VAL
|
#undef VAL
|
||||||
#define VAL(x) (*(char ***)(x))
|
|
||||||
|
|
||||||
// Read s sub-option name, or a positional sub-opt value.
|
// Read s sub-option name, or a positional sub-opt value.
|
||||||
// termset is a string containing the set of chars that terminate an option.
|
// termset is a string containing the set of chars that terminate an option.
|
||||||
|
@ -1750,50 +1747,6 @@ static int split_subconf(struct mp_log *log, bstr optname, bstr *str,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_subconf(struct mp_log *log, const m_option_t *opt,
|
|
||||||
struct bstr name, struct bstr param, void *dst)
|
|
||||||
{
|
|
||||||
int nr = 0;
|
|
||||||
char **lst = NULL;
|
|
||||||
|
|
||||||
if (param.len == 0)
|
|
||||||
return M_OPT_MISSING_PARAM;
|
|
||||||
|
|
||||||
struct bstr p = param;
|
|
||||||
|
|
||||||
while (p.len) {
|
|
||||||
bstr subopt, subparam;
|
|
||||||
int r = split_subconf(log, name, &p, &subopt, &subparam);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
if (bstr_startswith0(p, ":"))
|
|
||||||
p = bstr_cut(p, 1);
|
|
||||||
else if (p.len > 0) {
|
|
||||||
mp_err(log, "Incorrect termination for '%.*s'\n", BSTR_P(subopt));
|
|
||||||
return M_OPT_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst) {
|
|
||||||
lst = talloc_realloc(NULL, lst, char *, 2 * (nr + 2));
|
|
||||||
lst[2 * nr] = bstrto0(lst, subopt);
|
|
||||||
lst[2 * nr + 1] = bstrto0(lst, subparam);
|
|
||||||
memset(&lst[2 * (nr + 1)], 0, 2 * sizeof(char *));
|
|
||||||
nr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dst)
|
|
||||||
VAL(dst) = lst;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const m_option_type_t m_option_type_subconfig = {
|
|
||||||
.name = "Subconfig",
|
|
||||||
.flags = M_OPT_TYPE_HAS_CHILD,
|
|
||||||
.parse = parse_subconf,
|
|
||||||
};
|
|
||||||
|
|
||||||
#undef VAL
|
#undef VAL
|
||||||
|
|
||||||
// Split the string on the given split character.
|
// Split the string on the given split character.
|
||||||
|
@ -3370,13 +3323,6 @@ const m_option_type_t m_option_type_alias = {
|
||||||
const m_option_type_t m_option_type_removed = {
|
const m_option_type_t m_option_type_removed = {
|
||||||
.name = "removed",
|
.name = "removed",
|
||||||
};
|
};
|
||||||
|
const m_option_type_t m_option_type_subconfig = {
|
||||||
static int parse_dummy(struct mp_log *log, const m_option_t *opt,
|
.name = "Subconfig",
|
||||||
struct bstr name, struct bstr param, void *dst)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
const m_option_type_t m_option_type_subopt_legacy = {
|
|
||||||
.name = "legacy suboption",
|
|
||||||
.parse = parse_dummy,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,7 +53,6 @@ extern const m_option_type_t m_option_type_choice;
|
||||||
extern const m_option_type_t m_option_type_flags;
|
extern const m_option_type_t m_option_type_flags;
|
||||||
extern const m_option_type_t m_option_type_msglevels;
|
extern const m_option_type_t m_option_type_msglevels;
|
||||||
extern const m_option_type_t m_option_type_print_fn;
|
extern const m_option_type_t m_option_type_print_fn;
|
||||||
extern const m_option_type_t m_option_type_subconfig;
|
|
||||||
extern const m_option_type_t m_option_type_imgfmt;
|
extern const m_option_type_t m_option_type_imgfmt;
|
||||||
extern const m_option_type_t m_option_type_fourcc;
|
extern const m_option_type_t m_option_type_fourcc;
|
||||||
extern const m_option_type_t m_option_type_afmt;
|
extern const m_option_type_t m_option_type_afmt;
|
||||||
|
@ -63,11 +62,11 @@ extern const m_option_type_t m_option_type_size_box;
|
||||||
extern const m_option_type_t m_option_type_channels;
|
extern const m_option_type_t m_option_type_channels;
|
||||||
extern const m_option_type_t m_option_type_aspect;
|
extern const m_option_type_t m_option_type_aspect;
|
||||||
extern const m_option_type_t m_option_type_node;
|
extern const m_option_type_t m_option_type_node;
|
||||||
extern const m_option_type_t m_option_type_subopt_legacy;
|
|
||||||
|
|
||||||
// Used internally by m_config.c
|
// 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_alias;
|
||||||
extern const m_option_type_t m_option_type_removed;
|
extern const m_option_type_t m_option_type_removed;
|
||||||
|
extern const m_option_type_t m_option_type_subconfig;
|
||||||
|
|
||||||
// Callback used by m_option_type_print_fn options.
|
// Callback used by m_option_type_print_fn options.
|
||||||
typedef void (*m_opt_print_fn)(struct mp_log *log);
|
typedef void (*m_opt_print_fn)(struct mp_log *log);
|
||||||
|
@ -407,16 +406,6 @@ struct m_option {
|
||||||
|
|
||||||
// These flags are used to describe special parser capabilities or behavior.
|
// These flags are used to describe special parser capabilities or behavior.
|
||||||
|
|
||||||
// Suboption parser flag.
|
|
||||||
/** When this flag is set, m_option::p should point to another m_option
|
|
||||||
* array. Only the parse function will be called. If dst is set, it should
|
|
||||||
* create/update an array of char* containg opt/val pairs. The options in
|
|
||||||
* the child array will then be set automatically by the \ref Config.
|
|
||||||
* Also note that suboptions may be directly accessed by using
|
|
||||||
* -option:subopt blah.
|
|
||||||
*/
|
|
||||||
#define M_OPT_TYPE_HAS_CHILD (1 << 0)
|
|
||||||
|
|
||||||
// Wildcard matching flag.
|
// Wildcard matching flag.
|
||||||
/** If set the option type has a use for option names ending with a *
|
/** If set the option type has a use for option names ending with a *
|
||||||
* (used for -aa*), this only affects the option name matching.
|
* (used for -aa*), this only affects the option name matching.
|
||||||
|
@ -731,10 +720,4 @@ extern const char m_option_path_separator;
|
||||||
{.name = optname, .type = &m_option_type_removed, .priv = msg, \
|
{.name = optname, .type = &m_option_type_removed, .priv = msg, \
|
||||||
.deprecation_message = "", .offset = -1}
|
.deprecation_message = "", .offset = -1}
|
||||||
|
|
||||||
// Redirect a suboption (e.g. from --vo) to a global option. The redirection
|
|
||||||
// is handled as a special case instead of being applied automatically.
|
|
||||||
#define OPT_SUBOPT_LEGACY(optname, globalname) \
|
|
||||||
{.name = optname, .type = &m_option_type_subopt_legacy, .priv = globalname, \
|
|
||||||
.offset = -1}
|
|
||||||
|
|
||||||
#endif /* MPLAYER_M_OPTION_H */
|
#endif /* MPLAYER_M_OPTION_H */
|
||||||
|
|
|
@ -5552,8 +5552,7 @@ void command_init(struct MPContext *mpctx)
|
||||||
for (int n = 0; n < num_opts; n++) {
|
for (int n = 0; n < num_opts; n++) {
|
||||||
struct m_config_option *co = m_config_get_co_index(mpctx->mconfig, n);
|
struct m_config_option *co = m_config_get_co_index(mpctx->mconfig, n);
|
||||||
assert(co->name[0]);
|
assert(co->name[0]);
|
||||||
if ((co->opt->flags & M_OPT_NOPROP) ||
|
if (co->opt->flags & M_OPT_NOPROP)
|
||||||
(co->opt->type->flags & M_OPT_TYPE_HAS_CHILD))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct m_property prop = {0};
|
struct m_property prop = {0};
|
||||||
|
|
Loading…
Reference in New Issue