diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-12-18 01:00:28 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-12-18 10:14:25 +0200 |
commit | 7e366113f75c696ae2b32f5faa5f80ec3fca96b8 (patch) | |
tree | a205a59524df6a617c8a33afb17cce983a6a2901 /m_option.c | |
parent | 00c2bafb0ac25a9c5ce845f49f6718b06ff03bbe (diff) | |
download | mpv-7e366113f75c696ae2b32f5faa5f80ec3fca96b8.tar.bz2 mpv-7e366113f75c696ae2b32f5faa5f80ec3fca96b8.tar.xz |
options: add "choice" option type, use for -pts-association-mode
Add a "choice" option type. Options of this type take a string as
input and set an int option variable to the value corresponding to the
string. The string->int mapping is option-specific and is given in the
option definition. Strings not found in the mapping are rejected as
invalid option values.
Change the option -pts-association-mode to use this new option type
and accept values "auto, decoder, sort" instead of "0, 1, 2". The
change in accepted values shouldn't cause problems as this option is
not appropriate to use in normal user config files.
Diffstat (limited to 'm_option.c')
-rw-r--r-- | m_option.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/m_option.c b/m_option.c index daab955614..33c5e95a1b 100644 --- a/m_option.c +++ b/m_option.c @@ -267,6 +267,50 @@ const struct m_option_type m_option_type_intpair = { .set = copy_opt, }; +static int parse_choice(const struct m_option *opt, const char *name, + const char *param, void *dst, int src) +{ + if (param == NULL) + return M_OPT_MISSING_PARAM; + + struct m_opt_choice_alternatives *alt; + for (alt = opt->priv; alt->name; alt++) + if (!strcmp(param, alt->name)) + break; + if (!alt->name) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid value for option %s: %s\n", + name, param); + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Valid values are:"); + for (alt = opt->priv; alt->name; alt++) + mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", alt->name); + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n"); + return M_OPT_INVALID; + } + if (dst) + *(int *)dst = alt->value; + + return 1; +} + +static char *print_choice(const m_option_t *opt, const void *val) +{ + int v = *(int *)val; + struct m_opt_choice_alternatives *alt; + for (alt = opt->priv; alt->name; alt++) + if (alt->value == v) + return strdup(alt->name); + abort(); +} + +const struct m_option_type m_option_type_choice = { + .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, +}; + // Float #undef VAL |