From 415fc6e3271827fa9195a10c71bb5025e8733a5e Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 24 Jan 2018 04:54:48 +0100 Subject: 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. --- options/m_option.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'options') 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) { -- cgit v1.2.3