diff options
author | wm4 <wm4@nowhere> | 2017-12-26 03:26:59 +0100 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2017-12-26 00:54:05 -0700 |
commit | e530783cdbdd95500aa86cfbcbfe005f6e0f5f41 (patch) | |
tree | 1cafde0fc308f4203ab12651dceb30c0e64217b4 /options | |
parent | 98d62c49bd23cdd4f1373a088a38640bb85aee71 (diff) | |
download | mpv-e530783cdbdd95500aa86cfbcbfe005f6e0f5f41.tar.bz2 mpv-e530783cdbdd95500aa86cfbcbfe005f6e0f5f41.tar.xz |
options: add -add/-append actions to key/value lists
Requested.
Diffstat (limited to 'options')
-rw-r--r-- | options/m_option.c | 34 |
1 files changed, 30 insertions, 4 deletions
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} + }, }; |