diff --git a/cfg.c b/cfg.c index b0ea5d88..0c0e45f8 100644 --- a/cfg.c +++ b/cfg.c @@ -34,7 +34,7 @@ static u_int cfg_ncauses; struct client *cfg_client; static enum cmd_retval -cfg_done(__unused struct cmd_q *cmdq, __unused void *data) +cfg_done(__unused struct cmdq_item *item, __unused void *data) { if (cfg_finished) return (CMD_RETURN_NORMAL); @@ -78,15 +78,15 @@ start_cfg(void) } int -load_cfg(const char *path, struct client *c, struct cmd_q *cmdq, int quiet) +load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet) { - FILE *f; - char delim[3] = { '\\', '\\', '\0' }; - u_int found; - size_t line = 0; - char *buf, *cause1, *p; - struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; + FILE *f; + char delim[3] = { '\\', '\\', '\0' }; + u_int found; + size_t line = 0; + char *buf, *cause1, *p; + struct cmd_list *cmdlist; + struct cmdq_item *new_item; log_debug("loading %s", path); if ((f = fopen(path, "rb")) == NULL) { @@ -122,11 +122,11 @@ load_cfg(const char *path, struct client *c, struct cmd_q *cmdq, int quiet) if (cmdlist == NULL) continue; - new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); - if (cmdq != NULL) - cmdq_insert_after(cmdq, new_cmdq); + new_item = cmdq_get_command(cmdlist, NULL, NULL, 0); + if (item != NULL) + cmdq_insert_after(item, new_item); else - cmdq_append(c, new_cmdq); + cmdq_append(c, new_item); cmd_list_free(cmdlist); found++; @@ -152,12 +152,12 @@ cfg_add_cause(const char *fmt, ...) } void -cfg_print_causes(struct cmd_q *cmdq) +cfg_print_causes(struct cmdq_item *item) { u_int i; for (i = 0; i < cfg_ncauses; i++) { - cmdq_print(cmdq, "%s", cfg_causes[i]); + cmdq_print(item, "%s", cfg_causes[i]); free(cfg_causes[i]); } diff --git a/cmd-attach-session.c b/cmd-attach-session.c index f0e860f9..d999eb76 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -30,7 +30,8 @@ * Attach existing session to the current terminal. */ -static enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_attach_session_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_attach_session_entry = { .name = "attach-session", @@ -46,26 +47,26 @@ const struct cmd_entry cmd_attach_session_entry = { }; enum cmd_retval -cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, - int Eflag) +cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, + const char *cflag, int Eflag) { - struct session *s = cmdq->state.tflag.s; - struct client *c = cmdq->client, *c_loop; - struct winlink *wl = cmdq->state.tflag.wl; - struct window_pane *wp = cmdq->state.tflag.wp; + struct session *s = item->state.tflag.s; + struct client *c = item->client, *c_loop; + struct winlink *wl = item->state.tflag.wl; + struct window_pane *wp = item->state.tflag.wp; const char *update; char *cause, *cwd; struct format_tree *ft; if (RB_EMPTY(&sessions)) { - cmdq_error(cmdq, "no sessions"); + cmdq_error(item, "no sessions"); return (CMD_RETURN_ERROR); } if (c == NULL) return (CMD_RETURN_NORMAL); if (server_client_check_nested(c)) { - cmdq_error(cmdq, "sessions should be nested with care, " + cmdq_error(item, "sessions should be nested with care, " "unset $TMUX to force"); return (CMD_RETURN_ERROR); } @@ -77,7 +78,7 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, } if (cflag != NULL) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, wl, wp); cwd = format_expand(ft, cflag); format_free(ft); @@ -111,7 +112,7 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, s->curw->flags &= ~WINLINK_ALERTFLAGS; } else { if (server_client_open(c, &cause) != 0) { - cmdq_error(cmdq, "open terminal failed: %s", cause); + cmdq_error(item, "open terminal failed: %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -155,10 +156,10 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, } static enum cmd_retval -cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - return (cmd_attach_session(cmdq, args_has(args, 'd'), + return (cmd_attach_session(item, args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E'))); } diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 8c1acba9..4650afb1 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -27,10 +27,10 @@ * Bind a key to a command, this recurses through cmd_*. */ -static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, - key_code); +static enum cmd_retval cmd_bind_key_mode_table(struct cmd *, + struct cmdq_item *, key_code); const struct cmd_entry cmd_bind_key_entry = { .name = "bind-key", @@ -45,7 +45,7 @@ const struct cmd_entry cmd_bind_key_entry = { }; static enum cmd_retval -cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; char *cause; @@ -55,24 +55,24 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 't')) { if (args->argc != 2 && args->argc != 3) { - cmdq_error(cmdq, "not enough arguments"); + cmdq_error(item, "not enough arguments"); return (CMD_RETURN_ERROR); } } else { if (args->argc < 2) { - cmdq_error(cmdq, "not enough arguments"); + cmdq_error(item, "not enough arguments"); return (CMD_RETURN_ERROR); } } key = key_string_lookup_string(args->argv[0]); if (key == KEYC_NONE || key == KEYC_UNKNOWN) { - cmdq_error(cmdq, "unknown key: %s", args->argv[0]); + cmdq_error(item, "unknown key: %s", args->argv[0]); return (CMD_RETURN_ERROR); } if (args_has(args, 't')) - return (cmd_bind_key_mode_table(self, cmdq, key)); + return (cmd_bind_key_mode_table(self, item, key)); if (args_has(args, 'T')) tablename = args_get(args, 'T'); @@ -84,7 +84,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0, &cause); if (cmdlist == NULL) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -94,7 +94,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) +cmd_bind_key_mode_table(struct cmd *self, struct cmdq_item *item, key_code key) { struct args *args = self->args; const char *tablename; @@ -104,18 +104,18 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { - cmdq_error(cmdq, "unknown key table: %s", tablename); + cmdq_error(item, "unknown key table: %s", tablename); return (CMD_RETURN_ERROR); } cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); if (cmd == MODEKEY_NONE) { - cmdq_error(cmdq, "unknown command: %s", args->argv[1]); + cmdq_error(item, "unknown command: %s", args->argv[1]); return (CMD_RETURN_ERROR); } if (args->argc != 2) { - cmdq_error(cmdq, "no argument allowed"); + cmdq_error(item, "no argument allowed"); return (CMD_RETURN_ERROR); } diff --git a/cmd-break-pane.c b/cmd-break-pane.c index 75562750..a5d4e148 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -28,7 +28,7 @@ #define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_break_pane_entry = { .name = "break-pane", @@ -45,28 +45,28 @@ const struct cmd_entry cmd_break_pane_entry = { }; static enum cmd_retval -cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.sflag.wl; - struct session *src_s = cmdq->state.sflag.s; - struct session *dst_s = cmdq->state.tflag.s; - struct window_pane *wp = cmdq->state.sflag.wp; + struct winlink *wl = item->state.sflag.wl; + struct session *src_s = item->state.sflag.s; + struct session *dst_s = item->state.tflag.s; + struct window_pane *wp = item->state.sflag.wp; struct window *w = wl->window; char *name; char *cause; - int idx = cmdq->state.tflag.idx; + int idx = item->state.tflag.idx; struct format_tree *ft; const char *template; char *cp; if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) { - cmdq_error(cmdq, "index %d already in use", idx); + cmdq_error(item, "index %d already in use", idx); return (CMD_RETURN_ERROR); } if (window_count_panes(w) == 1) { - cmdq_error(cmdq, "can't break with only one pane"); + cmdq_error(item, "can't break with only one pane"); return (CMD_RETURN_ERROR); } server_unzoom_window(w); @@ -101,11 +101,11 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = BREAK_PANE_TEMPLATE; - ft = format_create(cmdq, 0); - format_defaults(ft, cmdq->state.c, dst_s, wl, wp); + ft = format_create(item, 0); + format_defaults(ft, item->state.c, dst_s, wl, wp); cp = format_expand(ft, template); - cmdq_print(cmdq, "%s", cp); + cmdq_print(item, "%s", cp); free(cp); format_free(ft); diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c index 6cf885bc..1ed00b9e 100644 --- a/cmd-capture-pane.c +++ b/cmd-capture-pane.c @@ -27,14 +27,13 @@ * Write the entire contents of a pane to a buffer or stdout. */ -static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *); -static char *cmd_capture_pane_append(char *, size_t *, char *, - size_t); -static char *cmd_capture_pane_pending(struct args *, - struct window_pane *, size_t *); -static char *cmd_capture_pane_history(struct args *, struct cmd_q *, - struct window_pane *, size_t *); +static char *cmd_capture_pane_append(char *, size_t *, char *, size_t); +static char *cmd_capture_pane_pending(struct args *, struct window_pane *, + size_t *); +static char *cmd_capture_pane_history(struct args *, struct cmdq_item *, + struct window_pane *, size_t *); const struct cmd_entry cmd_capture_pane_entry = { .name = "capture-pane", @@ -92,7 +91,8 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp, } static char * -cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq, + +cmd_capture_pane_history(struct args *args, struct cmdq_item *item, struct window_pane *wp, size_t *len) { struct grid *gd; @@ -109,7 +109,7 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq, gd = wp->saved_grid; if (gd == NULL) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "no alternate screen"); + cmdq_error(item, "no alternate screen"); return (NULL); } return (xstrdup("")); @@ -177,11 +177,11 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq, } static enum cmd_retval -cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct client *c; - struct window_pane *wp = cmdq->state.tflag.wp; + struct window_pane *wp = item->state.tflag.wp; char *buf, *cause; const char *bufname; size_t len; @@ -190,15 +190,15 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'P')) buf = cmd_capture_pane_pending(args, wp, &len); else - buf = cmd_capture_pane_history(args, cmdq, wp, &len); + buf = cmd_capture_pane_history(args, item, wp, &len); if (buf == NULL) return (CMD_RETURN_ERROR); if (args_has(args, 'p')) { - c = cmdq->client; + c = item->client; if (c == NULL || (c->session != NULL && !(c->flags & CLIENT_CONTROL))) { - cmdq_error(cmdq, "can't write to stdout"); + cmdq_error(item, "can't write to stdout"); free(buf); return (CMD_RETURN_ERROR); } @@ -213,7 +213,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) bufname = args_get(args, 'b'); if (paste_set(buf, len, bufname, &cause) != 0) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(cause); free(buf); return (CMD_RETURN_ERROR); diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c index fee4958a..ae619b6c 100644 --- a/cmd-choose-buffer.c +++ b/cmd-choose-buffer.c @@ -30,7 +30,8 @@ #define CHOOSE_BUFFER_TEMPLATE \ "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}" -static enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_buffer_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_choose_buffer_entry = { .name = "choose-buffer", @@ -46,11 +47,11 @@ const struct cmd_entry cmd_choose_buffer_entry = { }; static enum cmd_retval -cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; - struct winlink *wl = cmdq->state.tflag.wl; + struct client *c = item->state.c; + struct winlink *wl = item->state.tflag.wl; struct window_choose_data *cdata; struct paste_buffer *pb; char *action, *action_data; @@ -58,7 +59,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) u_int idx; if (c == NULL) { - cmdq_error(cmdq, "no client available"); + cmdq_error(item, "no client available"); return (CMD_RETURN_ERROR); } diff --git a/cmd-choose-client.c b/cmd-choose-client.c index 67d184b3..2a64da69 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -33,7 +33,8 @@ "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ "(last used #{t:client_activity})" -static enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_client_exec(struct cmd *, + struct cmdq_item *); static void cmd_choose_client_callback(struct window_choose_data *); @@ -55,19 +56,19 @@ struct cmd_choose_client_data { }; static enum cmd_retval -cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; struct client *c1; struct window_choose_data *cdata; - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; const char *template; char *action; u_int idx, cur; if (c == NULL) { - cmdq_error(cmdq, "no client available"); + cmdq_error(item, "no client available"); return (CMD_RETURN_ERROR); } @@ -86,7 +87,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq) TAILQ_FOREACH(c1, &clients, entry) { if (c1->session == NULL || c1->tty.path == NULL) continue; - if (c1 == cmdq->client) + if (c1 == item->client) cur = idx; cdata = window_choose_data_create(TREE_OTHER, c, c->session); diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index 13bbe2a7..65d55407 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -41,7 +41,7 @@ "#{window_index}: #{window_name}#{window_flags} " \ "\"#{pane_title}\"" -static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", @@ -84,12 +84,12 @@ const struct cmd_entry cmd_choose_window_entry = { }; static enum cmd_retval -cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; - struct winlink *wl = cmdq->state.tflag.wl, *wm; - struct session *s = cmdq->state.tflag.s, *s2; + struct client *c = item->state.c; + struct winlink *wl = item->state.tflag.wl, *wm; + struct session *s = item->state.tflag.s, *s2; struct window_choose_data *wcd = NULL; const char *ses_template, *win_template; char *final_win_action, *cur_win_template; @@ -103,7 +103,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq) ses_action = win_action = NULL; if (c == NULL) { - cmdq_error(cmdq, "no client available"); + cmdq_error(item, "no client available"); return (CMD_RETURN_ERROR); } diff --git a/cmd-clear-history.c b/cmd-clear-history.c index 46f1d4e6..1afd9053 100644 --- a/cmd-clear-history.c +++ b/cmd-clear-history.c @@ -24,7 +24,8 @@ * Clear pane history. */ -static enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_clear_history_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_clear_history_entry = { .name = "clear-history", @@ -40,12 +41,12 @@ const struct cmd_entry cmd_clear_history_entry = { }; static enum cmd_retval -cmd_clear_history_exec(__unused struct cmd *self, struct cmd_q *cmdq) +cmd_clear_history_exec(__unused struct cmd *self, struct cmdq_item *item) { - struct window_pane *wp = cmdq->state.tflag.wp; + struct window_pane *wp = item->state.tflag.wp; struct grid *gd; - gd = cmdq->state.tflag.wp->base.grid; + gd = item->state.tflag.wp->base.grid; if (wp->mode == &window_copy_mode) window_pane_reset_mode(wp); diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 5e21b2bc..4c1c8593 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -29,7 +29,8 @@ * Prompt for command in client. */ -static enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_command_prompt_exec(struct cmd *, + struct cmdq_item *); static int cmd_command_prompt_callback(void *, const char *); static void cmd_command_prompt_free(void *); @@ -59,12 +60,12 @@ struct cmd_command_prompt_cdata { }; static enum cmd_retval -cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const char *inputs, *prompts; struct cmd_command_prompt_cdata *cdata; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; char *prompt, *ptr, *input = NULL; size_t n; int flags; @@ -122,11 +123,11 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_command_prompt_error(struct cmd_q *cmdq, void *data) +cmd_command_prompt_error(struct cmdq_item *item, void *data) { char *error = data; - cmdq_error(cmdq, "%s", error); + cmdq_error(item, "%s", error); free(error); return (CMD_RETURN_NORMAL); @@ -138,7 +139,7 @@ cmd_command_prompt_callback(void *data, const char *s) struct cmd_command_prompt_cdata *cdata = data; struct client *c = cdata->c; struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; + struct cmdq_item *new_item; char *cause, *new_template, *prompt, *ptr; char *input = NULL; @@ -165,17 +166,17 @@ cmd_command_prompt_callback(void *data, const char *s) if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - new_cmdq = cmdq_get_callback(cmd_command_prompt_error, + new_item = cmdq_get_callback(cmd_command_prompt_error, cause); } else - new_cmdq = NULL; + new_item = NULL; } else { - new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); + new_item = cmdq_get_command(cmdlist, NULL, NULL, 0); cmd_list_free(cmdlist); } - if (new_cmdq != NULL) - cmdq_append(c, new_cmdq); + if (new_item != NULL) + cmdq_append(c, new_item); if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback) return (1); diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index 2dd52c81..d468bbc3 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -28,10 +28,11 @@ * Asks for confirmation before executing a command. */ -static enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_confirm_before_exec(struct cmd *, + struct cmdq_item *); -static int cmd_confirm_before_callback(void *, const char *); -static void cmd_confirm_before_free(void *); +static int cmd_confirm_before_callback(void *, const char *); +static void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { .name = "confirm-before", @@ -52,11 +53,11 @@ struct cmd_confirm_before_data { }; static enum cmd_retval -cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_confirm_before_data *cdata; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; char *cmd, *copy, *new_prompt, *ptr; const char *prompt; @@ -84,11 +85,11 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_confirm_before_error(struct cmd_q *cmdq, void *data) +cmd_confirm_before_error(struct cmdq_item *item, void *data) { char *error = data; - cmdq_error(cmdq, "%s", error); + cmdq_error(item, "%s", error); free(error); return (CMD_RETURN_NORMAL); @@ -100,7 +101,7 @@ cmd_confirm_before_callback(void *data, const char *s) struct cmd_confirm_before_data *cdata = data; struct client *c = cdata->client; struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; + struct cmdq_item *new_item; char *cause; if (c->flags & CLIENT_DEAD) @@ -113,17 +114,17 @@ cmd_confirm_before_callback(void *data, const char *s) if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - new_cmdq = cmdq_get_callback(cmd_confirm_before_error, + new_item = cmdq_get_callback(cmd_confirm_before_error, cause); } else - new_cmdq = NULL; + new_item = NULL; } else { - new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); + new_item = cmdq_get_command(cmdlist, NULL, NULL, 0); cmd_list_free(cmdlist); } - if (new_cmdq != NULL) - cmdq_append(c, new_cmdq); + if (new_item != NULL) + cmdq_append(c, new_item); return (0); } diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index dc880d56..448e7b9c 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -24,7 +24,7 @@ * Enter copy or clock mode. */ -static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_copy_mode_entry = { .name = "copy-mode", @@ -53,15 +53,15 @@ const struct cmd_entry cmd_clock_mode_entry = { }; static enum cmd_retval -cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->client; + struct client *c = item->client; struct session *s; - struct window_pane *wp = cmdq->state.tflag.wp; + struct window_pane *wp = item->state.tflag.wp; if (args_has(args, 'M')) { - if ((wp = cmd_mouse_pane(&cmdq->mouse, &s, NULL)) == NULL) + if ((wp = cmd_mouse_pane(&item->mouse, &s, NULL)) == NULL) return (CMD_RETURN_NORMAL); if (c == NULL || c->session != s) return (CMD_RETURN_NORMAL); @@ -80,7 +80,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'M')) { if (wp->mode != NULL && wp->mode != &window_copy_mode) return (CMD_RETURN_NORMAL); - window_copy_start_drag(c, &cmdq->mouse); + window_copy_start_drag(c, &item->mouse); } if (wp->mode == &window_copy_mode && args_has(self->args, 'u')) window_copy_pageup(wp, 0); diff --git a/cmd-detach-client.c b/cmd-detach-client.c index 814ba091..69225bae 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -26,7 +26,8 @@ * Detach a client. */ -static enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_detach_client_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_detach_client_entry = { .name = "detach-client", @@ -56,10 +57,10 @@ const struct cmd_entry cmd_suspend_client_entry = { }; static enum cmd_retval -cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c, *cloop; + struct client *c = item->state.c, *cloop; struct session *s; enum msgtype msgtype; @@ -76,7 +77,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) msgtype = MSG_DETACH; if (args_has(args, 's')) { - s = cmdq->state.sflag.s; + s = item->state.sflag.s; TAILQ_FOREACH(cloop, &clients, entry) { if (cloop->session == s) server_client_detach(cloop, msgtype); diff --git a/cmd-display-message.c b/cmd-display-message.c index 74fa7804..c57db579 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -32,7 +32,8 @@ "#{window_name}, current pane #{pane_index} " \ "- (%H:%M %d-%b-%y)" -static enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_display_message_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_display_message_entry = { .name = "display-message", @@ -50,19 +51,19 @@ const struct cmd_entry cmd_display_message_entry = { }; static enum cmd_retval -cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; - struct window_pane *wp = cmdq->state.tflag.wp; + struct client *c = item->state.c; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; + struct window_pane *wp = item->state.tflag.wp; const char *template; char *msg; struct format_tree *ft; if (args_has(args, 'F') && args->argc != 0) { - cmdq_error(cmdq, "only one of -F or argument must be given"); + cmdq_error(item, "only one of -F or argument must be given"); return (CMD_RETURN_ERROR); } @@ -72,12 +73,12 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq) if (template == NULL) template = DISPLAY_MESSAGE_TEMPLATE; - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, wl, wp); msg = format_expand_time(ft, template, time(NULL)); if (args_has(self->args, 'p')) - cmdq_print(cmdq, "%s", msg); + cmdq_print(item, "%s", msg); else if (c != NULL) status_message_set(c, "%s", msg); free(msg); diff --git a/cmd-display-panes.c b/cmd-display-panes.c index 471bec02..65813804 100644 --- a/cmd-display-panes.c +++ b/cmd-display-panes.c @@ -27,10 +27,11 @@ * Display panes on a client. */ -static enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_display_panes_exec(struct cmd *, + struct cmdq_item *); -static void cmd_display_panes_callback(struct client *, - struct window_pane *); +static void cmd_display_panes_callback(struct client *, + struct window_pane *); const struct cmd_entry cmd_display_panes_entry = { .name = "display-panes", @@ -46,10 +47,10 @@ const struct cmd_entry cmd_display_panes_entry = { }; static enum cmd_retval -cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; if (c->identify_callback != NULL) return (CMD_RETURN_NORMAL); @@ -66,11 +67,11 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_display_panes_error(struct cmd_q *cmdq, void *data) +cmd_display_panes_error(struct cmdq_item *item, void *data) { char *error = data; - cmdq_error(cmdq, "%s", error); + cmdq_error(item, "%s", error); free(error); return (CMD_RETURN_NORMAL); @@ -79,9 +80,9 @@ cmd_display_panes_error(struct cmd_q *cmdq, void *data) static void cmd_display_panes_callback(struct client *c, struct window_pane *wp) { - struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; - char *template, *cmd, *expanded, *cause; + struct cmd_list *cmdlist; + struct cmdq_item *new_item; + char *template, *cmd, *expanded, *cause; template = c->identify_callback_data; if (wp == NULL) @@ -91,17 +92,17 @@ cmd_display_panes_callback(struct client *c, struct window_pane *wp) if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - new_cmdq = cmdq_get_callback(cmd_display_panes_error, + new_item = cmdq_get_callback(cmd_display_panes_error, cause); } else - new_cmdq = NULL; + new_item = NULL; } else { - new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); + new_item = cmdq_get_command(cmdlist, NULL, NULL, 0); cmd_list_free(cmdlist); } - if (new_cmdq != NULL) - cmdq_append(c, new_cmdq); + if (new_item != NULL) + cmdq_append(c, new_item); free(cmd); free(expanded); diff --git a/cmd-find-window.c b/cmd-find-window.c index 6ab6fbcf..129f6afe 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -33,9 +33,9 @@ "[#{window_width}x#{window_height}] " \ "(#{window_panes} panes) #{window_find_matches}" -static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *); -static void cmd_find_window_callback(struct window_choose_data *); +static void cmd_find_window_callback(struct window_choose_data *); /* Flags for determining matching behavior. */ #define CMD_FIND_WINDOW_BY_TITLE 0x1 @@ -139,13 +139,13 @@ cmd_find_window_match(struct cmd_find_window_list *find_list, } static enum cmd_retval -cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; struct window_choose_data *cdata; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl, *wm; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl, *wm; struct cmd_find_window_list find_list; struct cmd_find_window_data *find_data; struct cmd_find_window_data *find_data1; @@ -154,7 +154,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq) u_int i, match_flags; if (c == NULL) { - cmdq_error(cmdq, "no client available"); + cmdq_error(item, "no client available"); return (CMD_RETURN_ERROR); } @@ -172,7 +172,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq) free(searchstr); if (TAILQ_EMPTY(&find_list)) { - cmdq_error(cmdq, "no windows matching: %s", str); + cmdq_error(item, "no windows matching: %s", str); return (CMD_RETURN_ERROR); } diff --git a/cmd-find.c b/cmd-find.c index dc4cd889..a2f9aa4e 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -37,7 +37,7 @@ static int cmd_find_best_winlink_with_window(struct cmd_find_state *); static int cmd_find_current_session_with_client(struct cmd_find_state *); static int cmd_find_current_session(struct cmd_find_state *); -static struct client *cmd_find_current_client(struct cmd_q *); +static struct client *cmd_find_current_client(struct cmdq_item *); static const char *cmd_find_map_table(const char *[][2], const char *); @@ -191,8 +191,8 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs) u_int ssize; struct session *s; - if (fs->cmdq != NULL && fs->cmdq->client != NULL) { - fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w); + if (fs->item != NULL && fs->item->client != NULL) { + fs->s = cmd_find_try_TMUX(fs->item->client, fs->w); if (fs->s != NULL) return (cmd_find_best_winlink_with_window(fs)); } @@ -255,9 +255,9 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) * sessions to those containing that pane (we still use the current * window in the best session). */ - if (fs->cmdq != NULL && fs->cmdq->client->tty.path != NULL) { + if (fs->item != NULL && fs->item->client->tty.path != NULL) { RB_FOREACH(wp, window_pane_tree, &all_window_panes) { - if (strcmp(wp->tty, fs->cmdq->client->tty.path) == 0) + if (strcmp(wp->tty, fs->item->client->tty.path) == 0) break; } } else @@ -291,8 +291,8 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs) unknown_pane: fs->s = NULL; - if (fs->cmdq != NULL) - fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL); + if (fs->item != NULL) + fs->s = cmd_find_try_TMUX(fs->item->client, NULL); if (fs->s == NULL) fs->s = cmd_find_best_session(NULL, 0, fs->flags); if (fs->s == NULL) @@ -313,12 +313,12 @@ static int cmd_find_current_session(struct cmd_find_state *fs) { /* If we know the current client, use it. */ - if (fs->cmdq != NULL && fs->cmdq->client != NULL) { - log_debug("%s: have client %p%s", __func__, fs->cmdq->client, - fs->cmdq->client->session == NULL ? "" : " (with session)"); - if (fs->cmdq->client->session == NULL) + if (fs->item != NULL && fs->item->client != NULL) { + log_debug("%s: have client %p%s", __func__, fs->item->client, + fs->item->client->session == NULL ? "" : " (with session)"); + if (fs->item->client->session == NULL) return (cmd_find_current_session_with_client(fs)); - fs->s = fs->cmdq->client->session; + fs->s = fs->item->client->session; fs->wl = fs->s->curw; fs->idx = fs->wl->idx; fs->w = fs->wl->window; @@ -340,7 +340,7 @@ cmd_find_current_session(struct cmd_find_state *fs) /* Work out the best current client. */ static struct client * -cmd_find_current_client(struct cmd_q *cmdq) +cmd_find_current_client(struct cmdq_item *item) { struct cmd_find_state current; struct session *s; @@ -348,14 +348,14 @@ cmd_find_current_client(struct cmd_q *cmdq) u_int csize; /* If the queue client has a session, use it. */ - if (cmdq->client != NULL && cmdq->client->session != NULL) { - log_debug("%s: using cmdq %p client %p", __func__, cmdq, - cmdq->client); - return (cmdq->client); + if (item->client != NULL && item->client->session != NULL) { + log_debug("%s: using item %p client %p", __func__, item, + item->client); + return (item->client); } /* Otherwise find the current session. */ - cmd_find_clear_state(¤t, cmdq, 0); + cmd_find_clear_state(¤t, item, 0); if (cmd_find_current_session(¤t) != 0) return (NULL); @@ -792,11 +792,12 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane) /* Clear state. */ void -cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) +cmd_find_clear_state(struct cmd_find_state *fs, struct cmdq_item *item, + int flags) { memset(fs, 0, sizeof *fs); - fs->cmdq = cmdq; + fs->item = item; fs->flags = flags; fs->idx = -1; @@ -951,12 +952,12 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp) /* Find current state. */ int -cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) +cmd_find_current(struct cmd_find_state *fs, struct cmdq_item *item, int flags) { - cmd_find_clear_state(fs, cmdq, flags); + cmd_find_clear_state(fs, item, flags); if (cmd_find_current_session(fs) != 0) { if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (-1); } return (0); @@ -968,7 +969,8 @@ cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags) */ int cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, - struct cmd_q *cmdq, const char *target, enum cmd_find_type type, int flags) + struct cmdq_item *item, const char *target, enum cmd_find_type type, + int flags) { struct mouse_event *m; char *colon, *period, *copy = NULL; @@ -979,17 +981,17 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, log_debug("%s: target none, type %d", __func__, type); else log_debug("%s: target %s, type %d", __func__, target, type); - log_debug("%s: cmdq %p, flags %#x", __func__, cmdq, flags); + log_debug("%s: item %p, flags %#x", __func__, item, flags); /* Clear new state. */ - cmd_find_clear_state(fs, cmdq, flags); + cmd_find_clear_state(fs, item, flags); /* Find current state. */ if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { fs->current = &marked_pane; log_debug(" current is marked pane"); - } else if (cmd_find_valid_state(&cmdq->current)) { - fs->current = &cmdq->current; + } else if (cmd_find_valid_state(&item->current)) { + fs->current = &item->current; log_debug(" current is from queue"); } else { fs->current = current; @@ -1005,7 +1007,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, /* Mouse target is a plain = or {mouse}. */ if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { - m = &cmdq->mouse; + m = &item->mouse; switch (type) { case CMD_FIND_PANE: fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); @@ -1023,7 +1025,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, } if (fs->wp == NULL) { if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "no mouse target"); + cmdq_error(item, "no mouse target"); goto error; } goto found; @@ -1033,7 +1035,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, if (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) { if (!server_check_marked()) { if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "no marked target"); + cmdq_error(item, "no marked target"); goto error; } cmd_find_copy_state(fs, &marked_pane); @@ -1119,7 +1121,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, /* No pane is allowed if want an index. */ if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) { if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "can't specify pane here"); + cmdq_error(item, "can't specify pane here"); goto error; } @@ -1218,23 +1220,23 @@ found: no_session: if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "can't find session %s", session); + cmdq_error(item, "can't find session %s", session); goto error; no_window: if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "can't find window %s", window); + cmdq_error(item, "can't find window %s", window); goto error; no_pane: if (~flags & CMD_FIND_QUIET) - cmdq_error(cmdq, "can't find pane %s", pane); + cmdq_error(item, "can't find pane %s", pane); goto error; } /* Find the target client or report an error and return NULL. */ struct client * -cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet) +cmd_find_client(struct cmdq_item *item, const char *target, int quiet) { struct client *c; char *copy; @@ -1242,10 +1244,10 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet) const char *path; /* A NULL argument means the current client. */ - if (cmdq != NULL && target == NULL) { - c = cmd_find_current_client(cmdq); + if (item != NULL && target == NULL) { + c = cmd_find_current_client(item); if (c == NULL && !quiet) - cmdq_error(cmdq, "no current client"); + cmdq_error(item, "no current client"); log_debug("%s: no target, return %p", __func__, c); return (c); } @@ -1275,7 +1277,7 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet) /* If no client found, report an error. */ if (c == NULL && !quiet) - cmdq_error(cmdq, "can't find client %s", copy); + cmdq_error(item, "can't find client %s", copy); free(copy); log_debug("%s: target %s, return %p", __func__, target, c); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 7192b204..5dfb5a19 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -29,11 +29,11 @@ * Executes a tmux command if a shell command returns true or false. */ -static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_if_shell_error(struct cmd_q *, void *); -static void cmd_if_shell_callback(struct job *); -static void cmd_if_shell_free(void *); +static enum cmd_retval cmd_if_shell_error(struct cmdq_item *, void *); +static void cmd_if_shell_callback(struct job *); +static void cmd_if_shell_free(void *); const struct cmd_entry cmd_if_shell_entry = { .name = "if-shell", @@ -57,33 +57,33 @@ struct cmd_if_shell_data { char *cmd_else; struct client *client; - struct cmd_q *cmdq; + struct cmdq_item *item; struct mouse_event mouse; }; static enum cmd_retval -cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_if_shell_data *cdata; char *shellcmd, *cmd, *cause; struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; - struct window_pane *wp = cmdq->state.tflag.wp; + struct cmdq_item *new_item; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; + struct window_pane *wp = item->state.tflag.wp; struct format_tree *ft; const char *cwd; - if (cmdq->client != NULL && cmdq->client->session == NULL) - cwd = cmdq->client->cwd; + if (item->client != NULL && item->client->session == NULL) + cwd = item->client->cwd; else if (s != NULL) cwd = s->cwd; else cwd = NULL; - ft = format_create(cmdq, 0); - format_defaults(ft, cmdq->state.c, s, wl, wp); + ft = format_create(item, 0); + format_defaults(ft, item->state.c, s, wl, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); @@ -98,13 +98,13 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(cause); } return (CMD_RETURN_ERROR); } - new_cmdq = cmdq_get_command(cmdlist, NULL, &cmdq->mouse, 0); - cmdq_insert_after(cmdq, new_cmdq); + new_item = cmdq_get_command(cmdlist, NULL, &item->mouse, 0); + cmdq_insert_after(item, new_item); cmd_list_free(cmdlist); return (CMD_RETURN_NORMAL); } @@ -121,14 +121,14 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) else cdata->cmd_else = NULL; - cdata->client = cmdq->client; + cdata->client = item->client; cdata->client->references++; if (!args_has(args, 'b')) - cdata->cmdq = cmdq; + cdata->item = item; else - cdata->cmdq = NULL; - memcpy(&cdata->mouse, &cmdq->mouse, sizeof cdata->mouse); + cdata->item = NULL; + memcpy(&cdata->mouse, &item->mouse, sizeof cdata->mouse); job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free, cdata); @@ -140,11 +140,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_if_shell_error(struct cmd_q *cmdq, void *data) +cmd_if_shell_error(struct cmdq_item *item, void *data) { char *error = data; - cmdq_error(cmdq, "%s", error); + cmdq_error(item, "%s", error); free(error); return (CMD_RETURN_NORMAL); @@ -156,7 +156,7 @@ cmd_if_shell_callback(struct job *job) struct cmd_if_shell_data *cdata = job->data; struct client *c = cdata->client; struct cmd_list *cmdlist; - struct cmd_q *new_cmdq; + struct cmdq_item *new_item; char *cause, *cmd, *file = cdata->file; u_int line = cdata->line; @@ -169,24 +169,24 @@ cmd_if_shell_callback(struct job *job) if (cmd_string_parse(cmd, &cmdlist, file, line, &cause) != 0) { if (cause != NULL) - new_cmdq = cmdq_get_callback(cmd_if_shell_error, cause); + new_item = cmdq_get_callback(cmd_if_shell_error, cause); else - new_cmdq = NULL; + new_item = NULL; } else { - new_cmdq = cmdq_get_command(cmdlist, NULL, &cdata->mouse, 0); + new_item = cmdq_get_command(cmdlist, NULL, &cdata->mouse, 0); cmd_list_free(cmdlist); } - if (new_cmdq != NULL) { - if (cdata->cmdq == NULL) - cmdq_append(c, new_cmdq); + if (new_item != NULL) { + if (cdata->item == NULL) + cmdq_append(c, new_item); else - cmdq_insert_after(cdata->cmdq, new_cmdq); + cmdq_insert_after(cdata->item, new_item); } out: - if (cdata->cmdq != NULL) - cdata->cmdq->flags &= ~CMD_Q_WAITING; + if (cdata->item != NULL) + cdata->item->flags &= ~CMDQ_WAITING; } static void diff --git a/cmd-join-pane.c b/cmd-join-pane.c index c5f6cc16..557de091 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -28,7 +28,7 @@ * Join or move a pane into another (like split/swap/kill). */ -static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_join_pane_entry = { .name = "join-pane", @@ -59,7 +59,7 @@ const struct cmd_entry cmd_move_pane_entry = { }; static enum cmd_retval -cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct session *dst_s; @@ -77,24 +77,24 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq) else not_same_window = 0; - dst_s = cmdq->state.tflag.s; - dst_wl = cmdq->state.tflag.wl; - dst_wp = cmdq->state.tflag.wp; + dst_s = item->state.tflag.s; + dst_wl = item->state.tflag.wl; + dst_wp = item->state.tflag.wp; dst_w = dst_wl->window; dst_idx = dst_wl->idx; server_unzoom_window(dst_w); - src_wl = cmdq->state.sflag.wl; - src_wp = cmdq->state.sflag.wp; + src_wl = item->state.sflag.wl; + src_wp = item->state.sflag.wp; src_w = src_wl->window; server_unzoom_window(src_w); if (not_same_window && src_w == dst_w) { - cmdq_error(cmdq, "can't join a pane to its own window"); + cmdq_error(item, "can't join a pane to its own window"); return (CMD_RETURN_ERROR); } if (!not_same_window && src_wp == dst_wp) { - cmdq_error(cmdq, "source and target panes must be different"); + cmdq_error(item, "source and target panes must be different"); return (CMD_RETURN_ERROR); } @@ -106,14 +106,14 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'l')) { size = args_strtonum(args, 'l', 0, INT_MAX, &cause); if (cause != NULL) { - cmdq_error(cmdq, "size %s", cause); + cmdq_error(item, "size %s", cause); free(cause); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { percentage = args_strtonum(args, 'p', 0, 100, &cause); if (cause != NULL) { - cmdq_error(cmdq, "percentage %s", cause); + cmdq_error(item, "percentage %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -124,7 +124,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq) } lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0); if (lc == NULL) { - cmdq_error(cmdq, "create pane failed: pane too small"); + cmdq_error(item, "create pane failed: pane too small"); return (CMD_RETURN_ERROR); } diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c index 76829aa3..59bbd19e 100644 --- a/cmd-kill-pane.c +++ b/cmd-kill-pane.c @@ -26,7 +26,7 @@ * Kill pane. */ -static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_kill_pane_entry = { .name = "kill-pane", @@ -42,10 +42,10 @@ const struct cmd_entry cmd_kill_pane_entry = { }; static enum cmd_retval -cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item) { - struct winlink *wl = cmdq->state.tflag.wl; - struct window_pane *loopwp, *tmpwp, *wp = cmdq->state.tflag.wp; + struct winlink *wl = item->state.tflag.wl; + struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp; server_unzoom_window(wl->window); diff --git a/cmd-kill-server.c b/cmd-kill-server.c index bbb4e8a0..d7eba692 100644 --- a/cmd-kill-server.c +++ b/cmd-kill-server.c @@ -27,7 +27,7 @@ * Kill the server and do nothing else. */ -static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_kill_server_entry = { .name = "kill-server", @@ -52,7 +52,7 @@ const struct cmd_entry cmd_start_server_entry = { }; static enum cmd_retval -cmd_kill_server_exec(struct cmd *self, __unused struct cmd_q *cmdq) +cmd_kill_server_exec(struct cmd *self, __unused struct cmdq_item *item) { if (self->entry == &cmd_kill_server_entry) kill(getpid(), SIGTERM); diff --git a/cmd-kill-session.c b/cmd-kill-session.c index ec7d5fb2..200fe4f9 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -27,7 +27,7 @@ * Note this deliberately has no alias to make it hard to hit by accident. */ -static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_kill_session_entry = { .name = "kill-session", @@ -43,13 +43,13 @@ const struct cmd_entry cmd_kill_session_entry = { }; static enum cmd_retval -cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct session *s, *sloop, *stmp; struct winlink *wl; - s = cmdq->state.tflag.s; + s = item->state.tflag.s; if (args_has(args, 'C')) { RB_FOREACH(wl, winlinks, &s->windows) { diff --git a/cmd-kill-window.c b/cmd-kill-window.c index c7534d5c..6365aecb 100644 --- a/cmd-kill-window.c +++ b/cmd-kill-window.c @@ -24,7 +24,7 @@ * Destroy window. */ -static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_kill_window_entry = { .name = "kill-window", @@ -53,16 +53,16 @@ const struct cmd_entry cmd_unlink_window_entry = { }; static enum cmd_retval -cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.tflag.wl, *wl2, *wl3; + struct winlink *wl = item->state.tflag.wl, *wl2, *wl3; struct window *w = wl->window; - struct session *s = cmdq->state.tflag.s; + struct session *s = item->state.tflag.s; if (self->entry == &cmd_unlink_window_entry) { if (!args_has(self->args, 'k') && !session_is_linked(s, w)) { - cmdq_error(cmdq, "window only linked to one session"); + cmdq_error(item, "window only linked to one session"); return (CMD_RETURN_ERROR); } server_unlink_window(s, wl); diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index f474b398..c67c3524 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -30,7 +30,7 @@ #define LIST_BUFFERS_TEMPLATE \ "#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\"" -static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_list_buffers_entry = { .name = "list-buffers", @@ -44,7 +44,7 @@ const struct cmd_entry cmd_list_buffers_entry = { }; static enum cmd_retval -cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct paste_buffer *pb; @@ -57,11 +57,11 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq) pb = NULL; while ((pb = paste_walk(pb)) != NULL) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults_paste_buffer(ft, pb); line = format_expand(ft, template); - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); format_free(ft); diff --git a/cmd-list-clients.c b/cmd-list-clients.c index d4bf02a9..f07cd45e 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -33,7 +33,7 @@ "[#{client_width}x#{client_height} #{client_termname}]" \ "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" -static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_list_clients_entry = { .name = "list-clients", @@ -49,7 +49,7 @@ const struct cmd_entry cmd_list_clients_entry = { }; static enum cmd_retval -cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct client *c; @@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq) char *line; if (args_has(args, 't')) - s = cmdq->state.tflag.s; + s = item->state.tflag.s; else s = NULL; @@ -72,12 +72,12 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq) if (c->session == NULL || (s != NULL && s != c->session)) continue; - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_add(ft, "line", "%u", idx); format_defaults(ft, c, NULL, NULL, NULL); line = format_expand(ft, template); - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); format_free(ft); diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 7823f475..f3462a10 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -27,10 +27,11 @@ * List key bindings. */ -static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *); -static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmdq_item *); +static enum cmd_retval cmd_list_keys_commands(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_list_keys_entry = { .name = "list-keys", @@ -55,7 +56,7 @@ const struct cmd_entry cmd_list_commands_entry = { }; static enum cmd_retval -cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct key_table *table; @@ -65,14 +66,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) int repeat, width, tablewidth, keywidth; if (self->entry == &cmd_list_commands_entry) - return (cmd_list_keys_commands(self, cmdq)); + return (cmd_list_keys_commands(self, item)); if (args_has(args, 't')) - return (cmd_list_keys_table(self, cmdq)); + return (cmd_list_keys_table(self, item)); tablename = args_get(args, 'T'); if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { - cmdq_error(cmdq, "table %s doesn't exist", tablename); + cmdq_error(item, "table %s doesn't exist", tablename); return (CMD_RETURN_ERROR); } @@ -124,7 +125,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) strlcat(tmp, cp, sizeof tmp); free(cp); - cmdq_print(cmdq, "bind-key %s", tmp); + cmdq_print(item, "bind-key %s", tmp); } } @@ -132,7 +133,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) +cmd_list_keys_table(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const char *tablename, *cmdstr; @@ -142,7 +143,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { - cmdq_error(cmdq, "unknown key table: %s", tablename); + cmdq_error(item, "unknown key table: %s", tablename); return (CMD_RETURN_ERROR); } @@ -156,7 +157,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) RB_FOREACH(mbind, mode_key_tree, mtab->tree) { cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); if (cmdstr != NULL) { - cmdq_print(cmdq, "bind-key -t %s %*s %s", + cmdq_print(item, "bind-key -t %s %*s %s", mtab->name, (int)keywidth, key_string_lookup_key(mbind->key), cmdstr); } @@ -166,13 +167,13 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq) +cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const struct cmd_entry **entryp; const struct cmd_entry *entry; struct format_tree *ft; - const char *template; + const char *template, *s; char *line; if ((template = args_get(args, 'F')) == NULL) { @@ -181,25 +182,27 @@ cmd_list_keys_commands(struct cmd *self, struct cmd_q *cmdq) "#{command_list_usage}"; } - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, NULL, NULL, NULL, NULL); for (entryp = cmd_table; *entryp != NULL; entryp++) { entry = *entryp; format_add(ft, "command_list_name", "%s", entry->name); - if (entry->alias != NULL) { - format_add(ft, "command_list_alias", "%s", - entry->alias); - } - if (entry->alias != NULL) { - format_add(ft, "command_list_usage", "%s", - entry->usage); - } + if (entry->alias != NULL) + s = entry->alias; + else + s = ""; + format_add(ft, "command_list_alias", "%s", s); + if (entry->usage != NULL) + s = entry->usage; + else + s = ""; + format_add(ft, "command_list_usage", "%s", s); line = format_expand(ft, template); if (*line != '\0') - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); } diff --git a/cmd-list-panes.c b/cmd-list-panes.c index 20663fd1..341bdd68 100644 --- a/cmd-list-panes.c +++ b/cmd-list-panes.c @@ -26,13 +26,13 @@ * List panes on given window. */ -static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmdq_item *); -static void cmd_list_panes_server(struct cmd *, struct cmd_q *); +static void cmd_list_panes_server(struct cmd *, struct cmdq_item *); static void cmd_list_panes_session(struct cmd *, struct session *, - struct cmd_q *, int); + struct cmdq_item *, int); static void cmd_list_panes_window(struct cmd *, struct session *, - struct winlink *, struct cmd_q *, int); + struct winlink *, struct cmdq_item *, int); const struct cmd_entry cmd_list_panes_entry = { .name = "list-panes", @@ -48,44 +48,44 @@ const struct cmd_entry cmd_list_panes_entry = { }; static enum cmd_retval -cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; if (args_has(args, 'a')) - cmd_list_panes_server(self, cmdq); + cmd_list_panes_server(self, item); else if (args_has(args, 's')) - cmd_list_panes_session(self, s, cmdq, 1); + cmd_list_panes_session(self, s, item, 1); else - cmd_list_panes_window(self, s, wl, cmdq, 0); + cmd_list_panes_window(self, s, wl, item, 0); return (CMD_RETURN_NORMAL); } static void -cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq) +cmd_list_panes_server(struct cmd *self, struct cmdq_item *item) { struct session *s; RB_FOREACH(s, sessions, &sessions) - cmd_list_panes_session(self, s, cmdq, 2); + cmd_list_panes_session(self, s, item, 2); } static void -cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, - int type) +cmd_list_panes_session(struct cmd *self, struct session *s, + struct cmdq_item *item, int type) { struct winlink *wl; RB_FOREACH(wl, winlinks, &s->windows) - cmd_list_panes_window(self, s, wl, cmdq, type); + cmd_list_panes_window(self, s, wl, item, type); } static void cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, - struct cmd_q *cmdq, int type) + struct cmdq_item *item, int type) { struct args *args = self->args; struct window_pane *wp; @@ -123,12 +123,12 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, n = 0; TAILQ_FOREACH(wp, &wl->window->panes, entry) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, wp); line = format_expand(ft, template); - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); format_free(ft); diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index bc352d25..d90c8970 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -36,7 +36,8 @@ "#{session_group}#{?session_grouped,),}" \ "#{?session_attached, (attached),}" -static enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_sessions_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_list_sessions_entry = { .name = "list-sessions", @@ -50,7 +51,7 @@ const struct cmd_entry cmd_list_sessions_entry = { }; static enum cmd_retval -cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct session *s; @@ -64,12 +65,12 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq) n = 0; RB_FOREACH(s, sessions, &sessions) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, NULL, NULL); line = format_expand(ft, template); - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); format_free(ft); diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 9d8a615c..cd7498f0 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -39,11 +39,11 @@ "(#{window_panes} panes) " \ "[#{window_width}x#{window_height}] " -static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmdq_item *); -static void cmd_list_windows_server(struct cmd *, struct cmd_q *); +static void cmd_list_windows_server(struct cmd *, struct cmdq_item *); static void cmd_list_windows_session(struct cmd *, struct session *, - struct cmd_q *, int); + struct cmdq_item *, int); const struct cmd_entry cmd_list_windows_entry = { .name = "list-windows", @@ -59,30 +59,30 @@ const struct cmd_entry cmd_list_windows_entry = { }; static enum cmd_retval -cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; if (args_has(args, 'a')) - cmd_list_windows_server(self, cmdq); + cmd_list_windows_server(self, item); else - cmd_list_windows_session(self, cmdq->state.tflag.s, cmdq, 0); + cmd_list_windows_session(self, item->state.tflag.s, item, 0); return (CMD_RETURN_NORMAL); } static void -cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq) +cmd_list_windows_server(struct cmd *self, struct cmdq_item *item) { struct session *s; RB_FOREACH(s, sessions, &sessions) - cmd_list_windows_session(self, s, cmdq, 1); + cmd_list_windows_session(self, s, item, 1); } static void cmd_list_windows_session(struct cmd *self, struct session *s, - struct cmd_q *cmdq, int type) + struct cmdq_item *item, int type) { struct args *args = self->args; struct winlink *wl; @@ -105,12 +105,12 @@ cmd_list_windows_session(struct cmd *self, struct session *s, n = 0; RB_FOREACH(wl, winlinks, &s->windows) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, NULL); line = format_expand(ft, template); - cmdq_print(cmdq, "%s", line); + cmdq_print(item, "%s", line); free(line); format_free(ft); diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index ae071968..2484bb66 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -31,9 +31,9 @@ * Loads a paste buffer from a file. */ -static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmdq_item *); -static void cmd_load_buffer_callback(struct client *, int, void *); +static void cmd_load_buffer_callback(struct client *, int, void *); const struct cmd_entry cmd_load_buffer_entry = { .name = "load-buffer", @@ -47,16 +47,16 @@ const struct cmd_entry cmd_load_buffer_entry = { }; struct cmd_load_buffer_data { - struct cmd_q *cmdq; - char *bufname; + struct cmdq_item *item; + char *bufname; }; static enum cmd_retval -cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_load_buffer_data *cdata; - struct client *c = cmdq->client; + struct client *c = item->client; struct session *s; FILE *f; const char *path, *bufname, *cwd; @@ -72,13 +72,13 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) path = args->argv[0]; if (strcmp(path, "-") == 0) { cdata = xcalloc(1, sizeof *cdata); - cdata->cmdq = cmdq; + cdata->item = item; cdata->bufname = xstrdup(bufname); error = server_set_stdin_callback(c, cmd_load_buffer_callback, cdata, &cause); if (error != 0) { - cmdq_error(cmdq, "%s: %s", path, cause); + cmdq_error(item, "%s: %s", path, cause); free(cause); return (CMD_RETURN_ERROR); } @@ -98,13 +98,13 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) xasprintf(&file, "%s/%s", cwd, path); if (realpath(file, resolved) == NULL && strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { - cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG)); + cmdq_error(item, "%s: %s", file, strerror(ENAMETOOLONG)); return (CMD_RETURN_ERROR); } f = fopen(resolved, "rb"); free(file); if (f == NULL) { - cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); + cmdq_error(item, "%s: %s", resolved, strerror(errno)); return (CMD_RETURN_ERROR); } @@ -113,14 +113,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) while ((ch = getc(f)) != EOF) { /* Do not let the server die due to memory exhaustion. */ if ((new_pdata = realloc(pdata, psize + 2)) == NULL) { - cmdq_error(cmdq, "realloc error: %s", strerror(errno)); + cmdq_error(item, "realloc error: %s", strerror(errno)); goto error; } pdata = new_pdata; pdata[psize++] = ch; } if (ferror(f)) { - cmdq_error(cmdq, "%s: read error", resolved); + cmdq_error(item, "%s: read error", resolved); goto error; } if (pdata != NULL) @@ -129,7 +129,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) fclose(f); if (paste_set(pdata, psize, bufname, &cause) != 0) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(pdata); free(cause); return (CMD_RETURN_ERROR); @@ -180,7 +180,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data) free(cause); } out: - cdata->cmdq->flags &= ~CMD_Q_WAITING; + cdata->item->flags &= ~CMDQ_WAITING; free(cdata->bufname); free(cdata); diff --git a/cmd-lock-server.c b/cmd-lock-server.c index b501efe8..117c423f 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -24,7 +24,7 @@ * Lock commands. */ -static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_lock_server_entry = { .name = "lock-server", @@ -64,14 +64,14 @@ const struct cmd_entry cmd_lock_client_entry = { }; static enum cmd_retval -cmd_lock_server_exec(struct cmd *self, __unused struct cmd_q *cmdq) +cmd_lock_server_exec(struct cmd *self, __unused struct cmdq_item *item) { if (self->entry == &cmd_lock_server_entry) server_lock(); else if (self->entry == &cmd_lock_session_entry) - server_lock_session(cmdq->state.tflag.s); + server_lock_session(item->state.tflag.s); else - server_lock_client(cmdq->state.c); + server_lock_client(item->state.c); recalculate_sizes(); diff --git a/cmd-move-window.c b/cmd-move-window.c index 1d423646..7f5cb74a 100644 --- a/cmd-move-window.c +++ b/cmd-move-window.c @@ -26,7 +26,7 @@ * Move a window. */ -static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_move_window_entry = { .name = "move-window", @@ -57,14 +57,14 @@ const struct cmd_entry cmd_link_window_entry = { }; static enum cmd_retval -cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_move_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *src = cmdq->state.sflag.s; - struct session *dst = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.sflag.wl; + struct session *src = item->state.sflag.s; + struct session *dst = item->state.tflag.s; + struct winlink *wl = item->state.sflag.wl; char *cause; - int idx = cmdq->state.tflag.idx, kflag, dflag, sflag; + int idx = item->state.tflag.idx, kflag, dflag, sflag; if (args_has(args, 'r')) { session_renumber_windows(dst); @@ -84,7 +84,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { - cmdq_error(cmdq, "can't link window: %s", cause); + cmdq_error(item, "can't link window: %s", cause); free(cause); return (CMD_RETURN_ERROR); } diff --git a/cmd-new-session.c b/cmd-new-session.c index e587e5ee..f6e728e4 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -33,7 +33,7 @@ #define NEW_SESSION_TEMPLATE "#{session_name}:" -static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_new_session_entry = { .name = "new-session", @@ -64,12 +64,12 @@ const struct cmd_entry cmd_has_session_entry = { }; static enum cmd_retval -cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->client; + struct client *c = item->client; struct session *s, *as; - struct session *groupwith = cmdq->state.tflag.s; + struct session *groupwith = item->state.tflag.s; struct window *w; struct environ *env; struct termios tio, *tiop; @@ -91,37 +91,37 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) } if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) { - cmdq_error(cmdq, "command or window name given with target"); + cmdq_error(item, "command or window name given with target"); return (CMD_RETURN_ERROR); } newname = args_get(args, 's'); if (newname != NULL) { if (!session_check_name(newname)) { - cmdq_error(cmdq, "bad session name: %s", newname); + cmdq_error(item, "bad session name: %s", newname); return (CMD_RETURN_ERROR); } if ((as = session_find(newname)) != NULL) { if (args_has(args, 'A')) { /* - * This cmdq is now destined for + * This item is now destined for * attach-session. Because attach-session * will have already been prepared, copy this * session into its tflag so it can be used. */ - cmd_find_from_session(&cmdq->state.tflag, as); - return (cmd_attach_session(cmdq, + cmd_find_from_session(&item->state.tflag, as); + return (cmd_attach_session(item, args_has(args, 'D'), 0, NULL, args_has(args, 'E'))); } - cmdq_error(cmdq, "duplicate session: %s", newname); + cmdq_error(item, "duplicate session: %s", newname); return (CMD_RETURN_ERROR); } } if ((target = args_get(args, 't')) != NULL) { if (groupwith == NULL) { - cmdq_error(cmdq, "no such session: %s", target); + cmdq_error(item, "no such session: %s", target); goto error; } } else @@ -139,7 +139,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) /* Get the new session working directory. */ if (args_has(args, 'c')) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, NULL, NULL, NULL); to_free = cwd = format_expand(ft, args_get(args, 'c')); format_free(ft); @@ -158,8 +158,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) * over. */ if (!detached && !already_attached && c->tty.fd != -1) { - if (server_client_check_nested(cmdq->client)) { - cmdq_error(cmdq, "sessions should be nested with care, " + if (server_client_check_nested(item->client)) { + cmdq_error(item, "sessions should be nested with care, " "unset $TMUX to force"); return (CMD_RETURN_ERROR); } @@ -172,7 +172,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) /* Open the terminal if necessary. */ if (!detached && !already_attached) { if (server_client_open(c, &cause) != 0) { - cmdq_error(cmdq, "open terminal failed: %s", cause); + cmdq_error(item, "open terminal failed: %s", cause); free(cause); goto error; } @@ -189,14 +189,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) if (detached && args_has(args, 'x')) { sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { - cmdq_error(cmdq, "width %s", errstr); + cmdq_error(item, "width %s", errstr); goto error; } } if (detached && args_has(args, 'y')) { sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr); if (errstr != NULL) { - cmdq_error(cmdq, "height %s", errstr); + cmdq_error(item, "height %s", errstr); goto error; } } @@ -246,7 +246,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) sy, &cause); environ_free(env); if (s == NULL) { - cmdq_error(cmdq, "create session failed: %s", cause); + cmdq_error(item, "create session failed: %s", cause); free(cause); goto error; } @@ -301,11 +301,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = NEW_SESSION_TEMPLATE; - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, NULL, NULL); cp = format_expand(ft, template); - cmdq_print(cmdq, "%s", cp); + cmdq_print(item, "%s", cp); free(cp); format_free(ft); @@ -318,7 +318,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) free((void *)to_free); cmd_find_from_session(&fs, s); - hooks_insert(s->hooks, cmdq, &fs, "after-new-session"); + hooks_insert(s->hooks, item, &fs, "after-new-session"); return (CMD_RETURN_NORMAL); diff --git a/cmd-new-window.c b/cmd-new-window.c index af476913..3e7f82d5 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -32,7 +32,7 @@ #define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_new_window_entry = { .name = "new-window", @@ -49,13 +49,13 @@ const struct cmd_entry cmd_new_window_entry = { }; static enum cmd_retval -cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; - struct client *c = cmdq->state.c; - int idx = cmdq->state.tflag.idx; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; + struct client *c = item->state.c; + int idx = item->state.tflag.idx; const char *cmd, *path, *template, *cwd, *to_free; char **argv, *cause, *cp; int argc, detached; @@ -65,7 +65,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'a')) { if ((idx = winlink_shuffle_up(s, wl)) == -1) { - cmdq_error(cmdq, "no free window indexes"); + cmdq_error(item, "no free window indexes"); return (CMD_RETURN_ERROR); } } @@ -86,8 +86,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) } path = NULL; - if (cmdq->client != NULL && cmdq->client->session == NULL) - envent = environ_find(cmdq->client->environ, "PATH"); + if (item->client != NULL && item->client->session == NULL) + envent = environ_find(item->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) @@ -95,12 +95,12 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) to_free = NULL; if (args_has(args, 'c')) { - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, NULL, NULL); cwd = to_free = format_expand(ft, args_get(args, 'c')); format_free(ft); - } else if (cmdq->client != NULL && cmdq->client->session == NULL) - cwd = cmdq->client->cwd; + } else if (item->client != NULL && item->client->session == NULL) + cwd = item->client->cwd; else cwd = s->cwd; @@ -129,7 +129,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx, &cause); if (wl == NULL) { - cmdq_error(cmdq, "create window failed: %s", cause); + cmdq_error(item, "create window failed: %s", cause); free(cause); goto error; } @@ -143,11 +143,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = NEW_WINDOW_TEMPLATE; - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, wl, NULL); cp = format_expand(ft, template); - cmdq_print(cmdq, "%s", cp); + cmdq_print(item, "%s", cp); free(cp); format_free(ft); @@ -157,7 +157,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) free((void *)to_free); cmd_find_from_winlink(&fs, s, wl); - hooks_insert(s->hooks, cmdq, &fs, "after-new-window"); + hooks_insert(s->hooks, item, &fs, "after-new-window"); return (CMD_RETURN_NORMAL); diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 611ca541..1ed22f3d 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -27,7 +27,7 @@ * Paste paste buffer if present. */ -static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_paste_buffer_entry = { .name = "paste-buffer", @@ -44,10 +44,10 @@ const struct cmd_entry cmd_paste_buffer_entry = { }; static enum cmd_retval -cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct window_pane *wp = cmdq->state.tflag.wp; + struct window_pane *wp = item->state.tflag.wp; struct paste_buffer *pb; const char *sepstr, *bufname, *bufdata, *bufend, *line; size_t seplen, bufsize; @@ -62,7 +62,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq) else { pb = paste_get_name(bufname); if (pb == NULL) { - cmdq_error(cmdq, "no buffer %s", bufname); + cmdq_error(item, "no buffer %s", bufname); return (CMD_RETURN_ERROR); } } diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index ec91dd32..ff37b0d8 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -32,7 +32,7 @@ * Open pipe to redirect pane output. If already open, close first. */ -static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *); static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); @@ -50,13 +50,13 @@ const struct cmd_entry cmd_pipe_pane_entry = { }; static enum cmd_retval -cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; - struct window_pane *wp = cmdq->state.tflag.wp; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct client *c = item->state.c; + struct window_pane *wp = item->state.tflag.wp; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; char *cmd; int old_fd, pipe_fd[2], null_fd; struct format_tree *ft; @@ -84,12 +84,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) /* Open the new pipe. */ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) { - cmdq_error(cmdq, "socketpair error: %s", strerror(errno)); + cmdq_error(item, "socketpair error: %s", strerror(errno)); return (CMD_RETURN_ERROR); } /* Expand the command. */ - ft = format_create(cmdq, 0); + ft = format_create(item, 0); format_defaults(ft, c, s, wl, wp); cmd = format_expand_time(ft, args->argv[0], time(NULL)); format_free(ft); @@ -97,7 +97,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) /* Fork the child. */ switch (fork()) { case -1: - cmdq_error(cmdq, "fork error: %s", strerror(errno)); + cmdq_error(item, "fork error: %s", strerror(errno)); free(cmd); return (CMD_RETURN_ERROR); diff --git a/cmd-queue.c b/cmd-queue.c index fca3bf04..5056fffc 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -26,7 +26,7 @@ #include "tmux.h" /* Global command queue. */ -static struct cmd_q_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue); +static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue); /* Get command queue name. */ static const char * @@ -41,7 +41,7 @@ cmdq_name(struct client *c) } /* Get command queue from client. */ -static struct cmd_q_list * +static struct cmdq_list * cmdq_get(struct client *c) { if (c == NULL) @@ -51,67 +51,68 @@ cmdq_get(struct client *c) /* Append an item. */ void -cmdq_append(struct client *c, struct cmd_q *cmdq) +cmdq_append(struct client *c, struct cmdq_item *item) { - struct cmd_q_list *queue = cmdq_get(c); - struct cmd_q *next; + struct cmdq_list *queue = cmdq_get(c); + struct cmdq_item *next; do { - next = cmdq->next; - cmdq->next = NULL; + next = item->next; + item->next = NULL; if (c != NULL) c->references++; - cmdq->client = c; + item->client = c; - cmdq->queue = queue; - TAILQ_INSERT_TAIL(queue, cmdq, entry); + item->queue = queue; + TAILQ_INSERT_TAIL(queue, item, entry); - cmdq = next; - } while (cmdq != NULL); + item = next; + } while (item != NULL); } /* Insert an item. */ void -cmdq_insert_after(struct cmd_q *after, struct cmd_q *cmdq) +cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item) { struct client *c = after->client; - struct cmd_q_list *queue = after->queue; - struct cmd_q *next; + struct cmdq_list *queue = after->queue; + struct cmdq_item *next; do { - next = cmdq->next; - cmdq->next = NULL; + next = item->next; + item->next = NULL; if (c != NULL) c->references++; - cmdq->client = c; + item->client = c; - cmdq->queue = queue; + item->queue = queue; if (after->next != NULL) - TAILQ_INSERT_AFTER(queue, after->next, cmdq, entry); + TAILQ_INSERT_AFTER(queue, after->next, item, entry); else - TAILQ_INSERT_AFTER(queue, after, cmdq, entry); - after->next = cmdq; + TAILQ_INSERT_AFTER(queue, after, item, entry); + after->next = item; - cmdq = next; - } while (cmdq != NULL); + item = next; + } while (item != NULL); } /* Remove an item. */ static void -cmdq_remove(struct cmd_q *cmdq) +cmdq_remove(struct cmdq_item *item) { - free((void *)cmdq->hook); + if (item->formats != NULL) + format_free(item->formats); - if (cmdq->client != NULL) - server_client_unref(cmdq->client); + if (item->client != NULL) + server_client_unref(item->client); - if (cmdq->type == CMD_Q_COMMAND) - cmd_list_free(cmdq->cmdlist); + if (item->type == CMDQ_COMMAND) + cmd_list_free(item->cmdlist); - TAILQ_REMOVE(cmdq->queue, cmdq, entry); - free(cmdq); + TAILQ_REMOVE(item->queue, item, entry); + free(item); } /* Set command group. */ @@ -125,129 +126,151 @@ cmdq_next_group(void) /* Remove all subsequent items that match this item's group. */ static void -cmdq_remove_group(struct cmd_q *cmdq) +cmdq_remove_group(struct cmdq_item *item) { - struct cmd_q *this, *next; + struct cmdq_item *this, *next; - this = TAILQ_NEXT(cmdq, entry); + this = TAILQ_NEXT(item, entry); while (this != NULL) { next = TAILQ_NEXT(this, entry); - if (this->group == cmdq->group) + if (this->group == item->group) cmdq_remove(this); this = next; } } /* Get a command for the command queue. */ -struct cmd_q * +struct cmdq_item * cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current, struct mouse_event *m, int flags) { - struct cmd_q *cmdq, *first = NULL, *last = NULL; - struct cmd *cmd; - u_int group = cmdq_next_group(); + struct cmdq_item *item, *first = NULL, *last = NULL; + struct cmd *cmd; + u_int group = cmdq_next_group(); TAILQ_FOREACH(cmd, &cmdlist->list, qentry) { - cmdq = xcalloc(1, sizeof *cmdq); - cmdq->type = CMD_Q_COMMAND; - cmdq->group = group; - cmdq->flags = flags; + item = xcalloc(1, sizeof *item); + item->type = CMDQ_COMMAND; + item->group = group; + item->flags = flags; - cmdq->cmdlist = cmdlist; - cmdq->cmd = cmd; + item->cmdlist = cmdlist; + item->cmd = cmd; if (current != NULL) - cmd_find_copy_state(&cmdq->current, current); + cmd_find_copy_state(&item->current, current); if (m != NULL) - memcpy(&cmdq->mouse, m, sizeof cmdq->mouse); + memcpy(&item->mouse, m, sizeof item->mouse); cmdlist->references++; if (first == NULL) - first = cmdq; + first = item; if (last != NULL) - last->next = cmdq; - last = cmdq; + last->next = item; + last = item; } return (first); } /* Fire command on command queue. */ static enum cmd_retval -cmdq_fire_command(struct cmd_q *cmdq) +cmdq_fire_command(struct cmdq_item *item) { - struct client *c = cmdq->client; - struct cmd *cmd = cmdq->cmd; + struct client *c = item->client; + struct cmd *cmd = item->cmd; enum cmd_retval retval; const char *name; struct cmd_find_state *fsp, fs; int flags; flags = !!(cmd->flags & CMD_CONTROL); - cmdq_guard(cmdq, "begin", flags); + cmdq_guard(item, "begin", flags); - if (cmd_prepare_state(cmd, cmdq) != 0) { + if (cmd_prepare_state(cmd, item) != 0) { retval = CMD_RETURN_ERROR; goto out; } - if (cmdq->client == NULL) - cmdq->client = cmd_find_client(cmdq, NULL, CMD_FIND_QUIET); + if (item->client == NULL) + item->client = cmd_find_client(item, NULL, CMD_FIND_QUIET); - retval = cmd->entry->exec(cmd, cmdq); + retval = cmd->entry->exec(cmd, item); if (retval == CMD_RETURN_ERROR) goto out; if (cmd->entry->flags & CMD_AFTERHOOK) { name = cmd->entry->name; - if (cmd_find_valid_state(&cmdq->state.tflag)) - fsp = &cmdq->state.tflag; + if (cmd_find_valid_state(&item->state.tflag)) + fsp = &item->state.tflag; else { - if (cmd_find_current(&fs, cmdq, CMD_FIND_QUIET) != 0) + if (cmd_find_current(&fs, item, CMD_FIND_QUIET) != 0) goto out; fsp = &fs; } - hooks_insert(fsp->s->hooks, cmdq, fsp, "after-%s", name); + hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name); } out: - cmdq->client = c; + item->client = c; if (retval == CMD_RETURN_ERROR) - cmdq_guard(cmdq, "error", flags); + cmdq_guard(item, "error", flags); else - cmdq_guard(cmdq, "end", flags); + cmdq_guard(item, "end", flags); return (retval); } /* Get a callback for the command queue. */ -struct cmd_q * -cmdq_get_callback(cmd_q_cb cb, void *data) +struct cmdq_item * +cmdq_get_callback(cmdq_cb cb, void *data) { - struct cmd_q *cmdq; + struct cmdq_item *item; - cmdq = xcalloc(1, sizeof *cmdq); - cmdq->type = CMD_Q_CALLBACK; - cmdq->group = 0; - cmdq->flags = 0; + item = xcalloc(1, sizeof *item); + item->type = CMDQ_CALLBACK; + item->group = 0; + item->flags = 0; - cmdq->cb = cb; - cmdq->data = data; + item->cb = cb; + item->data = data; - return (cmdq); + return (item); } /* Fire callback on callback queue. */ static enum cmd_retval -cmdq_fire_callback(struct cmd_q *cmdq) +cmdq_fire_callback(struct cmdq_item *item) { - return (cmdq->cb(cmdq, cmdq->data)); + return (item->cb(item, item->data)); } +/* Add a format to command queue. */ +void +cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...) +{ + va_list ap; + struct cmdq_item *loop; + char *value; + + va_start(ap, fmt); + xvasprintf(&value, fmt, ap); + va_end(ap); + + for (loop = item; loop != NULL; loop = item->next) { + if (loop->formats == NULL) + loop->formats = format_create(NULL, 0); + format_add(loop->formats, key, "%s", value); + } + + free(value); +} + + /* Process next item on command queue. */ u_int cmdq_next(struct client *c) { - struct cmd_q_list *queue = cmdq_get(c); + struct cmdq_list *queue = cmdq_get(c); const char *name = cmdq_name(c); - struct cmd_q *cmdq; + struct cmdq_item *item; enum cmd_retval retval; u_int items = 0; static u_int number; @@ -256,63 +279,63 @@ cmdq_next(struct client *c) log_debug("%s %s: empty", __func__, name); return (0); } - if (TAILQ_FIRST(queue)->flags & CMD_Q_WAITING) { + if (TAILQ_FIRST(queue)->flags & CMDQ_WAITING) { log_debug("%s %s: waiting", __func__, name); return (0); } log_debug("%s %s: enter", __func__, name); for (;;) { - cmdq = TAILQ_FIRST(queue); - if (cmdq == NULL) + item = TAILQ_FIRST(queue); + if (item == NULL) break; log_debug("%s %s: type %d, flags %x", __func__, name, - cmdq->type, cmdq->flags); + item->type, item->flags); /* * Any item with the waiting flag set waits until an external * event clears the flag (for example, a job - look at * run-shell). */ - if (cmdq->flags & CMD_Q_WAITING) + if (item->flags & CMDQ_WAITING) goto waiting; /* * Items are only fired once, once the fired flag is set, a * waiting flag can only be cleared by an external event. */ - if (~cmdq->flags & CMD_Q_FIRED) { - cmdq->time = time(NULL); - cmdq->number = ++number; + if (~item->flags & CMDQ_FIRED) { + item->time = time(NULL); + item->number = ++number; - switch (cmdq->type) + switch (item->type) { - case CMD_Q_COMMAND: - retval = cmdq_fire_command(cmdq); + case CMDQ_COMMAND: + retval = cmdq_fire_command(item); /* * If a command returns an error, remove any * subsequent commands in the same group. */ if (retval == CMD_RETURN_ERROR) - cmdq_remove_group(cmdq); + cmdq_remove_group(item); break; - case CMD_Q_CALLBACK: - retval = cmdq_fire_callback(cmdq); + case CMDQ_CALLBACK: + retval = cmdq_fire_callback(item); break; default: retval = CMD_RETURN_ERROR; break; } - cmdq->flags |= CMD_Q_FIRED; + item->flags |= CMDQ_FIRED; if (retval == CMD_RETURN_WAIT) { - cmdq->flags |= CMD_Q_WAITING; + item->flags |= CMDQ_WAITING; goto waiting; } items++; } - cmdq_remove(cmdq); + cmdq_remove(item); } log_debug("%s %s: exit (empty)", __func__, name); @@ -325,23 +348,23 @@ waiting: /* Print a guard line. */ void -cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags) +cmdq_guard(struct cmdq_item *item, const char *guard, int flags) { - struct client *c = cmdq->client; + struct client *c = item->client; if (c == NULL || !(c->flags & CLIENT_CONTROL)) return; evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard, - (long)cmdq->time, cmdq->number, flags); + (long)item->time, item->number, flags); server_client_push_stdout(c); } /* Show message from command. */ void -cmdq_print(struct cmd_q *cmdq, const char *fmt, ...) +cmdq_print(struct cmdq_item *item, const char *fmt, ...) { - struct client *c = cmdq->client; + struct client *c = item->client; struct window *w; va_list ap; char *tmp, *msg; @@ -376,10 +399,10 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...) /* Show error from command. */ void -cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) +cmdq_error(struct cmdq_item *item, const char *fmt, ...) { - struct client *c = cmdq->client; - struct cmd *cmd = cmdq->cmd; + struct client *c = item->client; + struct cmd *cmd = item->cmd; va_list ap; char *msg; size_t msglen; diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c index 68a7c22a..b1234f36 100644 --- a/cmd-refresh-client.c +++ b/cmd-refresh-client.c @@ -24,7 +24,7 @@ * Refresh client. */ -static enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_refresh_client_entry = { .name = "refresh-client", @@ -40,29 +40,29 @@ const struct cmd_entry cmd_refresh_client_entry = { }; static enum cmd_retval -cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; const char *size; u_int w, h; if (args_has(args, 'C')) { if ((size = args_get(args, 'C')) == NULL) { - cmdq_error(cmdq, "missing size"); + cmdq_error(item, "missing size"); return (CMD_RETURN_ERROR); } if (sscanf(size, "%u,%u", &w, &h) != 2) { - cmdq_error(cmdq, "bad size argument"); + cmdq_error(item, "bad size argument"); return (CMD_RETURN_ERROR); } if (w < PANE_MINIMUM || w > 5000 || h < PANE_MINIMUM || h > 5000) { - cmdq_error(cmdq, "size too small or too big"); + cmdq_error(item, "size too small or too big"); return (CMD_RETURN_ERROR); } if (!(c->flags & CLIENT_CONTROL)) { - cmdq_error(cmdq, "not a control client"); + cmdq_error(item, "not a control client"); return (CMD_RETURN_ERROR); } if (tty_set_size(&c->tty, w, h)) diff --git a/cmd-rename-session.c b/cmd-rename-session.c index d0f9b0e1..bcc896b2 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -26,7 +26,8 @@ * Change session name. */ -static enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rename_session_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_rename_session_entry = { .name = "rename-session", @@ -42,19 +43,19 @@ const struct cmd_entry cmd_rename_session_entry = { }; static enum cmd_retval -cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; + struct session *s = item->state.tflag.s; const char *newname; newname = args->argv[0]; if (!session_check_name(newname)) { - cmdq_error(cmdq, "bad session name: %s", newname); + cmdq_error(item, "bad session name: %s", newname); return (CMD_RETURN_ERROR); } if (session_find(newname) != NULL) { - cmdq_error(cmdq, "duplicate session: %s", newname); + cmdq_error(item, "duplicate session: %s", newname); return (CMD_RETURN_ERROR); } diff --git a/cmd-rename-window.c b/cmd-rename-window.c index 68d77678..89dfdf31 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -26,7 +26,8 @@ * Rename a window. */ -static enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rename_window_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_rename_window_entry = { .name = "rename-window", @@ -42,10 +43,10 @@ const struct cmd_entry cmd_rename_window_entry = { }; static enum cmd_retval -cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; window_set_name(wl->window, args->argv[0]); options_set_number(wl->window->options, "automatic-rename", 0); diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 3360bd6b..37bfcece 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -26,7 +26,7 @@ * Increase or decrease pane size. */ -static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *); static void cmd_resize_pane_mouse_update(struct client *, struct mouse_event *); @@ -46,26 +46,26 @@ const struct cmd_entry cmd_resize_pane_entry = { }; static enum cmd_retval -cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct window_pane *wp = cmdq->state.tflag.wp; - struct winlink *wl = cmdq->state.tflag.wl; + struct window_pane *wp = item->state.tflag.wp; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; - struct client *c = cmdq->client; - struct session *s = cmdq->state.tflag.s; + struct client *c = item->client; + struct session *s = item->state.tflag.s; const char *errstr; char *cause; u_int adjust; int x, y; if (args_has(args, 'M')) { - if (cmd_mouse_window(&cmdq->mouse, &s) == NULL) + if (cmd_mouse_window(&item->mouse, &s) == NULL) return (CMD_RETURN_NORMAL); if (c == NULL || c->session != s) return (CMD_RETURN_NORMAL); c->tty.mouse_drag_update = cmd_resize_pane_mouse_update; - cmd_resize_pane_mouse_update(c, &cmdq->mouse); + cmd_resize_pane_mouse_update(c, &item->mouse); return (CMD_RETURN_NORMAL); } @@ -85,7 +85,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) else { adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); if (errstr != NULL) { - cmdq_error(cmdq, "adjustment %s", errstr); + cmdq_error(item, "adjustment %s", errstr); return (CMD_RETURN_ERROR); } } @@ -94,7 +94,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX, &cause); if (cause != NULL) { - cmdq_error(cmdq, "width %s", cause); + cmdq_error(item, "width %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -104,7 +104,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX, &cause); if (cause != NULL) { - cmdq_error(cmdq, "height %s", cause); + cmdq_error(item, "height %s", cause); free(cause); return (CMD_RETURN_ERROR); } diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index 3a7c8090..b95fc596 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -28,7 +28,7 @@ * Respawn a pane (restart the command). Kill existing if -k given. */ -static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_respawn_pane_entry = { .name = "respawn-pane", @@ -44,13 +44,13 @@ const struct cmd_entry cmd_respawn_pane_entry = { }; static enum cmd_retval -cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; - struct window_pane *wp = cmdq->state.tflag.wp; - struct session *s = cmdq->state.tflag.s; + struct window_pane *wp = item->state.tflag.wp; + struct session *s = item->state.tflag.s; struct environ *env; const char *path; char *cause; @@ -60,7 +60,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) if (!args_has(self->args, 'k') && wp->fd != -1) { if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); - cmdq_error(cmdq, "pane still active: %s:%d.%u", + cmdq_error(item, "pane still active: %s:%d.%u", s->name, wl->idx, idx); return (CMD_RETURN_ERROR); } @@ -75,8 +75,8 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) input_init(wp); path = NULL; - if (cmdq->client != NULL && cmdq->client->session == NULL) - envent = environ_find(cmdq->client->environ, "PATH"); + if (item->client != NULL && item->client->session == NULL) + envent = environ_find(item->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) @@ -84,7 +84,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { - cmdq_error(cmdq, "respawn pane failed: %s", cause); + cmdq_error(item, "respawn pane failed: %s", cause); free(cause); environ_free(env); return (CMD_RETURN_ERROR); diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c index 42f7db19..92ba6299 100644 --- a/cmd-respawn-window.c +++ b/cmd-respawn-window.c @@ -27,7 +27,8 @@ * Respawn a window (restart the command). Kill existing if -k given. */ -static enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_respawn_window_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_respawn_window_entry = { .name = "respawn-window", @@ -43,11 +44,11 @@ const struct cmd_entry cmd_respawn_window_entry = { }; static enum cmd_retval -cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; struct window_pane *wp; struct environ *env; @@ -59,7 +60,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq) TAILQ_FOREACH(wp, &w->panes, entry) { if (wp->fd == -1) continue; - cmdq_error(cmdq, "window still active: %s:%d", s->name, + cmdq_error(item, "window still active: %s:%d", s->name, wl->idx); return (CMD_RETURN_ERROR); } @@ -78,8 +79,8 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq) window_pane_resize(wp, w->sx, w->sy); path = NULL; - if (cmdq->client != NULL && cmdq->client->session == NULL) - envent = environ_find(cmdq->client->environ, "PATH"); + if (item->client != NULL && item->client->session == NULL) + envent = environ_find(item->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) @@ -87,7 +88,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq) if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { - cmdq_error(cmdq, "respawn window failed: %s", cause); + cmdq_error(item, "respawn window failed: %s", cause); free(cause); environ_free(env); server_destroy_pane(wp, 0); diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c index bda810c3..aa83a25e 100644 --- a/cmd-rotate-window.c +++ b/cmd-rotate-window.c @@ -24,7 +24,8 @@ * Rotate the panes in a window. */ -static enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rotate_window_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_rotate_window_entry = { .name = "rotate-window", @@ -40,9 +41,9 @@ const struct cmd_entry cmd_rotate_window_entry = { }; static enum cmd_retval -cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item) { - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; struct window_pane *wp, *wp2; struct layout_cell *lc; diff --git a/cmd-run-shell.c b/cmd-run-shell.c index ad2d4c2f..1c9d5cbe 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -29,7 +29,7 @@ * Runs a command without a window. */ -static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *); static void cmd_run_shell_callback(struct job *); static void cmd_run_shell_free(void *); @@ -49,9 +49,9 @@ const struct cmd_entry cmd_run_shell_entry = { }; struct cmd_run_shell_data { - char *cmd; - struct cmd_q *cmdq; - int wp_id; + char *cmd; + struct cmdq_item *item; + int wp_id; }; static void @@ -63,7 +63,7 @@ cmd_run_shell_print(struct job *job, const char *msg) if (cdata->wp_id != -1) wp = window_pane_find_by_id(cdata->wp_id); if (wp == NULL) { - cmdq_print(cdata->cmdq, "%s", msg); + cmdq_print(cdata->item, "%s", msg); return; } @@ -74,26 +74,26 @@ cmd_run_shell_print(struct job *job, const char *msg) } static enum cmd_retval -cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_run_shell_data *cdata; char *shellcmd; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; - struct window_pane *wp = cmdq->state.tflag.wp; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; + struct window_pane *wp = item->state.tflag.wp; struct format_tree *ft; const char *cwd; - if (cmdq->client != NULL && cmdq->client->session == NULL) - cwd = cmdq->client->cwd; + if (item->client != NULL && item->client->session == NULL) + cwd = item->client->cwd; else if (s != NULL) cwd = s->cwd; else cwd = NULL; - ft = format_create(cmdq, 0); - format_defaults(ft, cmdq->state.c, s, wl, wp); + ft = format_create(item, 0); + format_defaults(ft, item->state.c, s, wl, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); @@ -111,7 +111,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) cdata->wp_id = -1; if (!args_has(args, 'b')) - cdata->cmdq = cmdq; + cdata->item = item; job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free, cdata); @@ -163,8 +163,8 @@ cmd_run_shell_callback(struct job *job) cmd_run_shell_print(job, msg); free(msg); - if (cdata->cmdq != NULL) - cdata->cmdq->flags &= ~CMD_Q_WAITING; + if (cdata->item != NULL) + cdata->item->flags &= ~CMDQ_WAITING; } static void diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index dbc819e3..4d36a6ae 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -31,7 +31,7 @@ * Saves a paste buffer to a file. */ -static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_save_buffer_entry = { .name = "save-buffer", @@ -56,10 +56,10 @@ const struct cmd_entry cmd_show_buffer_entry = { }; static enum cmd_retval -cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->client; + struct client *c = item->client; struct session *s; struct paste_buffer *pb; const char *path, *bufname, *bufdata, *start, *end, *cwd; @@ -70,14 +70,14 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) if (!args_has(args, 'b')) { if ((pb = paste_get_top(NULL)) == NULL) { - cmdq_error(cmdq, "no buffers"); + cmdq_error(item, "no buffers"); return (CMD_RETURN_ERROR); } } else { bufname = args_get(args, 'b'); pb = paste_get_name(bufname); if (pb == NULL) { - cmdq_error(cmdq, "no buffer %s", bufname); + cmdq_error(item, "no buffer %s", bufname); return (CMD_RETURN_ERROR); } } @@ -89,7 +89,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) path = args->argv[0]; if (strcmp(path, "-") == 0) { if (c == NULL) { - cmdq_error(cmdq, "can't write to stdout"); + cmdq_error(item, "can't write to stdout"); return (CMD_RETURN_ERROR); } if (c->session == NULL || (c->flags & CLIENT_CONTROL)) @@ -114,18 +114,18 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) xasprintf(&file, "%s/%s", cwd, path); if (realpath(file, resolved) == NULL && strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { - cmdq_error(cmdq, "%s: %s", file, strerror(ENAMETOOLONG)); + cmdq_error(item, "%s: %s", file, strerror(ENAMETOOLONG)); return (CMD_RETURN_ERROR); } f = fopen(resolved, flags); free(file); if (f == NULL) { - cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); + cmdq_error(item, "%s: %s", resolved, strerror(errno)); return (CMD_RETURN_ERROR); } if (fwrite(bufdata, 1, bufsize, f) != bufsize) { - cmdq_error(cmdq, "%s: write error", resolved); + cmdq_error(item, "%s: write error", resolved); fclose(f); return (CMD_RETURN_ERROR); } @@ -140,7 +140,7 @@ do_stdout: do_print: if (bufsize > (INT_MAX / 4) - 1) { - cmdq_error(cmdq, "buffer too big"); + cmdq_error(item, "buffer too big"); return (CMD_RETURN_ERROR); } msg = NULL; @@ -158,7 +158,7 @@ do_print: msg = xrealloc(msg, msglen); strvisx(msg, start, size, VIS_OCTAL|VIS_TAB); - cmdq_print(cmdq, "%s", msg); + cmdq_print(item, "%s", msg); used += size + (end != NULL); } diff --git a/cmd-select-layout.c b/cmd-select-layout.c index 4ecafc5c..10a7413c 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -26,7 +26,8 @@ * Switch window to selected layout. */ -static enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_layout_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_select_layout_entry = { .name = "select-layout", @@ -68,10 +69,10 @@ const struct cmd_entry cmd_previous_layout_entry = { }; static enum cmd_retval -cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; struct window *w; const char *layoutname; char *oldlayout; @@ -118,7 +119,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq) if (layoutname != NULL) { if (layout_parse(w, layoutname) == -1) { - cmdq_error(cmdq, "can't set layout: %s", layoutname); + cmdq_error(item, "can't set layout: %s", layoutname); goto error; } goto changed; diff --git a/cmd-select-pane.c b/cmd-select-pane.c index 956d42a8..c0374fa7 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -24,7 +24,7 @@ * Select pane. */ -static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_select_pane_entry = { .name = "select-pane", @@ -53,19 +53,19 @@ const struct cmd_entry cmd_last_pane_entry = { }; static enum cmd_retval -cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct winlink *wl = cmdq->state.tflag.wl; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; - struct session *s = cmdq->state.tflag.s; - struct window_pane *wp = cmdq->state.tflag.wp, *lastwp, *markedwp; + struct session *s = item->state.tflag.s; + struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp; const char *style; if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { if (wl->window->last == NULL) { - cmdq_error(cmdq, "no last pane"); + cmdq_error(item, "no last pane"); return (CMD_RETURN_ERROR); } @@ -112,13 +112,13 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) style = args_get(args, 'P'); if (style_parse(&grid_default_cell, &wp->colgc, style) == -1) { - cmdq_error(cmdq, "bad style: %s", style); + cmdq_error(item, "bad style: %s", style); return (CMD_RETURN_ERROR); } wp->flags |= PANE_REDRAW; } if (args_has(self->args, 'g')) - cmdq_print(cmdq, "%s", style_tostring(&wp->colgc)); + cmdq_print(item, "%s", style_tostring(&wp->colgc)); return (CMD_RETURN_NORMAL); } @@ -151,7 +151,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); server_unzoom_window(wp->window); if (!window_pane_visible(wp)) { - cmdq_error(cmdq, "pane not visible"); + cmdq_error(item, "pane not visible"); return (CMD_RETURN_ERROR); } window_redraw_active_switch(w, wp); diff --git a/cmd-select-window.c b/cmd-select-window.c index a1413ae0..b741af51 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -26,7 +26,8 @@ * Select window by index. */ -static enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_window_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_select_window_entry = { .name = "select-window", @@ -81,10 +82,10 @@ const struct cmd_entry cmd_last_window_entry = { }; static enum cmd_retval -cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_select_window_exec(struct cmd *self, struct cmdq_item *item) { - struct winlink *wl = cmdq->state.tflag.wl; - struct session *s = cmdq->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; + struct session *s = item->state.tflag.s; int next, previous, last, activity; next = self->entry == &cmd_next_window_entry; @@ -101,17 +102,17 @@ cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq) activity = args_has(self->args, 'a'); if (next) { if (session_next(s, activity) != 0) { - cmdq_error(cmdq, "no next window"); + cmdq_error(item, "no next window"); return (CMD_RETURN_ERROR); } } else if (previous) { if (session_previous(s, activity) != 0) { - cmdq_error(cmdq, "no previous window"); + cmdq_error(item, "no previous window"); return (CMD_RETURN_ERROR); } } else { if (session_last(s) != 0) { - cmdq_error(cmdq, "no last window"); + cmdq_error(item, "no last window"); return (CMD_RETURN_ERROR); } } @@ -124,7 +125,7 @@ cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq) */ if (args_has(self->args, 'T') && wl == s->curw) { if (session_last(s) != 0) { - cmdq_error(cmdq, "no last window"); + cmdq_error(item, "no last window"); return (-1); } server_redraw_session(s); diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 94316834..f94b8f6d 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -27,7 +27,7 @@ * Send keys to client. */ -static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_send_keys_entry = { .name = "send-keys", @@ -56,13 +56,13 @@ const struct cmd_entry cmd_send_prefix_entry = { }; static enum cmd_retval -cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; - struct window_pane *wp = cmdq->state.tflag.wp; - struct session *s = cmdq->state.tflag.s; - struct mouse_event *m = &cmdq->mouse; + struct client *c = item->state.c; + struct window_pane *wp = item->state.tflag.wp; + struct session *s = item->state.tflag.s; + struct mouse_event *m = &item->mouse; const u_char *keystr; int i, literal; key_code key; @@ -71,12 +71,12 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'N')) { if (wp->mode == NULL || wp->mode->command == NULL) { - cmdq_error(cmdq, "not in a mode"); + cmdq_error(item, "not in a mode"); return (CMD_RETURN_ERROR); } np = args_strtonum(args, 'N', 1, UINT_MAX, &cause); if (cause != NULL) { - cmdq_error(cmdq, "prefix %s", cause); + cmdq_error(item, "prefix %s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -85,7 +85,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'X')) { if (wp->mode == NULL || wp->mode->command == NULL) { - cmdq_error(cmdq, "not in a mode"); + cmdq_error(item, "not in a mode"); return (CMD_RETURN_ERROR); } if (!m->valid) @@ -101,7 +101,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'M')) { wp = cmd_mouse_pane(m, &s, NULL); if (wp == NULL) { - cmdq_error(cmdq, "no mouse target"); + cmdq_error(item, "no mouse target"); return (CMD_RETURN_ERROR); } window_pane_key(wp, NULL, s, m->key, m); diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c index d3f8ba4f..96fdf450 100644 --- a/cmd-set-buffer.c +++ b/cmd-set-buffer.c @@ -27,7 +27,7 @@ * Add, set, append to or delete a paste buffer. */ -static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_set_buffer_entry = { .name = "set-buffer", @@ -52,7 +52,7 @@ const struct cmd_entry cmd_delete_buffer_entry = { }; static enum cmd_retval -cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct paste_buffer *pb; @@ -70,7 +70,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) if (pb == NULL) pb = paste_get_top(&bufname); if (pb == NULL) { - cmdq_error(cmdq, "no buffer"); + cmdq_error(item, "no buffer"); return (CMD_RETURN_ERROR); } paste_free(pb); @@ -81,11 +81,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) if (pb == NULL) pb = paste_get_top(&bufname); if (pb == NULL) { - cmdq_error(cmdq, "no buffer"); + cmdq_error(item, "no buffer"); return (CMD_RETURN_ERROR); } if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(cause); return (CMD_RETURN_ERROR); } @@ -93,7 +93,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) } if (args->argc != 1) { - cmdq_error(cmdq, "no data specified"); + cmdq_error(item, "no data specified"); return (CMD_RETURN_ERROR); } if ((newsize = strlen(args->argv[0])) == 0) @@ -113,7 +113,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) bufsize += newsize; if (paste_set(bufdata, bufsize, bufname, &cause) != 0) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(bufdata); free(cause); return (CMD_RETURN_ERROR); diff --git a/cmd-set-environment.c b/cmd-set-environment.c index 186115b4..b3737e72 100644 --- a/cmd-set-environment.c +++ b/cmd-set-environment.c @@ -27,7 +27,8 @@ * Set an environment variable. */ -static enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_environment_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_set_environment_entry = { .name = "set-environment", @@ -43,7 +44,7 @@ const struct cmd_entry cmd_set_environment_entry = { }; static enum cmd_retval -cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct environ *env; @@ -51,11 +52,11 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq) name = args->argv[0]; if (*name == '\0') { - cmdq_error(cmdq, "empty variable name"); + cmdq_error(item, "empty variable name"); return (CMD_RETURN_ERROR); } if (strchr(name, '=') != NULL) { - cmdq_error(cmdq, "variable name contains ="); + cmdq_error(item, "variable name contains ="); return (CMD_RETURN_ERROR); } @@ -67,32 +68,32 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(self->args, 'g')) env = global_environ; else { - if (cmdq->state.tflag.s == NULL) { + if (item->state.tflag.s == NULL) { target = args_get(args, 't'); if (target != NULL) - cmdq_error(cmdq, "no such session: %s", target); + cmdq_error(item, "no such session: %s", target); else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } - env = cmdq->state.tflag.s->environ; + env = item->state.tflag.s->environ; } if (args_has(self->args, 'u')) { if (value != NULL) { - cmdq_error(cmdq, "can't specify a value with -u"); + cmdq_error(item, "can't specify a value with -u"); return (CMD_RETURN_ERROR); } environ_unset(env, name); } else if (args_has(self->args, 'r')) { if (value != NULL) { - cmdq_error(cmdq, "can't specify a value with -r"); + cmdq_error(item, "can't specify a value with -r"); return (CMD_RETURN_ERROR); } environ_clear(env, name); } else { if (value == NULL) { - cmdq_error(cmdq, "no value specified"); + cmdq_error(item, "no value specified"); return (CMD_RETURN_ERROR); } environ_set(env, name, "%s", value); diff --git a/cmd-set-hook.c b/cmd-set-hook.c index e4d4669c..2685fc8d 100644 --- a/cmd-set-hook.c +++ b/cmd-set-hook.c @@ -27,7 +27,7 @@ * Set or show global or session hooks. */ -static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_set_hook_entry = { .name = "set-hook", @@ -56,7 +56,7 @@ const struct cmd_entry cmd_show_hooks_entry = { }; static enum cmd_retval -cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_list *cmdlist; @@ -68,22 +68,22 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'g')) hooks = global_hooks; else { - if (cmdq->state.tflag.s == NULL) { + if (item->state.tflag.s == NULL) { target = args_get(args, 't'); if (target != NULL) - cmdq_error(cmdq, "no such session: %s", target); + cmdq_error(item, "no such session: %s", target); else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } - hooks = cmdq->state.tflag.s->hooks; + hooks = item->state.tflag.s->hooks; } if (self->entry == &cmd_show_hooks_entry) { hook = hooks_first(hooks); while (hook != NULL) { tmp = cmd_list_print(hook->cmdlist); - cmdq_print(cmdq, "%s -> %s", hook->name, tmp); + cmdq_print(item, "%s -> %s", hook->name, tmp); free(tmp); hook = hooks_next(hook); @@ -93,7 +93,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) name = args->argv[0]; if (*name == '\0') { - cmdq_error(cmdq, "invalid hook name"); + cmdq_error(item, "invalid hook name"); return (CMD_RETURN_ERROR); } if (args->argc < 2) @@ -103,7 +103,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'u')) { if (cmd != NULL) { - cmdq_error(cmdq, "command passed to unset hook: %s", + cmdq_error(item, "command passed to unset hook: %s", name); return (CMD_RETURN_ERROR); } @@ -112,12 +112,12 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) } if (cmd == NULL) { - cmdq_error(cmdq, "no command to set hook: %s", name); + cmdq_error(item, "no command to set hook: %s", name); return (CMD_RETURN_ERROR); } if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { - cmdq_error(cmdq, "%s", cause); + cmdq_error(item, "%s", cause); free(cause); } return (CMD_RETURN_ERROR); diff --git a/cmd-set-option.c b/cmd-set-option.c index 0c092e50..695f5690 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -27,42 +27,42 @@ * Set an option. */ -static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, - const char *, const char *); +static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmdq_item *, + const char *, const char *); -static int cmd_set_option_unset(struct cmd *, struct cmd_q *, +static int cmd_set_option_unset(struct cmd *, struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); -static int cmd_set_option_set(struct cmd *, struct cmd_q *, +static int cmd_set_option_set(struct cmd *, struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); -static struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_attributes(struct cmd *, - struct cmd_q *, const struct options_table_entry *, +static struct options_entry *cmd_set_option_string(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_number(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_key(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_colour(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_attributes(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_flag(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_choice(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_style(struct cmd *, + struct cmdq_item *, const struct options_table_entry *, struct options *, const char *); -static struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -static struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); const struct cmd_entry cmd_set_option_entry = { .name = "set-option", @@ -91,11 +91,11 @@ const struct cmd_entry cmd_set_window_option_entry = { }; static enum cmd_retval -cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; struct window *w; struct client *c; const struct options_table_entry *oe; @@ -105,7 +105,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) /* Get the option name and value. */ optstr = args->argv[0]; if (*optstr == '\0') { - cmdq_error(cmdq, "invalid option"); + cmdq_error(item, "invalid option"); return (CMD_RETURN_ERROR); } if (args->argc < 2) @@ -115,20 +115,20 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) /* Is this a user option? */ if (*optstr == '@') - return (cmd_set_option_user(self, cmdq, optstr, valstr)); + return (cmd_set_option_user(self, item, optstr, valstr)); /* Find the option entry, try each table. */ oe = NULL; if (options_table_find(optstr, &oe) != 0) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "ambiguous option: %s", optstr); + cmdq_error(item, "ambiguous option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (oe == NULL) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "unknown option: %s", optstr); + cmdq_error(item, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); @@ -143,10 +143,10 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such window: %s", + cmdq_error(item, "no such window: %s", target); } else - cmdq_error(cmdq, "no current window"); + cmdq_error(item, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; @@ -156,31 +156,31 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such session: %s", + cmdq_error(item, "no such session: %s", target); } else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; } else { - cmdq_error(cmdq, "unknown table"); + cmdq_error(item, "unknown table"); return (CMD_RETURN_ERROR); } /* Unset or set the option. */ if (args_has(args, 'u')) { - if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0) + if (cmd_set_option_unset(self, item, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } else { if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "already set: %s", optstr); + cmdq_error(item, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } - if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0) + if (cmd_set_option_set(self, item, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } @@ -224,12 +224,12 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) /* Set user option. */ static enum cmd_retval -cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, - const char *valstr) +cmd_set_option_user(struct cmd *self, struct cmdq_item *item, + const char *optstr, const char *valstr) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; struct options *oo; struct options_entry *o; const char *target; @@ -243,10 +243,10 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such window: %s", + cmdq_error(item, "no such window: %s", target); } else - cmdq_error(cmdq, "no current window"); + cmdq_error(item, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; @@ -256,10 +256,10 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such session: %s", + cmdq_error(item, "no such session: %s", target); } else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; @@ -268,13 +268,13 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, if (args_has(args, 'u')) { if (options_find1(oo, optstr) == NULL) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "unknown option: %s", optstr); + cmdq_error(item, "unknown option: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr != NULL) { - cmdq_error(cmdq, "value passed to unset option: %s", + cmdq_error(item, "value passed to unset option: %s", optstr); return (CMD_RETURN_ERROR); } @@ -283,13 +283,13 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, o = options_find1(oo, optstr); if (args_has(args, 'o') && o != NULL) { if (!args_has(args, 'q')) { - cmdq_error(cmdq, "already set: %s", optstr); + cmdq_error(item, "already set: %s", optstr); return (CMD_RETURN_ERROR); } return (CMD_RETURN_NORMAL); } if (valstr == NULL) { - cmdq_error(cmdq, "empty value"); + cmdq_error(item, "empty value"); return (CMD_RETURN_ERROR); } if (o != NULL && args_has(args, 'a')) @@ -302,14 +302,14 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, /* Unset an option. */ static int -cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_unset(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { struct args *args = self->args; if (value != NULL) { - cmdq_error(cmdq, "value passed to unset option: %s", oe->name); + cmdq_error(item, "value passed to unset option: %s", oe->name); return (-1); } @@ -332,7 +332,7 @@ cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, /* Set an option. */ static int -cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_set(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -344,7 +344,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, break; default: if (value == NULL) { - cmdq_error(cmdq, "empty value"); + cmdq_error(item, "empty value"); return (-1); } } @@ -352,32 +352,32 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, o = NULL; switch (oe->type) { case OPTIONS_TABLE_STRING: - o = cmd_set_option_string(self, cmdq, oe, oo, value); + o = cmd_set_option_string(self, item, oe, oo, value); break; case OPTIONS_TABLE_NUMBER: - o = cmd_set_option_number(self, cmdq, oe, oo, value); + o = cmd_set_option_number(self, item, oe, oo, value); break; case OPTIONS_TABLE_KEY: - o = cmd_set_option_key(self, cmdq, oe, oo, value); + o = cmd_set_option_key(self, item, oe, oo, value); break; case OPTIONS_TABLE_COLOUR: - o = cmd_set_option_colour(self, cmdq, oe, oo, value); + o = cmd_set_option_colour(self, item, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_ATTRIBUTES: - o = cmd_set_option_attributes(self, cmdq, oe, oo, value); + o = cmd_set_option_attributes(self, item, oe, oo, value); if (o != NULL) style_update_new(oo, o->name, oe->style); break; case OPTIONS_TABLE_FLAG: - o = cmd_set_option_flag(self, cmdq, oe, oo, value); + o = cmd_set_option_flag(self, item, oe, oo, value); break; case OPTIONS_TABLE_CHOICE: - o = cmd_set_option_choice(self, cmdq, oe, oo, value); + o = cmd_set_option_choice(self, item, oe, oo, value); break; case OPTIONS_TABLE_STYLE: - o = cmd_set_option_style(self, cmdq, oe, oo, value); + o = cmd_set_option_style(self, item, oe, oo, value); break; } if (o == NULL) @@ -387,7 +387,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, /* Set a string option. */ static struct options_entry * -cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq, +cmd_set_option_string(struct cmd *self, __unused struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -409,7 +409,7 @@ cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq, /* Set a number option. */ static struct options_entry * -cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_number(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -418,7 +418,7 @@ cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, ll = strtonum(value, oe->minimum, oe->maximum, &errstr); if (errstr != NULL) { - cmdq_error(cmdq, "value is %s: %s", errstr, value); + cmdq_error(item, "value is %s: %s", errstr, value); return (NULL); } @@ -427,7 +427,7 @@ cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, /* Set a key option. */ static struct options_entry * -cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_key(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -435,7 +435,7 @@ cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, key = key_string_lookup_string(value); if (key == KEYC_UNKNOWN) { - cmdq_error(cmdq, "bad key: %s", value); + cmdq_error(item, "bad key: %s", value); return (NULL); } @@ -444,14 +444,14 @@ cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, /* Set a colour option. */ static struct options_entry * -cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_colour(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { int colour; if ((colour = colour_fromstring(value)) == -1) { - cmdq_error(cmdq, "bad colour: %s", value); + cmdq_error(item, "bad colour: %s", value); return (NULL); } @@ -460,14 +460,14 @@ cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq, /* Set an attributes option. */ static struct options_entry * -cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_attributes(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { int attr; if ((attr = attributes_fromstring(value)) == -1) { - cmdq_error(cmdq, "bad attributes: %s", value); + cmdq_error(item, "bad attributes: %s", value); return (NULL); } @@ -476,7 +476,7 @@ cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq, /* Set a flag option. */ static struct options_entry * -cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_flag(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -494,7 +494,7 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, strcasecmp(value, "no") == 0) flag = 0; else { - cmdq_error(cmdq, "bad value: %s", value); + cmdq_error(item, "bad value: %s", value); return (NULL); } } @@ -504,7 +504,7 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, /* Set a choice option. */ static struct options_entry * -cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_choice(__unused struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -523,13 +523,13 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, continue; if (choice != -1) { - cmdq_error(cmdq, "ambiguous value: %s", value); + cmdq_error(item, "ambiguous value: %s", value); return (NULL); } choice = n - 1; } if (choice == -1) { - cmdq_error(cmdq, "unknown value: %s", value); + cmdq_error(item, "unknown value: %s", value); return (NULL); } } @@ -539,7 +539,7 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, /* Set a style option. */ static struct options_entry * -cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq, +cmd_set_option_style(struct cmd *self, struct cmdq_item *item, const struct options_table_entry *oe, struct options *oo, const char *value) { @@ -549,7 +549,7 @@ cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq, append = args_has(args, 'a'); if ((o = options_set_style(oo, oe->name, value, append)) == NULL) { - cmdq_error(cmdq, "bad style: %s", value); + cmdq_error(item, "bad style: %s", value); return (NULL); } diff --git a/cmd-show-environment.c b/cmd-show-environment.c index 659acfad..8b38de2c 100644 --- a/cmd-show-environment.c +++ b/cmd-show-environment.c @@ -27,10 +27,11 @@ * Show environment. */ -static enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_environment_exec(struct cmd *, + struct cmdq_item *); static char *cmd_show_environment_escape(struct environ_entry *); -static void cmd_show_environment_print(struct cmd *, struct cmd_q *, +static void cmd_show_environment_print(struct cmd *, struct cmdq_item *, struct environ_entry *); const struct cmd_entry cmd_show_environment_entry = { @@ -65,30 +66,30 @@ cmd_show_environment_escape(struct environ_entry *envent) } static void -cmd_show_environment_print(struct cmd *self, struct cmd_q *cmdq, +cmd_show_environment_print(struct cmd *self, struct cmdq_item *item, struct environ_entry *envent) { char *escaped; if (!args_has(self->args, 's')) { if (envent->value != NULL) - cmdq_print(cmdq, "%s=%s", envent->name, envent->value); + cmdq_print(item, "%s=%s", envent->name, envent->value); else - cmdq_print(cmdq, "-%s", envent->name); + cmdq_print(item, "-%s", envent->name); return; } if (envent->value != NULL) { escaped = cmd_show_environment_escape(envent); - cmdq_print(cmdq, "%s=\"%s\"; export %s;", envent->name, escaped, + cmdq_print(item, "%s=\"%s\"; export %s;", envent->name, escaped, envent->name); free(escaped); } else - cmdq_print(cmdq, "unset %s;", envent->name); + cmdq_print(item, "unset %s;", envent->name); } static enum cmd_retval -cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct environ *env; @@ -96,8 +97,8 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq) const char *target; if ((target = args_get(args, 't')) != NULL) { - if (cmdq->state.tflag.s == NULL) { - cmdq_error(cmdq, "no such session: %s", target); + if (item->state.tflag.s == NULL) { + cmdq_error(item, "no such session: %s", target); return (CMD_RETURN_ERROR); } } @@ -105,30 +106,30 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(self->args, 'g')) env = global_environ; else { - if (cmdq->state.tflag.s == NULL) { + if (item->state.tflag.s == NULL) { target = args_get(args, 't'); if (target != NULL) - cmdq_error(cmdq, "no such session: %s", target); + cmdq_error(item, "no such session: %s", target); else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } - env = cmdq->state.tflag.s->environ; + env = item->state.tflag.s->environ; } if (args->argc != 0) { envent = environ_find(env, args->argv[0]); if (envent == NULL) { - cmdq_error(cmdq, "unknown variable: %s", args->argv[0]); + cmdq_error(item, "unknown variable: %s", args->argv[0]); return (CMD_RETURN_ERROR); } - cmd_show_environment_print(self, cmdq, envent); + cmd_show_environment_print(self, item, envent); return (CMD_RETURN_NORMAL); } envent = environ_first(env); while (envent != NULL) { - cmd_show_environment_print(self, cmdq, envent); + cmd_show_environment_print(self, item, envent); envent = environ_next(envent); } return (CMD_RETURN_NORMAL); diff --git a/cmd-show-messages.c b/cmd-show-messages.c index 8d33cdd0..6eaf35d0 100644 --- a/cmd-show-messages.c +++ b/cmd-show-messages.c @@ -28,7 +28,8 @@ * Show client message log. */ -static enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_messages_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_show_messages_entry = { .name = "show-messages", @@ -54,11 +55,11 @@ const struct cmd_entry cmd_server_info_entry = { .exec = cmd_show_messages_exec }; -static int cmd_show_messages_terminals(struct cmd_q *, int); -static int cmd_show_messages_jobs(struct cmd_q *, int); +static int cmd_show_messages_terminals(struct cmdq_item *, int); +static int cmd_show_messages_jobs(struct cmdq_item *, int); static int -cmd_show_messages_terminals(struct cmd_q *cmdq, int blank) +cmd_show_messages_terminals(struct cmdq_item *item, int blank) { struct tty_term *term; u_int i, n; @@ -66,20 +67,20 @@ cmd_show_messages_terminals(struct cmd_q *cmdq, int blank) n = 0; LIST_FOREACH(term, &tty_terms, entry) { if (blank) { - cmdq_print(cmdq, "%s", ""); + cmdq_print(item, "%s", ""); blank = 0; } - cmdq_print(cmdq, "Terminal %u: %s [references=%u, flags=0x%x]:", + cmdq_print(item, "Terminal %u: %s [references=%u, flags=0x%x]:", n, term->name, term->references, term->flags); n++; for (i = 0; i < tty_term_ncodes(); i++) - cmdq_print(cmdq, "%s", tty_term_describe(term, i)); + cmdq_print(item, "%s", tty_term_describe(term, i)); } return (n != 0); } static int -cmd_show_messages_jobs(struct cmd_q *cmdq, int blank) +cmd_show_messages_jobs(struct cmdq_item *item, int blank) { struct job *job; u_int n; @@ -87,10 +88,10 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank) n = 0; LIST_FOREACH(job, &all_jobs, lentry) { if (blank) { - cmdq_print(cmdq, "%s", ""); + cmdq_print(item, "%s", ""); blank = 0; } - cmdq_print(cmdq, "Job %u: %s [fd=%d, pid=%d, status=%d]", + cmdq_print(item, "Job %u: %s [fd=%d, pid=%d, status=%d]", n, job->cmd, job->fd, job->pid, job->status); n++; } @@ -98,21 +99,21 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank) } static enum cmd_retval -cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct client *c = cmdq->state.c; + struct client *c = item->state.c; struct message_entry *msg; char *tim; int done, blank; done = blank = 0; if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) { - blank = cmd_show_messages_terminals(cmdq, blank); + blank = cmd_show_messages_terminals(item, blank); done = 1; } if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) { - cmd_show_messages_jobs(cmdq, blank); + cmd_show_messages_jobs(item, blank); done = 1; } if (done) @@ -122,7 +123,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) tim = ctime(&msg->msg_time); *strchr(tim, '\n') = '\0'; - cmdq_print(cmdq, "%s %s", tim, msg->msg); + cmdq_print(item, "%s %s", tim, msg->msg); } return (CMD_RETURN_NORMAL); diff --git a/cmd-show-options.c b/cmd-show-options.c index 4daa6969..93ae939f 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -27,11 +27,11 @@ * Show options. */ -static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, +static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *, struct options *, int); -static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, +static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *, struct options *, enum options_table_scope); const struct cmd_entry cmd_show_options_entry = { @@ -61,11 +61,11 @@ const struct cmd_entry cmd_show_window_options_entry = { }; static enum cmd_retval -cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_show_options_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; struct options *oo; enum options_table_scope scope; int quiet; @@ -82,9 +82,9 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) else if (wl == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such window: %s", target); + cmdq_error(item, "no such window: %s", target); } else - cmdq_error(cmdq, "no current window"); + cmdq_error(item, "no current window"); return (CMD_RETURN_ERROR); } else oo = wl->window->options; @@ -95,9 +95,9 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) else if (s == NULL) { target = args_get(args, 't'); if (target != NULL) { - cmdq_error(cmdq, "no such session: %s", target); + cmdq_error(item, "no such session: %s", target); } else - cmdq_error(cmdq, "no current session"); + cmdq_error(item, "no current session"); return (CMD_RETURN_ERROR); } else oo = s->options; @@ -105,13 +105,13 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) quiet = args_has(self->args, 'q'); if (args->argc == 0) - return (cmd_show_options_all(self, cmdq, oo, scope)); + return (cmd_show_options_all(self, item, oo, scope)); else - return (cmd_show_options_one(self, cmdq, oo, quiet)); + return (cmd_show_options_one(self, item, oo, quiet)); } static enum cmd_retval -cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, +cmd_show_options_one(struct cmd *self, struct cmdq_item *item, struct options *oo, int quiet) { struct args *args = self->args; @@ -125,25 +125,25 @@ retry: if ((o = options_find1(oo, name)) == NULL) { if (quiet) return (CMD_RETURN_NORMAL); - cmdq_error(cmdq, "unknown option: %s", name); + cmdq_error(item, "unknown option: %s", name); return (CMD_RETURN_ERROR); } if (args_has(self->args, 'v')) - cmdq_print(cmdq, "%s", o->str); + cmdq_print(item, "%s", o->str); else - cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); + cmdq_print(item, "%s \"%s\"", o->name, o->str); return (CMD_RETURN_NORMAL); } oe = NULL; if (options_table_find(name, &oe) != 0) { - cmdq_error(cmdq, "ambiguous option: %s", name); + cmdq_error(item, "ambiguous option: %s", name); return (CMD_RETURN_ERROR); } if (oe == NULL) { if (quiet) return (CMD_RETURN_NORMAL); - cmdq_error(cmdq, "unknown option: %s", name); + cmdq_error(item, "unknown option: %s", name); return (CMD_RETURN_ERROR); } if (oe->style != NULL) { @@ -154,15 +154,15 @@ retry: return (CMD_RETURN_NORMAL); optval = options_table_print_entry(oe, o, args_has(self->args, 'v')); if (args_has(self->args, 'v')) - cmdq_print(cmdq, "%s", optval); + cmdq_print(item, "%s", optval); else - cmdq_print(cmdq, "%s %s", oe->name, optval); + cmdq_print(item, "%s %s", oe->name, optval); return (CMD_RETURN_NORMAL); } static enum cmd_retval -cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, - enum options_table_scope scope) +cmd_show_options_all(struct cmd *self, struct cmdq_item *item, + struct options *oo, enum options_table_scope scope) { const struct options_table_entry *oe; struct options_entry *o; @@ -173,9 +173,9 @@ cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, while (o != NULL) { if (*o->name == '@') { if (args_has(self->args, 'v')) - cmdq_print(cmdq, "%s", o->str); + cmdq_print(item, "%s", o->str); else - cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); + cmdq_print(item, "%s \"%s\"", o->name, o->str); } o = options_next(o); } @@ -188,9 +188,9 @@ cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, continue; optval = options_table_print_entry(oe, o, vflag); if (vflag) - cmdq_print(cmdq, "%s", optval); + cmdq_print(item, "%s", optval); else - cmdq_print(cmdq, "%s %s", oe->name, optval); + cmdq_print(item, "%s %s", oe->name, optval); } return (CMD_RETURN_NORMAL); diff --git a/cmd-source-file.c b/cmd-source-file.c index 6f9c4451..d2178692 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -26,9 +26,9 @@ * Sources a configuration file. */ -static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *); -static enum cmd_retval cmd_source_file_done(struct cmd_q *, void *); +static enum cmd_retval cmd_source_file_done(struct cmdq_item *, void *); const struct cmd_entry cmd_source_file_entry = { .name = "source-file", @@ -42,34 +42,34 @@ const struct cmd_entry cmd_source_file_entry = { }; static enum cmd_retval -cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) { - struct args *args = self->args; - struct client *c = cmdq->client; - int quiet; - struct cmd_q *new_cmdq; + struct args *args = self->args; + struct client *c = item->client; + int quiet; + struct cmdq_item *new_item; quiet = args_has(args, 'q'); - switch (load_cfg(args->argv[0], c, cmdq, quiet)) { + switch (load_cfg(args->argv[0], c, item, quiet)) { case -1: if (cfg_finished) - cfg_print_causes(cmdq); + cfg_print_causes(item); return (CMD_RETURN_ERROR); case 0: if (cfg_finished) - cfg_print_causes(cmdq); + cfg_print_causes(item); return (CMD_RETURN_NORMAL); } if (cfg_finished) { - new_cmdq = cmdq_get_callback(cmd_source_file_done, NULL); - cmdq_insert_after(cmdq, new_cmdq); + new_item = cmdq_get_callback(cmd_source_file_done, NULL); + cmdq_insert_after(item, new_item); } return (CMD_RETURN_NORMAL); } static enum cmd_retval -cmd_source_file_done(struct cmd_q *cmdq, __unused void *data) +cmd_source_file_done(struct cmdq_item *item, __unused void *data) { - cfg_print_causes(cmdq); + cfg_print_causes(item); return (CMD_RETURN_NORMAL); } diff --git a/cmd-split-window.c b/cmd-split-window.c index 013391a6..5a724c36 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -32,7 +32,8 @@ #define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -static enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_split_window_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_split_window_entry = { .name = "split-window", @@ -49,13 +50,13 @@ const struct cmd_entry cmd_split_window_entry = { }; static enum cmd_retval -cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct session *s = cmdq->state.tflag.s; - struct winlink *wl = cmdq->state.tflag.wl; + struct session *s = item->state.tflag.s; + struct winlink *wl = item->state.tflag.wl; struct window *w = wl->window; - struct window_pane *wp = cmdq->state.tflag.wp, *new_wp = NULL; + struct window_pane *wp = item->state.tflag.wp, *new_wp = NULL; struct environ *env; const char *cmd, *path, *shell, *template, *cwd, *to_free; char **argv, *cause, *new_cause, *cp; @@ -90,12 +91,12 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) to_free = NULL; if (args_has(args, 'c')) { - ft = format_create(cmdq, 0); - format_defaults(ft, cmdq->state.c, s, NULL, NULL); + ft = format_create(item, 0); + format_defaults(ft, item->state.c, s, NULL, NULL); to_free = cwd = format_expand(ft, args_get(args, 'c')); format_free(ft); - } else if (cmdq->client != NULL && cmdq->client->session == NULL) - cwd = cmdq->client->cwd; + } else if (item->client != NULL && item->client->session == NULL) + cwd = item->client->cwd; else cwd = s->cwd; @@ -141,8 +142,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) layout_assign_pane(lc, new_wp); path = NULL; - if (cmdq->client != NULL && cmdq->client->session == NULL) - envent = environ_find(cmdq->client->environ, "PATH"); + if (item->client != NULL && item->client->session == NULL) + envent = environ_find(item->client->environ, "PATH"); else envent = environ_find(s->environ, "PATH"); if (envent != NULL) @@ -167,11 +168,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = SPLIT_WINDOW_TEMPLATE; - ft = format_create(cmdq, 0); - format_defaults(ft, cmdq->state.c, s, wl, new_wp); + ft = format_create(item, 0); + format_defaults(ft, item->state.c, s, wl, new_wp); cp = format_expand(ft, template); - cmdq_print(cmdq, "%s", cp); + cmdq_print(item, "%s", cp); free(cp); format_free(ft); @@ -187,7 +188,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) fs.w = w; fs.wp = new_wp; cmd_find_log_state(__func__, &fs); - hooks_insert(s->hooks, cmdq, &fs, "after-split-window"); + hooks_insert(s->hooks, item, &fs, "after-split-window"); return (CMD_RETURN_NORMAL); @@ -197,7 +198,7 @@ error: layout_close_pane(new_wp); window_remove_pane(w, new_wp); } - cmdq_error(cmdq, "create pane failed: %s", cause); + cmdq_error(item, "create pane failed: %s", cause); free(cause); if (to_free != NULL) diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index e5f5c810..43959140 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -26,7 +26,7 @@ * Swap two panes. */ -static enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_swap_pane_entry = { .name = "swap-pane", @@ -43,17 +43,17 @@ const struct cmd_entry cmd_swap_pane_entry = { }; static enum cmd_retval -cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) { struct window *src_w, *dst_w; struct window_pane *tmp_wp, *src_wp, *dst_wp; struct layout_cell *src_lc, *dst_lc; u_int sx, sy, xoff, yoff; - dst_w = cmdq->state.tflag.wl->window; - dst_wp = cmdq->state.tflag.wp; - src_w = cmdq->state.sflag.wl->window; - src_wp = cmdq->state.sflag.wp; + dst_w = item->state.tflag.wl->window; + dst_wp = item->state.tflag.wp; + src_w = item->state.sflag.wl->window; + src_wp = item->state.sflag.wp; server_unzoom_window(dst_w); if (args_has(self->args, 'D')) { diff --git a/cmd-swap-window.c b/cmd-swap-window.c index 904a974d..0a0fcab9 100644 --- a/cmd-swap-window.c +++ b/cmd-swap-window.c @@ -26,7 +26,7 @@ * Swap one window with another. */ -static enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_swap_window_entry = { .name = "swap-window", @@ -43,24 +43,24 @@ const struct cmd_entry cmd_swap_window_entry = { }; static enum cmd_retval -cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item) { struct session *src, *dst; struct session_group *sg_src, *sg_dst; struct winlink *wl_src, *wl_dst; struct window *w; - wl_src = cmdq->state.sflag.wl; - src = cmdq->state.sflag.s; + wl_src = item->state.sflag.wl; + src = item->state.sflag.s; sg_src = session_group_find(src); - wl_dst = cmdq->state.tflag.wl; - dst = cmdq->state.tflag.s; + wl_dst = item->state.tflag.wl; + dst = item->state.tflag.s; sg_dst = session_group_find(dst); if (src != dst && sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) { - cmdq_error(cmdq, "can't move window, sessions are grouped"); + cmdq_error(item, "can't move window, sessions are grouped"); return (CMD_RETURN_ERROR); } diff --git a/cmd-switch-client.c b/cmd-switch-client.c index cc3212db..eb7c5351 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -27,7 +27,8 @@ * Switch client to a different session. */ -static enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_switch_client_exec(struct cmd *, + struct cmdq_item *); const struct cmd_entry cmd_switch_client_entry = { .name = "switch-client", @@ -45,12 +46,12 @@ const struct cmd_entry cmd_switch_client_entry = { }; static enum cmd_retval -cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; - struct cmd_state *state = &cmdq->state; + struct cmd_state *state = &item->state; struct client *c = state->c; - struct session *s = cmdq->state.tflag.s; + struct session *s = item->state.tflag.s; struct window_pane *wp; const char *tablename, *update; struct key_table *table; @@ -62,7 +63,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) if (tablename != NULL) { table = key_bindings_get_table(tablename, 0); if (table == NULL) { - cmdq_error(cmdq, "table %s doesn't exist", tablename); + cmdq_error(item, "table %s doesn't exist", tablename); return (CMD_RETURN_ERROR); } table->references++; @@ -73,12 +74,12 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'n')) { if ((s = session_next_session(c->session)) == NULL) { - cmdq_error(cmdq, "can't find next session"); + cmdq_error(item, "can't find next session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'p')) { if ((s = session_previous_session(c->session)) == NULL) { - cmdq_error(cmdq, "can't find previous session"); + cmdq_error(item, "can't find previous session"); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'l')) { @@ -87,11 +88,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) else s = NULL; if (s == NULL) { - cmdq_error(cmdq, "can't find last session"); + cmdq_error(item, "can't find last session"); return (CMD_RETURN_ERROR); } } else { - if (cmdq->client == NULL) + if (item->client == NULL) return (CMD_RETURN_NORMAL); if (state->tflag.wl != NULL) { wp = state->tflag.wp; diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index a38799e4..69141346 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -26,9 +26,10 @@ * Unbind key from command. */ -static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); -static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, - key_code); +static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmdq_item *); + +static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, + struct cmdq_item *, key_code); const struct cmd_entry cmd_unbind_key_entry = { .name = "unbind-key", @@ -42,7 +43,7 @@ const struct cmd_entry cmd_unbind_key_entry = { }; static enum cmd_retval -cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; key_code key; @@ -50,24 +51,24 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) if (!args_has(args, 'a')) { if (args->argc != 1) { - cmdq_error(cmdq, "missing key"); + cmdq_error(item, "missing key"); return (CMD_RETURN_ERROR); } key = key_string_lookup_string(args->argv[0]); if (key == KEYC_NONE || key == KEYC_UNKNOWN) { - cmdq_error(cmdq, "unknown key: %s", args->argv[0]); + cmdq_error(item, "unknown key: %s", args->argv[0]); return (CMD_RETURN_ERROR); } } else { if (args->argc != 0) { - cmdq_error(cmdq, "key given with -a"); + cmdq_error(item, "key given with -a"); return (CMD_RETURN_ERROR); } key = KEYC_UNKNOWN; } if (args_has(args, 't')) - return (cmd_unbind_key_mode_table(self, cmdq, key)); + return (cmd_unbind_key_mode_table(self, item, key)); if (key == KEYC_UNKNOWN) { tablename = args_get(args, 'T'); @@ -77,7 +78,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } if (key_bindings_get_table(tablename, 0) == NULL) { - cmdq_error(cmdq, "table %s doesn't exist", tablename); + cmdq_error(item, "table %s doesn't exist", tablename); return (CMD_RETURN_ERROR); } key_bindings_remove_table(tablename); @@ -87,7 +88,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) if (args_has(args, 'T')) { tablename = args_get(args, 'T'); if (key_bindings_get_table(tablename, 0) == NULL) { - cmdq_error(cmdq, "table %s doesn't exist", tablename); + cmdq_error(item, "table %s doesn't exist", tablename); return (CMD_RETURN_ERROR); } } else if (args_has(args, 'n')) @@ -99,7 +100,8 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) } static enum cmd_retval -cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) +cmd_unbind_key_mode_table(struct cmd *self, struct cmdq_item *item, + key_code key) { struct args *args = self->args; const char *tablename; @@ -108,7 +110,7 @@ cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { - cmdq_error(cmdq, "unknown key table: %s", tablename); + cmdq_error(item, "unknown key table: %s", tablename); return (CMD_RETURN_ERROR); } diff --git a/cmd-wait-for.c b/cmd-wait-for.c index 505e4d63..396548a7 100644 --- a/cmd-wait-for.c +++ b/cmd-wait-for.c @@ -28,7 +28,7 @@ * Block or wake a client on a named wait channel. */ -static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_wait_for_entry = { .name = "wait-for", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_wait_for_entry = { }; struct wait_item { - struct cmd_q *cmdq; + struct cmdq_item *item; TAILQ_ENTRY(wait_item) entry; }; @@ -68,17 +68,17 @@ wait_channel_cmp(struct wait_channel *wc1, struct wait_channel *wc2) return (strcmp(wc1->name, wc2->name)); } -static enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *, +static enum cmd_retval cmd_wait_for_signal(struct cmdq_item *, const char *, struct wait_channel *); -static enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *, +static enum cmd_retval cmd_wait_for_wait(struct cmdq_item *, const char *, struct wait_channel *); -static enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *, +static enum cmd_retval cmd_wait_for_lock(struct cmdq_item *, const char *, struct wait_channel *); -static enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *, +static enum cmd_retval cmd_wait_for_unlock(struct cmdq_item *, const char *, struct wait_channel *); static struct wait_channel *cmd_wait_for_add(const char *); -static void cmd_wait_for_remove(struct wait_channel *wc); +static void cmd_wait_for_remove(struct wait_channel *); static struct wait_channel * cmd_wait_for_add(const char *name) @@ -118,7 +118,7 @@ cmd_wait_for_remove(struct wait_channel *wc) } static enum cmd_retval -cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq) +cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; const char *name = args->argv[0]; @@ -128,16 +128,16 @@ cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq) wc = RB_FIND(wait_channels, &wait_channels, &wc0); if (args_has(args, 'S')) - return (cmd_wait_for_signal(cmdq, name, wc)); + return (cmd_wait_for_signal(item, name, wc)); if (args_has(args, 'L')) - return (cmd_wait_for_lock(cmdq, name, wc)); + return (cmd_wait_for_lock(item, name, wc)); if (args_has(args, 'U')) - return (cmd_wait_for_unlock(cmdq, name, wc)); - return (cmd_wait_for_wait(cmdq, name, wc)); + return (cmd_wait_for_unlock(item, name, wc)); + return (cmd_wait_for_wait(item, name, wc)); } static enum cmd_retval -cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, +cmd_wait_for_signal(__unused struct cmdq_item *item, const char *name, struct wait_channel *wc) { struct wait_item *wi, *wi1; @@ -153,7 +153,7 @@ cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, log_debug("signal wait channel %s, with waiters", wc->name); TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { - wi->cmdq->flags &= ~CMD_Q_WAITING; + wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); @@ -164,13 +164,14 @@ cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, } static enum cmd_retval -cmd_wait_for_wait(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) +cmd_wait_for_wait(struct cmdq_item *item, const char *name, + struct wait_channel *wc) { - struct client *c = cmdq->client; + struct client *c = item->client; struct wait_item *wi; if (c == NULL || c->session != NULL) { - cmdq_error(cmdq, "not able to wait"); + cmdq_error(item, "not able to wait"); return (CMD_RETURN_ERROR); } @@ -185,19 +186,20 @@ cmd_wait_for_wait(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) log_debug("wait channel %s not woken (%p)", wc->name, c); wi = xcalloc(1, sizeof *wi); - wi->cmdq = cmdq; + wi->item = item; TAILQ_INSERT_TAIL(&wc->waiters, wi, entry); return (CMD_RETURN_WAIT); } static enum cmd_retval -cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) +cmd_wait_for_lock(struct cmdq_item *item, const char *name, + struct wait_channel *wc) { struct wait_item *wi; - if (cmdq->client == NULL || cmdq->client->session != NULL) { - cmdq_error(cmdq, "not able to lock"); + if (item->client == NULL || item->client->session != NULL) { + cmdq_error(item, "not able to lock"); return (CMD_RETURN_ERROR); } @@ -206,7 +208,7 @@ cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) if (wc->locked) { wi = xcalloc(1, sizeof *wi); - wi->cmdq = cmdq; + wi->item = item; TAILQ_INSERT_TAIL(&wc->lockers, wi, entry); return (CMD_RETURN_WAIT); } @@ -216,18 +218,18 @@ cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) } static enum cmd_retval -cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name, +cmd_wait_for_unlock(struct cmdq_item *item, const char *name, struct wait_channel *wc) { struct wait_item *wi; if (wc == NULL || !wc->locked) { - cmdq_error(cmdq, "channel %s not locked", name); + cmdq_error(item, "channel %s not locked", name); return (CMD_RETURN_ERROR); } if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) { - wi->cmdq->flags &= ~CMD_Q_WAITING; + wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); } else { @@ -246,13 +248,13 @@ cmd_wait_for_flush(void) RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) { TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { - wi->cmdq->flags &= ~CMD_Q_WAITING; + wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->waiters, wi, entry); free(wi); } wc->woken = 1; TAILQ_FOREACH_SAFE(wi, &wc->lockers, entry, wi1) { - wi->cmdq->flags &= ~CMD_Q_WAITING; + wi->item->flags &= ~CMDQ_WAITING; TAILQ_REMOVE(&wc->lockers, wi, entry); free(wi); } diff --git a/cmd.c b/cmd.c index a7de1f58..807c2de2 100644 --- a/cmd.c +++ b/cmd.c @@ -389,7 +389,7 @@ usage: static int cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, - struct cmd_q *cmdq) + struct cmdq_item *item) { int targetflags, error; struct cmd_find_state *fs = NULL; @@ -401,9 +401,9 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, return (0); if (c == 't') - fs = &cmdq->state.tflag; + fs = &item->state.tflag; else if (c == 's') - fs = &cmdq->state.sflag; + fs = &item->state.sflag; if (flag == CMD_SESSION_WITHPANE) { if (target != NULL && target[strcspn(target, ":.")] != '\0') @@ -449,7 +449,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, } log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags); - error = cmd_find_current(¤t, cmdq, targetflags); + error = cmd_find_current(¤t, item, targetflags); if (error != 0 && ~targetflags & CMD_FIND_QUIET) return (-1); if (!cmd_find_empty_state(¤t) && !cmd_find_valid_state(¤t)) @@ -464,13 +464,13 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, case CMD_SESSION_CANFAIL: case CMD_SESSION_PREFERUNATTACHED: case CMD_SESSION_WITHPANE: - error = cmd_find_target(fs, ¤t, cmdq, target, + error = cmd_find_target(fs, ¤t, item, target, CMD_FIND_SESSION, targetflags); if (error != 0 && ~targetflags & CMD_FIND_QUIET) return (-1); break; case CMD_MOVEW_R: - error = cmd_find_target(fs, ¤t, cmdq, target, + error = cmd_find_target(fs, ¤t, item, target, CMD_FIND_SESSION, CMD_FIND_QUIET); if (error == 0) break; @@ -479,7 +479,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, case CMD_WINDOW_CANFAIL: case CMD_WINDOW_MARKED: case CMD_WINDOW_INDEX: - error = cmd_find_target(fs, ¤t, cmdq, target, + error = cmd_find_target(fs, ¤t, item, target, CMD_FIND_WINDOW, targetflags); if (error != 0 && ~targetflags & CMD_FIND_QUIET) return (-1); @@ -487,7 +487,7 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, case CMD_PANE: case CMD_PANE_CANFAIL: case CMD_PANE_MARKED: - error = cmd_find_target(fs, ¤t, cmdq, target, + error = cmd_find_target(fs, ¤t, item, target, CMD_FIND_PANE, targetflags); if (error != 0 && ~targetflags & CMD_FIND_QUIET) return (-1); @@ -499,17 +499,17 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, } int -cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq) +cmd_prepare_state(struct cmd *cmd, struct cmdq_item *item) { const struct cmd_entry *entry = cmd->entry; - struct cmd_state *state = &cmdq->state; + struct cmd_state *state = &item->state; char *tmp; enum cmd_entry_flag flag; const char *s; int error; tmp = cmd_print(cmd); - log_debug("preparing state for %s (client %p)", tmp, cmdq->client); + log_debug("preparing state for %s (client %p)", tmp, item->client); free(tmp); state->c = NULL; @@ -527,12 +527,12 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq) s = args_get(cmd->args, 'c'); switch (flag) { case CMD_CLIENT: - state->c = cmd_find_client(cmdq, s, 0); + state->c = cmd_find_client(item, s, 0); if (state->c == NULL) return (-1); break; default: - state->c = cmd_find_client(cmdq, s, 1); + state->c = cmd_find_client(item, s, 1); break; } log_debug("using client %p", state->c); @@ -540,14 +540,14 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq) s = args_get(cmd->args, 't'); log_debug("preparing -t state: target %s", s == NULL ? "none" : s); - error = cmd_prepare_state_flag('t', s, entry->tflag, cmdq); + error = cmd_prepare_state_flag('t', s, entry->tflag, item); if (error != 0) return (error); s = args_get(cmd->args, 's'); log_debug("preparing -s state: target %s", s == NULL ? "none" : s); - error = cmd_prepare_state_flag('s', s, entry->sflag, cmdq); + error = cmd_prepare_state_flag('s', s, entry->sflag, item); if (error != 0) return (error); diff --git a/control.c b/control.c index cd605f4f..e9b1e8ea 100644 --- a/control.c +++ b/control.c @@ -51,14 +51,14 @@ control_write_buffer(struct client *c, struct evbuffer *buffer) /* Control error callback. */ static enum cmd_retval -control_error(struct cmd_q *cmdq, void *data) +control_error(struct cmdq_item *item, void *data) { - struct client *c = cmdq->client; + struct client *c = item->client; char *error = data; - cmdq_guard(cmdq, "begin", 1); + cmdq_guard(item, "begin", 1); control_write(c, "parse error: %s", error); - cmdq_guard(cmdq, "error", 1); + cmdq_guard(item, "error", 1); free(error); return (CMD_RETURN_NORMAL); @@ -68,10 +68,10 @@ control_error(struct cmd_q *cmdq, void *data) void control_callback(struct client *c, int closed, __unused void *data) { - char *line, *cause; - struct cmd_list *cmdlist; - struct cmd *cmd; - struct cmd_q *cmdq; + char *line, *cause; + struct cmd_list *cmdlist; + struct cmd *cmd; + struct cmdq_item *item; if (closed) c->flags |= CLIENT_EXIT; @@ -86,13 +86,13 @@ control_callback(struct client *c, int closed, __unused void *data) } if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) { - cmdq = cmdq_get_callback(control_error, cause); - cmdq_append(c, cmdq); + item = cmdq_get_callback(control_error, cause); + cmdq_append(c, item); } else { TAILQ_FOREACH(cmd, &cmdlist->list, qentry) cmd->flags |= CMD_CONTROL; - cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); - cmdq_append(c, cmdq); + item = cmdq_get_command(cmdlist, NULL, NULL, 0); + cmdq_append(c, item); cmd_list_free(cmdlist); } diff --git a/format.c b/format.c index 632dfaf0..3ddb87ca 100644 --- a/format.c +++ b/format.c @@ -487,9 +487,22 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) evbuffer_free(buffer); } +/* Merge a format tree. */ +static void +format_merge(struct format_tree *ft, struct format_tree *from) +{ + struct format_entry *fe; + + RB_FOREACH(fe, format_entry_tree, &from->tree) { + if (fe->value != NULL) + format_add(ft, fe->key, "%s", fe->value); + } + +} + /* Create a new tree. */ struct format_tree * -format_create(struct cmd_q *cmdq, int flags) +format_create(struct cmdq_item *item, int flags) { struct format_tree *ft; @@ -508,10 +521,10 @@ format_create(struct cmd_q *cmdq, int flags) format_add(ft, "socket_path", "%s", socket_path); format_add_tv(ft, "start_time", &start_time); - if (cmdq != NULL && cmdq->cmd != NULL) - format_add(ft, "command", "%s", cmdq->cmd->entry->name); - if (cmdq != NULL && cmdq->hook != NULL) - format_add(ft, "hook", "%s", cmdq->hook); + if (item != NULL && item->cmd != NULL) + format_add(ft, "command", "%s", item->cmd->entry->name); + if (item != NULL && item->formats != NULL) + format_merge(ft, item->formats); return (ft); } diff --git a/hooks.c b/hooks.c index cdd2cf45..832e6f84 100644 --- a/hooks.c +++ b/hooks.c @@ -143,10 +143,10 @@ void hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, const char *fmt, ...) { - struct hook *hook; - va_list ap; - char *name; - struct cmd_q *new_cmdq, *loop; + struct hook *hook; + va_list ap; + char *name; + struct cmdq_item *new_item; va_start(ap, fmt); xvasprintf(&name, fmt, ap); @@ -159,25 +159,23 @@ hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, } log_debug("running hook %s", name); - new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); + new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS); + cmdq_format(new_item, "hook", "%s", name); + cmdq_append(c, new_item); - for (loop = new_cmdq; loop != NULL; loop = loop->next) - loop->hook = xstrdup(name); free(name); - - cmdq_append(c, new_cmdq); } void -hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, - const char *fmt, ...) +hooks_insert(struct hooks *hooks, struct cmdq_item *item, + struct cmd_find_state *fs, const char *fmt, ...) { - struct hook *hook; - va_list ap; - char *name; - struct cmd_q *new_cmdq, *loop; + struct hook *hook; + va_list ap; + char *name; + struct cmdq_item *new_item; - if (cmdq->flags & CMD_Q_NOHOOKS) + if (item->flags & CMDQ_NOHOOKS) return; va_start(ap, fmt); @@ -189,16 +187,14 @@ hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, free(name); return; } - log_debug("running hook %s (parent %p)", name, cmdq); + log_debug("running hook %s (parent %p)", name, item); - new_cmdq = cmdq_get_command(hook->cmdlist, fs, NULL, CMD_Q_NOHOOKS); - - for (loop = new_cmdq; loop != NULL; loop = loop->next) - loop->hook = xstrdup(name); - free(name); - - if (cmdq != NULL) - cmdq_insert_after(cmdq, new_cmdq); + new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS); + cmdq_format(new_item, "hook", "%s", name); + if (item != NULL) + cmdq_insert_after(item, new_item); else - cmdq_append(NULL, new_cmdq); + cmdq_append(NULL, new_item); + + free(name); } diff --git a/key-bindings.c b/key-bindings.c index af53720c..968337a3 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -389,9 +389,9 @@ key_bindings_init(void) } static enum cmd_retval -key_bindings_read_only(struct cmd_q *cmdq, __unused void *data) +key_bindings_read_only(struct cmdq_item *item, __unused void *data) { - cmdq_error(cmdq, "client is read-only"); + cmdq_error(item, "client is read-only"); return (CMD_RETURN_ERROR); } diff --git a/notify.c b/notify.c index cca4ff31..92939c5e 100644 --- a/notify.c +++ b/notify.c @@ -40,8 +40,8 @@ static const char *notify_hooks[] = { "window-renamed", NULL, /* "attached-session-changed", */ "session-renamed", - NULL, /* "session-created", */ - NULL, /* "session-closed" */ + "session-created", + "session-closed" }; struct notify_entry { @@ -50,34 +50,31 @@ struct notify_entry { struct client *client; struct session *session; struct window *window; - - TAILQ_ENTRY(notify_entry) entry; }; -TAILQ_HEAD(notify_queue, notify_entry); -static struct notify_queue notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue); - -static void notify_add(enum notify_type, struct client *, struct session *, - struct window *); static void -notify_hook(struct notify_entry *ne) +notify_hook(struct cmdq_item *item, struct notify_entry *ne) { const char *name; struct cmd_find_state fs; struct hook *hook; - struct cmd_q *new_cmdq, *loop; + struct cmdq_item *new_item; + struct session *s = ne->session; + struct window *w = ne->window; name = notify_hooks[ne->type]; if (name == NULL) return; cmd_find_clear_state(&fs, NULL, 0); - if (ne->session != NULL && ne->window != NULL) - cmd_find_from_session_window(&fs, ne->session, ne->window); - else if (ne->window != NULL) - cmd_find_from_window(&fs, ne->window); - else if (ne->session != NULL) - cmd_find_from_session(&fs, ne->session); + if (s != NULL && w != NULL) + cmd_find_from_session_window(&fs, s, w); + else if (w != NULL) + cmd_find_from_window(&fs, w); + else if (s != NULL && session_alive(s)) + cmd_find_from_session(&fs, s); + else + cmd_find_current(&fs, item, CMD_FIND_QUIET); if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs)) return; @@ -86,12 +83,63 @@ notify_hook(struct notify_entry *ne) return; log_debug("notify hook %s", name); - new_cmdq = cmdq_get_command(hook->cmdlist, &fs, NULL, CMD_Q_NOHOOKS); + new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS); + cmdq_format(new_item, "hook", "%s", name); - for (loop = new_cmdq; loop != NULL; loop = loop->next) - loop->hook = xstrdup(name); + if (s != NULL) { + cmdq_format(new_item, "hook_session", "$%u", s->id); + cmdq_format(new_item, "hook_session_name", "%s", s->name); + } + if (w != NULL) { + cmdq_format(new_item, "hook_window", "@%u", w->id); + cmdq_format(new_item, "hook_window_name", "%s", w->name); + } - cmdq_append(NULL, new_cmdq); + cmdq_insert_after(item, new_item); +} + +static enum cmd_retval +notify_callback(struct cmdq_item *item, void *data) +{ + struct notify_entry *ne = data; + + switch (ne->type) { + case NOTIFY_WINDOW_LAYOUT_CHANGED: + control_notify_window_layout_changed(ne->window); + break; + case NOTIFY_WINDOW_UNLINKED: + control_notify_window_unlinked(ne->session, ne->window); + break; + case NOTIFY_WINDOW_LINKED: + control_notify_window_linked(ne->session, ne->window); + break; + case NOTIFY_WINDOW_RENAMED: + control_notify_window_renamed(ne->window); + break; + case NOTIFY_ATTACHED_SESSION_CHANGED: + control_notify_attached_session_changed(ne->client); + break; + case NOTIFY_SESSION_RENAMED: + control_notify_session_renamed(ne->session); + break; + case NOTIFY_SESSION_CREATED: + control_notify_session_created(ne->session); + break; + case NOTIFY_SESSION_CLOSED: + control_notify_session_closed(ne->session); + break; + } + notify_hook(item, ne); + + if (ne->client != NULL) + server_client_unref(ne->client); + if (ne->session != NULL) + session_unref(ne->session); + if (ne->window != NULL) + window_remove_ref(ne->window); + free(ne); + + return (CMD_RETURN_NORMAL); } static void @@ -99,13 +147,13 @@ notify_add(enum notify_type type, struct client *c, struct session *s, struct window *w) { struct notify_entry *ne; + struct cmdq_item *new_item; ne = xcalloc(1, sizeof *ne); ne->type = type; ne->client = c; ne->session = s; ne->window = w; - TAILQ_INSERT_TAIL(¬ify_queue, ne, entry); if (c != NULL) c->references++; @@ -113,51 +161,9 @@ notify_add(enum notify_type type, struct client *c, struct session *s, s->references++; if (w != NULL) w->references++; -} -void -notify_drain(void) -{ - struct notify_entry *ne, *ne1; - - TAILQ_FOREACH_SAFE(ne, ¬ify_queue, entry, ne1) { - switch (ne->type) { - case NOTIFY_WINDOW_LAYOUT_CHANGED: - control_notify_window_layout_changed(ne->window); - break; - case NOTIFY_WINDOW_UNLINKED: - control_notify_window_unlinked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_LINKED: - control_notify_window_linked(ne->session, ne->window); - break; - case NOTIFY_WINDOW_RENAMED: - control_notify_window_renamed(ne->window); - break; - case NOTIFY_ATTACHED_SESSION_CHANGED: - control_notify_attached_session_changed(ne->client); - break; - case NOTIFY_SESSION_RENAMED: - control_notify_session_renamed(ne->session); - break; - case NOTIFY_SESSION_CREATED: - control_notify_session_created(ne->session); - break; - case NOTIFY_SESSION_CLOSED: - control_notify_session_closed(ne->session); - break; - } - TAILQ_REMOVE(¬ify_queue, ne, entry); - notify_hook(ne); - - if (ne->client != NULL) - server_client_unref(ne->client); - if (ne->session != NULL) - session_unref(ne->session); - if (ne->window != NULL) - window_remove_ref(ne->window); - free(ne); - } + new_item = cmdq_get_callback(notify_callback, ne); + cmdq_append(NULL, new_item); } void @@ -175,54 +181,46 @@ void notify_window_layout_changed(struct window *w) { notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w); - notify_drain(); } void notify_window_unlinked(struct session *s, struct window *w) { notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w); - notify_drain(); } void notify_window_linked(struct session *s, struct window *w) { notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w); - notify_drain(); } void notify_window_renamed(struct window *w) { notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w); - notify_drain(); } void notify_attached_session_changed(struct client *c) { notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL); - notify_drain(); } void notify_session_renamed(struct session *s) { notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL); - notify_drain(); } void notify_session_created(struct session *s) { notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL); - notify_drain(); } void notify_session_closed(struct session *s) { notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL); - notify_drain(); } diff --git a/server-client.c b/server-client.c index 83202a47..4437fe75 100644 --- a/server-client.c +++ b/server-client.c @@ -1262,9 +1262,9 @@ server_client_dispatch(struct imsg *imsg, void *arg) /* Callback when command is done. */ static enum cmd_retval -server_client_command_done(struct cmd_q *cmdq, __unused void *data) +server_client_command_done(struct cmdq_item *item, __unused void *data) { - struct client *c = cmdq->client; + struct client *c = item->client; if (~c->flags & CLIENT_ATTACHED) c->flags |= CLIENT_EXIT; @@ -1273,11 +1273,11 @@ server_client_command_done(struct cmd_q *cmdq, __unused void *data) /* Show an error message. */ static enum cmd_retval -server_client_command_error(struct cmd_q *cmdq, void *data) +server_client_command_error(struct cmdq_item *item, void *data) { char *error = data; - cmdq_error(cmdq, "%s", error); + cmdq_error(item, "%s", error); free(error); return (CMD_RETURN_NORMAL); diff --git a/server.c b/server.c index cc6563de..e9c22987 100644 --- a/server.c +++ b/server.c @@ -194,8 +194,6 @@ server_loop(void) struct client *c; u_int items; - notify_drain(); - do { items = cmdq_next(NULL); TAILQ_FOREACH(c, &clients, entry) diff --git a/tmux.1 b/tmux.1 index 7d743e51..dc621e63 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3248,6 +3248,10 @@ Run when the program running in a pane exits, but is on so the pane has not closed. .It pane-exited Run when the program running in a pane exits. +.It session-created +Run when a new session created. +.It session-closed +Run when a session closed. .It session-renamed Run when a session is renamed. .It window-renamed @@ -3471,6 +3475,10 @@ The following variables are available, where appropriate: .It Li "history_limit" Ta "" Ta "Maximum window history lines" .It Li "history_size" Ta "" Ta "Size of history in bytes" .It Li "hook" Ta "" Ta "Name of running hook, if any" +.It Li "hook_session" Ta "" Ta "ID of session where hook was run, if any" +.It Li "hook_session_name" Ta "" Ta "Name of session where hook was run, if any" +.It Li "hook_window" Ta "" Ta "ID of window where hook was run, if any" +.It Li "hook_window_name" Ta "" Ta "Name of window where hook was run, if any" .It Li "host" Ta "#H" Ta "Hostname of local host" .It Li "host_short" Ta "#h" Ta "Hostname of local host (no domain name)" .It Li "insert_flag" Ta "" Ta "Pane insert flag" diff --git a/tmux.h b/tmux.h index 7ced6131..1c25e2a7 100644 --- a/tmux.h +++ b/tmux.h @@ -42,8 +42,8 @@ extern char **environ; struct args; struct client; -struct cmd_q; -struct cmd_q_list; +struct cmdq_item; +struct cmdq_list; struct environ; struct input_ctx; struct mode_key_cmdstr; @@ -1179,7 +1179,7 @@ enum cmd_find_type { CMD_FIND_SESSION, }; struct cmd_find_state { - struct cmd_q *cmdq; + struct cmdq_item *item; int flags; struct cmd_find_state *current; @@ -1233,35 +1233,36 @@ enum cmd_retval { }; /* Command queue item type. */ -enum cmd_q_type { - CMD_Q_COMMAND, - CMD_Q_CALLBACK, +enum cmdq_type { + CMDQ_COMMAND, + CMDQ_CALLBACK, }; /* Command queue item. */ -typedef enum cmd_retval (*cmd_q_cb) (struct cmd_q *, void *); -struct cmd_q { - struct cmd_q_list *queue; - struct cmd_q *next; +typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *); +struct cmdq_item { + struct cmdq_list *queue; + struct cmdq_item *next; struct client *client; - enum cmd_q_type type; + enum cmdq_type type; u_int group; u_int number; time_t time; - const char *hook; + struct format_tree *formats; + int flags; -#define CMD_Q_FIRED 0x1 -#define CMD_Q_WAITING 0x2 -#define CMD_Q_NOHOOKS 0x4 +#define CMDQ_FIRED 0x1 +#define CMDQ_WAITING 0x2 +#define CMDQ_NOHOOKS 0x4 struct cmd_list *cmdlist; struct cmd *cmd; - cmd_q_cb cb; + cmdq_cb cb; void *data; struct cmd_find_state current; @@ -1269,9 +1270,9 @@ struct cmd_q { struct mouse_event mouse; - TAILQ_ENTRY(cmd_q) entry; + TAILQ_ENTRY(cmdq_item) entry; }; -TAILQ_HEAD(cmd_q_list, cmd_q); +TAILQ_HEAD(cmdq_list, cmdq_item); /* Command -c, -t or -s flags. */ enum cmd_entry_flag { @@ -1318,13 +1319,13 @@ struct cmd_entry { #define CMD_AFTERHOOK 0x4 int flags; - enum cmd_retval (*exec)(struct cmd *, struct cmd_q *); + enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *); }; /* Client connection. */ struct client { struct tmuxpeer *peer; - struct cmd_q_list queue; + struct cmdq_list queue; pid_t pid; int fd; @@ -1512,12 +1513,12 @@ void proc_kill_peer(struct tmuxpeer *); /* cfg.c */ extern int cfg_finished; extern struct client *cfg_client; -void start_cfg(void); -int load_cfg(const char *, struct client *, struct cmd_q *, int); -void set_cfg_file(const char *); +void start_cfg(void); +int load_cfg(const char *, struct client *, struct cmdq_item *, int); +void set_cfg_file(const char *); void printflike(1, 2) cfg_add_cause(const char *, ...); -void cfg_print_causes(struct cmd_q *); -void cfg_show_causes(struct session *); +void cfg_print_causes(struct cmdq_item *); +void cfg_show_causes(struct session *); /* paste.c */ struct paste_buffer; @@ -1538,7 +1539,7 @@ char *paste_make_sample(struct paste_buffer *); #define FORMAT_STATUS 0x1 #define FORMAT_FORCE 0x2 struct format_tree; -struct format_tree *format_create(struct cmd_q *, int); +struct format_tree *format_create(struct cmdq_item *, int); void format_free(struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); @@ -1565,7 +1566,7 @@ void hooks_remove(struct hooks *, const char *); struct hook *hooks_find(struct hooks *, const char *); void printflike(4, 5) hooks_run(struct hooks *, struct client *, struct cmd_find_state *, const char *, ...); -void printflike(4, 5) hooks_insert(struct hooks *, struct cmd_q *, +void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *, struct cmd_find_state *, const char *, ...); /* mode-key.c */ @@ -1583,7 +1584,6 @@ void mode_key_init(struct mode_key_data *, struct mode_key_tree *); enum mode_key_cmd mode_key_lookup(struct mode_key_data *, key_code); /* notify.c */ -void notify_drain(void); void notify_input(struct window_pane *, struct evbuffer *); void notify_window_layout_changed(struct window *); void notify_window_unlinked(struct session *, struct window *); @@ -1731,14 +1731,14 @@ long long args_strtonum(struct args *, u_char, long long, long long, char **); /* cmd-find.c */ -int cmd_find_current(struct cmd_find_state *, struct cmd_q *, +int cmd_find_current(struct cmd_find_state *, struct cmdq_item *, int); int cmd_find_target(struct cmd_find_state *, - struct cmd_find_state *, struct cmd_q *, const char *, + struct cmd_find_state *, struct cmdq_item *, const char *, enum cmd_find_type, int); -struct client *cmd_find_client(struct cmd_q *, const char *, int); -void cmd_find_clear_state(struct cmd_find_state *, struct cmd_q *, - int); +struct client *cmd_find_client(struct cmdq_item *, const char *, int); +void cmd_find_clear_state(struct cmd_find_state *, + struct cmdq_item *, int); int cmd_find_empty_state(struct cmd_find_state *); int cmd_find_valid_state(struct cmd_find_state *); void cmd_find_copy_state(struct cmd_find_state *, @@ -1761,7 +1761,7 @@ char **cmd_copy_argv(int, char **); void cmd_free_argv(int, char **); char *cmd_stringify_argv(int, char **); struct cmd *cmd_parse(int, char **, const char *, u_int, char **); -int cmd_prepare_state(struct cmd *, struct cmd_q *); +int cmd_prepare_state(struct cmd *, struct cmdq_item *); char *cmd_print(struct cmd *); int cmd_mouse_at(struct window_pane *, struct mouse_event *, u_int *, u_int *, int); @@ -1772,8 +1772,8 @@ char *cmd_template_replace(const char *, const char *, int); extern const struct cmd_entry *cmd_table[]; /* cmd-attach-session.c */ -enum cmd_retval cmd_attach_session(struct cmd_q *, int, int, const char *, - int); +enum cmd_retval cmd_attach_session(struct cmdq_item *, int, int, const char *, + int); /* cmd-list.c */ struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **); @@ -1781,15 +1781,17 @@ void cmd_list_free(struct cmd_list *); char *cmd_list_print(struct cmd_list *); /* cmd-queue.c */ -struct cmd_q *cmdq_get_command(struct cmd_list *, struct cmd_find_state *, +struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *, struct mouse_event *, int); -struct cmd_q *cmdq_get_callback(cmd_q_cb, void *); -void cmdq_insert_after(struct cmd_q *, struct cmd_q *); -void cmdq_append(struct client *, struct cmd_q *); +struct cmdq_item *cmdq_get_callback(cmdq_cb, void *); +void cmdq_insert_after(struct cmdq_item *, struct cmdq_item *); +void cmdq_append(struct client *, struct cmdq_item *); +void printflike(3, 4) cmdq_format(struct cmdq_item *, const char *, + const char *, ...); u_int cmdq_next(struct client *); -void cmdq_guard(struct cmd_q *, const char *, int); -void printflike(2, 3) cmdq_print(struct cmd_q *, const char *, ...); -void printflike(2, 3) cmdq_error(struct cmd_q *, const char *, ...); +void cmdq_guard(struct cmdq_item *, const char *, int); +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 *, diff --git a/window-choose.c b/window-choose.c index b7720e8d..a30916a1 100644 --- a/window-choose.c +++ b/window-choose.c @@ -244,9 +244,9 @@ window_choose_data_free(struct window_choose_data *wcd) void window_choose_data_run(struct window_choose_data *cdata) { - struct cmd_list *cmdlist; - char *cause; - struct cmd_q *cmdq; + struct cmd_list *cmdlist; + char *cause; + struct cmdq_item *item; /* * The command template will have already been replaced. But if it's @@ -264,8 +264,8 @@ window_choose_data_run(struct window_choose_data *cdata) return; } - cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); - cmdq_append(cdata->start_client, cmdq); + item = cmdq_get_command(cmdlist, NULL, NULL, 0); + cmdq_append(cdata->start_client, item); cmd_list_free(cmdlist); }