summaryrefslogtreecommitdiffstats
path: root/m_option.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-05 02:17:13 +0200
committerwm4 <wm4@nowhere>2012-09-18 21:07:29 +0200
commitc955549204c433abd1a3c8783f1b988e29315337 (patch)
tree47da7a2a9f552a810713b788513683f694eeec0c /m_option.c
parentd29d4df634a9d847a2b5ef7a04f32726cd03c1ef (diff)
downloadmpv-c955549204c433abd1a3c8783f1b988e29315337.tar.bz2
mpv-c955549204c433abd1a3c8783f1b988e29315337.tar.xz
options: change --loop option, and extend choice option type
The --loop option takes slightly different parameters now. --loop=0 used to mean looping forever. Now it means looping is disabled (this is more logical: 2 means playing 2 more times, 1 means playing 1 more time, and 0 should mean playing not again). Now --loop=inf must be used to enable looping forever. Extend choice types to allow an optional range of integers as values. If CONF_RANGE is added to the flags of a m_option_type_choice option, m_option.min/max specify a range of allowed integer values. This can be used to remove "special" values from make integer range options. These special values are unintuitive, and sometimes expose mplayer internals to the user. The (internal) choice values can be freely mixed with the specified integer value range. If there are overlaps, the choice values are preferred for conversion to/from strings. Also make sure the extension to choice options works with properties. Add the ability to step choice properties downwards, instead of just upwards.
Diffstat (limited to 'm_option.c')
-rw-r--r--m_option.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/m_option.c b/m_option.c
index d2ab925a70..2f8daa42de 100644
--- a/m_option.c
+++ b/m_option.c
@@ -274,6 +274,14 @@ static int parse_choice(const struct m_option *opt, struct bstr name,
if (!alt->name) {
if (param.len == 0)
return M_OPT_MISSING_PARAM;
+ if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) {
+ long long val;
+ if (parse_longlong(opt, name, param, &val) == 1) {
+ if (dst)
+ *(int *)dst = val;
+ return 1;
+ }
+ }
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
"Invalid value for option %.*s: %.*s\n",
BSTR_P(name), BSTR_P(param));
@@ -296,6 +304,10 @@ static char *print_choice(const m_option_t *opt, const void *val)
for (alt = opt->priv; alt->name; alt++)
if (alt->value == v)
return talloc_strdup(NULL, alt->name);
+ if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) {
+ if (v >= opt->min && v <= opt->max)
+ return talloc_asprintf(NULL, "%d", v);
+ }
abort();
}