summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-15 23:59:03 +0100
committerwm4 <wm4@nowhere>2013-12-16 20:03:00 +0100
commit19b506ea65ef9c6ade6bdc0991a66020f9af00fc (patch)
tree3e43bd2036fd9fa36ec6c25aeac6170f3f4805e1
parent5173900ed42074c1cf53d4eef622d5a1241d0325 (diff)
downloadmpv-19b506ea65ef9c6ade6bdc0991a66020f9af00fc.tar.bz2
mpv-19b506ea65ef9c6ade6bdc0991a66020f9af00fc.tar.xz
input: better error reporting for missing commands
Don't print an empty string if the command is missing.
-rw-r--r--mpvcore/input/input.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c
index 2aa2a8ef36..464aeb47ea 100644
--- a/mpvcore/input/input.c
+++ b/mpvcore/input/input.c
@@ -974,19 +974,24 @@ static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str,
cont: ;
}
- int cmd_idx = 0;
- while (mp_cmds[cmd_idx].name != NULL) {
- if (eat_token(&str, mp_cmds[cmd_idx].name))
+ bstr cmd_name;
+ if (!read_token(str, &str, &cmd_name)) {
+ MP_ERR(ictx, "Command name missing.\n");
+ goto error;
+ }
+ const struct mp_cmd_def *cmd_def = NULL;
+ for (int n = 0; mp_cmds[n].name; n++) {
+ if (bstr_equals0(cmd_name, mp_cmds[n].name)) {
+ cmd_def = &mp_cmds[n];
break;
- cmd_idx++;
+ }
}
- if (mp_cmds[cmd_idx].name == NULL) {
- MP_ERR(ictx, "Command '%.*s' not found.\n", BSTR_P(str));
+ if (!cmd_def) {
+ MP_ERR(ictx, "Command '%.*s' not found.\n", BSTR_P(cmd_name));
goto error;
}
- const struct mp_cmd_def *cmd_def = &mp_cmds[cmd_idx];
cmd = talloc_ptrtype(NULL, cmd);
*cmd = (struct mp_cmd) {
.name = (char *)cmd_def->name,