summaryrefslogtreecommitdiffstats
path: root/options/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-05 21:02:09 +0200
committerwm4 <wm4@nowhere>2016-09-05 21:03:46 +0200
commitcc813647d54843e4731cc36160f0c1e04e4b1404 (patch)
tree0e69e94129a7bc3dbf47549b3a8497adf64e2245 /options/m_config.c
parent6cd80e972e12c6eeaa7bbfcb1e1e6f3342aae8c2 (diff)
downloadmpv-cc813647d54843e4731cc36160f0c1e04e4b1404.tar.bz2
mpv-cc813647d54843e4731cc36160f0c1e04e4b1404.tar.xz
m_config: move parts of m_config_add_option into its own function
Preparation for the next commit.
Diffstat (limited to 'options/m_config.c')
-rw-r--r--options/m_config.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/options/m_config.c b/options/m_config.c
index a456430ceb..3d1355904e 100644
--- a/options/m_config.c
+++ b/options/m_config.c
@@ -371,6 +371,41 @@ static void add_options(struct m_config *config,
m_config_add_option(config, parent, optstruct, optstruct_def, &defs[i]);
}
+static void add_sub_options(struct m_config *config,
+ struct m_config_option *parent,
+ const struct m_sub_options *subopts)
+{
+ // Can't be used multiple times.
+ for (int n = 0; n < config->num_groups; n++)
+ assert(config->groups[n].group != subopts);
+
+ void *new_optstruct = NULL;
+ if (config->optstruct) // only if not noalloc
+ new_optstruct = m_config_alloc_struct(config, subopts);
+ if (parent && parent->data)
+ substruct_write_ptr(parent->data, new_optstruct);
+
+ const void *new_optstruct_def = NULL;
+ if (parent && parent->default_data)
+ new_optstruct_def = substruct_read_ptr(parent->default_data);
+ if (!new_optstruct_def)
+ new_optstruct_def = subopts->defaults;
+
+ int group = config->num_groups++;
+ MP_TARRAY_GROW(config, config->groups, group);
+ config->groups[group] = (struct m_config_group){
+ .group = subopts,
+ .parent_group = parent ? parent->group : 0,
+ .opts = new_optstruct,
+ };
+
+ struct m_config_option next = {
+ .name = parent ? parent->name : "",
+ .group = group,
+ };
+ add_options(config, &next, new_optstruct, new_optstruct_def, subopts->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,
@@ -435,32 +470,7 @@ static void m_config_add_option(struct m_config *config,
// Option with children -> add them
if (arg->type->flags & M_OPT_TYPE_HAS_CHILD) {
const struct m_sub_options *subopts = arg->priv;
-
- // Can't be used multiple times.
- for (int n = 0; n < config->num_groups; n++)
- assert(config->groups[n].group != subopts);
-
- void *new_optstruct = NULL;
- if (co.data) {
- new_optstruct = m_config_alloc_struct(config, subopts);
- substruct_write_ptr(co.data, new_optstruct);
- }
-
- const void *new_optstruct_def = substruct_read_ptr(co.default_data);
- if (!new_optstruct_def)
- new_optstruct_def = subopts->defaults;
-
- int parent_group = co.group;
- co.group = config->num_groups++;
- MP_TARRAY_GROW(config, config->groups, co.group);
- struct m_config_group *group = &config->groups[co.group];
- *group = (struct m_config_group){
- .group = subopts,
- .parent_group = parent_group,
- .opts = new_optstruct,
- };
-
- add_options(config, &co, new_optstruct, new_optstruct_def, subopts->opts);
+ add_sub_options(config, &co, subopts);
} else {
// Initialize options
if (co.data && co.default_data)