Stop caring about empty commands, just treat as a null command.

This commit is contained in:
nicm 2021-08-21 17:25:32 +00:00
parent 68cacaec68
commit 5241dae87d
9 changed files with 16 additions and 30 deletions

4
cfg.c
View File

@ -125,8 +125,6 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
pr = cmd_parse_from_file(f, &pi); pr = cmd_parse_from_file(f, &pi);
fclose(f); fclose(f);
if (pr->status == CMD_PARSE_EMPTY)
return (0);
if (pr->status == CMD_PARSE_ERROR) { if (pr->status == CMD_PARSE_ERROR) {
cfg_add_cause("%s", pr->error); cfg_add_cause("%s", pr->error);
free(pr->error); free(pr->error);
@ -179,8 +177,6 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
pi.c = c; pi.c = c;
pr = cmd_parse_from_buffer(buf, len, &pi); pr = cmd_parse_from_buffer(buf, len, &pi);
if (pr->status == CMD_PARSE_EMPTY)
return (0);
if (pr->status == CMD_PARSE_ERROR) { if (pr->status == CMD_PARSE_ERROR) {
cfg_add_cause("%s", pr->error); cfg_add_cause("%s", pr->error);
free(pr->error); free(pr->error);

View File

@ -75,9 +75,6 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
cmd_free_argv(argc, argv); cmd_free_argv(argc, argv);
} }
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
cmdq_error(item, "empty command");
return (CMD_RETURN_ERROR);
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
cmdq_error(item, "%s", pr->error); cmdq_error(item, "%s", pr->error);
free(pr->error); free(pr->error);

View File

@ -159,8 +159,6 @@ cmd_if_shell_callback(struct job *job)
pr = cmd_parse_from_string(cmd, &cdata->input); pr = cmd_parse_from_string(cmd, &cdata->input);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
break;
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
if (cdata->item != NULL) if (cdata->item != NULL)
cmdq_error(cdata->item, "%s", pr->error); cmdq_error(cdata->item, "%s", pr->error);

View File

@ -744,7 +744,8 @@ cmd_parse_expand_alias(struct cmd_parse_command *cmd,
first = TAILQ_FIRST(&cmd->arguments); first = TAILQ_FIRST(&cmd->arguments);
if (first == NULL || first->type != CMD_PARSE_STRING) { if (first == NULL || first->type != CMD_PARSE_STRING) {
pr->status = CMD_PARSE_EMPTY; pr->status = CMD_PARSE_SUCCESS;
pr->cmdlist = cmd_list_new();
return (1); return (1);
} }
name = first->string; name = first->string;
@ -840,7 +841,8 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds,
/* Check for an empty list. */ /* Check for an empty list. */
if (TAILQ_EMPTY(cmds)) { if (TAILQ_EMPTY(cmds)) {
pr->status = CMD_PARSE_EMPTY; pr->status = CMD_PARSE_SUCCESS;
pr->cmdlist = cmd_list_new();
return; return;
} }
cmd_parse_log_commands(cmds, __func__); cmd_parse_log_commands(cmds, __func__);
@ -942,8 +944,6 @@ cmd_parse_and_insert(const char *s, struct cmd_parse_input *pi,
pr = cmd_parse_from_string(s, pi); pr = cmd_parse_from_string(s, pi);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
break;
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
if (error != NULL) if (error != NULL)
*error = pr->error; *error = pr->error;
@ -968,8 +968,6 @@ cmd_parse_and_append(const char *s, struct cmd_parse_input *pi,
pr = cmd_parse_from_string(s, pi); pr = cmd_parse_from_string(s, pi);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
break;
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
if (error != NULL) if (error != NULL)
*error = pr->error; *error = pr->error;
@ -1000,9 +998,8 @@ cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi)
memset(&pr, 0, sizeof pr); memset(&pr, 0, sizeof pr);
if (len == 0) { if (len == 0) {
pr.status = CMD_PARSE_EMPTY; pr.status = CMD_PARSE_SUCCESS;
pr.cmdlist = NULL; pr.cmdlist = cmd_list_new();
pr.error = NULL;
return (&pr); return (&pr);
} }

View File

@ -478,6 +478,13 @@ cmdq_remove_group(struct cmdq_item *item)
} }
} }
/* Empty command callback. */
static enum cmd_retval
cmdq_empty_command(__unused struct cmdq_item *item, __unused void *data)
{
return (CMD_RETURN_NORMAL);
}
/* Get a command for the command queue. */ /* Get a command for the command queue. */
struct cmdq_item * struct cmdq_item *
cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state) cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
@ -487,12 +494,14 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
const struct cmd_entry *entry; const struct cmd_entry *entry;
int created = 0; int created = 0;
if ((cmd = cmd_list_first(cmdlist)) == NULL)
return (cmdq_get_callback(cmdq_empty_command, NULL));
if (state == NULL) { if (state == NULL) {
state = cmdq_new_state(NULL, NULL, 0); state = cmdq_new_state(NULL, NULL, 0);
created = 1; created = 1;
} }
cmd = cmd_list_first(cmdlist);
while (cmd != NULL) { while (cmd != NULL) {
entry = cmd_get_entry(cmd); entry = cmd_get_entry(cmd);

View File

@ -443,10 +443,6 @@ options_array_set(struct options_entry *o, u_int idx, const char *value,
if (OPTIONS_IS_COMMAND(o)) { if (OPTIONS_IS_COMMAND(o)) {
pr = cmd_parse_from_string(value, NULL); pr = cmd_parse_from_string(value, NULL);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
if (cause != NULL)
*cause = xstrdup("empty command");
return (-1);
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
if (cause != NULL) if (cause != NULL)
*cause = pr->error; *cause = pr->error;

View File

@ -2151,9 +2151,6 @@ server_client_dispatch_command(struct client *c, struct imsg *imsg)
pr = cmd_parse_from_arguments(argc, argv, NULL); pr = cmd_parse_from_arguments(argc, argv, NULL);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
cause = xstrdup("empty command");
goto error;
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
cause = pr->error; cause = pr->error;
goto error; goto error;

1
tmux.h
View File

@ -1417,7 +1417,6 @@ enum cmd_retval {
/* Command parse result. */ /* Command parse result. */
enum cmd_parse_status { enum cmd_parse_status {
CMD_PARSE_EMPTY,
CMD_PARSE_ERROR, CMD_PARSE_ERROR,
CMD_PARSE_SUCCESS CMD_PARSE_SUCCESS
}; };

View File

@ -1185,9 +1185,6 @@ window_customize_set_command_callback(struct client *c, void *itemdata,
pr = cmd_parse_from_string(s, NULL); pr = cmd_parse_from_string(s, NULL);
switch (pr->status) { switch (pr->status) {
case CMD_PARSE_EMPTY:
error = xstrdup("empty command");
goto fail;
case CMD_PARSE_ERROR: case CMD_PARSE_ERROR:
error = pr->error; error = pr->error;
goto fail; goto fail;