It is silly for cmd_list_parse to return an integer error when it could

just return NULL.
This commit is contained in:
nicm 2017-01-15 22:00:56 +00:00
parent 3054846143
commit 52847a9518
11 changed files with 31 additions and 45 deletions

3
cfg.c
View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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 {

View File

@ -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,
"<default-keys>", i, &cause);
if (error != 0)
cmdlist = cmd_string_parse(defaults[i], "<default>", i, &cause);
if (cmdlist == NULL)
fatalx("bad default key");
cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0));
cmd_list_free(cmdlist);

3
tmux.h
View File

@ -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);

View File

@ -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);