summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-05-08 02:10:39 +0300
committerUoti Urpala <uau@mplayer2.org>2012-05-08 20:19:32 +0300
commit1e90a8657d19918dc7564f559b96dc3982286ba2 (patch)
tree1992e988e0328eb141b06cbb3ad180bbcf0f274d
parent9fbfac25daaf6bdaab4c1213a294b59bded29b24 (diff)
downloadmpv-1e90a8657d19918dc7564f559b96dc3982286ba2.tar.bz2
mpv-1e90a8657d19918dc7564f559b96dc3982286ba2.tar.xz
options: simplify option parsing/setting machinery
Each option type had three separate operations to copy option values between memory locations: copy between general memory locations ("copy"), copy from general memory to active configuration of the program ("set"), and in the other direction ("save"). No normal option depends on this distinction any more. Change everything to define and use a single "copy" operation only. Change the special options "include" and "profile", which depended on hacky option types, to be special-cased directly in option parsing instead. Remove the now unused option types m_option_type_func and m_option_type_func_param.
-rw-r--r--m_config.c116
-rw-r--r--m_config.h5
-rw-r--r--m_option.c457
-rw-r--r--m_option.h71
-rw-r--r--m_struct.c7
-rw-r--r--mplayer.c4
6 files changed, 160 insertions, 500 deletions
diff --git a/m_config.c b/m_config.c
index 94d7e26b2e..3da7707f14 100644
--- a/m_config.c
+++ b/m_config.c
@@ -36,12 +36,21 @@
#define MAX_PROFILE_DEPTH 20
-static int parse_profile(const struct m_option *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
+static int parse_include(struct m_config *config, struct bstr param, bool set)
+{
+ if (param.len == 0)
+ return M_OPT_MISSING_PARAM;
+ if (!set)
+ return 1;
+ char *filename = bstrdup0(NULL, param);
+ config->includefunc(config, filename);
+ talloc_free(filename);
+ return 1;
+}
+
+static int parse_profile(struct m_config *config, const struct m_option *opt,
+ struct bstr name, struct bstr param, bool set)
{
- struct m_config *config = opt->priv;
- char **list = NULL;
- int i, r;
if (!bstrcmp0(param, "help")) {
struct m_profile *p;
if (!config->profiles) {
@@ -57,40 +66,23 @@ static int parse_profile(const struct m_option *opt, struct bstr name,
return M_OPT_EXIT - 1;
}
- r = m_option_type_string_list.parse(opt, name, param, false, &list);
+ char **list = NULL;
+ int r = m_option_type_string_list.parse(opt, name, param, false, &list);
if (r < 0)
return r;
if (!list || !list[0])
return M_OPT_INVALID;
- for (i = 0; list[i]; i++)
- if (!m_config_get_profile(config, list[i])) {
+ for (int i = 0; list[i]; i++) {
+ struct m_profile *p = m_config_get_profile(config, list[i]);
+ if (!p) {
mp_tmsg(MSGT_CFGPARSER, MSGL_WARN, "Unknown profile '%s'.\n",
list[i]);
r = M_OPT_INVALID;
- }
- if (dst)
- m_option_copy(opt, dst, &list);
- else
- m_option_free(opt, &list);
- return r;
-}
-
-static void set_profile(const struct m_option *opt, void *dst, const void *src)
-{
- struct m_config *config = opt->priv;
- struct m_profile *p;
- char **list = NULL;
- int i;
- if (!src || !*(char ***)src)
- return;
- m_option_copy(opt, &list, src);
- for (i = 0; list[i]; i++) {
- p = m_config_get_profile(config, list[i]);
- if (!p)
- continue;
- m_config_set_profile(config, p);
+ } else if (set)
+ m_config_set_profile(config, p);
}
m_option_free(opt, &list);
+ return r;
}
static int show_profile(struct m_option *opt, char *name, char *param)
@@ -150,18 +142,18 @@ static int list_options(struct m_option *opt, char *name, char *param)
static void m_option_save(const struct m_config *config,
const struct m_option *opt, void *dst)
{
- if (opt->type->save) {
+ if (opt->type->copy) {
const void *src = m_option_get_ptr(opt, config->optstruct);
- opt->type->save(opt, dst, src);
+ opt->type->copy(opt, dst, src);
}
}
static void m_option_set(const struct m_config *config,
const struct m_option *opt, const void *src)
{
- if (opt->type->set) {
+ if (opt->type->copy) {
void *dst = m_option_get_ptr(opt, config->optstruct);
- opt->type->set(opt, dst, src);
+ opt->type->copy(opt, dst, src);
}
}
@@ -172,40 +164,31 @@ static void m_config_add_option(struct m_config *config,
const char *prefix, char *disabled_feature);
struct m_config *m_config_new(void *optstruct,
- int includefunc(struct m_option *conf,
+ int includefunc(struct m_config *conf,
char *filename))
{
struct m_config *config;
- static int initialized = 0;
- static struct m_option_type profile_opt_type;
static const struct m_option ref_opts[] = {
- { "profile", NULL, &profile_opt_type, CONF_NOSAVE, 0, 0, NULL },
+ { "profile", NULL, CONF_TYPE_STRING_LIST, CONF_NOSAVE, 0, 0, NULL },
{ "show-profile", show_profile, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
{ "list-options", list_options, CONF_TYPE_PRINT_FUNC, CONF_NOCFG },
{ NULL }
};
- int i;
config = talloc_zero(NULL, struct m_config);
config->lvl = 1; // 0 Is the defaults
- if (!initialized) {
- initialized = 1;
- profile_opt_type = m_option_type_string_list;
- profile_opt_type.parse = parse_profile;
- profile_opt_type.set = set_profile;
- }
struct m_option *self_opts = talloc_memdup(config, ref_opts,
sizeof(ref_opts));
- for (i = 0; self_opts[i].name; i++)
+ for (int i = 1; self_opts[i].name; i++)
self_opts[i].priv = config;
m_config_register_options(config, self_opts);
if (includefunc) {
struct m_option *p = talloc_ptrtype(config, p);
*p = (struct m_option){
- "include", includefunc, CONF_TYPE_FUNC_PARAM,
- CONF_NOSAVE, 0, 0, config
+ "include", NULL, CONF_TYPE_STRING, CONF_NOSAVE,
};
m_config_add_option(config, p, NULL, NULL);
+ config->includefunc = includefunc;
}
config->optstruct = optstruct;
@@ -420,18 +403,15 @@ static struct m_config_option *m_config_get_co(const struct m_config *config,
return NULL;
}
-static int m_config_parse_option(const struct m_config *config,
+static int m_config_parse_option(struct m_config *config,
struct bstr name, struct bstr param,
bool ambiguous_param, bool set)
{
- struct m_config_option *co;
- int r = 0;
-
assert(config != NULL);
assert(config->lvl > 0);
assert(name.len != 0);
- co = m_config_get_co(config, name);
+ struct m_config_option *co = m_config_get_co(config, name);
if (!co)
return M_OPT_UNKNOWN;
if (co->disabled_feature) {
@@ -466,23 +446,27 @@ static int m_config_parse_option(const struct m_config *config,
(co->opt->flags & M_OPT_PRE_PARSE) && (co->flags & M_CFG_OPT_SET)))
set = 0;
+ if (config->includefunc && !bstrcmp0(name, "include")) {
+ return parse_include(config, param, set);
+ } else if (!bstrcmp0(name, "profile"))
+ return parse_profile(config, co->opt, name, param, set);
+
// Option with children are a bit different to parse
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD) {
char **lst = NULL;
- int i, sr;
// Parse the child options
- r = m_option_parse(co->opt, name, param, false, &lst);
+ int r = m_option_parse(co->opt, name, param, false, &lst);
// Set them now
if (r >= 0)
- for (i = 0; lst && lst[2 * i]; i++) {
+ for (int i = 0; lst && lst[2 * i]; i++) {
int l = strlen(co->name) + 1 + strlen(lst[2 * i]) + 1;
if (r >= 0) {
// Build the full name
char n[l];
sprintf(n, "%s:%s", co->name, lst[2 * i]);
- sr = m_config_parse_option(config, bstr(n),
- bstr(lst[2 * i + 1]), false,
- set);
+ int sr = m_config_parse_option(config, bstr(n),
+ bstr(lst[2 * i + 1]), false,
+ set);
if (sr < 0) {
if (sr == M_OPT_UNKNOWN) {
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR,
@@ -502,18 +486,16 @@ static int m_config_parse_option(const struct m_config *config,
talloc_free(lst[2 * i + 1]);
}
talloc_free(lst);
- } else
- r = m_option_parse(co->opt, name, param, ambiguous_param,
- set ? co->slots->data : NULL);
+ return r;
+ }
+ void *dst = set ? m_option_get_ptr(co->opt, config->optstruct) : NULL;
+ int r = m_option_parse(co->opt, name, param, ambiguous_param, dst);
// Parsing failed ?
if (r < 0)
return r;
- // Set the option
- if (set) {
- m_option_set(config, co->opt, co->slots->data);
+ else if (set)
co->flags |= M_CFG_OPT_SET;
- }
return r;
}
@@ -526,7 +508,7 @@ int m_config_set_option(struct m_config *config, struct bstr name,
return m_config_parse_option(config, name, param, ambiguous_param, 1);
}
-int m_config_check_option(const struct m_config *config, struct bstr name,
+int m_config_check_option(struct m_config *config, struct bstr name,
struct bstr param, bool ambiguous_param)
{
int r;
diff --git a/m_config.h b/m_config.h
index 91ee7ffe43..ff54aae8b2 100644
--- a/m_config.h
+++ b/m_config.h
@@ -95,6 +95,7 @@ typedef struct m_config {
int profile_depth;
void *optstruct; // struct mpopts or other
+ int (*includefunc)(struct m_config *conf, char *filename);
} m_config_t;
@@ -107,7 +108,7 @@ typedef struct m_config {
// Create a new config object.
struct m_config *
m_config_new(void *optstruct,
- int includefunc(struct m_option *conf, char *filename));
+ int includefunc(struct m_config *conf, char *filename));
// Free a config object.
void m_config_free(struct m_config *config);
@@ -151,7 +152,7 @@ static inline int m_config_set_option0(struct m_config *config,
/* Check if an option setting is valid.
* Same as above m_config_set_option() but doesn't actually set anything.
*/
-int m_config_check_option(const struct m_config *config, struct bstr name,
+int m_config_check_option(struct m_config *config, struct bstr name,
struct bstr param, bool ambiguous_param);
static inline int m_config_check_option0(struct m_config *config,
diff --git a/m_option.c b/m_option.c
index d5113bb33a..55a58fc35c 100644
--- a/m_option.c
+++ b/m_option.c
@@ -129,16 +129,12 @@ static char *print_flag(const m_option_t *opt, const void *val)
}
const m_option_type_t m_option_type_flag = {
- "Flag",
- "need yes or no in config files",
- sizeof(int),
- 0,
- parse_flag,
- print_flag,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // need yes or no in config files
+ .name = "Flag",
+ .size = sizeof(int),
+ .parse = parse_flag,
+ .print = print_flag,
+ .copy = copy_opt,
};
// Integer
@@ -209,29 +205,19 @@ static char *print_int(const m_option_t *opt, const void *val)
}
const m_option_type_t m_option_type_int = {
- "Integer",
- "",
- sizeof(int),
- 0,
- parse_int,
- print_int,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ .name = "Integer",
+ .size = sizeof(int),
+ .parse = parse_int,
+ .print = print_int,
+ .copy = copy_opt,
};
const m_option_type_t m_option_type_int64 = {
- "Integer64",
- "",
- sizeof(int64_t),
- 0,
- parse_int64,
- print_int,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ .name = "Integer64",
+ .size = sizeof(int64_t),
+ .parse = parse_int64,
+ .print = print_int,
+ .copy = copy_opt,
};
static int parse_intpair(const struct m_option *opt, struct bstr name,
@@ -271,11 +257,10 @@ bad:
}
const struct m_option_type m_option_type_intpair = {
- .name = "Int[-Int]",
- .size = sizeof(int[2]),
+ .name = "Int[-Int]",
+ .size = sizeof(int[2]),
.parse = parse_intpair,
- .save = copy_opt,
- .set = copy_opt,
+ .copy = copy_opt,
};
static int parse_choice(const struct m_option *opt, struct bstr name,
@@ -315,12 +300,11 @@ static char *print_choice(const m_option_t *opt, const void *val)
}
const struct m_option_type m_option_type_choice = {
- .name = "String", // same as arbitrary strings in option list for now
- .size = sizeof(int),
+ .name = "String", // same as arbitrary strings in option list for now
+ .size = sizeof(int),
.parse = parse_choice,
.print = print_choice,
- .save = copy_opt,
- .set = copy_opt,
+ .copy = copy_opt,
};
// Float
@@ -391,16 +375,12 @@ static char *print_double(const m_option_t *opt, const void *val)
}
const m_option_type_t m_option_type_double = {
- "Double",
- "double precision floating point number or ratio (numerator[:/]denominator)",
- sizeof(double),
- 0,
- parse_double,
- print_double,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // double precision float or ratio (numerator[:/]denominator)
+ .name = "Double",
+ .size = sizeof(double),
+ .parse = parse_double,
+ .print = print_double,
+ .copy = copy_opt,
};
#undef VAL
@@ -423,16 +403,12 @@ static char *print_float(const m_option_t *opt, const void *val)
}
const m_option_type_t m_option_type_float = {
- "Float",
- "floating point number or ratio (numerator[:/]denominator)",
- sizeof(float),
- 0,
- parse_float,
- print_float,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // floating point number or ratio (numerator[:/]denominator)
+ .name = "Float",
+ .size = sizeof(float),
+ .parse = parse_float,
+ .print = print_float,
+ .copy = copy_opt,
};
///////////// Position
@@ -455,16 +431,12 @@ static char *print_position(const m_option_t *opt, const void *val)
}
const m_option_type_t m_option_type_position = {
- "Position",
- "Integer (off_t)",
- sizeof(off_t),
- 0,
- parse_position,
- print_position,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // Integer (off_t)
+ .name = "Position",
+ .size = sizeof(off_t),
+ .parse = parse_position,
+ .print = print_position,
+ .copy = copy_opt,
};
@@ -521,16 +493,13 @@ static void free_str(void *src)
}
const m_option_type_t m_option_type_string = {
- "String",
- "",
- sizeof(char *),
- M_OPT_TYPE_DYNAMIC,
- parse_str,
- print_str,
- copy_str,
- copy_str,
- copy_str,
- free_str
+ .name = "String",
+ .size = sizeof(char *),
+ .flags = M_OPT_TYPE_DYNAMIC,
+ .parse = parse_str,
+ .print = print_str,
+ .copy = copy_str,
+ .free = free_str,
};
//////////// String list
@@ -788,164 +757,24 @@ static char *print_str_list(const m_option_t *opt, const void *src)
}
const m_option_type_t m_option_type_string_list = {
- "String list",
- "A list of strings separated by ','\n"
- "Option with a name ending in an * permits using the following suffix: \n"
- "\t-add: Add the given parameters at the end of the list.\n"
- "\t-pre: Add the given parameters at the beginning of the list.\n"
- "\t-del: Remove the entry at the given indices.\n"
- "\t-clr: Clear the list.\n"
- "e.g: -vf-add flip,mirror -vf-del 2,5\n",
- sizeof(char **),
- M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
- parse_str_list,
- print_str_list,
- copy_str_list,
- copy_str_list,
- copy_str_list,
- free_str_list
+ /* A list of strings separated by ','.
+ * Option with a name ending in '*' permits using the following suffixes:
+ * -add: Add the given parameters at the end of the list.
+ * -pre: Add the given parameters at the beginning of the list.
+ * -del: Remove the entry at the given indices.
+ * -clr: Clear the list.
+ * e.g: -vf-add flip,mirror -vf-del 2,5
+ */
+ .name = "String list",
+ .size = sizeof(char **),
+ .flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
+ .parse = parse_str_list,
+ .print = print_str_list,
+ .copy = copy_str_list,
+ .free = free_str_list,
};
-/////////////////// Func based options
-
-// A chained list to save the various calls for func_param
-struct m_func_save {
- struct m_func_save *next;
- char *name;
- char *param;
-};
-
-#undef VAL
-#define VAL(x) (*(struct m_func_save **)(x))
-
-static void free_func_pf(void *src)
-{
- struct m_func_save *s, *n;
-
- if (!src)
- return;
-
- s = VAL(src);
-
- while (s) {
- n = s->next;
- talloc_free(s->name);
- talloc_free(s->param);
- talloc_free(s);
- s = n;
- }
- VAL(src) = NULL;
-}
-
-// Parser for func_param
-static int parse_func_pf(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
-{
- struct m_func_save *s, *p;
-
- if (!dst)
- return 1;
-
- s = talloc_zero(NULL, struct m_func_save);
- s->name = bstrdup0(NULL, name);
- s->param = bstrdup0(NULL, param);
-
- p = VAL(dst);
- if (p) {
- for (; p->next != NULL; p = p->next)
- /**/;
- p->next = s;
- } else
- VAL(dst) = s;
-
- return 1;
-}
-
-static void copy_func_pf(const m_option_t *opt, void *dst, const void *src)
-{
- struct m_func_save *d = NULL, *s, *last = NULL;
-
- if (!(dst && src))
- return;
- s = VAL(src);
-
- if (VAL(dst))
- free_func_pf(dst);
-
- while (s) {
- d = talloc_zero(NULL, struct m_func_save);
- d->name = talloc_strdup(NULL, s->name);
- d->param = talloc_strdup(NULL, s->param);
- if (last)
- last->next = d;
- else
- VAL(dst) = d;
- last = d;
- s = s->next;
- }
-
-
-}
-
-/////////////////// Func_param
-
-static void set_func_param(const m_option_t *opt, void *dst, const void *src)
-{
- struct m_func_save *s;
-
- if (!src)
- return;
- s = VAL(src);
-
- if (!s)
- return;
-
- for (; s != NULL; s = s->next)
- ((m_opt_func_param_t) opt->p)(opt, s->param);
-}
-
-const m_option_type_t m_option_type_func_param = {
- "Func param",
- "",
- sizeof(struct m_func_save *),
- M_OPT_TYPE_INDIRECT,
- parse_func_pf,
- NULL,
- NULL, // Nothing to do on save
- set_func_param,
- copy_func_pf,
- free_func_pf
-};
-
-/////////////// Func
-
-#undef VAL
-
-static int parse_func(const m_option_t *opt, struct bstr name,
- struct bstr param, bool ambiguous_param, void *dst)
-{
- return 0;
-}
-
-static void set_func(const m_option_t *opt, void *dst, const void *src)
-{
- ((m_opt_func_t) opt->p)(opt);
-}
-
-const m_option_type_t m_option_type_func = {
- "Func",
- "",
- sizeof(int),
- M_OPT_TYPE_INDIRECT,
- parse_func,
- NULL,
- NULL, // Nothing to do on save
- set_func,
- NULL,
- NULL
-};
-
/////////////////// Print
static int parse_print(const m_option_t *opt, struct bstr name,
@@ -969,42 +798,19 @@ static int parse_print(const m_option_t *opt, struct bstr name,
}
const m_option_type_t m_option_type_print = {
- "Print",
- "",
- 0,
- 0,
- parse_print,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Print",
+ .parse = parse_print,
};
const m_option_type_t m_option_type_print_indirect = {
- "Print",
- "",
- 0,
- 0,
- parse_print,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Print",
+ .parse = parse_print,
};
const m_option_type_t m_option_type_print_func = {
- "Print",
- "",
- 0,
- M_OPT_TYPE_ALLOW_WILDCARD,
- parse_print,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Print",
+ .flags = M_OPT_TYPE_ALLOW_WILDCARD,
+ .parse = parse_print,
};
@@ -1097,16 +903,10 @@ static int parse_subconf(const m_option_t *opt, struct bstr name,
}
const m_option_type_t m_option_type_subconfig = {
- "Subconfig",
- "The syntax is -option opt1=foo:flag:opt2=blah",
- sizeof(int),
- M_OPT_TYPE_HAS_CHILD,
- parse_subconf,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ // The syntax is -option opt1=foo:flag:opt2=blah
+ .name = "Subconfig",
+ .flags = M_OPT_TYPE_HAS_CHILD,
+ .parse = parse_subconf,
};
#include "libmpcodecs/img_format.h"
@@ -1230,16 +1030,11 @@ static int parse_imgfmt(const m_option_t *opt, struct bstr name,
}
const m_option_type_t m_option_type_imgfmt = {
- "Image format",
- "Please report any missing colorspaces.",
- sizeof(uint32_t),
- 0,
- parse_imgfmt,
- NULL,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // Please report any missing colorspaces
+ .name = "Image format",
+ .size = sizeof(uint32_t),
+ .parse = parse_imgfmt,
+ .copy = copy_opt,
};
#include "libaf/af_format.h"
@@ -1325,16 +1120,11 @@ static int parse_afmt(const m_option_t *opt, struct bstr name,
}
const m_option_type_t m_option_type_afmt = {
- "Audio format",
- "Please report any missing formats.",
- sizeof(uint32_t),
- 0,
- parse_afmt,
- NULL,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ // Please report any missing formats
+ .name = "Audio format",
+ .size = sizeof(uint32_t),
+ .parse = parse_afmt,
+ .copy = copy_opt,
};
@@ -1377,16 +1167,11 @@ static int parse_time(const m_option_t *opt, struct bstr name,
}
const m_option_type_t m_option_type_time = {
- "Time",
- "",
- sizeof(double),
- 0,
- parse_time,
- print_double,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ .name = "Time",
+ .size = sizeof(double),
+ .parse = parse_time,
+ .print = print_double,
+ .copy = copy_opt,
};
@@ -1441,16 +1226,10 @@ out:
}
const m_option_type_t m_option_type_time_size = {
- "Time or size",
- "",
- sizeof(m_time_size_t),
- 0,
- parse_time_size,
- NULL,
- copy_opt,
- copy_opt,
- NULL,
- NULL
+ .name = "Time or size",
+ .size = sizeof(m_time_size_t),
+ .parse = parse_time_size,
+ .copy = copy_opt,
};
@@ -1660,16 +1439,8 @@ static int parse_obj_params(const m_option_t *opt, struct bstr name,
const m_option_type_t m_option_type_obj_params = {
- "Object params",
- "",
- 0,
- 0,
- parse_obj_params,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Object params",
+ .parse = parse_obj_params,
};
/// Some predefined types as a definition would be quite lengthy
@@ -1999,16 +1770,12 @@ static void copy_obj_settings_list(const m_option_t *opt, void *dst,
}
const m_option_type_t m_option_type_obj_settings_list = {
- "Object settings list",
- "",
- sizeof(m_obj_settings_t *),
- M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
- parse_obj_settings_list,
- NULL,
- copy_obj_settings_list,
- copy_obj_settings_list,
- copy_obj_settings_list,
- free_obj_settings_list,
+ .name = "Object settings list",
+ .size = sizeof(m_obj_settings_t *),
+ .flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
+ .parse = parse_obj_settings_list,
+ .copy = copy_obj_settings_list,
+ .free = free_obj_settings_list,
};
@@ -2085,16 +1852,8 @@ static int parse_obj_presets(const m_option_t *opt, struct bstr name,
const m_option_type_t m_option_type_obj_presets = {
- "Object presets",
- "",
- 0,
- 0,
- parse_obj_presets,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Object presets",
+ .parse = parse_obj_presets,
};
static int parse_custom_url(const m_option_t *opt, struct bstr name,
@@ -2282,14 +2041,6 @@ static int parse_custom_url(const m_option_t *opt, struct bstr name,
/// TODO : Write the other needed funcs for 'normal' options
const m_option_type_t m_option_type_custom_url = {
- "Custom URL",
- "",
- 0,
- 0,
- parse_custom_url,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
+ .name = "Custom URL",
+ .parse = parse_custom_url,
};
diff --git a/m_option.h b/m_option.h
index de2854137d..879b9d6563 100644
--- a/m_option.h
+++ b/m_option.h
@@ -55,28 +55,9 @@ 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_afmt;
-// Func-based types
-extern const m_option_type_t m_option_type_func_param;
-extern const m_option_type_t m_option_type_func;
-
-// Callback used to reset func options.
-typedef void (*m_opt_default_func_t)(const m_option_t *, const char *);
-
-// Callback used by m_option_type_func_full options.
+// Callback used by m_option_type_print_func options.
typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *);
-// Callback used by m_option_type_func_param options.
-typedef int (*m_opt_func_param_t)(const m_option_t *, const char *);
-
-// Callback used by m_option_type_func options.
-typedef int (*m_opt_func_t)(const m_option_t *);
-
-// Backwards compatibility
-typedef m_opt_default_func_t cfg_default_func_t;
-typedef m_opt_func_full_t cfg_func_arg_param_t;
-typedef m_opt_func_param_t cfg_func_param_t;
-typedef m_opt_func_t cfg_func_t;
-
#define END_AT_NONE 0
#define END_AT_TIME 1
#define END_AT_SIZE 2
@@ -175,8 +156,6 @@ struct m_opt_choice_alternatives {
#define CONF_TYPE_FLOAT (&m_option_type_float)
#define CONF_TYPE_DOUBLE (&m_option_type_double)
#define CONF_TYPE_STRING (&m_option_type_string)
-#define CONF_TYPE_FUNC (&m_option_type_func)
-#define CONF_TYPE_FUNC_PARAM (&m_option_type_func_param)
#define CONF_TYPE_PRINT (&m_option_type_print)
#define CONF_TYPE_PRINT_INDIRECT (&m_option_type_print_indirect)
#define CONF_TYPE_PRINT_FUNC (&m_option_type_print_func)
@@ -198,8 +177,6 @@ struct m_opt_choice_alternatives {
// Option type description
struct m_option_type {
const char *name;
- // Syntax description, etc
- const char *comments;
// Size needed for the data.
unsigned int size;
// See \ref OptionTypeFlags.
@@ -229,35 +206,12 @@ struct m_option_type {
*/
char *(*print)(const m_option_t *opt, const void *val);
- /** \name
- * These functions are called to save/set/restore the status of the
- * variables. The difference between the 3 only matters for types like
- * \ref m_option_type_func where 'setting' needs to do more than just
- * copying some data.
- */
- //@{
-
- // Update a save slot (dst) from the current value in the program (src).
- /** \param opt The option to copy.
- * \param dst Pointer to the destination memory.
- * \param src Pointer to the source memory.
- */
- void (*save)(const m_option_t *opt, void *dst, const void *src);
-
- // Set the value in the program (dst) from a save slot.
- /** \param opt The option to copy.
- * \param dst Pointer to the destination memory.
- * \param src Pointer to the source memory.
- */
- void (*set)(const m_option_t *opt, void *dst, const void *src);
-
- // Copy the data between two save slots. If NULL and size is > 0 a memcpy will be used.
+ // Copy data between two locations. Deep copy if the data has pointers.
/** \param opt The option to copy.
* \param dst Pointer to the destination memory.
* \param src Pointer to the source memory.
*/
void (*copy)(const m_option_t *opt, void *dst, const void *src);
- //@}
// Free the data allocated for a save slot.
/** This is only needed for dynamic types like strings.
@@ -296,7 +250,6 @@ struct m_option {
// Type dependent data (for all kinds of extended settings).
/** This used to be a function pointer to hold a 'reverse to defaults' func.
* Now it can be used to pass any type of extra args needed by the parser.
- * Passing a 'default func' is still valid for all func based option types.
*/
void *priv;
@@ -374,17 +327,6 @@ struct m_option {
*/
#define M_OPT_TYPE_DYNAMIC (1 << 2)
-// Indirect option type.
-/** If this is set the parse function doesn't directly return
- * the wanted thing. Options use this if for some reasons they have to wait
- * until the set call to be able to correctly set the target var.
- * So for those types new values must first be parsed, then set to the target
- * var. If this flag isn't set then new values can be parsed directly to the
- * target var. It's used by the callback-based options as the callback call
- * may append later on.
- */
-#define M_OPT_TYPE_INDIRECT (1 << 3)
-
///////////////////////////// Parser flags /////////////////////////////////
// On success parsers return the number of arguments consumed: 0 or 1.
@@ -416,13 +358,6 @@ struct m_option {
*/
#define M_OPT_EXIT -6
-// These are kept for compatibility with older code.
-//
-#define ERR_NOT_AN_OPTION M_OPT_UNKNOWN
-#define ERR_MISSING_PARAM M_OPT_MISSING_PARAM
-#define ERR_OUT_OF_RANGE M_OPT_OUT_OF_RANGE
-#define ERR_FUNC_ERR M_OPT_PARSER_ERR
-
char *m_option_strerror(int code);
// Find the option matching the given name in the list.
@@ -465,8 +400,6 @@ static inline void m_option_copy(const m_option_t *opt, void *dst,
{
if (opt->type->copy)
opt->type->copy(opt, dst, src);
- else if (opt->type->size > 0)
- memcpy(dst, src, opt->type->size);
}
// Helper around \ref m_option_type::free.
diff --git a/m_struct.c b/m_struct.c
index 764f616a89..8b34cea359 100644
--- a/m_struct.c
+++ b/m_struct.c
@@ -48,13 +48,6 @@ m_struct_alloc(const m_struct_t* st) {
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s needs defaults\n",st->name);
return NULL;
}
- // Check the struct fields
- for(i = 0 ; st->fields[i].name ; i++) {
- if(st->fields[i].type->flags & M_OPT_TYPE_INDIRECT) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Struct %s->%s: Option types with the indirect flag are forbidden.\n",st->name,st->fields[i].name);
- return NULL;
- }
- }
r = calloc(1,st->size);
memcpy(r,st->defaults,st->size);
diff --git a/mplayer.c b/mplayer.c
index e1984e601c..f0c1e2fb83 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -857,9 +857,9 @@ static void exit_sighandler(int x)
#include "cfg-mplayer.h"
-static int cfg_include(m_option_t *conf, char *filename)
+static int cfg_include(struct m_config *conf, char *filename)
{
- return m_config_parse_config_file(conf->priv, filename);
+ return m_config_parse_config_file(conf, filename);
}
#define DEF_CONFIG "# Write your default config options here!\n\n\n"