diff options
author | wm4 <wm4@nowhere> | 2018-01-24 04:54:48 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2018-01-25 20:18:32 -0800 |
commit | 415fc6e3271827fa9195a10c71bb5025e8733a5e (patch) | |
tree | d43d49802c6f792fdb73c8beebeb28fddc54cf87 /options | |
parent | d8b013d45836a49c1c6b8e123b46c1d5aca440ac (diff) | |
download | mpv-415fc6e3271827fa9195a10c71bb5025e8733a5e.tar.bz2 mpv-415fc6e3271827fa9195a10c71bb5025e8733a5e.tar.xz |
m_option: remove string list -append action code duplication
Instead of duplicating the append code, reimplement it using the
existing code. The difference between -add and -append is that -append
does not take multiple items (thus removing the need for escaping), but
-append can reuse all code for -add by pretending the separator is never
found.
Diffstat (limited to 'options')
-rw-r--r-- | options/m_option.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/options/m_option.c b/options/m_option.c index fe656a07ac..d011c2a187 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1301,7 +1301,7 @@ static struct bstr get_nextsep(struct bstr *ptr, char sep, bool modify) struct bstr str = *ptr; struct bstr orig = str; for (;;) { - int idx = bstrchr(str, sep); + int idx = sep ? bstrchr(str, sep) : -1; if (idx > 0 && str.start[idx - 1] == '\\') { if (modify) { memmove(str.start + idx - 1, str.start + idx, str.len - idx); @@ -1324,11 +1324,13 @@ static int parse_str_list_impl(struct mp_log *log, const m_option_t *opt, { char **res; int op = default_op; + bool multi = true; if (bstr_endswith0(name, "-add")) { op = OP_ADD; } else if (bstr_endswith0(name, "-append")) { - op = OP_ADD_STR; + op = OP_ADD; + multi = false; } else if (bstr_endswith0(name, "-pre")) { op = OP_PRE; } else if (bstr_endswith0(name, "-del")) { @@ -1350,20 +1352,9 @@ static int parse_str_list_impl(struct mp_log *log, const m_option_t *opt, if (param.len == 0 && op != OP_NONE) return M_OPT_MISSING_PARAM; - if (op == OP_ADD_STR) { - if (dst) { - char **list= VAL(dst); - int len = 0; - while (list && list[len]) - len++; - MP_TARRAY_APPEND(NULL, list, len, bstrto0(NULL, param)); - MP_TARRAY_APPEND(NULL, list, len, NULL); - VAL(dst) = list; - } - return 1; - } - char separator = opt->priv ? *(char *)opt->priv : OPTION_LIST_SEPARATOR; + if (!multi) + separator = 0; // specially handled int n = 0; struct bstr str = param; while (str.len) { |