From 19b506ea65ef9c6ade6bdc0991a66020f9af00fc Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 15 Dec 2013 23:59:03 +0100 Subject: input: better error reporting for missing commands Don't print an empty string if the command is missing. --- mpvcore/input/input.c | 19 ++++++++++++------- 1 file 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, -- cgit v1.2.3