From e530783cdbdd95500aa86cfbcbfe005f6e0f5f41 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 26 Dec 2017 03:26:59 +0100 Subject: options: add -add/-append actions to key/value lists Requested. --- options/m_option.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'options') diff --git a/options/m_option.c b/options/m_option.c index 08f57f89c7..f4f79f772d 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1427,6 +1427,20 @@ static int parse_keyvalue_list(struct mp_log *log, const m_option_t *opt, char **lst = NULL; int num = 0; int r = 0; + bool append = false; + bool full_value = false; + + if (bstr_endswith0(name, "-add")) { + append = true; + } else if (bstr_endswith0(name, "-append")) { + append = full_value = true; + } + + if (append && dst) { + lst = VAL(dst); + for (int n = 0; lst && lst[n]; n++) + num++; + } while (param.len) { bstr key, val; @@ -1438,9 +1452,14 @@ static int parse_keyvalue_list(struct mp_log *log, const m_option_t *opt, r = M_OPT_INVALID; break; } - r = read_subparam(log, name, ",:", ¶m, &val); - if (r < 0) - break; + if (full_value) { + val = param; + param.len = 0; + } else { + r = read_subparam(log, name, ",:", ¶m, &val); + if (r < 0) + break; + } if (dst) { MP_TARRAY_APPEND(NULL, lst, num, bstrto0(NULL, key)); MP_TARRAY_APPEND(NULL, lst, num, bstrto0(NULL, val)); @@ -1459,7 +1478,8 @@ static int parse_keyvalue_list(struct mp_log *log, const m_option_t *opt, } if (dst) { - free_str_list(dst); + if (!append) + free_str_list(dst); VAL(dst) = lst; if (r < 0) free_str_list(dst); @@ -1532,6 +1552,12 @@ const m_option_type_t m_option_type_keyvalue_list = { .free = free_str_list, .get = keyvalue_list_get, .set = keyvalue_list_set, + .actions = (const struct m_option_action[]){ + {"add"}, + {"append"}, + {"set"}, + {0} + }, }; -- cgit v1.2.3