More cleanup.

This commit is contained in:
Nicholas Marriott
2026-06-30 22:32:36 +01:00
parent 6d56dd9e7b
commit e935342702
9 changed files with 23 additions and 87 deletions

12
cfg.c
View File

@@ -98,7 +98,6 @@ load_cfg(const char *path, struct cmdq_item *item,
{ {
FILE *f; FILE *f;
struct cmd_parse_input pi; struct cmd_parse_input pi;
struct cmd_invoke_input ci;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmdq_item *new_item0; struct cmdq_item *new_item0;
struct cmdq_state *state; struct cmdq_state *state;
@@ -138,10 +137,7 @@ load_cfg(const char *path, struct cmdq_item *item,
state = cmdq_new_state(NULL, NULL, 0); state = cmdq_new_state(NULL, NULL, 0);
cmdq_add_format(state, "current_file", "%s", pi.file); cmdq_add_format(state, "current_file", "%s", pi.file);
memset(&ci, 0, sizeof ci); new_item0 = cmd_invoke_get(tree, state, NULL);
ci.file = pi.file;
ci.flags = flags;
new_item0 = cmd_invoke_get(tree, state, &ci);
if (item != NULL) if (item != NULL)
new_item0 = cmdq_insert_after(item, new_item0); new_item0 = cmdq_insert_after(item, new_item0);
else else
@@ -160,7 +156,6 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
struct cmdq_item **new_item) struct cmdq_item **new_item)
{ {
struct cmd_parse_input pi; struct cmd_parse_input pi;
struct cmd_invoke_input ci;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmdq_item *new_item0; struct cmdq_item *new_item0;
struct cmdq_state *state; struct cmdq_state *state;
@@ -193,10 +188,7 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
state = cmdq_new_state(NULL, NULL, 0); state = cmdq_new_state(NULL, NULL, 0);
cmdq_add_format(state, "current_file", "%s", pi.file); cmdq_add_format(state, "current_file", "%s", pi.file);
memset(&ci, 0, sizeof ci); new_item0 = cmd_invoke_get(tree, state, NULL);
ci.file = pi.file;
ci.flags = flags;
new_item0 = cmd_invoke_get(tree, state, &ci);
if (item != NULL) if (item != NULL)
new_item0 = cmdq_insert_after(item, new_item0); new_item0 = cmdq_insert_after(item, new_item0);
else else

View File

@@ -58,8 +58,6 @@ struct cmd_command_prompt_prompt {
struct cmd_command_prompt_cdata { struct cmd_command_prompt_cdata {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
int flags; int flags;
enum prompt_type prompt_type; enum prompt_type prompt_type;
@@ -118,10 +116,6 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
} }
if ((s = args_get(args, 'p')) == NULL) { if ((s = args_get(args, 'p')) == NULL) {
@@ -259,8 +253,6 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
/* Explicit body: prompt inputs become the template argv. */ /* Explicit body: prompt inputs become the template argv. */
ci.argc = argc; ci.argc = argc;
ci.argv = argv; ci.argv = argv;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
new_item = cmd_invoke_get(cdata->tree, cs, &ci); new_item = cmd_invoke_get(cdata->tree, cs, &ci);
if (item == NULL) if (item == NULL)
cmdq_append(c, new_item); cmdq_append(c, new_item);
@@ -320,6 +312,5 @@ cmd_command_prompt_free(void *data)
free(cdata->prompts); free(cdata->prompts);
cmd_free_argv(cdata->argc, cdata->argv); cmd_free_argv(cdata->argc, cdata->argv);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -52,8 +52,6 @@ const struct cmd_entry cmd_confirm_before_entry = {
struct cmd_confirm_before_data { struct cmd_confirm_before_data {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
u_char confirm_key; u_char confirm_key;
int default_yes; int default_yes;
}; };
@@ -73,7 +71,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
char *new_prompt, *cause = NULL; char *new_prompt, *cause = NULL;
const char *confirm_key, *prompt, *cmd, *file; const char *confirm_key, *prompt, *cmd;
int wait = !args_has(args, 'b'), n; int wait = !args_has(args, 'b'), n;
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
@@ -84,10 +82,6 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (wait) if (wait)
cdata->item = item; cdata->item = item;
@@ -133,7 +127,6 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmdq_state *cs; struct cmdq_state *cs;
struct cmd_invoke_input ci = { 0 };
int retcode = 1; int retcode = 1;
if (c->flags & CLIENT_DEAD) if (c->flags & CLIENT_DEAD)
@@ -145,14 +138,12 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
goto out; goto out;
retcode = 0; retcode = 0;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
if (item == NULL) { if (item == NULL) {
new_item = cmd_invoke_get(cdata->tree, NULL, &ci); new_item = cmd_invoke_get(cdata->tree, NULL, NULL);
cmdq_append(c, new_item); cmdq_append(c, new_item);
} else { } else {
cs = cmdq_get_state(item); cs = cmdq_get_state(item);
new_item = cmd_invoke_get(cdata->tree, cs, &ci); new_item = cmd_invoke_get(cdata->tree, cs, NULL);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
} }
@@ -172,6 +163,5 @@ cmd_confirm_before_free(void *data)
struct cmd_confirm_before_data *cdata = data; struct cmd_confirm_before_data *cdata = data;
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -46,8 +46,6 @@ const struct cmd_entry cmd_display_panes_entry = {
struct cmd_display_panes_data { struct cmd_display_panes_data {
struct cmdq_item *item; struct cmdq_item *item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
}; };
struct cmd_display_panes_ctx { struct cmd_display_panes_ctx {
@@ -300,7 +298,6 @@ cmd_display_panes_free(__unused struct client *c, void *data)
if (cdata->item != NULL) if (cdata->item != NULL)
cmdq_continue(cdata->item); cmdq_continue(cdata->item);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata); free(cdata);
} }
@@ -336,8 +333,6 @@ cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
xasprintf(&expanded, "%%%u", wp->id); xasprintf(&expanded, "%%%u", wp->id);
ci.argc = 1; ci.argc = 1;
ci.argv = &expanded; ci.argv = &expanded;
ci.file = cdata->file;
ci.flags = cdata->parse_flags;
if (item != NULL) if (item != NULL)
cs = cmdq_get_state(item); cs = cmdq_get_state(item);
@@ -359,7 +354,6 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = tc->session; struct session *s = tc->session;
u_int delay; u_int delay;
char *cause; char *cause;
const char *file;
struct cmd_display_panes_data *cdata; struct cmd_display_panes_data *cdata;
int wait = !args_has(args, 'b'); int wait = !args_has(args, 'b');
@@ -388,10 +382,6 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
free(cdata); free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (args_has(args, 'N')) { if (args_has(args, 'N')) {
server_client_set_overlay(tc, delay, NULL, NULL, server_client_set_overlay(tc, delay, NULL, NULL,

View File

@@ -56,8 +56,6 @@ struct cmd_if_shell_data {
struct cmd_parse_tree *cmd_if; struct cmd_parse_tree *cmd_if;
struct cmd_parse_tree *cmd_else; struct cmd_parse_tree *cmd_else;
char *file;
int parse_flags;
struct client *client; struct client *client;
struct cmdq_item *item; struct cmdq_item *item;
@@ -80,8 +78,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
struct cmdq_item *new_item; struct cmdq_item *new_item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmd_invoke_input input = { 0 };
const char *file;
char *shellcmd, *cause = NULL; char *shellcmd, *cause = NULL;
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct session *s = target->s; struct session *s = target->s;
@@ -106,10 +102,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL); new_item = cmd_invoke_get(tree, cmdq_get_state(item), NULL);
input.file = file;
input.flags = cmd_get_parse_flags(self);
new_item = cmd_invoke_get(tree, cmdq_get_state(item), &input);
cmd_parse_free(tree); cmd_parse_free(tree);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -129,10 +122,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
goto fail; goto fail;
} }
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
if (!wait) if (!wait)
cdata->client = tc; cdata->client = tc;
@@ -170,7 +159,6 @@ cmd_if_shell_callback(struct job *job)
struct client *c = cdata->client; struct client *c = cdata->client;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
struct cmd_invoke_input input = { 0 };
int status; int status;
status = job_get_status(job); status = job_get_status(job);
@@ -181,13 +169,11 @@ cmd_if_shell_callback(struct job *job)
if (tree == NULL) if (tree == NULL)
goto out; goto out;
input.file = cdata->file;
input.flags = cdata->parse_flags;
if (item == NULL) { if (item == NULL) {
new_item = cmd_invoke_get(tree, NULL, &input); new_item = cmd_invoke_get(tree, NULL, NULL);
cmdq_append(c, new_item); cmdq_append(c, new_item);
} else { } else {
new_item = cmd_invoke_get(tree, cmdq_get_state(item), &input); new_item = cmd_invoke_get(tree, cmdq_get_state(item), NULL);
cmdq_insert_after(item, new_item); cmdq_insert_after(item, new_item);
} }
@@ -208,6 +194,5 @@ cmd_if_shell_free(void *data)
cmd_parse_free(cdata->cmd_else); cmd_parse_free(cdata->cmd_else);
if (cdata->cmd_if != NULL) if (cdata->cmd_if != NULL)
cmd_parse_free(cdata->cmd_if); cmd_parse_free(cdata->cmd_if);
free(cdata->file);
free(cdata); free(cdata);
} }

View File

@@ -342,9 +342,9 @@ cmd_invoke_build_command(struct cmdq_item *item, struct cmd_invoke_state *is,
struct cmd_parse_node *child; struct cmd_parse_node *child;
struct args_value *values = NULL; struct args_value *values = NULL;
struct cmd *cmd; struct cmd *cmd;
const char *file = cmd_parse_file(is->tree); const char *file = cmd_parse_file(tree);
u_int line = cmd_parse_node_line(node); u_int line = cmd_parse_node_line(node);
int flags = cmd_parse_flags(is->tree); int flags = cmd_parse_flags(tree);
char *cause = NULL; char *cause = NULL;
u_int count = 0; u_int count = 0;
@@ -497,16 +497,16 @@ cmd_invoke_fire(struct cmdq_item *item, struct cmd_invoke_state *is)
break; break;
case CMD_PARSE_ASSIGN: case CMD_PARSE_ASSIGN:
case CMD_PARSE_HIDDEN_ASSIGN: case CMD_PARSE_HIDDEN_ASSIGN:
if (cmd_invoke_assignment(item, is, node) != 0) { if (cmd_invoke_assignment(item, is, node) == 0)
cmdq_error(item, "bad assignment"); break;
cmd_invoke_skip_sequence(is); cmd_invoke_error(item, is, node, "bad assignment");
} cmd_invoke_skip_sequence(is);
break; break;
case CMD_PARSE_IF: case CMD_PARSE_IF:
if (cmd_invoke_if(item, is, node) != 0) { if (cmd_invoke_if(item, is, node) == 0)
cmdq_error(item, "bad condition"); break;
cmd_invoke_skip_sequence(is); cmd_invoke_error(item, is, node, "bad condition");
} cmd_invoke_skip_sequence(is);
break; break;
case CMD_PARSE_ELIF: case CMD_PARSE_ELIF:
case CMD_PARSE_ELSE: case CMD_PARSE_ELSE:

View File

@@ -1285,6 +1285,7 @@ cmd_parse_command_any_have(struct cmd_parse_tree *tree,
struct cmd_parse_node *node, int flag) struct cmd_parse_node *node, int flag)
{ {
struct cmd_parse_node *child; struct cmd_parse_node *child;
int flags = tree->flags;
struct args_value *values = NULL; struct args_value *values = NULL;
struct cmd *cmd; struct cmd *cmd;
char *cause = NULL; char *cause = NULL;
@@ -1317,7 +1318,7 @@ cmd_parse_command_any_have(struct cmd_parse_tree *tree,
count++; count++;
} }
cmd = cmd_parse(values, count, NULL, node->line, 0, &cause); cmd = cmd_parse(values, count, tree->file, node->line, flags, &cause);
if (cmd == NULL) { if (cmd == NULL) {
free(cause); free(cause);
found = -1; found = -1;

View File

@@ -58,8 +58,6 @@ struct cmd_run_shell_data {
struct client *client; struct client *client;
char *cmd; char *cmd;
struct cmd_parse_tree *tree; struct cmd_parse_tree *tree;
char *file;
int parse_flags;
char *cwd; char *cwd;
struct cmdq_item *item; struct cmdq_item *item;
struct session *s; struct session *s;
@@ -92,7 +90,7 @@ cmd_run_shell_print(struct job *job, const char *msg)
cmdq_print(cdata->item, "%s", msg); cmdq_print(cdata->item, "%s", msg);
return; return;
} }
if (cdata->item != NULL && cdata->client != NULL) if (cdata->client != NULL)
wp = server_client_get_pane(cdata->client); wp = server_client_get_pane(cdata->client);
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0) if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
wp = fs.wp; wp = fs.wp;
@@ -116,7 +114,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item); struct client *tc = cmdq_get_target_client(item);
struct session *s = target->s; struct session *s = target->s;
struct window_pane *wp = target->wp; struct window_pane *wp = target->wp;
const char *delay, *cmd, *file; const char *delay, *cmd;
struct format_tree *ft; struct format_tree *ft;
double d; double d;
struct timeval tv; struct timeval tv;
@@ -155,10 +153,6 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cmd_run_shell_free(cdata); cmd_run_shell_free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
cmd_get_source(self, &file, NULL);
if (file != NULL)
cdata->file = xstrdup(file);
cdata->parse_flags = cmd_get_parse_flags(self);
} }
if (args_has(args, 't') && wp != NULL) if (args_has(args, 't') && wp != NULL)
@@ -212,7 +206,6 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
const char *cmd = cdata->cmd; const char *cmd = cdata->cmd;
struct cmdq_item *item = cdata->item, *new_item; struct cmdq_item *item = cdata->item, *new_item;
struct cmdq_state *cs = NULL; struct cmdq_state *cs = NULL;
struct cmd_invoke_input input = { 0 };
if (cdata->tree == NULL) { if (cdata->tree == NULL) {
if (cmd == NULL) { if (cmd == NULL) {
@@ -239,9 +232,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
if (item != NULL) if (item != NULL)
cs = cmdq_get_state(item); cs = cmdq_get_state(item);
input.file = cdata->file; new_item = cmd_invoke_get(cdata->tree, cs, NULL);
input.flags = cdata->parse_flags;
new_item = cmd_invoke_get(cdata->tree, cs, &input);
if (item == NULL) if (item == NULL)
cmdq_append(c, new_item); cmdq_append(c, new_item);
else else
@@ -314,7 +305,6 @@ cmd_run_shell_free(void *data)
if (cdata->client != NULL) if (cdata->client != NULL)
server_client_unref(cdata->client); server_client_unref(cdata->client);
cmd_parse_free(cdata->tree); cmd_parse_free(cdata->tree);
free(cdata->file);
free(cdata->cwd); free(cdata->cwd);
free(cdata->cmd); free(cdata->cmd);
free(cdata); free(cdata);

3
tmux.h
View File

@@ -1971,9 +1971,6 @@ struct cmd_entry {
/* Command invocation input. */ /* Command invocation input. */
struct cmd_invoke_input { struct cmd_invoke_input {
const char *file;
int flags;
int argc; int argc;
char **argv; char **argv;
}; };