From 52847a951802fda7a3ce36cdac77c34914b0ccca Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 15 Jan 2017 22:00:56 +0000 Subject: [PATCH] It is silly for cmd_list_parse to return an integer error when it could just return NULL. --- cfg.c | 3 ++- cmd-command-prompt.c | 3 ++- cmd-confirm-before.c | 3 ++- cmd-display-panes.c | 3 ++- cmd-if-shell.c | 6 ++++-- cmd-set-hook.c | 3 ++- cmd-string.c | 40 ++++++++++------------------------------ control.c | 3 ++- key-bindings.c | 6 ++---- tmux.h | 3 +-- window-choose.c | 3 ++- 11 files changed, 31 insertions(+), 45 deletions(-) diff --git a/cfg.c b/cfg.c index 8424bb20..2be34fda 100644 --- a/cfg.c +++ b/cfg.c @@ -141,7 +141,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet) if (condition == -1) continue; - if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) { + cmdlist = cmd_string_parse(p, path, line, &cause1); + if (cmdlist == NULL) { free(buf); if (cause1 == NULL) continue; diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index dec40bf2..3cc5b2fb 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -175,7 +175,8 @@ cmd_command_prompt_callback(void *data, const char *s, int done) return (1); } - if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(new_template, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { new_item = cmdq_get_callback(cmd_command_prompt_error, cause); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index a2ffd059..e7366ec2 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -112,7 +112,8 @@ cmd_confirm_before_callback(void *data, const char *s, __unused int done) if (tolower((u_char) s[0]) != 'y' || s[1] != '\0') return (0); - if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { new_item = cmdq_get_callback(cmd_confirm_before_error, cause); diff --git a/cmd-display-panes.c b/cmd-display-panes.c index 65813804..e670c1b9 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -90,7 +90,8 @@ cmd_display_panes_callback(struct client *c, struct window_pane *wp) xasprintf(&expanded, "%%%u", wp->id); cmd = cmd_template_replace(template, expanded, 1); - if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(cmd, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { new_item = cmdq_get_callback(cmd_display_panes_error, cause); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 5dfb5a19..93910f34 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -96,7 +96,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) free(shellcmd); if (cmd == NULL) return (CMD_RETURN_NORMAL); - if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(cmd, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { cmdq_error(item, "%s", cause); free(cause); @@ -167,7 +168,8 @@ cmd_if_shell_callback(struct job *job) if (cmd == NULL) goto out; - if (cmd_string_parse(cmd, &cmdlist, file, line, &cause) != 0) { + cmdlist = cmd_string_parse(cmd, file, line, &cause); + if (cmdlist == NULL) { if (cause != NULL) new_item = cmdq_get_callback(cmd_if_shell_error, cause); else diff --git a/cmd-set-hook.c b/cmd-set-hook.c index 2685fc8d..fff7ccd7 100644 --- a/cmd-set-hook.c +++ b/cmd-set-hook.c @@ -115,7 +115,8 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item) cmdq_error(item, "no command to set hook: %s", name); return (CMD_RETURN_ERROR); } - if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(cmd, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { cmdq_error(item, "%s", cause); free(cause); diff --git a/cmd-string.c b/cmd-string.c index 7c6d9ad6..1b96b280 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -54,32 +54,17 @@ cmd_string_ungetc(size_t *p) (*p)--; } -/* - * Parse command string. Returns -1 on error. If returning -1, cause is error - * string, or NULL for empty command. - */ -int -cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, - u_int line, char **cause) +struct cmd_list * +cmd_string_parse(const char *s, const char *file, u_int line, char **cause) { - size_t p; - int ch, i, argc, rval; - char **argv, *buf, *t; - const char *whitespace, *equals; - size_t len; - - argv = NULL; - argc = 0; - - buf = NULL; - len = 0; + size_t p = 0; + int ch, i, argc = 0; + char **argv = NULL, *buf = NULL, *t; + const char *whitespace, *equals; + size_t len = 0; + struct cmd_list *cmdlist = NULL; *cause = NULL; - - *cmdlist = NULL; - rval = -1; - - p = 0; for (;;) { ch = cmd_string_getc(s, &p); switch (ch) { @@ -133,12 +118,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file, if (argc == 0) goto out; - *cmdlist = cmd_list_parse(argc, argv, file, line, - cause); - if (*cmdlist == NULL) - goto out; - - rval = 0; + cmdlist = cmd_list_parse(argc, argv, file, line, cause); goto out; case '~': if (buf == NULL) { @@ -171,7 +151,7 @@ out: free(argv); } - return (rval); + return (cmdlist); } static void diff --git a/control.c b/control.c index e9b1e8ea..64e9fec1 100644 --- a/control.c +++ b/control.c @@ -85,7 +85,8 @@ control_callback(struct client *c, int closed, __unused void *data) break; } - if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(line, NULL, 0, &cause); + if (cmdlist == NULL) { item = cmdq_get_callback(control_error, cause); cmdq_append(c, item); } else { diff --git a/key-bindings.c b/key-bindings.c index 838510c6..65cc9b10 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -379,12 +379,10 @@ key_bindings_init(void) u_int i; struct cmd_list *cmdlist; char *cause; - int error; for (i = 0; i < nitems(defaults); i++) { - error = cmd_string_parse(defaults[i], &cmdlist, - "", i, &cause); - if (error != 0) + cmdlist = cmd_string_parse(defaults[i], "", i, &cause); + if (cmdlist == NULL) fatalx("bad default key"); cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0)); cmd_list_free(cmdlist); diff --git a/tmux.h b/tmux.h index 52778c46..54e20873 100644 --- a/tmux.h +++ b/tmux.h @@ -1823,8 +1823,7 @@ void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...); void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...); /* cmd-string.c */ -int cmd_string_parse(const char *, struct cmd_list **, const char *, - u_int, char **); +struct cmd_list *cmd_string_parse(const char *, const char *, u_int, char **); /* cmd-wait-for.c */ void cmd_wait_for_flush(void); diff --git a/window-choose.c b/window-choose.c index e18b89a3..edfc9916 100644 --- a/window-choose.c +++ b/window-choose.c @@ -255,7 +255,8 @@ window_choose_data_run(struct window_choose_data *cdata) if (cdata->command == NULL) return; - if (cmd_string_parse(cdata->command, &cmdlist, NULL, 0, &cause) != 0) { + cmdlist = cmd_string_parse(cdata->command, NULL, 0, &cause); + if (cmdlist == NULL) { if (cause != NULL) { *cause = toupper((u_char) *cause); status_message_set(cdata->start_client, "%s", cause);