Skip to content

Commit

Permalink
Make struct cmd local to cmd.c and move it out of tmux.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicm committed Apr 13, 2020
1 parent 9cbe967 commit c20eb0c
Show file tree
Hide file tree
Showing 65 changed files with 314 additions and 247 deletions.
7 changes: 2 additions & 5 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ int
client_main(struct event_base *base, int argc, char **argv, int flags)
{
struct cmd_parse_result *pr;
struct cmd *cmd;
struct msg_command *data;
int fd, i;
const char *ttynam, *cwd;
Expand Down Expand Up @@ -265,10 +264,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
*/
pr = cmd_parse_from_arguments(argc, argv, NULL);
if (pr->status == CMD_PARSE_SUCCESS) {
TAILQ_FOREACH(cmd, &pr->cmdlist->list, qentry) {
if (cmd->entry->flags & CMD_STARTSERVER)
flags |= CLIENT_STARTSERVER;
}
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
flags |= CLIENT_STARTSERVER;
cmd_list_free(pr->cmdlist);
} else
free(pr->error);
Expand Down
2 changes: 1 addition & 1 deletion cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
static enum cmd_retval
cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);

return (cmd_attach_session(item, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'x'), args_has(args, 'r'),
Expand Down
2 changes: 1 addition & 1 deletion cmd-bind-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const struct cmd_entry cmd_bind_key_entry = {
static enum cmd_retval
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
key_code key;
const char *tablename, *note;
struct cmd_parse_result *pr;
Expand Down
4 changes: 2 additions & 2 deletions cmd-break-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const struct cmd_entry cmd_break_pane_entry = {
static enum cmd_retval
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct cmd_find_state *current = &item->shared->current;
struct client *c = cmd_find_client(item, NULL, 1);
struct winlink *wl = item->source.wl;
Expand Down Expand Up @@ -98,7 +98,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
if (idx == -1)
idx = -1 - options_get_number(dst_s->options, "base-index");
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
if (!args_has(self->args, 'd')) {
if (!args_has(args, 'd')) {
session_select(dst_s, wl->idx);
cmd_find_from_session(current, dst_s, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions cmd-capture-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
static enum cmd_retval
cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c = item->client;
struct window_pane *wp = item->target.wp;
char *buf, *cause;
const char *bufname;
size_t len;

if (self->entry == &cmd_clear_history_entry) {
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
window_pane_reset_mode_all(wp);
grid_clear_history(wp->base.grid);
return (CMD_RETURN_NORMAL);
Expand Down
6 changes: 3 additions & 3 deletions cmd-choose-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ const struct cmd_entry cmd_choose_buffer_entry = {
static enum cmd_retval
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct window_pane *wp = item->target.wp;
const struct window_mode *mode;

if (self->entry == &cmd_choose_buffer_entry) {
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
if (paste_get_top(NULL) == NULL)
return (CMD_RETURN_NORMAL);
mode = &window_buffer_mode;
} else if (self->entry == &cmd_choose_client_entry) {
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
if (server_client_how_many() == 0)
return (CMD_RETURN_NORMAL);
mode = &window_client_mode;
Expand Down
2 changes: 1 addition & 1 deletion cmd-command-prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct cmd_command_prompt_cdata {
static enum cmd_retval
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata;
struct client *c;
Expand Down
2 changes: 1 addition & 1 deletion cmd-confirm-before.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct cmd_confirm_before_data {
static enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct cmd_confirm_before_data *cdata;
struct client *c;
char *cmd, *copy, *new_prompt, *ptr;
Expand Down
6 changes: 3 additions & 3 deletions cmd-copy-mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
static enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = item->shared;
struct client *c = item->client;
struct session *s;
Expand All @@ -74,7 +74,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}

if (self->entry == &cmd_clock_mode_entry) {
if (cmd_get_entry(self) == &cmd_clock_mode_entry) {
window_pane_set_mode(wp, NULL, &window_clock_mode, NULL, NULL);
return (CMD_RETURN_NORMAL);
}
Expand All @@ -87,7 +87,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'M'))
window_copy_start_drag(c, &shared->mouse);
}
if (args_has(self->args, 'u'))
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);

return (CMD_RETURN_NORMAL);
Expand Down
4 changes: 2 additions & 2 deletions cmd-detach-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const struct cmd_entry cmd_suspend_client_entry = {
static enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c, *cloop;
struct session *s;
enum msgtype msgtype;
Expand All @@ -66,7 +66,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);

if (self->entry == &cmd_suspend_client_entry) {
if (cmd_get_entry(self) == &cmd_suspend_client_entry) {
server_client_suspend(c);
return (CMD_RETURN_NORMAL);
}
Expand Down
4 changes: 2 additions & 2 deletions cmd-display-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
static enum cmd_retval
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
Expand Down Expand Up @@ -239,7 +239,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
static enum cmd_retval
cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c;
struct cmd_find_state *fs = &item->target;
const char *value, *cmd = NULL, **lines = NULL;
Expand Down
6 changes: 3 additions & 3 deletions cmd-display-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cmd_display_message_each(const char *key, const char *value, void *arg)
static enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c, *target_c;
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
Expand Down Expand Up @@ -101,7 +101,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
target_c = c;
else
target_c = cmd_find_best_client(s);
if (args_has(self->args, 'v'))
if (args_has(args, 'v'))
flags = FORMAT_VERBOSE;
else
flags = 0;
Expand All @@ -114,7 +114,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
}

msg = format_expand_time(ft, template);
if (args_has(self->args, 'p'))
if (args_has(args, 'p'))
cmdq_print(item, "%s", msg);
else if (c != NULL)
status_message_set(c, "%s", msg);
Expand Down
2 changes: 1 addition & 1 deletion cmd-display-panes.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ cmd_display_panes_key(struct client *c, struct key_event *event)
static enum cmd_retval
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c;
struct session *s;
u_int delay;
Expand Down
2 changes: 1 addition & 1 deletion cmd-find-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const struct cmd_entry cmd_find_window_entry = {
static enum cmd_retval
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args, *new_args;
struct args *args = cmd_get_args(self), *new_args;
struct window_pane *wp = item->target.wp;
const char *s = args->argv[0];
char *filter, *argv = { NULL };
Expand Down
14 changes: 6 additions & 8 deletions cmd-if-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ struct cmd_if_shell_data {
static enum cmd_retval
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct mouse_event *m = &item->shared->mouse;
struct cmd_if_shell_data *cdata;
char *shellcmd, *cmd;
const char *file;
struct cmdq_item *new_item;
struct cmd_find_state *fs = &item->target;
struct client *c = cmd_find_client(item, NULL, 1);
Expand All @@ -88,9 +89,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);

memset(&pi, 0, sizeof pi);
if (self->file != NULL)
pi.file = self->file;
pi.line = self->line;
cmd_get_source(self, &pi.file, &pi.line);
pi.item = item;
pi.c = c;
cmd_find_copy_state(&pi.fs, fs);
Expand Down Expand Up @@ -134,10 +133,9 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata->item = NULL;

memset(&cdata->input, 0, sizeof cdata->input);
if (self->file != NULL)
cdata->input.file = xstrdup(self->file);
cdata->input.line = self->line;
cdata->input.item = cdata->item;
cmd_get_source(self, &file, &cdata->input.line);
if (file != NULL)
cdata->input.file = xstrdup(file);
cdata->input.c = c;
if (cdata->input.c != NULL)
cdata->input.c->references++;
Expand Down
4 changes: 2 additions & 2 deletions cmd-join-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const struct cmd_entry cmd_move_pane_entry = {
static enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct cmd_find_state *current = &item->shared->current;
struct session *dst_s;
struct winlink *src_wl, *dst_wl;
Expand All @@ -75,7 +75,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
enum layout_type type;
struct layout_cell *lc;

if (self->entry == &cmd_join_pane_entry)
if (cmd_get_entry(self) == &cmd_join_pane_entry)
not_same_window = 1;
else
not_same_window = 0;
Expand Down
3 changes: 2 additions & 1 deletion cmd-kill-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ const struct cmd_entry cmd_kill_pane_entry = {
static enum cmd_retval
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct winlink *wl = item->target.wl;
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;

if (args_has(self->args, 'a')) {
if (args_has(args, 'a')) {
server_unzoom_window(wl->window);
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
if (loopwp == wp)
Expand Down
2 changes: 1 addition & 1 deletion cmd-kill-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const struct cmd_entry cmd_start_server_entry = {
static enum cmd_retval
cmd_kill_server_exec(struct cmd *self, __unused struct cmdq_item *item)
{
if (self->entry == &cmd_kill_server_entry)
if (cmd_get_entry(self) == &cmd_kill_server_entry)
kill(getpid(), SIGTERM);

return (CMD_RETURN_NORMAL);
Expand Down
2 changes: 1 addition & 1 deletion cmd-kill-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const struct cmd_entry cmd_kill_session_entry = {
static enum cmd_retval
cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct session *s, *sloop, *stmp;
struct winlink *wl;

Expand Down
6 changes: 3 additions & 3 deletions cmd-kill-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ const struct cmd_entry cmd_unlink_window_entry = {
static enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct winlink *wl = item->target.wl, *wl2, *wl3;
struct window *w = wl->window;
struct session *s = item->target.s;

if (self->entry == &cmd_unlink_window_entry) {
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
if (cmd_get_entry(self) == &cmd_unlink_window_entry) {
if (!args_has(args, 'k') && !session_is_linked(s, w)) {
cmdq_error(item, "window only linked to one session");
return (CMD_RETURN_ERROR);
}
Expand Down
2 changes: 1 addition & 1 deletion cmd-list-buffers.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
static enum cmd_retval
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct paste_buffer *pb;
struct format_tree *ft;
const char *template, *filter;
Expand Down
2 changes: 1 addition & 1 deletion cmd-list-clients.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const struct cmd_entry cmd_list_clients_entry = {
static enum cmd_retval
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct client *c;
struct session *s;
struct format_tree *ft;
Expand Down
6 changes: 3 additions & 3 deletions cmd-list-keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ cmd_list_keys_get_prefix(struct args *args, key_code *prefix)
static enum cmd_retval
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct key_table *table;
struct key_binding *bd;
const char *tablename, *r;
Expand All @@ -153,7 +153,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
int repeat, width, tablewidth, keywidth, found = 0;
size_t tmpsize, tmpused, cplen;

if (self->entry == &cmd_list_commands_entry)
if (cmd_get_entry(self) == &cmd_list_commands_entry)
return (cmd_list_keys_commands(self, item));

if (args->argc != 0) {
Expand Down Expand Up @@ -313,7 +313,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
static enum cmd_retval
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
const struct cmd_entry **entryp;
const struct cmd_entry *entry;
struct format_tree *ft;
Expand Down
4 changes: 2 additions & 2 deletions cmd-list-panes.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const struct cmd_entry cmd_list_panes_entry = {
static enum cmd_retval
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct session *s = item->target.s;
struct winlink *wl = item->target.wl;

Expand Down Expand Up @@ -87,7 +87,7 @@ static void
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
struct cmdq_item *item, int type)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct window_pane *wp;
u_int n;
struct format_tree *ft;
Expand Down
2 changes: 1 addition & 1 deletion cmd-list-sessions.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
static enum cmd_retval
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
struct args *args = cmd_get_args(self);
struct session *s;
u_int n;
struct format_tree *ft;
Expand Down
Loading

0 comments on commit c20eb0c

Please sign in to comment.