diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-04-24 20:09:31 +0300 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-04-25 22:48:10 +0300 |
commit | a2133d76847dd4c7a19d6826cd9a6562bedfdbc4 (patch) | |
tree | 84d45683615f51b73c624f51ad62f46247ccedfc /m_option.c | |
parent | 9c63c084ff589de88ddf26c64a074cdac0eca046 (diff) | |
download | mpv-a2133d76847dd4c7a19d6826cd9a6562bedfdbc4.tar.bz2 mpv-a2133d76847dd4c7a19d6826cd9a6562bedfdbc4.tar.xz |
options: move -chapter values to option struct
-chapter can optionally take a range with a start and an end. Add a
new option type which supports such values and use that instead of a
custom per-option function.
This commit also fixes a build configuration bug: before the
availability of the -chapter option depended on DVD functionality
being enabled in the binary, even though the option works with other
sources too.
Diffstat (limited to 'm_option.c')
-rw-r--r-- | m_option.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/m_option.c b/m_option.c index b37a94966d..63436bb165 100644 --- a/m_option.c +++ b/m_option.c @@ -221,6 +221,52 @@ const m_option_type_t m_option_type_int64 = { NULL }; +static int parse_intpair(const struct m_option *opt, const char *name, + const char *param, void *dst, int src) +{ + if (param == NULL) + return M_OPT_MISSING_PARAM; + + char *s = (char *)param; + int start = -1; + int end = -1; + if (*s) { + start = strtol(s, &s, 10); + if (s == param) + goto bad; + } + if (*s) { + if (*s != '-') + goto bad; + s++; + } + if (*s) + end = strtol(s, &s, 10); + if (*s) + goto bad; + + if (dst) { + int *p = dst; + p[0] = start; + p[1] = end; + } + + return 1; + + bad: + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range " + "specification for option %s: %s\n", name, param); + return M_OPT_INVALID; +} + +const struct m_option_type m_option_type_intpair = { + .name = "Int[-Int]", + .size = sizeof(int[2]), + .parse = parse_intpair, + .save = copy_opt, + .set = copy_opt, +}; + // Float #undef VAL |