summaryrefslogtreecommitdiffstats
path: root/core/m_config.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-21 19:33:08 +0200
committerwm4 <wm4@nowhere>2013-07-21 23:27:31 +0200
commit6629a95b928499a46c9686f0800b65aec7fcbb22 (patch)
tree67e158d3678b54fc521b4fedb19a7dd20b823512 /core/m_config.c
parent111a455ec621103b714a199217471af5f3efe35a (diff)
downloadmpv-6629a95b928499a46c9686f0800b65aec7fcbb22.tar.bz2
mpv-6629a95b928499a46c9686f0800b65aec7fcbb22.tar.xz
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except that m_config is much more powerful. m_config is used for VOs and some other things, so to unify them. We plan to kick out m_struct and use m_config for everything. (Unfortunately, m_config is also a bit more bloated, so this commit isn't all that great, but it will allow to reduce the option parser mess somewhat.) This commit also switches all video filters to use the option macros. One reason is that m_struct and m_config, even though they both use m_option, store the offsets of the option fields differently (sigh...), meaning the options defined for either are incompatible. It's easier to switch everything in one go. This commit will allow using the -vf option parser for other things, like VOs and AOs.
Diffstat (limited to 'core/m_config.c')
-rw-r--r--core/m_config.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/core/m_config.c b/core/m_config.c
index 336af39447..a447621009 100644
--- a/core/m_config.c
+++ b/core/m_config.c
@@ -182,6 +182,49 @@ struct m_config *m_config_simple(void *optstruct)
return config;
}
+struct m_config *m_config_from_obj_desc(void *talloc_parent,
+ struct m_obj_desc *desc)
+{
+ struct m_config *config = m_config_simple(NULL);
+ talloc_steal(talloc_parent, config);
+ if (desc->priv_size) {
+ config->optstruct = talloc_zero_size(config, desc->priv_size);
+ if (desc->priv_defaults)
+ memcpy(config->optstruct, desc->priv_defaults, desc->priv_size);
+ m_config_register_options(config, desc->options);
+ }
+ return config;
+}
+
+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]),
+ bstr0(args[n * 2 + 1]));
+ if (r < 0)
+ return r;
+ }
+ return 0;
+}
+
+int m_config_initialize_obj(struct m_config *config, struct m_obj_desc *desc,
+ void **ppriv, char ***pargs)
+{
+ if (desc->priv_size) {
+ int r = m_config_set_obj_params(config, *pargs);
+ if (r < 0)
+ return r;
+ *ppriv = config->optstruct;
+ *pargs = NULL;
+ } else if (*pargs && !strcmp((*pargs)[0], "_oldargs_")) {
+ // Handle things which still use the old subopt parser
+ *pargs = (char **)((*pargs)[1]);
+ } else {
+ *pargs = NULL;
+ }
+ return 0;
+}
+
struct m_config *m_config_new(void *optstruct,
int includefunc(struct m_config *conf,
char *filename))
@@ -414,8 +457,14 @@ static void m_config_add_option(struct m_config *config,
// pretend that merge options don't exist (only their children matter)
if (!is_merge_opt(co->opt)) {
- co->next = config->opts;
- config->opts = co;
+ struct m_config_option **last = &config->opts;
+ while (*last)
+ last = &(*last)->next;
+ *last = co;
+ if (!co->alias_owner) { // don't make no- etc. options positional
+ config->num_pos_opts += 1;
+ co->pos = config->num_pos_opts;
+ }
}
add_negation_option(config, parent, arg);
@@ -425,10 +474,8 @@ int m_config_register_options(struct m_config *config,
const struct m_option *args)
{
assert(config != NULL);
- assert(args != NULL);
-
- add_options(config, NULL, args);
-
+ if (args)
+ add_options(config, NULL, args);
return 1;
}
@@ -450,6 +497,15 @@ struct m_config_option *m_config_get_co(const struct m_config *config,
return NULL;
}
+const char *m_config_get_positional_option(const struct m_config *config, int n)
+{
+ for (struct m_config_option *co = config->opts; co; co = co->next) {
+ if (co->pos && co->pos - 1 == n)
+ return co->name;
+ }
+ return NULL;
+}
+
static int parse_subopts(struct m_config *config, void *optstruct, char *name,
char *prefix, struct bstr param, int flags);