diff options
author | wm4 <wm4@nowhere> | 2016-09-02 14:49:34 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-02 14:49:34 +0200 |
commit | 4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345 (patch) | |
tree | f4c900cdf5536a1a7373965b49d92943fbb59aed /options/m_config.c | |
parent | 875aeb0f5c0c2853fc85b28727b5b849bee4a74d (diff) | |
download | mpv-4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345.tar.bz2 mpv-4fa6bcbb902d500ca0a1b9d2feeab5a4e5a98345.tar.xz |
m_config: add helper function for initializing af/ao/vf/vo suboptions
Normally I'd prefer a bunch of smaller functions with fewer parameters
over a single function with a lot of parameters. But future changes will
require messing with the parameters in a slightly more complex way, so a
combined function will be needed anyway. The now-unused "global"
parameter is required for later as well.
Diffstat (limited to 'options/m_config.c')
-rw-r--r-- | options/m_config.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/options/m_config.c b/options/m_config.c index d4c19808b0..7da23dc8d0 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -221,7 +221,7 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options); } -int m_config_set_obj_params(struct m_config *conf, char **args) +static int m_config_set_obj_params(struct m_config *conf, char **args) { for (int n = 0; args && args[n * 2 + 0]; n++) { int r = m_config_set_option(conf, bstr0(args[n * 2 + 0]), @@ -232,8 +232,8 @@ int m_config_set_obj_params(struct m_config *conf, char **args) return 0; } -int m_config_apply_defaults(struct m_config *config, const char *name, - struct m_obj_settings *defaults) +static int m_config_apply_defaults(struct m_config *config, const char *name, + struct m_obj_settings *defaults) { int r = 0; for (int n = 0; defaults && defaults[n].name; n++) { @@ -246,6 +246,22 @@ int m_config_apply_defaults(struct m_config *config, const char *name, return r; } +struct m_config *m_config_from_obj_desc_and_args(void *ta_parent, + struct mp_log *log, struct mpv_global *global, struct m_obj_desc *desc, + const char *name, struct m_obj_settings *defaults, char **args) +{ + struct m_config *config = m_config_from_obj_desc(ta_parent, log, desc); + if (m_config_apply_defaults(config, name, defaults) < 0) + goto error; + if (m_config_set_obj_params(config, args) < 0) + goto error; + + return config; +error: + talloc_free(config); + return NULL; +} + static void ensure_backup(struct m_config *config, struct m_config_option *co) { if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) |