summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-10-25 13:33:59 -0500
committerDudemanguy <random342@airmail.cc>2023-10-30 16:47:44 +0000
commitd72c86f95c9292c15e96a1f3fb8471ebb28aa6da (patch)
tree23ab89e09aae7c3d72a4a026c8ea4bd09a72380a /options
parent991e2a599c464e3c27d0447fb8198ac44731574a (diff)
downloadmpv-d72c86f95c9292c15e96a1f3fb8471ebb28aa6da.tar.bz2
mpv-d72c86f95c9292c15e96a1f3fb8471ebb28aa6da.tar.xz
m_option: remove all matches when using -remove
When using -remove with list options, it previously only removed the first match. Technically, it is possible for there to be more than entry with the same name. They should all be removed. key/value lists specifically only allow unique keys so we don't need to do anything there.
Diffstat (limited to 'options')
-rw-r--r--options/m_option.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 458d38bafc..cf1ea53948 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -1456,14 +1456,20 @@ static int parse_str_list_impl(struct mp_log *log, const m_option_t *opt,
if (op == OP_TOGGLE || op == OP_REMOVE) {
if (dst) {
char **list = VAL(dst);
- int index = find_list_bstr(list, param);
- if (index >= 0) {
- char *old = list[index];
- for (int n = index; list[n]; n++)
- list[n] = list[n + 1];
- talloc_free(old);
+ bool found = false;
+ int index = 0;
+ do {
+ index = find_list_bstr(list, param);
+ if (index >= 0) {
+ found = true;
+ char *old = list[index];
+ for (int n = index; list[n]; n++)
+ list[n] = list[n + 1];
+ talloc_free(old);
+ }
+ } while (index >= 0);
+ if (found)
return 1;
- }
}
if (op == OP_REMOVE)
return 1; // ignore if not found
@@ -3344,12 +3350,15 @@ static int parse_obj_settings_del(struct mp_log *log, struct bstr opt_name,
if (bstr_startswith0(s, ":"))
return 0;
if (dst) {
- int label_index = obj_settings_list_find_by_label(VAL(dst), label);
- if (label_index >= 0) {
- mark_del[label_index] = true;
- } else {
- mp_warn(log, "Option %.*s: item label @%.*s not found.\n",
- BSTR_P(opt_name), BSTR_P(label));
+ int label_index = 0;
+ while (label_index >= 0) {
+ label_index = obj_settings_list_find_by_label(VAL(dst), label);
+ if (label_index >= 0) {
+ mark_del[label_index] = true;
+ } else {
+ mp_warn(log, "Option %.*s: item label @%.*s not found.\n",
+ BSTR_P(opt_name), BSTR_P(label));
+ }
}
}
*param = s;