From 924d4db0de4969b6713b96be73cc947bbff05ad1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 7 Jun 2014 23:41:47 +0200 Subject: options: change --sub-file behavior --sub-file is actually a string list, so you can add multipel external subtitle files. But to be able to set a list, the option value was split on ",". This made it impossible to add filenames. One possible solution would be adding escaping. That's probably a good idea (and some other options already do this), but it's also complicated both to implement and for the user. The simpler solution is making --sub-file appending, and make it take only a single entry. I'm not quite sure about this yet. It breaks the invariant that if a value is printed and parsed, you get the same value back. So for now, just go with the simple solution. Fixes #840. --- options/m_option.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'options/m_option.c') diff --git a/options/m_option.c b/options/m_option.c index f52a81a0b9..77e610f08c 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1344,6 +1344,42 @@ const m_option_type_t m_option_type_string_list = { .set = str_list_set, }; +static void str_list_append(void *dst, bstr s) +{ + if (!dst) + return; + char **list= VAL(dst); + int len = 0; + while (list && list[len]) + len++; + MP_TARRAY_APPEND(NULL, list, len, bstrto0(NULL, s)); + MP_TARRAY_APPEND(NULL, list, len, NULL); + VAL(dst) = list; +} + +static int parse_str_append_list(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) +{ + if (param.len == 0) + return M_OPT_MISSING_PARAM; + + str_list_append(dst, param); + + return 1; +} + +const m_option_type_t m_option_type_string_append_list = { + .name = "String list", + .size = sizeof(char **), + .flags = M_OPT_TYPE_DYNAMIC, + .parse = parse_str_append_list, + .print = print_str_list, + .copy = copy_str_list, + .free = free_str_list, + .get = str_list_get, + .set = str_list_set, +}; + static int read_subparam(struct mp_log *log, bstr optname, bstr *str, bstr *out_subparam); -- cgit v1.2.3