diff options
author | Uoti Urpala <uau@mplayer2.org> | 2012-05-17 03:31:11 +0300 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2012-07-16 21:08:42 +0300 |
commit | dc2a4863af9b0e587ac4ec3e2096639098e99a8f (patch) | |
tree | 15807fb5de256f91f730c435ab614332f12fa255 /m_option.c | |
parent | f63dbaddb6de6add6d987dc28ca8771aca230451 (diff) | |
download | mpv-dc2a4863af9b0e587ac4ec3e2096639098e99a8f.tar.bz2 mpv-dc2a4863af9b0e587ac4ec3e2096639098e99a8f.tar.xz |
options: support parsing values into substructs
Add an alternate mode for option parser objects (struct m_config)
which is not inherently tied to any particular instance of an option
value struct. Instead, this type or parsers can be used to initialize
defaults in or parse values into a struct given as a parameter. They
do not have the save slot functionality used for main player
configuration. The new functionality will be used to replace the
separate subopt_helper.c parsing code that is currently used to parse
per-object suboptions in VOs etc.
Previously, option default values were handled by initializing them in
external code before creating a parser. This initialization was done
with constants even for dynamically-allocated types like strings.
Because trying to free a pointer to a constant would cause a crash
when trying to replace the default with another value, parser
initialization code then replaced all the original defaults with
dynamically-allocated copies. This replace-with-copy behavior is no
longer supported for new-style options; instead the option definition
itself may contain a default value (new OPTDEF macros), and the new
function m_config_initialize() is used to set all options to their
default values. Convert the existing initialized dynamically allocated
options in main config (the string options --dumpfile, --term-osd-esc,
--input=conf) to use this. Other non-dynamic ones could be later
converted to use this style of initialization too.
There's currently no public call to free all dynamically allocated
options in a given option struct because I intend to use talloc
functionality for that (make them children of the struct and free with
it).
Diffstat (limited to 'm_option.c')
-rw-r--r-- | m_option.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/m_option.c b/m_option.c index 55a58fc35c..7e701765b7 100644 --- a/m_option.c +++ b/m_option.c @@ -821,14 +821,13 @@ const m_option_type_t m_option_type_print_func = { static int parse_subconf(const m_option_t *opt, struct bstr name, struct bstr param, bool ambiguous_param, void *dst) { - int nr = 0, i; + int nr = 0; char **lst = NULL; if (param.len == 0) return M_OPT_MISSING_PARAM; struct bstr p = param; - const struct m_option *subopts = opt->p; while (p.len) { int optlen = bstrcspn(p, ":="); @@ -874,23 +873,11 @@ static int parse_subconf(const m_option_t *opt, struct bstr name, return M_OPT_INVALID; } - for (i = 0; subopts[i].name; i++) - if (!bstrcmp0(subopt, subopts[i].name)) - break; - if (!subopts[i].name) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: Unknown suboption %.*s\n", - BSTR_P(name), BSTR_P(subopt)); - return M_OPT_UNKNOWN; - } - int r = m_option_parse(&subopts[i], subopt, subparam, false, NULL); - if (r < 0) - return r; if (dst) { lst = talloc_realloc(NULL, lst, char *, 2 * (nr + 2)); - lst[2 * nr] = bstrdup0(NULL, subopt); + lst[2 * nr] = bstrdup0(lst, subopt); lst[2 * nr + 1] = subparam.len == 0 ? NULL : - bstrdup0(NULL, subparam); + bstrdup0(lst, subparam); memset(&lst[2 * (nr + 1)], 0, 2 * sizeof(char *)); nr++; } |