summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-11-29 15:18:40 +0100
committerwm4 <wm4@nowhere>2016-11-29 17:10:06 +0100
commit4958c1a556fa4f3bc4e4b3b36e04a056d90f69e1 (patch)
tree78c7f3bfc46dbf571685b69af324a6367a14b5aa
parent3203d6003c8e308b2ba4e277a64e717696b1b8b7 (diff)
downloadmpv-4958c1a556fa4f3bc4e4b3b36e04a056d90f69e1.tar.bz2
mpv-4958c1a556fa4f3bc4e4b3b36e04a056d90f69e1.tar.xz
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.
-rw-r--r--options/m_config.c53
-rw-r--r--options/m_option.c58
-rw-r--r--options/m_option.h19
-rw-r--r--player/command.c3
4 files changed, 21 insertions, 112 deletions
diff --git a/options/m_config.c b/options/m_config.c
index 256e4653e7..2dc3eb569d 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -344,8 +344,6 @@ error:
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)
return;
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,
.shadow_offset = -1,
.group = parent ? parent->group : 0,
+ .default_data = &default_value,
+ .is_hidden = !!arg->deprecation_message,
};
if (arg->offset >= 0) {
@@ -560,22 +560,11 @@ static void m_config_add_option(struct m_config *config,
co.data = (char *)optstruct + arg->offset;
if (optstruct_def)
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)
co.default_data = arg->defval;
- if (!co.default_data)
- co.default_data = &default_value;
-
// Fill in the full name
if (!co.name[0]) {
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);
}
- if (co.opt->deprecation_message)
- co.is_hidden = true;
-
- // Option with children -> add them
- if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
+ if (arg->type == &m_option_type_subconfig) {
const struct m_sub_options *subopts = arg->priv;
add_sub_options(config, &co, subopts);
} 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
if (co.data && co.default_data)
init_opt_inplace(arg, co.data, co.default_data);
- }
-
- if (arg->type == &m_option_type_obj_settings_list)
- 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);
+
+ if (arg->type == &m_option_type_obj_settings_list)
+ init_obj_settings_list(config, (const struct m_obj_list *)arg->priv);
+ }
}
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"))
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};
- // 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)
if (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++) {
struct m_config_option *co = &sorted[i];
const struct m_option *opt = co->opt;
- if (opt->type->flags & M_OPT_TYPE_HAS_CHILD)
- continue;
if (co->is_hidden)
continue;
#if HAVE_FNMATCH
@@ -1022,9 +1006,6 @@ char **m_config_list_options(void *ta_parent, const struct m_config *config)
int count = 0;
for (int i = 0; i < config->num_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)
continue;
// For use with CONF_TYPE_STRING_LIST, it's important not to set list
diff --git a/options/m_option.c b/options/m_option.c
index 6baa87c163..11bb677b97 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -1662,10 +1662,7 @@ const m_option_type_t m_option_type_print_fn = {
.parse = parse_print,
};
-
-/////////////////////// Subconfig
#undef VAL
-#define VAL(x) (*(char ***)(x))
// Read s sub-option name, or a positional sub-opt value.
// 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;
}
-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
// 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 = {
.name = "removed",
};
-
-static int parse_dummy(struct mp_log *log, const m_option_t *opt,
- 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,
+const m_option_type_t m_option_type_subconfig = {
+ .name = "Subconfig",
};
diff --git a/options/m_option.h b/options/m_option.h
index 8faaad2133..8709d20bb2 100644
--- a/options/m_option.h
+++ b/options/m_option.h
@@ -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_msglevels;
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_fourcc;
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_aspect;
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
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_subconfig;
// Callback used by m_option_type_print_fn options.
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.
-// 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.
/** If set the option type has a use for option names ending with a *
* (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, \
.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 */
diff --git a/player/command.c b/player/command.c
index 3d56a56fca..36850a2c51 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5552,8 +5552,7 @@ void command_init(struct MPContext *mpctx)
for (int n = 0; n < num_opts; n++) {
struct m_config_option *co = m_config_get_co_index(mpctx->mconfig, n);
assert(co->name[0]);
- if ((co->opt->flags & M_OPT_NOPROP) ||
- (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD))
+ if (co->opt->flags & M_OPT_NOPROP)
continue;
struct m_property prop = {0};