command: change and simplify filter toggle syntax

"@name:!" becomes simply "@name". This is actually slightly more complex
to parse, but makes for a much simpler syntax and will be less weird to
the user. Suggested by haasn.

The old syntax is now rejected with an error.

Also add some more explicit error checks, instead of e.g. allowing empty
filter names and erroring only when it's not found.
This commit is contained in:
wm4 committed 2017-03-26 13:13:34 +02:00
1 parent 439e2b43c3
commit a94013f585
3 files changed
+31 -8

No files matched your search

+4 -3
View File
@@ -452,8 +452,9 @@ Input Commands that are Possibly Subject to Change
(If several filters are passed to the command, this is done for
each filter.)
A special variant is combining this with labels, and using ``@name:!``
as filter entry. This toggles the enable/disable flag.
A special variant is combining this with labels, and using ``@name``
without filter name and parameters as filter entry. This toggles the
enable/disable flag.
del
Remove the given filters from the video chain. Unlike in the other
@@ -497,7 +498,7 @@ Input Commands that are Possibly Subject to Change
name for this filter entry. The ``!`` before the filter name disables
the filter by default. Everything after this is the normal filter name
and the filter parameters.
- Add ``a vf toggle @deband:!`` to ``input.conf``. This toggles the
- Add ``a vf toggle @deband`` to ``input.conf``. This toggles the
"disabled" flag for the filter identified with ``deband``.
``cycle-values ["!reverse"] <property> "<value1>" "<value2>" ...``
+4
View File
@@ -24,6 +24,10 @@ syntax is:
``["@"<label-name>":"] ["!"] <filter-name> [ "=" <filter-parameter-list> ]``
or for the special "toggle" syntax (see ``vf`` command):
``"@"<label-name>``
and the ``filter-parameter-list``:
``<filter-parameter> | <filter-parameter> "," <filter-parameter-list>``
+23 -5
View File
@@ -2762,15 +2762,31 @@ static int parse_obj_settings(struct mp_log *log, struct bstr opt, int op,
int r;
char **plist = NULL;
struct m_obj_desc desc;
bstr str = {0};
bstr label = {0};
bool nopos = list->disallow_positional_parameters;
bool enabled = true;
if (bstr_eatstart0(pstr, "@")) {
if (!bstr_split_tok(*pstr, ":", &label, pstr)) {
bstr rest;
if (!bstr_split_tok(*pstr, ":", &label, &rest)) {
// "@labelname" is the special enable/disable toggle syntax
if (op == OP_TOGGLE) {
int idx = bstrspn(*pstr, NAMECH);
label = bstr_splice(*pstr, 0, idx);
if (label.len) {
*pstr = bstr_cut(*pstr, idx);
goto done;
}
}
mp_err(log, "Option %.*s: ':' expected after label.\n", BSTR_P(opt));
return M_OPT_INVALID;
}
*pstr = rest;
if (label.len == 0) {
mp_err(log, "Option %.*s: label name expected.\n", BSTR_P(opt));
return M_OPT_INVALID;
}
}
if (list->allow_disable_entries && bstr_eatstart0(pstr, "!"))
@@ -2778,9 +2794,11 @@ static int parse_obj_settings(struct mp_log *log, struct bstr opt, int op,
bool has_param = false;
int idx = bstrspn(*pstr, NAMECH);
bstr str = bstr_splice(*pstr, 0, idx);
if (str.len == 0 && !enabled && label.len && op == OP_TOGGLE)
goto done; // "@labelname:!" is the special enable/disable toggle syntax
str = bstr_splice(*pstr, 0, idx);
if (!str.len) {
mp_err(log, "Option %.*s: filter name expected.\n", BSTR_P(opt));
return M_OPT_INVALID;
}
*pstr = bstr_cut(*pstr, idx);
// video filters use "=", VOs use ":"
if (bstr_eatstart0(pstr, "=") || bstr_eatstart0(pstr, ":"))
@@ -3026,7 +3044,7 @@ static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt,
talloc_free(res);
} else if (op == OP_TOGGLE) {
for (int n = 0; res && res[n].name; n++) {
if (!res[n].enabled && !res[n].name[0]) {
if (res[n].label && !res[n].name[0]) {
// Toggle enable/disable special case.
int found =
obj_settings_list_find_by_label0(list, res[n].label);