From 4ab860cddc177047663bbe8940b0d34c621b6425 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 5 Sep 2016 21:04:17 +0200 Subject: options: add a mechanism to make sub-option replacement slightly easier Instead of requiring each VO or AO to manually add members to MPOpts and the global option table, make it possible to register them automatically via vo_driver/ao_driver.global_opts members. This avoids modifying options.c/options.h every time, including having to duplicate the exact ifdeffery used to enable a driver. --- options/m_config.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'options/m_config.c') diff --git a/options/m_config.c b/options/m_config.c index 3d1355904e..18a9ad4de7 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -406,6 +406,18 @@ static void add_sub_options(struct m_config *config, add_options(config, &next, new_optstruct, new_optstruct_def, subopts->opts); } +static void add_global_subopts(struct m_config *config, + const struct m_obj_list *list) +{ + struct m_obj_desc desc; + for (int n = 0; ; n++) { + if (!list->get_desc(&desc, n)) + break; + if (desc.global_opts) + add_sub_options(config, NULL, desc.global_opts); + } +} + // Initialize a field with a given value. In case this is dynamic data, it has // to be allocated and copied. src can alias dst, also can be NULL. static void init_opt_inplace(const struct m_option *opt, void *dst, @@ -477,6 +489,10 @@ static void m_config_add_option(struct m_config *config, init_opt_inplace(arg, co.data, co.default_data); } + // (The deprecation_message check is a hack to exclude --vo-defaults etc.) + if (arg->type == &m_option_type_obj_settings_list && !arg->deprecation_message) + add_global_subopts(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); } -- cgit v1.2.3