Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2016-10-16 22:01:14 +01:00
75 changed files with 1120 additions and 1052 deletions

30
cfg.c
View File

@@ -34,7 +34,7 @@ static u_int cfg_ncauses;
struct client *cfg_client; struct client *cfg_client;
static enum cmd_retval 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) if (cfg_finished)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -78,15 +78,15 @@ start_cfg(void)
} }
int 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; FILE *f;
char delim[3] = { '\\', '\\', '\0' }; char delim[3] = { '\\', '\\', '\0' };
u_int found; u_int found;
size_t line = 0; size_t line = 0;
char *buf, *cause1, *p; char *buf, *cause1, *p;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
log_debug("loading %s", path); log_debug("loading %s", path);
if ((f = fopen(path, "rb")) == NULL) { 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) if (cmdlist == NULL)
continue; continue;
new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
if (cmdq != NULL) if (item != NULL)
cmdq_insert_after(cmdq, new_cmdq); cmdq_insert_after(item, new_item);
else else
cmdq_append(c, new_cmdq); cmdq_append(c, new_item);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
found++; found++;
@@ -152,12 +152,12 @@ cfg_add_cause(const char *fmt, ...)
} }
void void
cfg_print_causes(struct cmd_q *cmdq) cfg_print_causes(struct cmdq_item *item)
{ {
u_int i; u_int i;
for (i = 0; i < cfg_ncauses; 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]); free(cfg_causes[i]);
} }

View File

@@ -30,7 +30,8 @@
* Attach existing session to the current terminal. * 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 = { const struct cmd_entry cmd_attach_session_entry = {
.name = "attach-session", .name = "attach-session",
@@ -46,26 +47,26 @@ const struct cmd_entry cmd_attach_session_entry = {
}; };
enum cmd_retval enum cmd_retval
cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
int Eflag) const char *cflag, int Eflag)
{ {
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct client *c = cmdq->client, *c_loop; struct client *c = item->client, *c_loop;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
const char *update; const char *update;
char *cause, *cwd; char *cause, *cwd;
struct format_tree *ft; struct format_tree *ft;
if (RB_EMPTY(&sessions)) { if (RB_EMPTY(&sessions)) {
cmdq_error(cmdq, "no sessions"); cmdq_error(item, "no sessions");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (c == NULL) if (c == NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
if (server_client_check_nested(c)) { 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"); "unset $TMUX to force");
return (CMD_RETURN_ERROR); 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) { if (cflag != NULL) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, wl, wp); format_defaults(ft, c, s, wl, wp);
cwd = format_expand(ft, cflag); cwd = format_expand(ft, cflag);
format_free(ft); 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; s->curw->flags &= ~WINLINK_ALERTFLAGS;
} else { } else {
if (server_client_open(c, &cause) != 0) { 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); free(cause);
return (CMD_RETURN_ERROR); 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 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; 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'))); args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E')));
} }

View File

@@ -27,10 +27,10 @@
* Bind a key to a command, this recurses through cmd_*. * 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 *, static enum cmd_retval cmd_bind_key_mode_table(struct cmd *,
key_code); struct cmdq_item *, key_code);
const struct cmd_entry cmd_bind_key_entry = { const struct cmd_entry cmd_bind_key_entry = {
.name = "bind-key", .name = "bind-key",
@@ -45,7 +45,7 @@ const struct cmd_entry cmd_bind_key_entry = {
}; };
static enum cmd_retval 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; struct args *args = self->args;
char *cause; char *cause;
@@ -55,24 +55,24 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 't')) { if (args_has(args, 't')) {
if (args->argc != 2 && args->argc != 3) { if (args->argc != 2 && args->argc != 3) {
cmdq_error(cmdq, "not enough arguments"); cmdq_error(item, "not enough arguments");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} else { } else {
if (args->argc < 2) { if (args->argc < 2) {
cmdq_error(cmdq, "not enough arguments"); cmdq_error(item, "not enough arguments");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} }
key = key_string_lookup_string(args->argv[0]); key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE || key == KEYC_UNKNOWN) { 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); return (CMD_RETURN_ERROR);
} }
if (args_has(args, 't')) 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')) if (args_has(args, 'T'))
tablename = args_get(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, cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
&cause); &cause);
if (cmdlist == NULL) { if (cmdlist == NULL) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -94,7 +94,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
} }
static enum cmd_retval 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; struct args *args = self->args;
const char *tablename; 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'); tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]); cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
if (cmd == MODEKEY_NONE) { 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); return (CMD_RETURN_ERROR);
} }
if (args->argc != 2) { if (args->argc != 2) {
cmdq_error(cmdq, "no argument allowed"); cmdq_error(item, "no argument allowed");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -28,7 +28,7 @@
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" #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 = { const struct cmd_entry cmd_break_pane_entry = {
.name = "break-pane", .name = "break-pane",
@@ -45,28 +45,28 @@ const struct cmd_entry cmd_break_pane_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct winlink *wl = cmdq->state.sflag.wl; struct winlink *wl = item->state.sflag.wl;
struct session *src_s = cmdq->state.sflag.s; struct session *src_s = item->state.sflag.s;
struct session *dst_s = cmdq->state.tflag.s; struct session *dst_s = item->state.tflag.s;
struct window_pane *wp = cmdq->state.sflag.wp; struct window_pane *wp = item->state.sflag.wp;
struct window *w = wl->window; struct window *w = wl->window;
char *name; char *name;
char *cause; char *cause;
int idx = cmdq->state.tflag.idx; int idx = item->state.tflag.idx;
struct format_tree *ft; struct format_tree *ft;
const char *template; const char *template;
char *cp; char *cp;
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) { 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); return (CMD_RETURN_ERROR);
} }
if (window_count_panes(w) == 1) { 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); return (CMD_RETURN_ERROR);
} }
server_unzoom_window(w); 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) if ((template = args_get(args, 'F')) == NULL)
template = BREAK_PANE_TEMPLATE; template = BREAK_PANE_TEMPLATE;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, cmdq->state.c, dst_s, wl, wp); format_defaults(ft, item->state.c, dst_s, wl, wp);
cp = format_expand(ft, template); cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp); cmdq_print(item, "%s", cp);
free(cp); free(cp);
format_free(ft); format_free(ft);

View File

@@ -27,14 +27,13 @@
* Write the entire contents of a pane to a buffer or stdout. * 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 *, static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
size_t); static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
static char *cmd_capture_pane_pending(struct args *, size_t *);
struct window_pane *, size_t *); static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
static char *cmd_capture_pane_history(struct args *, struct cmd_q *, struct window_pane *, size_t *);
struct window_pane *, size_t *);
const struct cmd_entry cmd_capture_pane_entry = { const struct cmd_entry cmd_capture_pane_entry = {
.name = "capture-pane", .name = "capture-pane",
@@ -92,7 +91,8 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
} }
static char * 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 window_pane *wp, size_t *len)
{ {
struct grid *gd; struct grid *gd;
@@ -109,7 +109,7 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
gd = wp->saved_grid; gd = wp->saved_grid;
if (gd == NULL) { if (gd == NULL) {
if (!args_has(args, 'q')) { if (!args_has(args, 'q')) {
cmdq_error(cmdq, "no alternate screen"); cmdq_error(item, "no alternate screen");
return (NULL); return (NULL);
} }
return (xstrdup("")); return (xstrdup(""));
@@ -177,11 +177,11 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
} }
static enum cmd_retval 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 args *args = self->args;
struct client *c; struct client *c;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
char *buf, *cause; char *buf, *cause;
const char *bufname; const char *bufname;
size_t len; size_t len;
@@ -190,15 +190,15 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'P')) if (args_has(args, 'P'))
buf = cmd_capture_pane_pending(args, wp, &len); buf = cmd_capture_pane_pending(args, wp, &len);
else else
buf = cmd_capture_pane_history(args, cmdq, wp, &len); buf = cmd_capture_pane_history(args, item, wp, &len);
if (buf == NULL) if (buf == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if (args_has(args, 'p')) { if (args_has(args, 'p')) {
c = cmdq->client; c = item->client;
if (c == NULL || if (c == NULL ||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) { (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); free(buf);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -213,7 +213,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
bufname = args_get(args, 'b'); bufname = args_get(args, 'b');
if (paste_set(buf, len, bufname, &cause) != 0) { if (paste_set(buf, len, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(cause); free(cause);
free(buf); free(buf);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@@ -30,7 +30,8 @@
#define CHOOSE_BUFFER_TEMPLATE \ #define CHOOSE_BUFFER_TEMPLATE \
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}" "#{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 = { const struct cmd_entry cmd_choose_buffer_entry = {
.name = "choose-buffer", .name = "choose-buffer",
@@ -46,11 +47,11 @@ const struct cmd_entry cmd_choose_buffer_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window_choose_data *cdata; struct window_choose_data *cdata;
struct paste_buffer *pb; struct paste_buffer *pb;
char *action, *action_data; char *action, *action_data;
@@ -58,7 +59,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
u_int idx; u_int idx;
if (c == NULL) { if (c == NULL) {
cmdq_error(cmdq, "no client available"); cmdq_error(item, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -33,7 +33,8 @@
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
"(last used #{t:client_activity})" "(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 *); static void cmd_choose_client_callback(struct window_choose_data *);
@@ -55,19 +56,19 @@ struct cmd_choose_client_data {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct client *c1; struct client *c1;
struct window_choose_data *cdata; struct window_choose_data *cdata;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
const char *template; const char *template;
char *action; char *action;
u_int idx, cur; u_int idx, cur;
if (c == NULL) { if (c == NULL) {
cmdq_error(cmdq, "no client available"); cmdq_error(item, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -86,7 +87,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
TAILQ_FOREACH(c1, &clients, entry) { TAILQ_FOREACH(c1, &clients, entry) {
if (c1->session == NULL || c1->tty.path == NULL) if (c1->session == NULL || c1->tty.path == NULL)
continue; continue;
if (c1 == cmdq->client) if (c1 == item->client)
cur = idx; cur = idx;
cdata = window_choose_data_create(TREE_OTHER, c, c->session); cdata = window_choose_data_create(TREE_OTHER, c, c->session);

View File

@@ -41,7 +41,7 @@
"#{window_index}: #{window_name}#{window_flags} " \ "#{window_index}: #{window_name}#{window_flags} " \
"\"#{pane_title}\"" "\"#{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 = { const struct cmd_entry cmd_choose_tree_entry = {
.name = "choose-tree", .name = "choose-tree",
@@ -84,12 +84,12 @@ const struct cmd_entry cmd_choose_window_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct winlink *wl = cmdq->state.tflag.wl, *wm; struct winlink *wl = item->state.tflag.wl, *wm;
struct session *s = cmdq->state.tflag.s, *s2; struct session *s = item->state.tflag.s, *s2;
struct window_choose_data *wcd = NULL; struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template; const char *ses_template, *win_template;
char *final_win_action, *cur_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; ses_action = win_action = NULL;
if (c == NULL) { if (c == NULL) {
cmdq_error(cmdq, "no client available"); cmdq_error(item, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -24,7 +24,8 @@
* Clear pane history. * 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 = { const struct cmd_entry cmd_clear_history_entry = {
.name = "clear-history", .name = "clear-history",
@@ -40,12 +41,12 @@ const struct cmd_entry cmd_clear_history_entry = {
}; };
static enum cmd_retval 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; struct grid *gd;
gd = cmdq->state.tflag.wp->base.grid; gd = item->state.tflag.wp->base.grid;
if (wp->mode == &window_copy_mode) if (wp->mode == &window_copy_mode)
window_pane_reset_mode(wp); window_pane_reset_mode(wp);

View File

@@ -29,7 +29,8 @@
* Prompt for command in client. * 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 int cmd_command_prompt_callback(void *, const char *);
static void cmd_command_prompt_free(void *); static void cmd_command_prompt_free(void *);
@@ -59,12 +60,12 @@ struct cmd_command_prompt_cdata {
}; };
static enum cmd_retval 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; struct args *args = self->args;
const char *inputs, *prompts; const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata; struct cmd_command_prompt_cdata *cdata;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
char *prompt, *ptr, *input = NULL; char *prompt, *ptr, *input = NULL;
size_t n; size_t n;
int flags; int flags;
@@ -122,11 +123,11 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
} }
static enum cmd_retval 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; char *error = data;
cmdq_error(cmdq, "%s", error); cmdq_error(item, "%s", error);
free(error); free(error);
return (CMD_RETURN_NORMAL); 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 cmd_command_prompt_cdata *cdata = data;
struct client *c = cdata->c; struct client *c = cdata->c;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
char *cause, *new_template, *prompt, *ptr; char *cause, *new_template, *prompt, *ptr;
char *input = NULL; 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 (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) { if (cause != NULL) {
new_cmdq = cmdq_get_callback(cmd_command_prompt_error, new_item = cmdq_get_callback(cmd_command_prompt_error,
cause); cause);
} else } else
new_cmdq = NULL; new_item = NULL;
} else { } else {
new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
} }
if (new_cmdq != NULL) if (new_item != NULL)
cmdq_append(c, new_cmdq); cmdq_append(c, new_item);
if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback) if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback)
return (1); return (1);

View File

@@ -28,10 +28,11 @@
* Asks for confirmation before executing a command. * 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 int cmd_confirm_before_callback(void *, const char *);
static void cmd_confirm_before_free(void *); static void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = { const struct cmd_entry cmd_confirm_before_entry = {
.name = "confirm-before", .name = "confirm-before",
@@ -52,11 +53,11 @@ struct cmd_confirm_before_data {
}; };
static enum cmd_retval 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 args *args = self->args;
struct cmd_confirm_before_data *cdata; struct cmd_confirm_before_data *cdata;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
char *cmd, *copy, *new_prompt, *ptr; char *cmd, *copy, *new_prompt, *ptr;
const char *prompt; const char *prompt;
@@ -84,11 +85,11 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
} }
static enum cmd_retval 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; char *error = data;
cmdq_error(cmdq, "%s", error); cmdq_error(item, "%s", error);
free(error); free(error);
return (CMD_RETURN_NORMAL); 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 cmd_confirm_before_data *cdata = data;
struct client *c = cdata->client; struct client *c = cdata->client;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
char *cause; char *cause;
if (c->flags & CLIENT_DEAD) 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 (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) { if (cause != NULL) {
new_cmdq = cmdq_get_callback(cmd_confirm_before_error, new_item = cmdq_get_callback(cmd_confirm_before_error,
cause); cause);
} else } else
new_cmdq = NULL; new_item = NULL;
} else { } else {
new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
} }
if (new_cmdq != NULL) if (new_item != NULL)
cmdq_append(c, new_cmdq); cmdq_append(c, new_item);
return (0); return (0);
} }

View File

@@ -24,7 +24,7 @@
* Enter copy or clock mode. * 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 = { const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode", .name = "copy-mode",
@@ -53,15 +53,15 @@ const struct cmd_entry cmd_clock_mode_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->client; struct client *c = item->client;
struct session *s; 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 (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); return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s) if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL); 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 (args_has(args, 'M')) {
if (wp->mode != NULL && wp->mode != &window_copy_mode) if (wp->mode != NULL && wp->mode != &window_copy_mode)
return (CMD_RETURN_NORMAL); 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')) if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
window_copy_pageup(wp, 0); window_copy_pageup(wp, 0);

View File

@@ -26,7 +26,8 @@
* Detach a client. * 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 = { const struct cmd_entry cmd_detach_client_entry = {
.name = "detach-client", .name = "detach-client",
@@ -56,10 +57,10 @@ const struct cmd_entry cmd_suspend_client_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c, *cloop; struct client *c = item->state.c, *cloop;
struct session *s; struct session *s;
enum msgtype msgtype; enum msgtype msgtype;
@@ -76,7 +77,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
msgtype = MSG_DETACH; msgtype = MSG_DETACH;
if (args_has(args, 's')) { if (args_has(args, 's')) {
s = cmdq->state.sflag.s; s = item->state.sflag.s;
TAILQ_FOREACH(cloop, &clients, entry) { TAILQ_FOREACH(cloop, &clients, entry) {
if (cloop->session == s) if (cloop->session == s)
server_client_detach(cloop, msgtype); server_client_detach(cloop, msgtype);

View File

@@ -32,7 +32,8 @@
"#{window_name}, current pane #{pane_index} " \ "#{window_name}, current pane #{pane_index} " \
"- (%H:%M %d-%b-%y)" "- (%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 = { const struct cmd_entry cmd_display_message_entry = {
.name = "display-message", .name = "display-message",
@@ -50,19 +51,19 @@ const struct cmd_entry cmd_display_message_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
const char *template; const char *template;
char *msg; char *msg;
struct format_tree *ft; struct format_tree *ft;
if (args_has(args, 'F') && args->argc != 0) { 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); return (CMD_RETURN_ERROR);
} }
@@ -72,12 +73,12 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
if (template == NULL) if (template == NULL)
template = DISPLAY_MESSAGE_TEMPLATE; template = DISPLAY_MESSAGE_TEMPLATE;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, wl, wp); format_defaults(ft, c, s, wl, wp);
msg = format_expand_time(ft, template, time(NULL)); msg = format_expand_time(ft, template, time(NULL));
if (args_has(self->args, 'p')) if (args_has(self->args, 'p'))
cmdq_print(cmdq, "%s", msg); cmdq_print(item, "%s", msg);
else if (c != NULL) else if (c != NULL)
status_message_set(c, "%s", msg); status_message_set(c, "%s", msg);
free(msg); free(msg);

View File

@@ -27,10 +27,11 @@
* Display panes on a client. * 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 *, static void cmd_display_panes_callback(struct client *,
struct window_pane *); struct window_pane *);
const struct cmd_entry cmd_display_panes_entry = { const struct cmd_entry cmd_display_panes_entry = {
.name = "display-panes", .name = "display-panes",
@@ -46,10 +47,10 @@ const struct cmd_entry cmd_display_panes_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
if (c->identify_callback != NULL) if (c->identify_callback != NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -66,11 +67,11 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
} }
static enum cmd_retval 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; char *error = data;
cmdq_error(cmdq, "%s", error); cmdq_error(item, "%s", error);
free(error); free(error);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -79,9 +80,9 @@ cmd_display_panes_error(struct cmd_q *cmdq, void *data)
static void static void
cmd_display_panes_callback(struct client *c, struct window_pane *wp) cmd_display_panes_callback(struct client *c, struct window_pane *wp)
{ {
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
char *template, *cmd, *expanded, *cause; char *template, *cmd, *expanded, *cause;
template = c->identify_callback_data; template = c->identify_callback_data;
if (wp == NULL) 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 (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) { if (cause != NULL) {
new_cmdq = cmdq_get_callback(cmd_display_panes_error, new_item = cmdq_get_callback(cmd_display_panes_error,
cause); cause);
} else } else
new_cmdq = NULL; new_item = NULL;
} else { } else {
new_cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
} }
if (new_cmdq != NULL) if (new_item != NULL)
cmdq_append(c, new_cmdq); cmdq_append(c, new_item);
free(cmd); free(cmd);
free(expanded); free(expanded);

View File

@@ -33,9 +33,9 @@
"[#{window_width}x#{window_height}] " \ "[#{window_width}x#{window_height}] " \
"(#{window_panes} panes) #{window_find_matches}" "(#{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. */ /* Flags for determining matching behavior. */
#define CMD_FIND_WINDOW_BY_TITLE 0x1 #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 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct window_choose_data *cdata; struct window_choose_data *cdata;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl, *wm; struct winlink *wl = item->state.tflag.wl, *wm;
struct cmd_find_window_list find_list; struct cmd_find_window_list find_list;
struct cmd_find_window_data *find_data; struct cmd_find_window_data *find_data;
struct cmd_find_window_data *find_data1; 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; u_int i, match_flags;
if (c == NULL) { if (c == NULL) {
cmdq_error(cmdq, "no client available"); cmdq_error(item, "no client available");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -172,7 +172,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
free(searchstr); free(searchstr);
if (TAILQ_EMPTY(&find_list)) { 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); return (CMD_RETURN_ERROR);
} }

View File

@@ -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_with_client(struct cmd_find_state *);
static int cmd_find_current_session(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 *); 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; u_int ssize;
struct session *s; struct session *s;
if (fs->cmdq != NULL && fs->cmdq->client != NULL) { if (fs->item != NULL && fs->item->client != NULL) {
fs->s = cmd_find_try_TMUX(fs->cmdq->client, fs->w); fs->s = cmd_find_try_TMUX(fs->item->client, fs->w);
if (fs->s != NULL) if (fs->s != NULL)
return (cmd_find_best_winlink_with_window(fs)); 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 * sessions to those containing that pane (we still use the current
* window in the best session). * 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) { 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; break;
} }
} else } else
@@ -291,8 +291,8 @@ cmd_find_current_session_with_client(struct cmd_find_state *fs)
unknown_pane: unknown_pane:
fs->s = NULL; fs->s = NULL;
if (fs->cmdq != NULL) if (fs->item != NULL)
fs->s = cmd_find_try_TMUX(fs->cmdq->client, NULL); fs->s = cmd_find_try_TMUX(fs->item->client, NULL);
if (fs->s == NULL) if (fs->s == NULL)
fs->s = cmd_find_best_session(NULL, 0, fs->flags); fs->s = cmd_find_best_session(NULL, 0, fs->flags);
if (fs->s == NULL) if (fs->s == NULL)
@@ -313,12 +313,12 @@ static int
cmd_find_current_session(struct cmd_find_state *fs) cmd_find_current_session(struct cmd_find_state *fs)
{ {
/* If we know the current client, use it. */ /* If we know the current client, use it. */
if (fs->cmdq != NULL && fs->cmdq->client != NULL) { if (fs->item != NULL && fs->item->client != NULL) {
log_debug("%s: have client %p%s", __func__, fs->cmdq->client, log_debug("%s: have client %p%s", __func__, fs->item->client,
fs->cmdq->client->session == NULL ? "" : " (with session)"); fs->item->client->session == NULL ? "" : " (with session)");
if (fs->cmdq->client->session == NULL) if (fs->item->client->session == NULL)
return (cmd_find_current_session_with_client(fs)); 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->wl = fs->s->curw;
fs->idx = fs->wl->idx; fs->idx = fs->wl->idx;
fs->w = fs->wl->window; fs->w = fs->wl->window;
@@ -340,7 +340,7 @@ cmd_find_current_session(struct cmd_find_state *fs)
/* Work out the best current client. */ /* Work out the best current client. */
static struct 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 cmd_find_state current;
struct session *s; struct session *s;
@@ -348,14 +348,14 @@ cmd_find_current_client(struct cmd_q *cmdq)
u_int csize; u_int csize;
/* If the queue client has a session, use it. */ /* If the queue client has a session, use it. */
if (cmdq->client != NULL && cmdq->client->session != NULL) { if (item->client != NULL && item->client->session != NULL) {
log_debug("%s: using cmdq %p client %p", __func__, cmdq, log_debug("%s: using item %p client %p", __func__, item,
cmdq->client); item->client);
return (cmdq->client); return (item->client);
} }
/* Otherwise find the current session. */ /* Otherwise find the current session. */
cmd_find_clear_state(&current, cmdq, 0); cmd_find_clear_state(&current, item, 0);
if (cmd_find_current_session(&current) != 0) if (cmd_find_current_session(&current) != 0)
return (NULL); return (NULL);
@@ -792,11 +792,12 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
/* Clear state. */ /* Clear state. */
void 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); memset(fs, 0, sizeof *fs);
fs->cmdq = cmdq; fs->item = item;
fs->flags = flags; fs->flags = flags;
fs->idx = -1; fs->idx = -1;
@@ -951,12 +952,12 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
/* Find current state. */ /* Find current state. */
int 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 (cmd_find_current_session(fs) != 0) {
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (-1); return (-1);
} }
return (0); return (0);
@@ -968,7 +969,8 @@ cmd_find_current(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
*/ */
int int
cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current, 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; struct mouse_event *m;
char *colon, *period, *copy = NULL; 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); log_debug("%s: target none, type %d", __func__, type);
else else
log_debug("%s: target %s, type %d", __func__, target, type); 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. */ /* Clear new state. */
cmd_find_clear_state(fs, cmdq, flags); cmd_find_clear_state(fs, item, flags);
/* Find current state. */ /* Find current state. */
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
fs->current = &marked_pane; fs->current = &marked_pane;
log_debug(" current is marked pane"); log_debug(" current is marked pane");
} else if (cmd_find_valid_state(&cmdq->current)) { } else if (cmd_find_valid_state(&item->current)) {
fs->current = &cmdq->current; fs->current = &item->current;
log_debug(" current is from queue"); log_debug(" current is from queue");
} else { } else {
fs->current = current; 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}. */ /* Mouse target is a plain = or {mouse}. */
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
m = &cmdq->mouse; m = &item->mouse;
switch (type) { switch (type) {
case CMD_FIND_PANE: case CMD_FIND_PANE:
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); 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 (fs->wp == NULL) {
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)
cmdq_error(cmdq, "no mouse target"); cmdq_error(item, "no mouse target");
goto error; goto error;
} }
goto found; 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 (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) {
if (!server_check_marked()) { if (!server_check_marked()) {
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)
cmdq_error(cmdq, "no marked target"); cmdq_error(item, "no marked target");
goto error; goto error;
} }
cmd_find_copy_state(fs, &marked_pane); 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. */ /* No pane is allowed if want an index. */
if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) { if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) {
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)
cmdq_error(cmdq, "can't specify pane here"); cmdq_error(item, "can't specify pane here");
goto error; goto error;
} }
@@ -1218,23 +1220,23 @@ found:
no_session: no_session:
if (~flags & CMD_FIND_QUIET) 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; goto error;
no_window: no_window:
if (~flags & CMD_FIND_QUIET) 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; goto error;
no_pane: no_pane:
if (~flags & CMD_FIND_QUIET) 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; goto error;
} }
/* Find the target client or report an error and return NULL. */ /* Find the target client or report an error and return NULL. */
struct client * 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; struct client *c;
char *copy; char *copy;
@@ -1242,10 +1244,10 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
const char *path; const char *path;
/* A NULL argument means the current client. */ /* A NULL argument means the current client. */
if (cmdq != NULL && target == NULL) { if (item != NULL && target == NULL) {
c = cmd_find_current_client(cmdq); c = cmd_find_current_client(item);
if (c == NULL && !quiet) 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); log_debug("%s: no target, return %p", __func__, c);
return (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 no client found, report an error. */
if (c == NULL && !quiet) if (c == NULL && !quiet)
cmdq_error(cmdq, "can't find client %s", copy); cmdq_error(item, "can't find client %s", copy);
free(copy); free(copy);
log_debug("%s: target %s, return %p", __func__, target, c); log_debug("%s: target %s, return %p", __func__, target, c);

View File

@@ -29,11 +29,11 @@
* Executes a tmux command if a shell command returns true or false. * 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 enum cmd_retval cmd_if_shell_error(struct cmdq_item *, void *);
static void cmd_if_shell_callback(struct job *); static void cmd_if_shell_callback(struct job *);
static void cmd_if_shell_free(void *); static void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = { const struct cmd_entry cmd_if_shell_entry = {
.name = "if-shell", .name = "if-shell",
@@ -57,33 +57,33 @@ struct cmd_if_shell_data {
char *cmd_else; char *cmd_else;
struct client *client; struct client *client;
struct cmd_q *cmdq; struct cmdq_item *item;
struct mouse_event mouse; struct mouse_event mouse;
}; };
static enum cmd_retval 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 args *args = self->args;
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
char *shellcmd, *cmd, *cause; char *shellcmd, *cmd, *cause;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct format_tree *ft; struct format_tree *ft;
const char *cwd; const char *cwd;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
cwd = cmdq->client->cwd; cwd = item->client->cwd;
else if (s != NULL) else if (s != NULL)
cwd = s->cwd; cwd = s->cwd;
else else
cwd = NULL; cwd = NULL;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, cmdq->state.c, s, wl, wp); format_defaults(ft, item->state.c, s, wl, wp);
shellcmd = format_expand(ft, args->argv[0]); shellcmd = format_expand(ft, args->argv[0]);
format_free(ft); format_free(ft);
@@ -98,13 +98,13 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(cause); free(cause);
} }
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
new_cmdq = cmdq_get_command(cmdlist, NULL, &cmdq->mouse, 0); new_item = cmdq_get_command(cmdlist, NULL, &item->mouse, 0);
cmdq_insert_after(cmdq, new_cmdq); cmdq_insert_after(item, new_item);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
@@ -121,14 +121,14 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
else else
cdata->cmd_else = NULL; cdata->cmd_else = NULL;
cdata->client = cmdq->client; cdata->client = item->client;
cdata->client->references++; cdata->client->references++;
if (!args_has(args, 'b')) if (!args_has(args, 'b'))
cdata->cmdq = cmdq; cdata->item = item;
else else
cdata->cmdq = NULL; cdata->item = NULL;
memcpy(&cdata->mouse, &cmdq->mouse, sizeof cdata->mouse); memcpy(&cdata->mouse, &item->mouse, sizeof cdata->mouse);
job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free, job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free,
cdata); cdata);
@@ -140,11 +140,11 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
} }
static enum cmd_retval 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; char *error = data;
cmdq_error(cmdq, "%s", error); cmdq_error(item, "%s", error);
free(error); free(error);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -156,7 +156,7 @@ cmd_if_shell_callback(struct job *job)
struct cmd_if_shell_data *cdata = job->data; struct cmd_if_shell_data *cdata = job->data;
struct client *c = cdata->client; struct client *c = cdata->client;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
char *cause, *cmd, *file = cdata->file; char *cause, *cmd, *file = cdata->file;
u_int line = cdata->line; 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 (cmd_string_parse(cmd, &cmdlist, file, line, &cause) != 0) {
if (cause != NULL) if (cause != NULL)
new_cmdq = cmdq_get_callback(cmd_if_shell_error, cause); new_item = cmdq_get_callback(cmd_if_shell_error, cause);
else else
new_cmdq = NULL; new_item = NULL;
} else { } 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); cmd_list_free(cmdlist);
} }
if (new_cmdq != NULL) { if (new_item != NULL) {
if (cdata->cmdq == NULL) if (cdata->item == NULL)
cmdq_append(c, new_cmdq); cmdq_append(c, new_item);
else else
cmdq_insert_after(cdata->cmdq, new_cmdq); cmdq_insert_after(cdata->item, new_item);
} }
out: out:
if (cdata->cmdq != NULL) if (cdata->item != NULL)
cdata->cmdq->flags &= ~CMD_Q_WAITING; cdata->item->flags &= ~CMDQ_WAITING;
} }
static void static void

View File

@@ -28,7 +28,7 @@
* Join or move a pane into another (like split/swap/kill). * 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 = { const struct cmd_entry cmd_join_pane_entry = {
.name = "join-pane", .name = "join-pane",
@@ -59,7 +59,7 @@ const struct cmd_entry cmd_move_pane_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *dst_s; struct session *dst_s;
@@ -77,24 +77,24 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
else else
not_same_window = 0; not_same_window = 0;
dst_s = cmdq->state.tflag.s; dst_s = item->state.tflag.s;
dst_wl = cmdq->state.tflag.wl; dst_wl = item->state.tflag.wl;
dst_wp = cmdq->state.tflag.wp; dst_wp = item->state.tflag.wp;
dst_w = dst_wl->window; dst_w = dst_wl->window;
dst_idx = dst_wl->idx; dst_idx = dst_wl->idx;
server_unzoom_window(dst_w); server_unzoom_window(dst_w);
src_wl = cmdq->state.sflag.wl; src_wl = item->state.sflag.wl;
src_wp = cmdq->state.sflag.wp; src_wp = item->state.sflag.wp;
src_w = src_wl->window; src_w = src_wl->window;
server_unzoom_window(src_w); server_unzoom_window(src_w);
if (not_same_window && src_w == dst_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); return (CMD_RETURN_ERROR);
} }
if (!not_same_window && src_wp == dst_wp) { 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); return (CMD_RETURN_ERROR);
} }
@@ -106,14 +106,14 @@ cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'l')) { if (args_has(args, 'l')) {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause); size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "size %s", cause); cmdq_error(item, "size %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} else if (args_has(args, 'p')) { } else if (args_has(args, 'p')) {
percentage = args_strtonum(args, 'p', 0, 100, &cause); percentage = args_strtonum(args, 'p', 0, 100, &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "percentage %s", cause); cmdq_error(item, "percentage %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); 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); lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0);
if (lc == NULL) { 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); return (CMD_RETURN_ERROR);
} }

View File

@@ -26,7 +26,7 @@
* Kill pane. * 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 = { const struct cmd_entry cmd_kill_pane_entry = {
.name = "kill-pane", .name = "kill-pane",
@@ -42,10 +42,10 @@ const struct cmd_entry cmd_kill_pane_entry = {
}; };
static enum cmd_retval 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 winlink *wl = item->state.tflag.wl;
struct window_pane *loopwp, *tmpwp, *wp = cmdq->state.tflag.wp; struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp;
server_unzoom_window(wl->window); server_unzoom_window(wl->window);

View File

@@ -27,7 +27,7 @@
* Kill the server and do nothing else. * 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 = { const struct cmd_entry cmd_kill_server_entry = {
.name = "kill-server", .name = "kill-server",
@@ -52,7 +52,7 @@ const struct cmd_entry cmd_start_server_entry = {
}; };
static enum cmd_retval 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) if (self->entry == &cmd_kill_server_entry)
kill(getpid(), SIGTERM); kill(getpid(), SIGTERM);

View File

@@ -27,7 +27,7 @@
* Note this deliberately has no alias to make it hard to hit by accident. * 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 = { const struct cmd_entry cmd_kill_session_entry = {
.name = "kill-session", .name = "kill-session",
@@ -43,13 +43,13 @@ const struct cmd_entry cmd_kill_session_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s, *sloop, *stmp; struct session *s, *sloop, *stmp;
struct winlink *wl; struct winlink *wl;
s = cmdq->state.tflag.s; s = item->state.tflag.s;
if (args_has(args, 'C')) { if (args_has(args, 'C')) {
RB_FOREACH(wl, winlinks, &s->windows) { RB_FOREACH(wl, winlinks, &s->windows) {

View File

@@ -24,7 +24,7 @@
* Destroy window. * 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 = { const struct cmd_entry cmd_kill_window_entry = {
.name = "kill-window", .name = "kill-window",
@@ -53,16 +53,16 @@ const struct cmd_entry cmd_unlink_window_entry = {
}; };
static enum cmd_retval 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 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 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 (self->entry == &cmd_unlink_window_entry) {
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) { 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); return (CMD_RETURN_ERROR);
} }
server_unlink_window(s, wl); server_unlink_window(s, wl);

View File

@@ -30,7 +30,7 @@
#define LIST_BUFFERS_TEMPLATE \ #define LIST_BUFFERS_TEMPLATE \
"#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\"" "#{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 = { const struct cmd_entry cmd_list_buffers_entry = {
.name = "list-buffers", .name = "list-buffers",
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct paste_buffer *pb; struct paste_buffer *pb;
@@ -57,11 +57,11 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq)
pb = NULL; pb = NULL;
while ((pb = paste_walk(pb)) != NULL) { while ((pb = paste_walk(pb)) != NULL) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults_paste_buffer(ft, pb); format_defaults_paste_buffer(ft, pb);
line = format_expand(ft, template); line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
format_free(ft); format_free(ft);

View File

@@ -33,7 +33,7 @@
"[#{client_width}x#{client_height} #{client_termname}]" \ "[#{client_width}x#{client_height} #{client_termname}]" \
"#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" "#{?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 = { const struct cmd_entry cmd_list_clients_entry = {
.name = "list-clients", .name = "list-clients",
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_list_clients_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c; struct client *c;
@@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
char *line; char *line;
if (args_has(args, 't')) if (args_has(args, 't'))
s = cmdq->state.tflag.s; s = item->state.tflag.s;
else else
s = NULL; 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)) if (c->session == NULL || (s != NULL && s != c->session))
continue; continue;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_add(ft, "line", "%u", idx); format_add(ft, "line", "%u", idx);
format_defaults(ft, c, NULL, NULL, NULL); format_defaults(ft, c, NULL, NULL, NULL);
line = format_expand(ft, template); line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
format_free(ft); format_free(ft);

View File

@@ -27,10 +27,11 @@
* List key bindings. * 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_table(struct cmd *, struct cmdq_item *);
static enum cmd_retval cmd_list_keys_commands(struct cmd *, struct cmd_q *); static enum cmd_retval cmd_list_keys_commands(struct cmd *,
struct cmdq_item *);
const struct cmd_entry cmd_list_keys_entry = { const struct cmd_entry cmd_list_keys_entry = {
.name = "list-keys", .name = "list-keys",
@@ -55,7 +56,7 @@ const struct cmd_entry cmd_list_commands_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct key_table *table; struct key_table *table;
@@ -65,14 +66,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
int repeat, width, tablewidth, keywidth; int repeat, width, tablewidth, keywidth;
if (self->entry == &cmd_list_commands_entry) 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')) if (args_has(args, 't'))
return (cmd_list_keys_table(self, cmdq)); return (cmd_list_keys_table(self, item));
tablename = args_get(args, 'T'); tablename = args_get(args, 'T');
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
@@ -124,7 +125,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
strlcat(tmp, cp, sizeof tmp); strlcat(tmp, cp, sizeof tmp);
free(cp); 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 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; struct args *args = self->args;
const char *tablename, *cmdstr; const char *tablename, *cmdstr;
@@ -142,7 +143,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
tablename = args_get(args, 't'); tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) { 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); 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) { RB_FOREACH(mbind, mode_key_tree, mtab->tree) {
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
if (cmdstr != NULL) { 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, mtab->name, (int)keywidth,
key_string_lookup_key(mbind->key), cmdstr); 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 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; struct args *args = self->args;
const struct cmd_entry **entryp; const struct cmd_entry **entryp;
const struct cmd_entry *entry; const struct cmd_entry *entry;
struct format_tree *ft; struct format_tree *ft;
const char *template; const char *template, *s;
char *line; char *line;
if ((template = args_get(args, 'F')) == NULL) { 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}"; "#{command_list_usage}";
} }
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, NULL, NULL, NULL, NULL); format_defaults(ft, NULL, NULL, NULL, NULL);
for (entryp = cmd_table; *entryp != NULL; entryp++) { for (entryp = cmd_table; *entryp != NULL; entryp++) {
entry = *entryp; entry = *entryp;
format_add(ft, "command_list_name", "%s", entry->name); format_add(ft, "command_list_name", "%s", entry->name);
if (entry->alias != NULL) { if (entry->alias != NULL)
format_add(ft, "command_list_alias", "%s", s = entry->alias;
entry->alias); else
} s = "";
if (entry->alias != NULL) { format_add(ft, "command_list_alias", "%s", s);
format_add(ft, "command_list_usage", "%s", if (entry->usage != NULL)
entry->usage); s = entry->usage;
} else
s = "";
format_add(ft, "command_list_usage", "%s", s);
line = format_expand(ft, template); line = format_expand(ft, template);
if (*line != '\0') if (*line != '\0')
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
} }

View File

@@ -26,13 +26,13 @@
* List panes on given window. * 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 *, 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 *, 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 = { const struct cmd_entry cmd_list_panes_entry = {
.name = "list-panes", .name = "list-panes",
@@ -48,44 +48,44 @@ const struct cmd_entry cmd_list_panes_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
if (args_has(args, 'a')) if (args_has(args, 'a'))
cmd_list_panes_server(self, cmdq); cmd_list_panes_server(self, item);
else if (args_has(args, 's')) else if (args_has(args, 's'))
cmd_list_panes_session(self, s, cmdq, 1); cmd_list_panes_session(self, s, item, 1);
else else
cmd_list_panes_window(self, s, wl, cmdq, 0); cmd_list_panes_window(self, s, wl, item, 0);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
static void 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; struct session *s;
RB_FOREACH(s, sessions, &sessions) RB_FOREACH(s, sessions, &sessions)
cmd_list_panes_session(self, s, cmdq, 2); cmd_list_panes_session(self, s, item, 2);
} }
static void static void
cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, cmd_list_panes_session(struct cmd *self, struct session *s,
int type) struct cmdq_item *item, int type)
{ {
struct winlink *wl; struct winlink *wl;
RB_FOREACH(wl, winlinks, &s->windows) 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 static void
cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, 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 args *args = self->args;
struct window_pane *wp; struct window_pane *wp;
@@ -123,12 +123,12 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
n = 0; n = 0;
TAILQ_FOREACH(wp, &wl->window->panes, entry) { TAILQ_FOREACH(wp, &wl->window->panes, entry) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_add(ft, "line", "%u", n); format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, wp); format_defaults(ft, NULL, s, wl, wp);
line = format_expand(ft, template); line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
format_free(ft); format_free(ft);

View File

@@ -36,7 +36,8 @@
"#{session_group}#{?session_grouped,),}" \ "#{session_group}#{?session_grouped,),}" \
"#{?session_attached, (attached),}" "#{?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 = { const struct cmd_entry cmd_list_sessions_entry = {
.name = "list-sessions", .name = "list-sessions",
@@ -50,7 +51,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s; struct session *s;
@@ -64,12 +65,12 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
n = 0; n = 0;
RB_FOREACH(s, sessions, &sessions) { RB_FOREACH(s, sessions, &sessions) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_add(ft, "line", "%u", n); format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, NULL, NULL); format_defaults(ft, NULL, s, NULL, NULL);
line = format_expand(ft, template); line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
format_free(ft); format_free(ft);

View File

@@ -39,11 +39,11 @@
"(#{window_panes} panes) " \ "(#{window_panes} panes) " \
"[#{window_width}x#{window_height}] " "[#{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 *, 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 = { const struct cmd_entry cmd_list_windows_entry = {
.name = "list-windows", .name = "list-windows",
@@ -59,30 +59,30 @@ const struct cmd_entry cmd_list_windows_entry = {
}; };
static enum cmd_retval 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; struct args *args = self->args;
if (args_has(args, 'a')) if (args_has(args, 'a'))
cmd_list_windows_server(self, cmdq); cmd_list_windows_server(self, item);
else 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); return (CMD_RETURN_NORMAL);
} }
static void 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; struct session *s;
RB_FOREACH(s, sessions, &sessions) RB_FOREACH(s, sessions, &sessions)
cmd_list_windows_session(self, s, cmdq, 1); cmd_list_windows_session(self, s, item, 1);
} }
static void static void
cmd_list_windows_session(struct cmd *self, struct session *s, 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 args *args = self->args;
struct winlink *wl; struct winlink *wl;
@@ -105,12 +105,12 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
n = 0; n = 0;
RB_FOREACH(wl, winlinks, &s->windows) { RB_FOREACH(wl, winlinks, &s->windows) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_add(ft, "line", "%u", n); format_add(ft, "line", "%u", n);
format_defaults(ft, NULL, s, wl, NULL); format_defaults(ft, NULL, s, wl, NULL);
line = format_expand(ft, template); line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line); cmdq_print(item, "%s", line);
free(line); free(line);
format_free(ft); format_free(ft);

View File

@@ -31,9 +31,9 @@
* Loads a paste buffer from a file. * 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 = { const struct cmd_entry cmd_load_buffer_entry = {
.name = "load-buffer", .name = "load-buffer",
@@ -47,16 +47,16 @@ const struct cmd_entry cmd_load_buffer_entry = {
}; };
struct cmd_load_buffer_data { struct cmd_load_buffer_data {
struct cmd_q *cmdq; struct cmdq_item *item;
char *bufname; char *bufname;
}; };
static enum cmd_retval 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 args *args = self->args;
struct cmd_load_buffer_data *cdata; struct cmd_load_buffer_data *cdata;
struct client *c = cmdq->client; struct client *c = item->client;
struct session *s; struct session *s;
FILE *f; FILE *f;
const char *path, *bufname, *cwd; const char *path, *bufname, *cwd;
@@ -72,13 +72,13 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
path = args->argv[0]; path = args->argv[0];
if (strcmp(path, "-") == 0) { if (strcmp(path, "-") == 0) {
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
cdata->cmdq = cmdq; cdata->item = item;
cdata->bufname = xstrdup(bufname); cdata->bufname = xstrdup(bufname);
error = server_set_stdin_callback(c, cmd_load_buffer_callback, error = server_set_stdin_callback(c, cmd_load_buffer_callback,
cdata, &cause); cdata, &cause);
if (error != 0) { if (error != 0) {
cmdq_error(cmdq, "%s: %s", path, cause); cmdq_error(item, "%s: %s", path, cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); 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); xasprintf(&file, "%s/%s", cwd, path);
if (realpath(file, resolved) == NULL && if (realpath(file, resolved) == NULL &&
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { 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); return (CMD_RETURN_ERROR);
} }
f = fopen(resolved, "rb"); f = fopen(resolved, "rb");
free(file); free(file);
if (f == NULL) { if (f == NULL) {
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); cmdq_error(item, "%s: %s", resolved, strerror(errno));
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -113,14 +113,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
while ((ch = getc(f)) != EOF) { while ((ch = getc(f)) != EOF) {
/* Do not let the server die due to memory exhaustion. */ /* Do not let the server die due to memory exhaustion. */
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) { 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; goto error;
} }
pdata = new_pdata; pdata = new_pdata;
pdata[psize++] = ch; pdata[psize++] = ch;
} }
if (ferror(f)) { if (ferror(f)) {
cmdq_error(cmdq, "%s: read error", resolved); cmdq_error(item, "%s: read error", resolved);
goto error; goto error;
} }
if (pdata != NULL) if (pdata != NULL)
@@ -129,7 +129,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
fclose(f); fclose(f);
if (paste_set(pdata, psize, bufname, &cause) != 0) { if (paste_set(pdata, psize, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(pdata); free(pdata);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
@@ -180,7 +180,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
free(cause); free(cause);
} }
out: out:
cdata->cmdq->flags &= ~CMD_Q_WAITING; cdata->item->flags &= ~CMDQ_WAITING;
free(cdata->bufname); free(cdata->bufname);
free(cdata); free(cdata);

View File

@@ -24,7 +24,7 @@
* Lock commands. * 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 = { const struct cmd_entry cmd_lock_server_entry = {
.name = "lock-server", .name = "lock-server",
@@ -64,14 +64,14 @@ const struct cmd_entry cmd_lock_client_entry = {
}; };
static enum cmd_retval 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) if (self->entry == &cmd_lock_server_entry)
server_lock(); server_lock();
else if (self->entry == &cmd_lock_session_entry) else if (self->entry == &cmd_lock_session_entry)
server_lock_session(cmdq->state.tflag.s); server_lock_session(item->state.tflag.s);
else else
server_lock_client(cmdq->state.c); server_lock_client(item->state.c);
recalculate_sizes(); recalculate_sizes();

View File

@@ -26,7 +26,7 @@
* Move a window. * 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 = { const struct cmd_entry cmd_move_window_entry = {
.name = "move-window", .name = "move-window",
@@ -57,14 +57,14 @@ const struct cmd_entry cmd_link_window_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *src = cmdq->state.sflag.s; struct session *src = item->state.sflag.s;
struct session *dst = cmdq->state.tflag.s; struct session *dst = item->state.tflag.s;
struct winlink *wl = cmdq->state.sflag.wl; struct winlink *wl = item->state.sflag.wl;
char *cause; 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')) { if (args_has(args, 'r')) {
session_renumber_windows(dst); 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, if (server_link_window(src, wl, dst, idx, kflag, !dflag,
&cause) != 0) { &cause) != 0) {
cmdq_error(cmdq, "can't link window: %s", cause); cmdq_error(item, "can't link window: %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -33,7 +33,7 @@
#define NEW_SESSION_TEMPLATE "#{session_name}:" #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 = { const struct cmd_entry cmd_new_session_entry = {
.name = "new-session", .name = "new-session",
@@ -64,12 +64,12 @@ const struct cmd_entry cmd_has_session_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->client; struct client *c = item->client;
struct session *s, *as; struct session *s, *as;
struct session *groupwith = cmdq->state.tflag.s; struct session *groupwith = item->state.tflag.s;
struct window *w; struct window *w;
struct environ *env; struct environ *env;
struct termios tio, *tiop; 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'))) { 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); return (CMD_RETURN_ERROR);
} }
newname = args_get(args, 's'); newname = args_get(args, 's');
if (newname != NULL) { if (newname != NULL) {
if (!session_check_name(newname)) { 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); return (CMD_RETURN_ERROR);
} }
if ((as = session_find(newname)) != NULL) { if ((as = session_find(newname)) != NULL) {
if (args_has(args, 'A')) { if (args_has(args, 'A')) {
/* /*
* This cmdq is now destined for * This item is now destined for
* attach-session. Because attach-session * attach-session. Because attach-session
* will have already been prepared, copy this * will have already been prepared, copy this
* session into its tflag so it can be used. * session into its tflag so it can be used.
*/ */
cmd_find_from_session(&cmdq->state.tflag, as); cmd_find_from_session(&item->state.tflag, as);
return (cmd_attach_session(cmdq, return (cmd_attach_session(item,
args_has(args, 'D'), 0, NULL, args_has(args, 'D'), 0, NULL,
args_has(args, 'E'))); args_has(args, 'E')));
} }
cmdq_error(cmdq, "duplicate session: %s", newname); cmdq_error(item, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} }
if ((target = args_get(args, 't')) != NULL) { if ((target = args_get(args, 't')) != NULL) {
if (groupwith == NULL) { if (groupwith == NULL) {
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
goto error; goto error;
} }
} else } else
@@ -139,7 +139,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Get the new session working directory. */ /* Get the new session working directory. */
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, NULL, NULL, NULL); format_defaults(ft, c, NULL, NULL, NULL);
to_free = cwd = format_expand(ft, args_get(args, 'c')); to_free = cwd = format_expand(ft, args_get(args, 'c'));
format_free(ft); format_free(ft);
@@ -158,8 +158,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
* over. * over.
*/ */
if (!detached && !already_attached && c->tty.fd != -1) { if (!detached && !already_attached && c->tty.fd != -1) {
if (server_client_check_nested(cmdq->client)) { if (server_client_check_nested(item->client)) {
cmdq_error(cmdq, "sessions should be nested with care, " cmdq_error(item, "sessions should be nested with care, "
"unset $TMUX to force"); "unset $TMUX to force");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -172,7 +172,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Open the terminal if necessary. */ /* Open the terminal if necessary. */
if (!detached && !already_attached) { if (!detached && !already_attached) {
if (server_client_open(c, &cause) != 0) { 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); free(cause);
goto error; goto error;
} }
@@ -189,14 +189,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (detached && args_has(args, 'x')) { if (detached && args_has(args, 'x')) {
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr); sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
cmdq_error(cmdq, "width %s", errstr); cmdq_error(item, "width %s", errstr);
goto error; goto error;
} }
} }
if (detached && args_has(args, 'y')) { if (detached && args_has(args, 'y')) {
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr); sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
cmdq_error(cmdq, "height %s", errstr); cmdq_error(item, "height %s", errstr);
goto error; goto error;
} }
} }
@@ -246,7 +246,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
sy, &cause); sy, &cause);
environ_free(env); environ_free(env);
if (s == NULL) { if (s == NULL) {
cmdq_error(cmdq, "create session failed: %s", cause); cmdq_error(item, "create session failed: %s", cause);
free(cause); free(cause);
goto error; goto error;
} }
@@ -301,11 +301,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if ((template = args_get(args, 'F')) == NULL) if ((template = args_get(args, 'F')) == NULL)
template = NEW_SESSION_TEMPLATE; template = NEW_SESSION_TEMPLATE;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, NULL, NULL); format_defaults(ft, c, s, NULL, NULL);
cp = format_expand(ft, template); cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp); cmdq_print(item, "%s", cp);
free(cp); free(cp);
format_free(ft); format_free(ft);
@@ -318,7 +318,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
free((void *)to_free); free((void *)to_free);
cmd_find_from_session(&fs, s); 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); return (CMD_RETURN_NORMAL);

View File

@@ -32,7 +32,7 @@
#define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" #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 = { const struct cmd_entry cmd_new_window_entry = {
.name = "new-window", .name = "new-window",
@@ -49,13 +49,13 @@ const struct cmd_entry cmd_new_window_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
int idx = cmdq->state.tflag.idx; int idx = item->state.tflag.idx;
const char *cmd, *path, *template, *cwd, *to_free; const char *cmd, *path, *template, *cwd, *to_free;
char **argv, *cause, *cp; char **argv, *cause, *cp;
int argc, detached; int argc, detached;
@@ -65,7 +65,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'a')) { if (args_has(args, 'a')) {
if ((idx = winlink_shuffle_up(s, wl)) == -1) { 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); return (CMD_RETURN_ERROR);
} }
} }
@@ -86,8 +86,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
} }
path = NULL; path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
envent = environ_find(cmdq->client->environ, "PATH"); envent = environ_find(item->client->environ, "PATH");
else else
envent = environ_find(s->environ, "PATH"); envent = environ_find(s->environ, "PATH");
if (envent != NULL) if (envent != NULL)
@@ -95,12 +95,12 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
to_free = NULL; to_free = NULL;
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, NULL, NULL); format_defaults(ft, c, s, NULL, NULL);
cwd = to_free = format_expand(ft, args_get(args, 'c')); cwd = to_free = format_expand(ft, args_get(args, 'c'));
format_free(ft); format_free(ft);
} else if (cmdq->client != NULL && cmdq->client->session == NULL) } else if (item->client != NULL && item->client->session == NULL)
cwd = cmdq->client->cwd; cwd = item->client->cwd;
else else
cwd = s->cwd; 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, wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
&cause); &cause);
if (wl == NULL) { if (wl == NULL) {
cmdq_error(cmdq, "create window failed: %s", cause); cmdq_error(item, "create window failed: %s", cause);
free(cause); free(cause);
goto error; goto error;
} }
@@ -143,11 +143,11 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
if ((template = args_get(args, 'F')) == NULL) if ((template = args_get(args, 'F')) == NULL)
template = NEW_WINDOW_TEMPLATE; template = NEW_WINDOW_TEMPLATE;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, wl, NULL); format_defaults(ft, c, s, wl, NULL);
cp = format_expand(ft, template); cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp); cmdq_print(item, "%s", cp);
free(cp); free(cp);
format_free(ft); format_free(ft);
@@ -157,7 +157,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
free((void *)to_free); free((void *)to_free);
cmd_find_from_winlink(&fs, s, wl); 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); return (CMD_RETURN_NORMAL);

View File

@@ -27,7 +27,7 @@
* Paste paste buffer if present. * 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 = { const struct cmd_entry cmd_paste_buffer_entry = {
.name = "paste-buffer", .name = "paste-buffer",
@@ -44,10 +44,10 @@ const struct cmd_entry cmd_paste_buffer_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct paste_buffer *pb; struct paste_buffer *pb;
const char *sepstr, *bufname, *bufdata, *bufend, *line; const char *sepstr, *bufname, *bufdata, *bufend, *line;
size_t seplen, bufsize; size_t seplen, bufsize;
@@ -62,7 +62,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
else { else {
pb = paste_get_name(bufname); pb = paste_get_name(bufname);
if (pb == NULL) { if (pb == NULL) {
cmdq_error(cmdq, "no buffer %s", bufname); cmdq_error(item, "no buffer %s", bufname);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} }

View File

@@ -32,7 +32,7 @@
* Open pipe to redirect pane output. If already open, close first. * 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 *); 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 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
char *cmd; char *cmd;
int old_fd, pipe_fd[2], null_fd; int old_fd, pipe_fd[2], null_fd;
struct format_tree *ft; struct format_tree *ft;
@@ -84,12 +84,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
/* Open the new pipe. */ /* Open the new pipe. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) { 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); return (CMD_RETURN_ERROR);
} }
/* Expand the command. */ /* Expand the command. */
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, c, s, wl, wp); format_defaults(ft, c, s, wl, wp);
cmd = format_expand_time(ft, args->argv[0], time(NULL)); cmd = format_expand_time(ft, args->argv[0], time(NULL));
format_free(ft); format_free(ft);
@@ -97,7 +97,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
/* Fork the child. */ /* Fork the child. */
switch (fork()) { switch (fork()) {
case -1: case -1:
cmdq_error(cmdq, "fork error: %s", strerror(errno)); cmdq_error(item, "fork error: %s", strerror(errno));
free(cmd); free(cmd);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@@ -26,7 +26,7 @@
#include "tmux.h" #include "tmux.h"
/* Global command queue. */ /* 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. */ /* Get command queue name. */
static const char * static const char *
@@ -41,7 +41,7 @@ cmdq_name(struct client *c)
} }
/* Get command queue from client. */ /* Get command queue from client. */
static struct cmd_q_list * static struct cmdq_list *
cmdq_get(struct client *c) cmdq_get(struct client *c)
{ {
if (c == NULL) if (c == NULL)
@@ -51,67 +51,68 @@ cmdq_get(struct client *c)
/* Append an item. */ /* Append an item. */
void 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 cmdq_list *queue = cmdq_get(c);
struct cmd_q *next; struct cmdq_item *next;
do { do {
next = cmdq->next; next = item->next;
cmdq->next = NULL; item->next = NULL;
if (c != NULL) if (c != NULL)
c->references++; c->references++;
cmdq->client = c; item->client = c;
cmdq->queue = queue; item->queue = queue;
TAILQ_INSERT_TAIL(queue, cmdq, entry); TAILQ_INSERT_TAIL(queue, item, entry);
cmdq = next; item = next;
} while (cmdq != NULL); } while (item != NULL);
} }
/* Insert an item. */ /* Insert an item. */
void 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 client *c = after->client;
struct cmd_q_list *queue = after->queue; struct cmdq_list *queue = after->queue;
struct cmd_q *next; struct cmdq_item *next;
do { do {
next = cmdq->next; next = item->next;
cmdq->next = NULL; item->next = NULL;
if (c != NULL) if (c != NULL)
c->references++; c->references++;
cmdq->client = c; item->client = c;
cmdq->queue = queue; item->queue = queue;
if (after->next != NULL) if (after->next != NULL)
TAILQ_INSERT_AFTER(queue, after->next, cmdq, entry); TAILQ_INSERT_AFTER(queue, after->next, item, entry);
else else
TAILQ_INSERT_AFTER(queue, after, cmdq, entry); TAILQ_INSERT_AFTER(queue, after, item, entry);
after->next = cmdq; after->next = item;
cmdq = next; item = next;
} while (cmdq != NULL); } while (item != NULL);
} }
/* Remove an item. */ /* Remove an item. */
static void 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) if (item->client != NULL)
server_client_unref(cmdq->client); server_client_unref(item->client);
if (cmdq->type == CMD_Q_COMMAND) if (item->type == CMDQ_COMMAND)
cmd_list_free(cmdq->cmdlist); cmd_list_free(item->cmdlist);
TAILQ_REMOVE(cmdq->queue, cmdq, entry); TAILQ_REMOVE(item->queue, item, entry);
free(cmdq); free(item);
} }
/* Set command group. */ /* Set command group. */
@@ -125,129 +126,151 @@ cmdq_next_group(void)
/* Remove all subsequent items that match this item's group. */ /* Remove all subsequent items that match this item's group. */
static void 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) { while (this != NULL) {
next = TAILQ_NEXT(this, entry); next = TAILQ_NEXT(this, entry);
if (this->group == cmdq->group) if (this->group == item->group)
cmdq_remove(this); cmdq_remove(this);
this = next; this = next;
} }
} }
/* Get a command for the command queue. */ /* 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, cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
struct mouse_event *m, int flags) struct mouse_event *m, int flags)
{ {
struct cmd_q *cmdq, *first = NULL, *last = NULL; struct cmdq_item *item, *first = NULL, *last = NULL;
struct cmd *cmd; struct cmd *cmd;
u_int group = cmdq_next_group(); u_int group = cmdq_next_group();
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) { TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
cmdq = xcalloc(1, sizeof *cmdq); item = xcalloc(1, sizeof *item);
cmdq->type = CMD_Q_COMMAND; item->type = CMDQ_COMMAND;
cmdq->group = group; item->group = group;
cmdq->flags = flags; item->flags = flags;
cmdq->cmdlist = cmdlist; item->cmdlist = cmdlist;
cmdq->cmd = cmd; item->cmd = cmd;
if (current != NULL) if (current != NULL)
cmd_find_copy_state(&cmdq->current, current); cmd_find_copy_state(&item->current, current);
if (m != NULL) if (m != NULL)
memcpy(&cmdq->mouse, m, sizeof cmdq->mouse); memcpy(&item->mouse, m, sizeof item->mouse);
cmdlist->references++; cmdlist->references++;
if (first == NULL) if (first == NULL)
first = cmdq; first = item;
if (last != NULL) if (last != NULL)
last->next = cmdq; last->next = item;
last = cmdq; last = item;
} }
return (first); return (first);
} }
/* Fire command on command queue. */ /* Fire command on command queue. */
static enum cmd_retval static enum cmd_retval
cmdq_fire_command(struct cmd_q *cmdq) cmdq_fire_command(struct cmdq_item *item)
{ {
struct client *c = cmdq->client; struct client *c = item->client;
struct cmd *cmd = cmdq->cmd; struct cmd *cmd = item->cmd;
enum cmd_retval retval; enum cmd_retval retval;
const char *name; const char *name;
struct cmd_find_state *fsp, fs; struct cmd_find_state *fsp, fs;
int flags; int flags;
flags = !!(cmd->flags & CMD_CONTROL); 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; retval = CMD_RETURN_ERROR;
goto out; goto out;
} }
if (cmdq->client == NULL) if (item->client == NULL)
cmdq->client = cmd_find_client(cmdq, NULL, CMD_FIND_QUIET); 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) if (retval == CMD_RETURN_ERROR)
goto out; goto out;
if (cmd->entry->flags & CMD_AFTERHOOK) { if (cmd->entry->flags & CMD_AFTERHOOK) {
name = cmd->entry->name; name = cmd->entry->name;
if (cmd_find_valid_state(&cmdq->state.tflag)) if (cmd_find_valid_state(&item->state.tflag))
fsp = &cmdq->state.tflag; fsp = &item->state.tflag;
else { else {
if (cmd_find_current(&fs, cmdq, CMD_FIND_QUIET) != 0) if (cmd_find_current(&fs, item, CMD_FIND_QUIET) != 0)
goto out; goto out;
fsp = &fs; fsp = &fs;
} }
hooks_insert(fsp->s->hooks, cmdq, fsp, "after-%s", name); hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
} }
out: out:
cmdq->client = c; item->client = c;
if (retval == CMD_RETURN_ERROR) if (retval == CMD_RETURN_ERROR)
cmdq_guard(cmdq, "error", flags); cmdq_guard(item, "error", flags);
else else
cmdq_guard(cmdq, "end", flags); cmdq_guard(item, "end", flags);
return (retval); return (retval);
} }
/* Get a callback for the command queue. */ /* Get a callback for the command queue. */
struct cmd_q * struct cmdq_item *
cmdq_get_callback(cmd_q_cb cb, void *data) cmdq_get_callback(cmdq_cb cb, void *data)
{ {
struct cmd_q *cmdq; struct cmdq_item *item;
cmdq = xcalloc(1, sizeof *cmdq); item = xcalloc(1, sizeof *item);
cmdq->type = CMD_Q_CALLBACK; item->type = CMDQ_CALLBACK;
cmdq->group = 0; item->group = 0;
cmdq->flags = 0; item->flags = 0;
cmdq->cb = cb; item->cb = cb;
cmdq->data = data; item->data = data;
return (cmdq); return (item);
} }
/* Fire callback on callback queue. */ /* Fire callback on callback queue. */
static enum cmd_retval 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. */ /* Process next item on command queue. */
u_int u_int
cmdq_next(struct client *c) 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); const char *name = cmdq_name(c);
struct cmd_q *cmdq; struct cmdq_item *item;
enum cmd_retval retval; enum cmd_retval retval;
u_int items = 0; u_int items = 0;
static u_int number; static u_int number;
@@ -256,63 +279,63 @@ cmdq_next(struct client *c)
log_debug("%s %s: empty", __func__, name); log_debug("%s %s: empty", __func__, name);
return (0); return (0);
} }
if (TAILQ_FIRST(queue)->flags & CMD_Q_WAITING) { if (TAILQ_FIRST(queue)->flags & CMDQ_WAITING) {
log_debug("%s %s: waiting", __func__, name); log_debug("%s %s: waiting", __func__, name);
return (0); return (0);
} }
log_debug("%s %s: enter", __func__, name); log_debug("%s %s: enter", __func__, name);
for (;;) { for (;;) {
cmdq = TAILQ_FIRST(queue); item = TAILQ_FIRST(queue);
if (cmdq == NULL) if (item == NULL)
break; break;
log_debug("%s %s: type %d, flags %x", __func__, name, 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 * Any item with the waiting flag set waits until an external
* event clears the flag (for example, a job - look at * event clears the flag (for example, a job - look at
* run-shell). * run-shell).
*/ */
if (cmdq->flags & CMD_Q_WAITING) if (item->flags & CMDQ_WAITING)
goto waiting; goto waiting;
/* /*
* Items are only fired once, once the fired flag is set, a * Items are only fired once, once the fired flag is set, a
* waiting flag can only be cleared by an external event. * waiting flag can only be cleared by an external event.
*/ */
if (~cmdq->flags & CMD_Q_FIRED) { if (~item->flags & CMDQ_FIRED) {
cmdq->time = time(NULL); item->time = time(NULL);
cmdq->number = ++number; item->number = ++number;
switch (cmdq->type) switch (item->type)
{ {
case CMD_Q_COMMAND: case CMDQ_COMMAND:
retval = cmdq_fire_command(cmdq); retval = cmdq_fire_command(item);
/* /*
* If a command returns an error, remove any * If a command returns an error, remove any
* subsequent commands in the same group. * subsequent commands in the same group.
*/ */
if (retval == CMD_RETURN_ERROR) if (retval == CMD_RETURN_ERROR)
cmdq_remove_group(cmdq); cmdq_remove_group(item);
break; break;
case CMD_Q_CALLBACK: case CMDQ_CALLBACK:
retval = cmdq_fire_callback(cmdq); retval = cmdq_fire_callback(item);
break; break;
default: default:
retval = CMD_RETURN_ERROR; retval = CMD_RETURN_ERROR;
break; break;
} }
cmdq->flags |= CMD_Q_FIRED; item->flags |= CMDQ_FIRED;
if (retval == CMD_RETURN_WAIT) { if (retval == CMD_RETURN_WAIT) {
cmdq->flags |= CMD_Q_WAITING; item->flags |= CMDQ_WAITING;
goto waiting; goto waiting;
} }
items++; items++;
} }
cmdq_remove(cmdq); cmdq_remove(item);
} }
log_debug("%s %s: exit (empty)", __func__, name); log_debug("%s %s: exit (empty)", __func__, name);
@@ -325,23 +348,23 @@ waiting:
/* Print a guard line. */ /* Print a guard line. */
void 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)) if (c == NULL || !(c->flags & CLIENT_CONTROL))
return; return;
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard, 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); server_client_push_stdout(c);
} }
/* Show message from command. */ /* Show message from command. */
void 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; struct window *w;
va_list ap; va_list ap;
char *tmp, *msg; char *tmp, *msg;
@@ -376,10 +399,10 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
/* Show error from command. */ /* Show error from command. */
void 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 client *c = item->client;
struct cmd *cmd = cmdq->cmd; struct cmd *cmd = item->cmd;
va_list ap; va_list ap;
char *msg; char *msg;
size_t msglen; size_t msglen;

View File

@@ -24,7 +24,7 @@
* Refresh client. * 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 = { const struct cmd_entry cmd_refresh_client_entry = {
.name = "refresh-client", .name = "refresh-client",
@@ -40,29 +40,29 @@ const struct cmd_entry cmd_refresh_client_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
const char *size; const char *size;
u_int w, h; u_int w, h;
if (args_has(args, 'C')) { if (args_has(args, 'C')) {
if ((size = args_get(args, 'C')) == NULL) { if ((size = args_get(args, 'C')) == NULL) {
cmdq_error(cmdq, "missing size"); cmdq_error(item, "missing size");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (sscanf(size, "%u,%u", &w, &h) != 2) { if (sscanf(size, "%u,%u", &w, &h) != 2) {
cmdq_error(cmdq, "bad size argument"); cmdq_error(item, "bad size argument");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (w < PANE_MINIMUM || w > 5000 || if (w < PANE_MINIMUM || w > 5000 ||
h < PANE_MINIMUM || h > 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); return (CMD_RETURN_ERROR);
} }
if (!(c->flags & CLIENT_CONTROL)) { if (!(c->flags & CLIENT_CONTROL)) {
cmdq_error(cmdq, "not a control client"); cmdq_error(item, "not a control client");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (tty_set_size(&c->tty, w, h)) if (tty_set_size(&c->tty, w, h))

View File

@@ -26,7 +26,8 @@
* Change session name. * 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 = { const struct cmd_entry cmd_rename_session_entry = {
.name = "rename-session", .name = "rename-session",
@@ -42,19 +43,19 @@ const struct cmd_entry cmd_rename_session_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
const char *newname; const char *newname;
newname = args->argv[0]; newname = args->argv[0];
if (!session_check_name(newname)) { 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); return (CMD_RETURN_ERROR);
} }
if (session_find(newname) != NULL) { if (session_find(newname) != NULL) {
cmdq_error(cmdq, "duplicate session: %s", newname); cmdq_error(item, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -26,7 +26,8 @@
* Rename a window. * 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 = { const struct cmd_entry cmd_rename_window_entry = {
.name = "rename-window", .name = "rename-window",
@@ -42,10 +43,10 @@ const struct cmd_entry cmd_rename_window_entry = {
}; };
static enum cmd_retval 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 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]); window_set_name(wl->window, args->argv[0]);
options_set_number(wl->window->options, "automatic-rename", 0); options_set_number(wl->window->options, "automatic-rename", 0);

View File

@@ -26,7 +26,7 @@
* Increase or decrease pane size. * 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 *, static void cmd_resize_pane_mouse_update(struct client *,
struct mouse_event *); struct mouse_event *);
@@ -46,26 +46,26 @@ const struct cmd_entry cmd_resize_pane_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window *w = wl->window; struct window *w = wl->window;
struct client *c = cmdq->client; struct client *c = item->client;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
const char *errstr; const char *errstr;
char *cause; char *cause;
u_int adjust; u_int adjust;
int x, y; int x, y;
if (args_has(args, 'M')) { 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); return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s) if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update; 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); return (CMD_RETURN_NORMAL);
} }
@@ -85,7 +85,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
else { else {
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr); adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
cmdq_error(cmdq, "adjustment %s", errstr); cmdq_error(item, "adjustment %s", errstr);
return (CMD_RETURN_ERROR); 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, x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
&cause); &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "width %s", cause); cmdq_error(item, "width %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); 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, y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
&cause); &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "height %s", cause); cmdq_error(item, "height %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

View File

@@ -28,7 +28,7 @@
* Respawn a pane (restart the command). Kill existing if -k given. * 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 = { const struct cmd_entry cmd_respawn_pane_entry = {
.name = "respawn-pane", .name = "respawn-pane",
@@ -44,13 +44,13 @@ const struct cmd_entry cmd_respawn_pane_entry = {
}; };
static enum cmd_retval 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 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 *w = wl->window;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct environ *env; struct environ *env;
const char *path; const char *path;
char *cause; 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 (!args_has(self->args, 'k') && wp->fd != -1) {
if (window_pane_index(wp, &idx) != 0) if (window_pane_index(wp, &idx) != 0)
fatalx("index not found"); 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); s->name, wl->idx, idx);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -75,8 +75,8 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
input_init(wp); input_init(wp);
path = NULL; path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
envent = environ_find(cmdq->client->environ, "PATH"); envent = environ_find(item->client->environ, "PATH");
else else
envent = environ_find(s->environ, "PATH"); envent = environ_find(s->environ, "PATH");
if (envent != NULL) 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, if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
s->tio, &cause) != 0) { s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn pane failed: %s", cause); cmdq_error(item, "respawn pane failed: %s", cause);
free(cause); free(cause);
environ_free(env); environ_free(env);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@@ -27,7 +27,8 @@
* Respawn a window (restart the command). Kill existing if -k given. * 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 = { const struct cmd_entry cmd_respawn_window_entry = {
.name = "respawn-window", .name = "respawn-window",
@@ -43,11 +44,11 @@ const struct cmd_entry cmd_respawn_window_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window *w = wl->window; struct window *w = wl->window;
struct window_pane *wp; struct window_pane *wp;
struct environ *env; struct environ *env;
@@ -59,7 +60,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
TAILQ_FOREACH(wp, &w->panes, entry) { TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->fd == -1) if (wp->fd == -1)
continue; continue;
cmdq_error(cmdq, "window still active: %s:%d", s->name, cmdq_error(item, "window still active: %s:%d", s->name,
wl->idx); wl->idx);
return (CMD_RETURN_ERROR); 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); window_pane_resize(wp, w->sx, w->sy);
path = NULL; path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
envent = environ_find(cmdq->client->environ, "PATH"); envent = environ_find(item->client->environ, "PATH");
else else
envent = environ_find(s->environ, "PATH"); envent = environ_find(s->environ, "PATH");
if (envent != NULL) 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, if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
s->tio, &cause) != 0) { s->tio, &cause) != 0) {
cmdq_error(cmdq, "respawn window failed: %s", cause); cmdq_error(item, "respawn window failed: %s", cause);
free(cause); free(cause);
environ_free(env); environ_free(env);
server_destroy_pane(wp, 0); server_destroy_pane(wp, 0);

View File

@@ -24,7 +24,8 @@
* Rotate the panes in a window. * 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 = { const struct cmd_entry cmd_rotate_window_entry = {
.name = "rotate-window", .name = "rotate-window",
@@ -40,9 +41,9 @@ const struct cmd_entry cmd_rotate_window_entry = {
}; };
static enum cmd_retval 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 *w = wl->window;
struct window_pane *wp, *wp2; struct window_pane *wp, *wp2;
struct layout_cell *lc; struct layout_cell *lc;

View File

@@ -29,7 +29,7 @@
* Runs a command without a window. * 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_callback(struct job *);
static void cmd_run_shell_free(void *); static void cmd_run_shell_free(void *);
@@ -49,9 +49,9 @@ const struct cmd_entry cmd_run_shell_entry = {
}; };
struct cmd_run_shell_data { struct cmd_run_shell_data {
char *cmd; char *cmd;
struct cmd_q *cmdq; struct cmdq_item *item;
int wp_id; int wp_id;
}; };
static void static void
@@ -63,7 +63,7 @@ cmd_run_shell_print(struct job *job, const char *msg)
if (cdata->wp_id != -1) if (cdata->wp_id != -1)
wp = window_pane_find_by_id(cdata->wp_id); wp = window_pane_find_by_id(cdata->wp_id);
if (wp == NULL) { if (wp == NULL) {
cmdq_print(cdata->cmdq, "%s", msg); cmdq_print(cdata->item, "%s", msg);
return; return;
} }
@@ -74,26 +74,26 @@ cmd_run_shell_print(struct job *job, const char *msg)
} }
static enum cmd_retval 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 args *args = self->args;
struct cmd_run_shell_data *cdata; struct cmd_run_shell_data *cdata;
char *shellcmd; char *shellcmd;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct format_tree *ft; struct format_tree *ft;
const char *cwd; const char *cwd;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
cwd = cmdq->client->cwd; cwd = item->client->cwd;
else if (s != NULL) else if (s != NULL)
cwd = s->cwd; cwd = s->cwd;
else else
cwd = NULL; cwd = NULL;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, cmdq->state.c, s, wl, wp); format_defaults(ft, item->state.c, s, wl, wp);
shellcmd = format_expand(ft, args->argv[0]); shellcmd = format_expand(ft, args->argv[0]);
format_free(ft); format_free(ft);
@@ -111,7 +111,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
cdata->wp_id = -1; cdata->wp_id = -1;
if (!args_has(args, 'b')) if (!args_has(args, 'b'))
cdata->cmdq = cmdq; cdata->item = item;
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free, job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
cdata); cdata);
@@ -163,8 +163,8 @@ cmd_run_shell_callback(struct job *job)
cmd_run_shell_print(job, msg); cmd_run_shell_print(job, msg);
free(msg); free(msg);
if (cdata->cmdq != NULL) if (cdata->item != NULL)
cdata->cmdq->flags &= ~CMD_Q_WAITING; cdata->item->flags &= ~CMDQ_WAITING;
} }
static void static void

View File

@@ -31,7 +31,7 @@
* Saves a paste buffer to a file. * 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 = { const struct cmd_entry cmd_save_buffer_entry = {
.name = "save-buffer", .name = "save-buffer",
@@ -56,10 +56,10 @@ const struct cmd_entry cmd_show_buffer_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->client; struct client *c = item->client;
struct session *s; struct session *s;
struct paste_buffer *pb; struct paste_buffer *pb;
const char *path, *bufname, *bufdata, *start, *end, *cwd; 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 (!args_has(args, 'b')) {
if ((pb = paste_get_top(NULL)) == NULL) { if ((pb = paste_get_top(NULL)) == NULL) {
cmdq_error(cmdq, "no buffers"); cmdq_error(item, "no buffers");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} else { } else {
bufname = args_get(args, 'b'); bufname = args_get(args, 'b');
pb = paste_get_name(bufname); pb = paste_get_name(bufname);
if (pb == NULL) { if (pb == NULL) {
cmdq_error(cmdq, "no buffer %s", bufname); cmdq_error(item, "no buffer %s", bufname);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} }
@@ -89,7 +89,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
path = args->argv[0]; path = args->argv[0];
if (strcmp(path, "-") == 0) { if (strcmp(path, "-") == 0) {
if (c == NULL) { if (c == NULL) {
cmdq_error(cmdq, "can't write to stdout"); cmdq_error(item, "can't write to stdout");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (c->session == NULL || (c->flags & CLIENT_CONTROL)) 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); xasprintf(&file, "%s/%s", cwd, path);
if (realpath(file, resolved) == NULL && if (realpath(file, resolved) == NULL &&
strlcpy(resolved, file, sizeof resolved) >= sizeof resolved) { 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); return (CMD_RETURN_ERROR);
} }
f = fopen(resolved, flags); f = fopen(resolved, flags);
free(file); free(file);
if (f == NULL) { if (f == NULL) {
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno)); cmdq_error(item, "%s: %s", resolved, strerror(errno));
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (fwrite(bufdata, 1, bufsize, f) != bufsize) { if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
cmdq_error(cmdq, "%s: write error", resolved); cmdq_error(item, "%s: write error", resolved);
fclose(f); fclose(f);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -140,7 +140,7 @@ do_stdout:
do_print: do_print:
if (bufsize > (INT_MAX / 4) - 1) { if (bufsize > (INT_MAX / 4) - 1) {
cmdq_error(cmdq, "buffer too big"); cmdq_error(item, "buffer too big");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
msg = NULL; msg = NULL;
@@ -158,7 +158,7 @@ do_print:
msg = xrealloc(msg, msglen); msg = xrealloc(msg, msglen);
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB); strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
cmdq_print(cmdq, "%s", msg); cmdq_print(item, "%s", msg);
used += size + (end != NULL); used += size + (end != NULL);
} }

View File

@@ -26,7 +26,8 @@
* Switch window to selected layout. * 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 = { const struct cmd_entry cmd_select_layout_entry = {
.name = "select-layout", .name = "select-layout",
@@ -68,10 +69,10 @@ const struct cmd_entry cmd_previous_layout_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window *w; struct window *w;
const char *layoutname; const char *layoutname;
char *oldlayout; char *oldlayout;
@@ -118,7 +119,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
if (layoutname != NULL) { if (layoutname != NULL) {
if (layout_parse(w, layoutname) == -1) { 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 error;
} }
goto changed; goto changed;

View File

@@ -24,7 +24,7 @@
* Select pane. * 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 = { const struct cmd_entry cmd_select_pane_entry = {
.name = "select-pane", .name = "select-pane",
@@ -53,19 +53,19 @@ const struct cmd_entry cmd_last_pane_entry = {
}; };
static enum cmd_retval 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 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 *w = wl->window;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct window_pane *wp = cmdq->state.tflag.wp, *lastwp, *markedwp; struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
const char *style; const char *style;
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
if (wl->window->last == NULL) { if (wl->window->last == NULL) {
cmdq_error(cmdq, "no last pane"); cmdq_error(item, "no last pane");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -112,13 +112,13 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
style = args_get(args, 'P'); style = args_get(args, 'P');
if (style_parse(&grid_default_cell, &wp->colgc, if (style_parse(&grid_default_cell, &wp->colgc,
style) == -1) { style) == -1) {
cmdq_error(cmdq, "bad style: %s", style); cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
} }
if (args_has(self->args, 'g')) 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); return (CMD_RETURN_NORMAL);
} }
@@ -151,7 +151,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
server_unzoom_window(wp->window); server_unzoom_window(wp->window);
if (!window_pane_visible(wp)) { if (!window_pane_visible(wp)) {
cmdq_error(cmdq, "pane not visible"); cmdq_error(item, "pane not visible");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
window_redraw_active_switch(w, wp); window_redraw_active_switch(w, wp);

View File

@@ -26,7 +26,8 @@
* Select window by index. * 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 = { const struct cmd_entry cmd_select_window_entry = {
.name = "select-window", .name = "select-window",
@@ -81,10 +82,10 @@ const struct cmd_entry cmd_last_window_entry = {
}; };
static enum cmd_retval 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 winlink *wl = item->state.tflag.wl;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
int next, previous, last, activity; int next, previous, last, activity;
next = self->entry == &cmd_next_window_entry; 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'); activity = args_has(self->args, 'a');
if (next) { if (next) {
if (session_next(s, activity) != 0) { if (session_next(s, activity) != 0) {
cmdq_error(cmdq, "no next window"); cmdq_error(item, "no next window");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} else if (previous) { } else if (previous) {
if (session_previous(s, activity) != 0) { if (session_previous(s, activity) != 0) {
cmdq_error(cmdq, "no previous window"); cmdq_error(item, "no previous window");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
} else { } else {
if (session_last(s) != 0) { if (session_last(s) != 0) {
cmdq_error(cmdq, "no last window"); cmdq_error(item, "no last window");
return (CMD_RETURN_ERROR); 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 (args_has(self->args, 'T') && wl == s->curw) {
if (session_last(s) != 0) { if (session_last(s) != 0) {
cmdq_error(cmdq, "no last window"); cmdq_error(item, "no last window");
return (-1); return (-1);
} }
server_redraw_session(s); server_redraw_session(s);

View File

@@ -27,7 +27,7 @@
* Send keys to client. * 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 = { const struct cmd_entry cmd_send_keys_entry = {
.name = "send-keys", .name = "send-keys",
@@ -56,13 +56,13 @@ const struct cmd_entry cmd_send_prefix_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct window_pane *wp = cmdq->state.tflag.wp; struct window_pane *wp = item->state.tflag.wp;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct mouse_event *m = &cmdq->mouse; struct mouse_event *m = &item->mouse;
const u_char *keystr; const u_char *keystr;
int i, literal; int i, literal;
key_code key; key_code key;
@@ -71,12 +71,12 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'N')) { if (args_has(args, 'N')) {
if (wp->mode == NULL || wp->mode->command == NULL) { 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); return (CMD_RETURN_ERROR);
} }
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause); np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "prefix %s", cause); cmdq_error(item, "prefix %s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); 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 (args_has(args, 'X')) {
if (wp->mode == NULL || wp->mode->command == NULL) { 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); return (CMD_RETURN_ERROR);
} }
if (!m->valid) if (!m->valid)
@@ -101,7 +101,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'M')) { if (args_has(args, 'M')) {
wp = cmd_mouse_pane(m, &s, NULL); wp = cmd_mouse_pane(m, &s, NULL);
if (wp == NULL) { if (wp == NULL) {
cmdq_error(cmdq, "no mouse target"); cmdq_error(item, "no mouse target");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
window_pane_key(wp, NULL, s, m->key, m); window_pane_key(wp, NULL, s, m->key, m);

View File

@@ -27,7 +27,7 @@
* Add, set, append to or delete a paste buffer. * 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 = { const struct cmd_entry cmd_set_buffer_entry = {
.name = "set-buffer", .name = "set-buffer",
@@ -52,7 +52,7 @@ const struct cmd_entry cmd_delete_buffer_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct paste_buffer *pb; struct paste_buffer *pb;
@@ -70,7 +70,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
if (pb == NULL) if (pb == NULL)
pb = paste_get_top(&bufname); pb = paste_get_top(&bufname);
if (pb == NULL) { if (pb == NULL) {
cmdq_error(cmdq, "no buffer"); cmdq_error(item, "no buffer");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
paste_free(pb); paste_free(pb);
@@ -81,11 +81,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
if (pb == NULL) if (pb == NULL)
pb = paste_get_top(&bufname); pb = paste_get_top(&bufname);
if (pb == NULL) { if (pb == NULL) {
cmdq_error(cmdq, "no buffer"); cmdq_error(item, "no buffer");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) { if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -93,7 +93,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
} }
if (args->argc != 1) { if (args->argc != 1) {
cmdq_error(cmdq, "no data specified"); cmdq_error(item, "no data specified");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if ((newsize = strlen(args->argv[0])) == 0) if ((newsize = strlen(args->argv[0])) == 0)
@@ -113,7 +113,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
bufsize += newsize; bufsize += newsize;
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) { if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(bufdata); free(bufdata);
free(cause); free(cause);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@@ -27,7 +27,8 @@
* Set an environment variable. * 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 = { const struct cmd_entry cmd_set_environment_entry = {
.name = "set-environment", .name = "set-environment",
@@ -43,7 +44,7 @@ const struct cmd_entry cmd_set_environment_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct environ *env; struct environ *env;
@@ -51,11 +52,11 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
name = args->argv[0]; name = args->argv[0];
if (*name == '\0') { if (*name == '\0') {
cmdq_error(cmdq, "empty variable name"); cmdq_error(item, "empty variable name");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (strchr(name, '=') != NULL) { if (strchr(name, '=') != NULL) {
cmdq_error(cmdq, "variable name contains ="); cmdq_error(item, "variable name contains =");
return (CMD_RETURN_ERROR); 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')) if (args_has(self->args, 'g'))
env = global_environ; env = global_environ;
else { else {
if (cmdq->state.tflag.s == NULL) { if (item->state.tflag.s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) if (target != NULL)
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
else else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
env = cmdq->state.tflag.s->environ; env = item->state.tflag.s->environ;
} }
if (args_has(self->args, 'u')) { if (args_has(self->args, 'u')) {
if (value != NULL) { 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); return (CMD_RETURN_ERROR);
} }
environ_unset(env, name); environ_unset(env, name);
} else if (args_has(self->args, 'r')) { } else if (args_has(self->args, 'r')) {
if (value != NULL) { 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); return (CMD_RETURN_ERROR);
} }
environ_clear(env, name); environ_clear(env, name);
} else { } else {
if (value == NULL) { if (value == NULL) {
cmdq_error(cmdq, "no value specified"); cmdq_error(item, "no value specified");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
environ_set(env, name, "%s", value); environ_set(env, name, "%s", value);

View File

@@ -27,7 +27,7 @@
* Set or show global or session hooks. * 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 = { const struct cmd_entry cmd_set_hook_entry = {
.name = "set-hook", .name = "set-hook",
@@ -56,7 +56,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
@@ -68,22 +68,22 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'g')) if (args_has(args, 'g'))
hooks = global_hooks; hooks = global_hooks;
else { else {
if (cmdq->state.tflag.s == NULL) { if (item->state.tflag.s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) if (target != NULL)
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
else else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
hooks = cmdq->state.tflag.s->hooks; hooks = item->state.tflag.s->hooks;
} }
if (self->entry == &cmd_show_hooks_entry) { if (self->entry == &cmd_show_hooks_entry) {
hook = hooks_first(hooks); hook = hooks_first(hooks);
while (hook != NULL) { while (hook != NULL) {
tmp = cmd_list_print(hook->cmdlist); tmp = cmd_list_print(hook->cmdlist);
cmdq_print(cmdq, "%s -> %s", hook->name, tmp); cmdq_print(item, "%s -> %s", hook->name, tmp);
free(tmp); free(tmp);
hook = hooks_next(hook); hook = hooks_next(hook);
@@ -93,7 +93,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
name = args->argv[0]; name = args->argv[0];
if (*name == '\0') { if (*name == '\0') {
cmdq_error(cmdq, "invalid hook name"); cmdq_error(item, "invalid hook name");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (args->argc < 2) 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 (args_has(args, 'u')) {
if (cmd != NULL) { if (cmd != NULL) {
cmdq_error(cmdq, "command passed to unset hook: %s", cmdq_error(item, "command passed to unset hook: %s",
name); name);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@@ -112,12 +112,12 @@ cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq)
} }
if (cmd == NULL) { 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); return (CMD_RETURN_ERROR);
} }
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) { if (cause != NULL) {
cmdq_error(cmdq, "%s", cause); cmdq_error(item, "%s", cause);
free(cause); free(cause);
} }
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);

View File

@@ -27,42 +27,42 @@
* Set an option. * 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 *, static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmdq_item *,
const char *, const char *); 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 struct options_table_entry *, struct options *,
const char *); 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 struct options_table_entry *, struct options *,
const char *); const char *);
static struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, static struct options_entry *cmd_set_option_string(struct cmd *,
const struct options_table_entry *, struct options *, struct cmdq_item *, const struct options_table_entry *,
const char *); struct options *, const char *);
static struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, static struct options_entry *cmd_set_option_number(struct cmd *,
const struct options_table_entry *, struct options *, struct cmdq_item *, const struct options_table_entry *,
const char *); struct options *, const char *);
static struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, static struct options_entry *cmd_set_option_key(struct cmd *,
const struct options_table_entry *, struct options *, struct cmdq_item *, const struct options_table_entry *,
const char *); struct options *, const char *);
static struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, static struct options_entry *cmd_set_option_colour(struct cmd *,
const struct options_table_entry *, struct options *, struct cmdq_item *, const struct options_table_entry *,
const char *); struct options *, const char *);
static struct options_entry *cmd_set_option_attributes(struct cmd *, static struct options_entry *cmd_set_option_attributes(struct cmd *,
struct cmd_q *, const struct options_table_entry *, 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 *); 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 = { const struct cmd_entry cmd_set_option_entry = {
.name = "set-option", .name = "set-option",
@@ -91,11 +91,11 @@ const struct cmd_entry cmd_set_window_option_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window *w; struct window *w;
struct client *c; struct client *c;
const struct options_table_entry *oe; 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. */ /* Get the option name and value. */
optstr = args->argv[0]; optstr = args->argv[0];
if (*optstr == '\0') { if (*optstr == '\0') {
cmdq_error(cmdq, "invalid option"); cmdq_error(item, "invalid option");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (args->argc < 2) if (args->argc < 2)
@@ -115,20 +115,20 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
/* Is this a user option? */ /* Is this a user option? */
if (*optstr == '@') 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. */ /* Find the option entry, try each table. */
oe = NULL; oe = NULL;
if (options_table_find(optstr, &oe) != 0) { if (options_table_find(optstr, &oe) != 0) {
if (!args_has(args, 'q')) { 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_ERROR);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (oe == NULL) { if (oe == NULL) {
if (!args_has(args, 'q')) { 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_ERROR);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -143,10 +143,10 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
else if (wl == NULL) { else if (wl == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such window: %s", cmdq_error(item, "no such window: %s",
target); target);
} else } else
cmdq_error(cmdq, "no current window"); cmdq_error(item, "no current window");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = wl->window->options; oo = wl->window->options;
@@ -156,31 +156,31 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
else if (s == NULL) { else if (s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such session: %s", cmdq_error(item, "no such session: %s",
target); target);
} else } else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = s->options; oo = s->options;
} else { } else {
cmdq_error(cmdq, "unknown table"); cmdq_error(item, "unknown table");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
/* Unset or set the option. */ /* Unset or set the option. */
if (args_has(args, 'u')) { 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); return (CMD_RETURN_ERROR);
} else { } else {
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
if (!args_has(args, 'q')) { 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_ERROR);
} }
return (CMD_RETURN_NORMAL); 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); return (CMD_RETURN_ERROR);
} }
@@ -224,12 +224,12 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
/* Set user option. */ /* Set user option. */
static enum cmd_retval static enum cmd_retval
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, cmd_set_option_user(struct cmd *self, struct cmdq_item *item,
const char *valstr) const char *optstr, const char *valstr)
{ {
struct args *args = self->args; struct args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct options *oo; struct options *oo;
struct options_entry *o; struct options_entry *o;
const char *target; 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) { else if (wl == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such window: %s", cmdq_error(item, "no such window: %s",
target); target);
} else } else
cmdq_error(cmdq, "no current window"); cmdq_error(item, "no current window");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = wl->window->options; 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) { else if (s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such session: %s", cmdq_error(item, "no such session: %s",
target); target);
} else } else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = s->options; 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 (args_has(args, 'u')) {
if (options_find1(oo, optstr) == NULL) { if (options_find1(oo, optstr) == NULL) {
if (!args_has(args, 'q')) { 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_ERROR);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (valstr != NULL) { if (valstr != NULL) {
cmdq_error(cmdq, "value passed to unset option: %s", cmdq_error(item, "value passed to unset option: %s",
optstr); optstr);
return (CMD_RETURN_ERROR); 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); o = options_find1(oo, optstr);
if (args_has(args, 'o') && o != NULL) { if (args_has(args, 'o') && o != NULL) {
if (!args_has(args, 'q')) { 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_ERROR);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (valstr == NULL) { if (valstr == NULL) {
cmdq_error(cmdq, "empty value"); cmdq_error(item, "empty value");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (o != NULL && args_has(args, 'a')) 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. */ /* Unset an option. */
static int 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
struct args *args = self->args; struct args *args = self->args;
if (value != NULL) { 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); return (-1);
} }
@@ -332,7 +332,7 @@ cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
/* Set an option. */ /* Set an option. */
static int 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
@@ -344,7 +344,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
break; break;
default: default:
if (value == NULL) { if (value == NULL) {
cmdq_error(cmdq, "empty value"); cmdq_error(item, "empty value");
return (-1); return (-1);
} }
} }
@@ -352,32 +352,32 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
o = NULL; o = NULL;
switch (oe->type) { switch (oe->type) {
case OPTIONS_TABLE_STRING: 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; break;
case OPTIONS_TABLE_NUMBER: 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; break;
case OPTIONS_TABLE_KEY: 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; break;
case OPTIONS_TABLE_COLOUR: 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) if (o != NULL)
style_update_new(oo, o->name, oe->style); style_update_new(oo, o->name, oe->style);
break; break;
case OPTIONS_TABLE_ATTRIBUTES: 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) if (o != NULL)
style_update_new(oo, o->name, oe->style); style_update_new(oo, o->name, oe->style);
break; break;
case OPTIONS_TABLE_FLAG: 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; break;
case OPTIONS_TABLE_CHOICE: 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; break;
case OPTIONS_TABLE_STYLE: 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; break;
} }
if (o == NULL) if (o == NULL)
@@ -387,7 +387,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
/* Set a string option. */ /* Set a string option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
@@ -409,7 +409,7 @@ cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq,
/* Set a number option. */ /* Set a number option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) 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); ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
if (errstr != NULL) { if (errstr != NULL) {
cmdq_error(cmdq, "value is %s: %s", errstr, value); cmdq_error(item, "value is %s: %s", errstr, value);
return (NULL); return (NULL);
} }
@@ -427,7 +427,7 @@ cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set a key option. */ /* Set a key option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) 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); key = key_string_lookup_string(value);
if (key == KEYC_UNKNOWN) { if (key == KEYC_UNKNOWN) {
cmdq_error(cmdq, "bad key: %s", value); cmdq_error(item, "bad key: %s", value);
return (NULL); return (NULL);
} }
@@ -444,14 +444,14 @@ cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set a colour option. */ /* Set a colour option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
int colour; int colour;
if ((colour = colour_fromstring(value)) == -1) { if ((colour = colour_fromstring(value)) == -1) {
cmdq_error(cmdq, "bad colour: %s", value); cmdq_error(item, "bad colour: %s", value);
return (NULL); return (NULL);
} }
@@ -460,14 +460,14 @@ cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set an attributes option. */ /* Set an attributes option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
int attr; int attr;
if ((attr = attributes_fromstring(value)) == -1) { if ((attr = attributes_fromstring(value)) == -1) {
cmdq_error(cmdq, "bad attributes: %s", value); cmdq_error(item, "bad attributes: %s", value);
return (NULL); return (NULL);
} }
@@ -476,7 +476,7 @@ cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set a flag option. */ /* Set a flag option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
@@ -494,7 +494,7 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq,
strcasecmp(value, "no") == 0) strcasecmp(value, "no") == 0)
flag = 0; flag = 0;
else { else {
cmdq_error(cmdq, "bad value: %s", value); cmdq_error(item, "bad value: %s", value);
return (NULL); return (NULL);
} }
} }
@@ -504,7 +504,7 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set a choice option. */ /* Set a choice option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
@@ -523,13 +523,13 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq,
continue; continue;
if (choice != -1) { if (choice != -1) {
cmdq_error(cmdq, "ambiguous value: %s", value); cmdq_error(item, "ambiguous value: %s", value);
return (NULL); return (NULL);
} }
choice = n - 1; choice = n - 1;
} }
if (choice == -1) { if (choice == -1) {
cmdq_error(cmdq, "unknown value: %s", value); cmdq_error(item, "unknown value: %s", value);
return (NULL); return (NULL);
} }
} }
@@ -539,7 +539,7 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq,
/* Set a style option. */ /* Set a style option. */
static struct options_entry * 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 struct options_table_entry *oe, struct options *oo,
const char *value) const char *value)
{ {
@@ -549,7 +549,7 @@ cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq,
append = args_has(args, 'a'); append = args_has(args, 'a');
if ((o = options_set_style(oo, oe->name, value, append)) == NULL) { 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); return (NULL);
} }

View File

@@ -27,10 +27,11 @@
* Show environment. * 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 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 *); struct environ_entry *);
const struct cmd_entry cmd_show_environment_entry = { const struct cmd_entry cmd_show_environment_entry = {
@@ -65,30 +66,30 @@ cmd_show_environment_escape(struct environ_entry *envent)
} }
static void 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) struct environ_entry *envent)
{ {
char *escaped; char *escaped;
if (!args_has(self->args, 's')) { if (!args_has(self->args, 's')) {
if (envent->value != NULL) if (envent->value != NULL)
cmdq_print(cmdq, "%s=%s", envent->name, envent->value); cmdq_print(item, "%s=%s", envent->name, envent->value);
else else
cmdq_print(cmdq, "-%s", envent->name); cmdq_print(item, "-%s", envent->name);
return; return;
} }
if (envent->value != NULL) { if (envent->value != NULL) {
escaped = cmd_show_environment_escape(envent); 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); envent->name);
free(escaped); free(escaped);
} else } else
cmdq_print(cmdq, "unset %s;", envent->name); cmdq_print(item, "unset %s;", envent->name);
} }
static enum cmd_retval 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 args *args = self->args;
struct environ *env; struct environ *env;
@@ -96,8 +97,8 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
const char *target; const char *target;
if ((target = args_get(args, 't')) != NULL) { if ((target = args_get(args, 't')) != NULL) {
if (cmdq->state.tflag.s == NULL) { if (item->state.tflag.s == NULL) {
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
return (CMD_RETURN_ERROR); 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')) if (args_has(self->args, 'g'))
env = global_environ; env = global_environ;
else { else {
if (cmdq->state.tflag.s == NULL) { if (item->state.tflag.s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) if (target != NULL)
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
else else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
env = cmdq->state.tflag.s->environ; env = item->state.tflag.s->environ;
} }
if (args->argc != 0) { if (args->argc != 0) {
envent = environ_find(env, args->argv[0]); envent = environ_find(env, args->argv[0]);
if (envent == NULL) { 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); return (CMD_RETURN_ERROR);
} }
cmd_show_environment_print(self, cmdq, envent); cmd_show_environment_print(self, item, envent);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
envent = environ_first(env); envent = environ_first(env);
while (envent != NULL) { while (envent != NULL) {
cmd_show_environment_print(self, cmdq, envent); cmd_show_environment_print(self, item, envent);
envent = environ_next(envent); envent = environ_next(envent);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@@ -28,7 +28,8 @@
* Show client message log. * 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 = { const struct cmd_entry cmd_show_messages_entry = {
.name = "show-messages", .name = "show-messages",
@@ -54,11 +55,11 @@ const struct cmd_entry cmd_server_info_entry = {
.exec = cmd_show_messages_exec .exec = cmd_show_messages_exec
}; };
static int cmd_show_messages_terminals(struct cmd_q *, int); static int cmd_show_messages_terminals(struct cmdq_item *, int);
static int cmd_show_messages_jobs(struct cmd_q *, int); static int cmd_show_messages_jobs(struct cmdq_item *, int);
static 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; struct tty_term *term;
u_int i, n; u_int i, n;
@@ -66,20 +67,20 @@ cmd_show_messages_terminals(struct cmd_q *cmdq, int blank)
n = 0; n = 0;
LIST_FOREACH(term, &tty_terms, entry) { LIST_FOREACH(term, &tty_terms, entry) {
if (blank) { if (blank) {
cmdq_print(cmdq, "%s", ""); cmdq_print(item, "%s", "");
blank = 0; 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, term->name, term->references, term->flags);
n++; n++;
for (i = 0; i < tty_term_ncodes(); i++) 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); return (n != 0);
} }
static int 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; struct job *job;
u_int n; u_int n;
@@ -87,10 +88,10 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
n = 0; n = 0;
LIST_FOREACH(job, &all_jobs, lentry) { LIST_FOREACH(job, &all_jobs, lentry) {
if (blank) { if (blank) {
cmdq_print(cmdq, "%s", ""); cmdq_print(item, "%s", "");
blank = 0; 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, job->cmd, job->fd, job->pid, job->status);
n++; n++;
} }
@@ -98,21 +99,21 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank)
} }
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->state.c; struct client *c = item->state.c;
struct message_entry *msg; struct message_entry *msg;
char *tim; char *tim;
int done, blank; int done, blank;
done = blank = 0; done = blank = 0;
if (args_has(args, 'T') || self->entry == &cmd_server_info_entry) { 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; done = 1;
} }
if (args_has(args, 'J') || self->entry == &cmd_server_info_entry) { 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; done = 1;
} }
if (done) if (done)
@@ -122,7 +123,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
tim = ctime(&msg->msg_time); tim = ctime(&msg->msg_time);
*strchr(tim, '\n') = '\0'; *strchr(tim, '\n') = '\0';
cmdq_print(cmdq, "%s %s", tim, msg->msg); cmdq_print(item, "%s %s", tim, msg->msg);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@@ -27,11 +27,11 @@
* Show options. * 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); 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); struct options *, enum options_table_scope);
const struct cmd_entry cmd_show_options_entry = { 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 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct options *oo; struct options *oo;
enum options_table_scope scope; enum options_table_scope scope;
int quiet; int quiet;
@@ -82,9 +82,9 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
else if (wl == NULL) { else if (wl == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such window: %s", target); cmdq_error(item, "no such window: %s", target);
} else } else
cmdq_error(cmdq, "no current window"); cmdq_error(item, "no current window");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = wl->window->options; oo = wl->window->options;
@@ -95,9 +95,9 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
else if (s == NULL) { else if (s == NULL) {
target = args_get(args, 't'); target = args_get(args, 't');
if (target != NULL) { if (target != NULL) {
cmdq_error(cmdq, "no such session: %s", target); cmdq_error(item, "no such session: %s", target);
} else } else
cmdq_error(cmdq, "no current session"); cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} else } else
oo = s->options; oo = s->options;
@@ -105,13 +105,13 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
quiet = args_has(self->args, 'q'); quiet = args_has(self->args, 'q');
if (args->argc == 0) if (args->argc == 0)
return (cmd_show_options_all(self, cmdq, oo, scope)); return (cmd_show_options_all(self, item, oo, scope));
else else
return (cmd_show_options_one(self, cmdq, oo, quiet)); return (cmd_show_options_one(self, item, oo, quiet));
} }
static enum cmd_retval 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 options *oo, int quiet)
{ {
struct args *args = self->args; struct args *args = self->args;
@@ -125,25 +125,25 @@ retry:
if ((o = options_find1(oo, name)) == NULL) { if ((o = options_find1(oo, name)) == NULL) {
if (quiet) if (quiet)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", name); cmdq_error(item, "unknown option: %s", name);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (args_has(self->args, 'v')) if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", o->str); cmdq_print(item, "%s", o->str);
else else
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); cmdq_print(item, "%s \"%s\"", o->name, o->str);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
oe = NULL; oe = NULL;
if (options_table_find(name, &oe) != 0) { 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); return (CMD_RETURN_ERROR);
} }
if (oe == NULL) { if (oe == NULL) {
if (quiet) if (quiet)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", name); cmdq_error(item, "unknown option: %s", name);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (oe->style != NULL) { if (oe->style != NULL) {
@@ -154,15 +154,15 @@ retry:
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
optval = options_table_print_entry(oe, o, args_has(self->args, 'v')); optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
if (args_has(self->args, 'v')) if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", optval); cmdq_print(item, "%s", optval);
else else
cmdq_print(cmdq, "%s %s", oe->name, optval); cmdq_print(item, "%s %s", oe->name, optval);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
static enum cmd_retval static enum cmd_retval
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
enum options_table_scope scope) struct options *oo, enum options_table_scope scope)
{ {
const struct options_table_entry *oe; const struct options_table_entry *oe;
struct options_entry *o; 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) { while (o != NULL) {
if (*o->name == '@') { if (*o->name == '@') {
if (args_has(self->args, 'v')) if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", o->str); cmdq_print(item, "%s", o->str);
else else
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str); cmdq_print(item, "%s \"%s\"", o->name, o->str);
} }
o = options_next(o); o = options_next(o);
} }
@@ -188,9 +188,9 @@ cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo,
continue; continue;
optval = options_table_print_entry(oe, o, vflag); optval = options_table_print_entry(oe, o, vflag);
if (vflag) if (vflag)
cmdq_print(cmdq, "%s", optval); cmdq_print(item, "%s", optval);
else else
cmdq_print(cmdq, "%s %s", oe->name, optval); cmdq_print(item, "%s %s", oe->name, optval);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@@ -26,9 +26,9 @@
* Sources a configuration file. * 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 = { const struct cmd_entry cmd_source_file_entry = {
.name = "source-file", .name = "source-file",
@@ -42,34 +42,34 @@ const struct cmd_entry cmd_source_file_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct client *c = cmdq->client; struct client *c = item->client;
int quiet; int quiet;
struct cmd_q *new_cmdq; struct cmdq_item *new_item;
quiet = args_has(args, 'q'); 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: case -1:
if (cfg_finished) if (cfg_finished)
cfg_print_causes(cmdq); cfg_print_causes(item);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
case 0: case 0:
if (cfg_finished) if (cfg_finished)
cfg_print_causes(cmdq); cfg_print_causes(item);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (cfg_finished) { if (cfg_finished) {
new_cmdq = cmdq_get_callback(cmd_source_file_done, NULL); new_item = cmdq_get_callback(cmd_source_file_done, NULL);
cmdq_insert_after(cmdq, new_cmdq); cmdq_insert_after(item, new_item);
} }
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
static enum cmd_retval 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); return (CMD_RETURN_NORMAL);
} }

View File

@@ -32,7 +32,8 @@
#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" #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 = { const struct cmd_entry cmd_split_window_entry = {
.name = "split-window", .name = "split-window",
@@ -49,13 +50,13 @@ const struct cmd_entry cmd_split_window_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct winlink *wl = cmdq->state.tflag.wl; struct winlink *wl = item->state.tflag.wl;
struct window *w = wl->window; 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; struct environ *env;
const char *cmd, *path, *shell, *template, *cwd, *to_free; const char *cmd, *path, *shell, *template, *cwd, *to_free;
char **argv, *cause, *new_cause, *cp; char **argv, *cause, *new_cause, *cp;
@@ -90,12 +91,12 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
to_free = NULL; to_free = NULL;
if (args_has(args, 'c')) { if (args_has(args, 'c')) {
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, cmdq->state.c, s, NULL, NULL); format_defaults(ft, item->state.c, s, NULL, NULL);
to_free = cwd = format_expand(ft, args_get(args, 'c')); to_free = cwd = format_expand(ft, args_get(args, 'c'));
format_free(ft); format_free(ft);
} else if (cmdq->client != NULL && cmdq->client->session == NULL) } else if (item->client != NULL && item->client->session == NULL)
cwd = cmdq->client->cwd; cwd = item->client->cwd;
else else
cwd = s->cwd; cwd = s->cwd;
@@ -141,8 +142,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
layout_assign_pane(lc, new_wp); layout_assign_pane(lc, new_wp);
path = NULL; path = NULL;
if (cmdq->client != NULL && cmdq->client->session == NULL) if (item->client != NULL && item->client->session == NULL)
envent = environ_find(cmdq->client->environ, "PATH"); envent = environ_find(item->client->environ, "PATH");
else else
envent = environ_find(s->environ, "PATH"); envent = environ_find(s->environ, "PATH");
if (envent != NULL) 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) if ((template = args_get(args, 'F')) == NULL)
template = SPLIT_WINDOW_TEMPLATE; template = SPLIT_WINDOW_TEMPLATE;
ft = format_create(cmdq, 0); ft = format_create(item, 0);
format_defaults(ft, cmdq->state.c, s, wl, new_wp); format_defaults(ft, item->state.c, s, wl, new_wp);
cp = format_expand(ft, template); cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp); cmdq_print(item, "%s", cp);
free(cp); free(cp);
format_free(ft); format_free(ft);
@@ -187,7 +188,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
fs.w = w; fs.w = w;
fs.wp = new_wp; fs.wp = new_wp;
cmd_find_log_state(__func__, &fs); 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); return (CMD_RETURN_NORMAL);
@@ -197,7 +198,7 @@ error:
layout_close_pane(new_wp); layout_close_pane(new_wp);
window_remove_pane(w, 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); free(cause);
if (to_free != NULL) if (to_free != NULL)

View File

@@ -26,7 +26,7 @@
* Swap two panes. * 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 = { const struct cmd_entry cmd_swap_pane_entry = {
.name = "swap-pane", .name = "swap-pane",
@@ -43,17 +43,17 @@ const struct cmd_entry cmd_swap_pane_entry = {
}; };
static enum cmd_retval 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 *src_w, *dst_w;
struct window_pane *tmp_wp, *src_wp, *dst_wp; struct window_pane *tmp_wp, *src_wp, *dst_wp;
struct layout_cell *src_lc, *dst_lc; struct layout_cell *src_lc, *dst_lc;
u_int sx, sy, xoff, yoff; u_int sx, sy, xoff, yoff;
dst_w = cmdq->state.tflag.wl->window; dst_w = item->state.tflag.wl->window;
dst_wp = cmdq->state.tflag.wp; dst_wp = item->state.tflag.wp;
src_w = cmdq->state.sflag.wl->window; src_w = item->state.sflag.wl->window;
src_wp = cmdq->state.sflag.wp; src_wp = item->state.sflag.wp;
server_unzoom_window(dst_w); server_unzoom_window(dst_w);
if (args_has(self->args, 'D')) { if (args_has(self->args, 'D')) {

View File

@@ -26,7 +26,7 @@
* Swap one window with another. * 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 = { const struct cmd_entry cmd_swap_window_entry = {
.name = "swap-window", .name = "swap-window",
@@ -43,24 +43,24 @@ const struct cmd_entry cmd_swap_window_entry = {
}; };
static enum cmd_retval 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 *src, *dst;
struct session_group *sg_src, *sg_dst; struct session_group *sg_src, *sg_dst;
struct winlink *wl_src, *wl_dst; struct winlink *wl_src, *wl_dst;
struct window *w; struct window *w;
wl_src = cmdq->state.sflag.wl; wl_src = item->state.sflag.wl;
src = cmdq->state.sflag.s; src = item->state.sflag.s;
sg_src = session_group_find(src); sg_src = session_group_find(src);
wl_dst = cmdq->state.tflag.wl; wl_dst = item->state.tflag.wl;
dst = cmdq->state.tflag.s; dst = item->state.tflag.s;
sg_dst = session_group_find(dst); sg_dst = session_group_find(dst);
if (src != dst && sg_src != NULL && sg_dst != NULL && if (src != dst && sg_src != NULL && sg_dst != NULL &&
sg_src == sg_dst) { 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); return (CMD_RETURN_ERROR);
} }

View File

@@ -27,7 +27,8 @@
* Switch client to a different session. * 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 = { const struct cmd_entry cmd_switch_client_entry = {
.name = "switch-client", .name = "switch-client",
@@ -45,12 +46,12 @@ const struct cmd_entry cmd_switch_client_entry = {
}; };
static enum cmd_retval 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 args *args = self->args;
struct cmd_state *state = &cmdq->state; struct cmd_state *state = &item->state;
struct client *c = state->c; struct client *c = state->c;
struct session *s = cmdq->state.tflag.s; struct session *s = item->state.tflag.s;
struct window_pane *wp; struct window_pane *wp;
const char *tablename, *update; const char *tablename, *update;
struct key_table *table; struct key_table *table;
@@ -62,7 +63,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
if (tablename != NULL) { if (tablename != NULL) {
table = key_bindings_get_table(tablename, 0); table = key_bindings_get_table(tablename, 0);
if (table == NULL) { 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); return (CMD_RETURN_ERROR);
} }
table->references++; table->references++;
@@ -73,12 +74,12 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'n')) { if (args_has(args, 'n')) {
if ((s = session_next_session(c->session)) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
} else if (args_has(args, 'p')) { } else if (args_has(args, 'p')) {
if ((s = session_previous_session(c->session)) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
} else if (args_has(args, 'l')) { } else if (args_has(args, 'l')) {
@@ -87,11 +88,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
else else
s = NULL; s = NULL;
if (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); return (CMD_RETURN_ERROR);
} }
} else { } else {
if (cmdq->client == NULL) if (item->client == NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
if (state->tflag.wl != NULL) { if (state->tflag.wl != NULL) {
wp = state->tflag.wp; wp = state->tflag.wp;

View File

@@ -26,9 +26,10 @@
* Unbind key from command. * Unbind key from command.
*/ */
static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); 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 cmd_q *,
key_code); static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *,
struct cmdq_item *, key_code);
const struct cmd_entry cmd_unbind_key_entry = { const struct cmd_entry cmd_unbind_key_entry = {
.name = "unbind-key", .name = "unbind-key",
@@ -42,7 +43,7 @@ const struct cmd_entry cmd_unbind_key_entry = {
}; };
static enum cmd_retval 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; struct args *args = self->args;
key_code key; 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_has(args, 'a')) {
if (args->argc != 1) { if (args->argc != 1) {
cmdq_error(cmdq, "missing key"); cmdq_error(item, "missing key");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
key = key_string_lookup_string(args->argv[0]); key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE || key == KEYC_UNKNOWN) { 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); return (CMD_RETURN_ERROR);
} }
} else { } else {
if (args->argc != 0) { if (args->argc != 0) {
cmdq_error(cmdq, "key given with -a"); cmdq_error(item, "key given with -a");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
key = KEYC_UNKNOWN; key = KEYC_UNKNOWN;
} }
if (args_has(args, 't')) 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) { if (key == KEYC_UNKNOWN) {
tablename = args_get(args, 'T'); tablename = args_get(args, 'T');
@@ -77,7 +78,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (key_bindings_get_table(tablename, 0) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
key_bindings_remove_table(tablename); 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')) { if (args_has(args, 'T')) {
tablename = args_get(args, 'T'); tablename = args_get(args, 'T');
if (key_bindings_get_table(tablename, 0) == NULL) { 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); return (CMD_RETURN_ERROR);
} }
} else if (args_has(args, 'n')) } 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 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; struct args *args = self->args;
const char *tablename; 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'); tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) { 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); return (CMD_RETURN_ERROR);
} }

View File

@@ -28,7 +28,7 @@
* Block or wake a client on a named wait channel. * 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 = { const struct cmd_entry cmd_wait_for_entry = {
.name = "wait-for", .name = "wait-for",
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_wait_for_entry = {
}; };
struct wait_item { struct wait_item {
struct cmd_q *cmdq; struct cmdq_item *item;
TAILQ_ENTRY(wait_item) entry; 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)); 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 *); 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 *); 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 *); 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 *); struct wait_channel *);
static struct wait_channel *cmd_wait_for_add(const char *); 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 * static struct wait_channel *
cmd_wait_for_add(const char *name) cmd_wait_for_add(const char *name)
@@ -118,7 +118,7 @@ cmd_wait_for_remove(struct wait_channel *wc)
} }
static enum cmd_retval 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; struct args *args = self->args;
const char *name = args->argv[0]; 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); wc = RB_FIND(wait_channels, &wait_channels, &wc0);
if (args_has(args, 'S')) 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')) 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')) if (args_has(args, 'U'))
return (cmd_wait_for_unlock(cmdq, name, wc)); return (cmd_wait_for_unlock(item, name, wc));
return (cmd_wait_for_wait(cmdq, name, wc)); return (cmd_wait_for_wait(item, name, wc));
} }
static enum cmd_retval 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_channel *wc)
{ {
struct wait_item *wi, *wi1; 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); log_debug("signal wait channel %s, with waiters", wc->name);
TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { 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); TAILQ_REMOVE(&wc->waiters, wi, entry);
free(wi); free(wi);
@@ -164,13 +164,14 @@ cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name,
} }
static enum cmd_retval 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; struct wait_item *wi;
if (c == NULL || c->session != NULL) { if (c == NULL || c->session != NULL) {
cmdq_error(cmdq, "not able to wait"); cmdq_error(item, "not able to wait");
return (CMD_RETURN_ERROR); 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); log_debug("wait channel %s not woken (%p)", wc->name, c);
wi = xcalloc(1, sizeof *wi); wi = xcalloc(1, sizeof *wi);
wi->cmdq = cmdq; wi->item = item;
TAILQ_INSERT_TAIL(&wc->waiters, wi, entry); TAILQ_INSERT_TAIL(&wc->waiters, wi, entry);
return (CMD_RETURN_WAIT); return (CMD_RETURN_WAIT);
} }
static enum cmd_retval 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; struct wait_item *wi;
if (cmdq->client == NULL || cmdq->client->session != NULL) { if (item->client == NULL || item->client->session != NULL) {
cmdq_error(cmdq, "not able to lock"); cmdq_error(item, "not able to lock");
return (CMD_RETURN_ERROR); 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) { if (wc->locked) {
wi = xcalloc(1, sizeof *wi); wi = xcalloc(1, sizeof *wi);
wi->cmdq = cmdq; wi->item = item;
TAILQ_INSERT_TAIL(&wc->lockers, wi, entry); TAILQ_INSERT_TAIL(&wc->lockers, wi, entry);
return (CMD_RETURN_WAIT); 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 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_channel *wc)
{ {
struct wait_item *wi; struct wait_item *wi;
if (wc == NULL || !wc->locked) { 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); return (CMD_RETURN_ERROR);
} }
if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) { if ((wi = TAILQ_FIRST(&wc->lockers)) != NULL) {
wi->cmdq->flags &= ~CMD_Q_WAITING; wi->item->flags &= ~CMDQ_WAITING;
TAILQ_REMOVE(&wc->lockers, wi, entry); TAILQ_REMOVE(&wc->lockers, wi, entry);
free(wi); free(wi);
} else { } else {
@@ -246,13 +248,13 @@ cmd_wait_for_flush(void)
RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) { RB_FOREACH_SAFE(wc, wait_channels, &wait_channels, wc1) {
TAILQ_FOREACH_SAFE(wi, &wc->waiters, entry, wi1) { 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); TAILQ_REMOVE(&wc->waiters, wi, entry);
free(wi); free(wi);
} }
wc->woken = 1; wc->woken = 1;
TAILQ_FOREACH_SAFE(wi, &wc->lockers, entry, wi1) { 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); TAILQ_REMOVE(&wc->lockers, wi, entry);
free(wi); free(wi);
} }

30
cmd.c
View File

@@ -389,7 +389,7 @@ usage:
static int static int
cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag, 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; int targetflags, error;
struct cmd_find_state *fs = NULL; 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); return (0);
if (c == 't') if (c == 't')
fs = &cmdq->state.tflag; fs = &item->state.tflag;
else if (c == 's') else if (c == 's')
fs = &cmdq->state.sflag; fs = &item->state.sflag;
if (flag == CMD_SESSION_WITHPANE) { if (flag == CMD_SESSION_WITHPANE) {
if (target != NULL && target[strcspn(target, ":.")] != '\0') 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); log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
error = cmd_find_current(&current, cmdq, targetflags); error = cmd_find_current(&current, item, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1); return (-1);
if (!cmd_find_empty_state(&current) && !cmd_find_valid_state(&current)) if (!cmd_find_empty_state(&current) && !cmd_find_valid_state(&current))
@@ -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_CANFAIL:
case CMD_SESSION_PREFERUNATTACHED: case CMD_SESSION_PREFERUNATTACHED:
case CMD_SESSION_WITHPANE: case CMD_SESSION_WITHPANE:
error = cmd_find_target(fs, &current, cmdq, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_SESSION, targetflags); CMD_FIND_SESSION, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1); return (-1);
break; break;
case CMD_MOVEW_R: case CMD_MOVEW_R:
error = cmd_find_target(fs, &current, cmdq, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_SESSION, CMD_FIND_QUIET); CMD_FIND_SESSION, CMD_FIND_QUIET);
if (error == 0) if (error == 0)
break; 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_CANFAIL:
case CMD_WINDOW_MARKED: case CMD_WINDOW_MARKED:
case CMD_WINDOW_INDEX: case CMD_WINDOW_INDEX:
error = cmd_find_target(fs, &current, cmdq, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_WINDOW, targetflags); CMD_FIND_WINDOW, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1); 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:
case CMD_PANE_CANFAIL: case CMD_PANE_CANFAIL:
case CMD_PANE_MARKED: case CMD_PANE_MARKED:
error = cmd_find_target(fs, &current, cmdq, target, error = cmd_find_target(fs, &current, item, target,
CMD_FIND_PANE, targetflags); CMD_FIND_PANE, targetflags);
if (error != 0 && ~targetflags & CMD_FIND_QUIET) if (error != 0 && ~targetflags & CMD_FIND_QUIET)
return (-1); return (-1);
@@ -499,17 +499,17 @@ cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
} }
int 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; const struct cmd_entry *entry = cmd->entry;
struct cmd_state *state = &cmdq->state; struct cmd_state *state = &item->state;
char *tmp; char *tmp;
enum cmd_entry_flag flag; enum cmd_entry_flag flag;
const char *s; const char *s;
int error; int error;
tmp = cmd_print(cmd); 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); free(tmp);
state->c = NULL; state->c = NULL;
@@ -527,12 +527,12 @@ cmd_prepare_state(struct cmd *cmd, struct cmd_q *cmdq)
s = args_get(cmd->args, 'c'); s = args_get(cmd->args, 'c');
switch (flag) { switch (flag) {
case CMD_CLIENT: case CMD_CLIENT:
state->c = cmd_find_client(cmdq, s, 0); state->c = cmd_find_client(item, s, 0);
if (state->c == NULL) if (state->c == NULL)
return (-1); return (-1);
break; break;
default: default:
state->c = cmd_find_client(cmdq, s, 1); state->c = cmd_find_client(item, s, 1);
break; break;
} }
log_debug("using client %p", state->c); 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'); s = args_get(cmd->args, 't');
log_debug("preparing -t state: target %s", s == NULL ? "none" : s); 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) if (error != 0)
return (error); return (error);
s = args_get(cmd->args, 's'); s = args_get(cmd->args, 's');
log_debug("preparing -s state: target %s", s == NULL ? "none" : 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) if (error != 0)
return (error); return (error);

View File

@@ -51,14 +51,14 @@ control_write_buffer(struct client *c, struct evbuffer *buffer)
/* Control error callback. */ /* Control error callback. */
static enum cmd_retval 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; char *error = data;
cmdq_guard(cmdq, "begin", 1); cmdq_guard(item, "begin", 1);
control_write(c, "parse error: %s", error); control_write(c, "parse error: %s", error);
cmdq_guard(cmdq, "error", 1); cmdq_guard(item, "error", 1);
free(error); free(error);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@@ -68,10 +68,10 @@ control_error(struct cmd_q *cmdq, void *data)
void void
control_callback(struct client *c, int closed, __unused void *data) control_callback(struct client *c, int closed, __unused void *data)
{ {
char *line, *cause; char *line, *cause;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd *cmd; struct cmd *cmd;
struct cmd_q *cmdq; struct cmdq_item *item;
if (closed) if (closed)
c->flags |= CLIENT_EXIT; 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) { if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) {
cmdq = cmdq_get_callback(control_error, cause); item = cmdq_get_callback(control_error, cause);
cmdq_append(c, cmdq); cmdq_append(c, item);
} else { } else {
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) TAILQ_FOREACH(cmd, &cmdlist->list, qentry)
cmd->flags |= CMD_CONTROL; cmd->flags |= CMD_CONTROL;
cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmdq_append(c, cmdq); cmdq_append(c, item);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
} }

View File

@@ -487,9 +487,22 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe)
evbuffer_free(buffer); 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. */ /* Create a new tree. */
struct format_tree * struct format_tree *
format_create(struct cmd_q *cmdq, int flags) format_create(struct cmdq_item *item, int flags)
{ {
struct format_tree *ft; 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(ft, "socket_path", "%s", socket_path);
format_add_tv(ft, "start_time", &start_time); format_add_tv(ft, "start_time", &start_time);
if (cmdq != NULL && cmdq->cmd != NULL) if (item != NULL && item->cmd != NULL)
format_add(ft, "command", "%s", cmdq->cmd->entry->name); format_add(ft, "command", "%s", item->cmd->entry->name);
if (cmdq != NULL && cmdq->hook != NULL) if (item != NULL && item->formats != NULL)
format_add(ft, "hook", "%s", cmdq->hook); format_merge(ft, item->formats);
return (ft); return (ft);
} }

48
hooks.c
View File

@@ -143,10 +143,10 @@ void
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs, hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
const char *fmt, ...) const char *fmt, ...)
{ {
struct hook *hook; struct hook *hook;
va_list ap; va_list ap;
char *name; char *name;
struct cmd_q *new_cmdq, *loop; struct cmdq_item *new_item;
va_start(ap, fmt); va_start(ap, fmt);
xvasprintf(&name, fmt, ap); 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); 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); free(name);
cmdq_append(c, new_cmdq);
} }
void void
hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs, hooks_insert(struct hooks *hooks, struct cmdq_item *item,
const char *fmt, ...) struct cmd_find_state *fs, const char *fmt, ...)
{ {
struct hook *hook; struct hook *hook;
va_list ap; va_list ap;
char *name; char *name;
struct cmd_q *new_cmdq, *loop; struct cmdq_item *new_item;
if (cmdq->flags & CMD_Q_NOHOOKS) if (item->flags & CMDQ_NOHOOKS)
return; return;
va_start(ap, fmt); va_start(ap, fmt);
@@ -189,16 +187,14 @@ hooks_insert(struct hooks *hooks, struct cmd_q *cmdq, struct cmd_find_state *fs,
free(name); free(name);
return; 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); 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) if (item != NULL)
loop->hook = xstrdup(name); cmdq_insert_after(item, new_item);
free(name);
if (cmdq != NULL)
cmdq_insert_after(cmdq, new_cmdq);
else else
cmdq_append(NULL, new_cmdq); cmdq_append(NULL, new_item);
free(name);
} }

View File

@@ -389,9 +389,9 @@ key_bindings_init(void)
} }
static enum cmd_retval 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); return (CMD_RETURN_ERROR);
} }

146
notify.c
View File

@@ -40,8 +40,8 @@ static const char *notify_hooks[] = {
"window-renamed", "window-renamed",
NULL, /* "attached-session-changed", */ NULL, /* "attached-session-changed", */
"session-renamed", "session-renamed",
NULL, /* "session-created", */ "session-created",
NULL, /* "session-closed" */ "session-closed"
}; };
struct notify_entry { struct notify_entry {
@@ -50,34 +50,31 @@ struct notify_entry {
struct client *client; struct client *client;
struct session *session; struct session *session;
struct window *window; 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 static void
notify_hook(struct notify_entry *ne) notify_hook(struct cmdq_item *item, struct notify_entry *ne)
{ {
const char *name; const char *name;
struct cmd_find_state fs; struct cmd_find_state fs;
struct hook *hook; 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]; name = notify_hooks[ne->type];
if (name == NULL) if (name == NULL)
return; return;
cmd_find_clear_state(&fs, NULL, 0); cmd_find_clear_state(&fs, NULL, 0);
if (ne->session != NULL && ne->window != NULL) if (s != NULL && w != NULL)
cmd_find_from_session_window(&fs, ne->session, ne->window); cmd_find_from_session_window(&fs, s, w);
else if (ne->window != NULL) else if (w != NULL)
cmd_find_from_window(&fs, ne->window); cmd_find_from_window(&fs, w);
else if (ne->session != NULL) else if (s != NULL && session_alive(s))
cmd_find_from_session(&fs, ne->session); 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)) if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs))
return; return;
@@ -86,12 +83,63 @@ notify_hook(struct notify_entry *ne)
return; return;
log_debug("notify hook %s", name); 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) if (s != NULL) {
loop->hook = xstrdup(name); 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 static void
@@ -99,13 +147,13 @@ notify_add(enum notify_type type, struct client *c, struct session *s,
struct window *w) struct window *w)
{ {
struct notify_entry *ne; struct notify_entry *ne;
struct cmdq_item *new_item;
ne = xcalloc(1, sizeof *ne); ne = xcalloc(1, sizeof *ne);
ne->type = type; ne->type = type;
ne->client = c; ne->client = c;
ne->session = s; ne->session = s;
ne->window = w; ne->window = w;
TAILQ_INSERT_TAIL(&notify_queue, ne, entry);
if (c != NULL) if (c != NULL)
c->references++; c->references++;
@@ -113,51 +161,9 @@ notify_add(enum notify_type type, struct client *c, struct session *s,
s->references++; s->references++;
if (w != NULL) if (w != NULL)
w->references++; w->references++;
}
void new_item = cmdq_get_callback(notify_callback, ne);
notify_drain(void) cmdq_append(NULL, new_item);
{
struct notify_entry *ne, *ne1;
TAILQ_FOREACH_SAFE(ne, &notify_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(&notify_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);
}
} }
void void
@@ -175,54 +181,46 @@ void
notify_window_layout_changed(struct window *w) notify_window_layout_changed(struct window *w)
{ {
notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w); notify_add(NOTIFY_WINDOW_LAYOUT_CHANGED, NULL, NULL, w);
notify_drain();
} }
void void
notify_window_unlinked(struct session *s, struct window *w) notify_window_unlinked(struct session *s, struct window *w)
{ {
notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w); notify_add(NOTIFY_WINDOW_UNLINKED, NULL, s, w);
notify_drain();
} }
void void
notify_window_linked(struct session *s, struct window *w) notify_window_linked(struct session *s, struct window *w)
{ {
notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w); notify_add(NOTIFY_WINDOW_LINKED, NULL, s, w);
notify_drain();
} }
void void
notify_window_renamed(struct window *w) notify_window_renamed(struct window *w)
{ {
notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w); notify_add(NOTIFY_WINDOW_RENAMED, NULL, NULL, w);
notify_drain();
} }
void void
notify_attached_session_changed(struct client *c) notify_attached_session_changed(struct client *c)
{ {
notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL); notify_add(NOTIFY_ATTACHED_SESSION_CHANGED, c, NULL, NULL);
notify_drain();
} }
void void
notify_session_renamed(struct session *s) notify_session_renamed(struct session *s)
{ {
notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL); notify_add(NOTIFY_SESSION_RENAMED, NULL, s, NULL);
notify_drain();
} }
void void
notify_session_created(struct session *s) notify_session_created(struct session *s)
{ {
notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL); notify_add(NOTIFY_SESSION_CREATED, NULL, s, NULL);
notify_drain();
} }
void void
notify_session_closed(struct session *s) notify_session_closed(struct session *s)
{ {
notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL); notify_add(NOTIFY_SESSION_CLOSED, NULL, s, NULL);
notify_drain();
} }

View File

@@ -1262,9 +1262,9 @@ server_client_dispatch(struct imsg *imsg, void *arg)
/* Callback when command is done. */ /* Callback when command is done. */
static enum cmd_retval 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) if (~c->flags & CLIENT_ATTACHED)
c->flags |= CLIENT_EXIT; c->flags |= CLIENT_EXIT;
@@ -1273,11 +1273,11 @@ server_client_command_done(struct cmd_q *cmdq, __unused void *data)
/* Show an error message. */ /* Show an error message. */
static enum cmd_retval 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; char *error = data;
cmdq_error(cmdq, "%s", error); cmdq_error(item, "%s", error);
free(error); free(error);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@@ -194,8 +194,6 @@ server_loop(void)
struct client *c; struct client *c;
u_int items; u_int items;
notify_drain();
do { do {
items = cmdq_next(NULL); items = cmdq_next(NULL);
TAILQ_FOREACH(c, &clients, entry) TAILQ_FOREACH(c, &clients, entry)

8
tmux.1
View File

@@ -3248,6 +3248,10 @@ Run when the program running in a pane exits, but
is on so the pane has not closed. is on so the pane has not closed.
.It pane-exited .It pane-exited
Run when the program running in a pane exits. 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 .It session-renamed
Run when a session is renamed. Run when a session is renamed.
.It window-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_limit" Ta "" Ta "Maximum window history lines"
.It Li "history_size" Ta "" Ta "Size of history in bytes" .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" 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" Ta "#H" Ta "Hostname of local host"
.It Li "host_short" Ta "#h" Ta "Hostname of local host (no domain name)" .It Li "host_short" Ta "#h" Ta "Hostname of local host (no domain name)"
.It Li "insert_flag" Ta "" Ta "Pane insert flag" .It Li "insert_flag" Ta "" Ta "Pane insert flag"

88
tmux.h
View File

@@ -42,8 +42,8 @@ extern char **environ;
struct args; struct args;
struct client; struct client;
struct cmd_q; struct cmdq_item;
struct cmd_q_list; struct cmdq_list;
struct environ; struct environ;
struct input_ctx; struct input_ctx;
struct mode_key_cmdstr; struct mode_key_cmdstr;
@@ -1179,7 +1179,7 @@ enum cmd_find_type {
CMD_FIND_SESSION, CMD_FIND_SESSION,
}; };
struct cmd_find_state { struct cmd_find_state {
struct cmd_q *cmdq; struct cmdq_item *item;
int flags; int flags;
struct cmd_find_state *current; struct cmd_find_state *current;
@@ -1233,35 +1233,36 @@ enum cmd_retval {
}; };
/* Command queue item type. */ /* Command queue item type. */
enum cmd_q_type { enum cmdq_type {
CMD_Q_COMMAND, CMDQ_COMMAND,
CMD_Q_CALLBACK, CMDQ_CALLBACK,
}; };
/* Command queue item. */ /* Command queue item. */
typedef enum cmd_retval (*cmd_q_cb) (struct cmd_q *, void *); typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *);
struct cmd_q { struct cmdq_item {
struct cmd_q_list *queue; struct cmdq_list *queue;
struct cmd_q *next; struct cmdq_item *next;
struct client *client; struct client *client;
enum cmd_q_type type; enum cmdq_type type;
u_int group; u_int group;
u_int number; u_int number;
time_t time; time_t time;
const char *hook; struct format_tree *formats;
int flags; int flags;
#define CMD_Q_FIRED 0x1 #define CMDQ_FIRED 0x1
#define CMD_Q_WAITING 0x2 #define CMDQ_WAITING 0x2
#define CMD_Q_NOHOOKS 0x4 #define CMDQ_NOHOOKS 0x4
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd *cmd; struct cmd *cmd;
cmd_q_cb cb; cmdq_cb cb;
void *data; void *data;
struct cmd_find_state current; struct cmd_find_state current;
@@ -1269,9 +1270,9 @@ struct cmd_q {
struct mouse_event mouse; 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. */ /* Command -c, -t or -s flags. */
enum cmd_entry_flag { enum cmd_entry_flag {
@@ -1318,13 +1319,13 @@ struct cmd_entry {
#define CMD_AFTERHOOK 0x4 #define CMD_AFTERHOOK 0x4
int flags; int flags;
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *); enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
}; };
/* Client connection. */ /* Client connection. */
struct client { struct client {
struct tmuxpeer *peer; struct tmuxpeer *peer;
struct cmd_q_list queue; struct cmdq_list queue;
pid_t pid; pid_t pid;
int fd; int fd;
@@ -1512,12 +1513,12 @@ void proc_kill_peer(struct tmuxpeer *);
/* cfg.c */ /* cfg.c */
extern int cfg_finished; extern int cfg_finished;
extern struct client *cfg_client; extern struct client *cfg_client;
void start_cfg(void); void start_cfg(void);
int load_cfg(const char *, struct client *, struct cmd_q *, int); int load_cfg(const char *, struct client *, struct cmdq_item *, int);
void set_cfg_file(const char *); void set_cfg_file(const char *);
void printflike(1, 2) cfg_add_cause(const char *, ...); void printflike(1, 2) cfg_add_cause(const char *, ...);
void cfg_print_causes(struct cmd_q *); void cfg_print_causes(struct cmdq_item *);
void cfg_show_causes(struct session *); void cfg_show_causes(struct session *);
/* paste.c */ /* paste.c */
struct paste_buffer; struct paste_buffer;
@@ -1538,7 +1539,7 @@ char *paste_make_sample(struct paste_buffer *);
#define FORMAT_STATUS 0x1 #define FORMAT_STATUS 0x1
#define FORMAT_FORCE 0x2 #define FORMAT_FORCE 0x2
struct format_tree; 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 format_free(struct format_tree *);
void printflike(3, 4) format_add(struct format_tree *, const char *, void printflike(3, 4) format_add(struct format_tree *, const char *,
const char *, ...); const char *, ...);
@@ -1565,7 +1566,7 @@ void hooks_remove(struct hooks *, const char *);
struct hook *hooks_find(struct hooks *, const char *); struct hook *hooks_find(struct hooks *, const char *);
void printflike(4, 5) hooks_run(struct hooks *, struct client *, void printflike(4, 5) hooks_run(struct hooks *, struct client *,
struct cmd_find_state *, const char *, ...); 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 *, ...); struct cmd_find_state *, const char *, ...);
/* mode-key.c */ /* 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); enum mode_key_cmd mode_key_lookup(struct mode_key_data *, key_code);
/* notify.c */ /* notify.c */
void notify_drain(void);
void notify_input(struct window_pane *, struct evbuffer *); void notify_input(struct window_pane *, struct evbuffer *);
void notify_window_layout_changed(struct window *); void notify_window_layout_changed(struct window *);
void notify_window_unlinked(struct session *, 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 **); char **);
/* cmd-find.c */ /* 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);
int cmd_find_target(struct cmd_find_state *, 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); enum cmd_find_type, int);
struct client *cmd_find_client(struct cmd_q *, const char *, int); struct client *cmd_find_client(struct cmdq_item *, const char *, int);
void cmd_find_clear_state(struct cmd_find_state *, struct cmd_q *, void cmd_find_clear_state(struct cmd_find_state *,
int); struct cmdq_item *, int);
int cmd_find_empty_state(struct cmd_find_state *); int cmd_find_empty_state(struct cmd_find_state *);
int cmd_find_valid_state(struct cmd_find_state *); int cmd_find_valid_state(struct cmd_find_state *);
void cmd_find_copy_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 **); void cmd_free_argv(int, char **);
char *cmd_stringify_argv(int, char **); char *cmd_stringify_argv(int, char **);
struct cmd *cmd_parse(int, char **, const char *, u_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 *); char *cmd_print(struct cmd *);
int cmd_mouse_at(struct window_pane *, struct mouse_event *, int cmd_mouse_at(struct window_pane *, struct mouse_event *,
u_int *, u_int *, int); 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[]; extern const struct cmd_entry *cmd_table[];
/* cmd-attach-session.c */ /* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmd_q *, int, int, const char *, enum cmd_retval cmd_attach_session(struct cmdq_item *, int, int, const char *,
int); int);
/* cmd-list.c */ /* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **); 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 *); char *cmd_list_print(struct cmd_list *);
/* cmd-queue.c */ /* 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 mouse_event *, int);
struct cmd_q *cmdq_get_callback(cmd_q_cb, void *); struct cmdq_item *cmdq_get_callback(cmdq_cb, void *);
void cmdq_insert_after(struct cmd_q *, struct cmd_q *); void cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
void cmdq_append(struct client *, struct cmd_q *); 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 *); u_int cmdq_next(struct client *);
void cmdq_guard(struct cmd_q *, const char *, int); void cmdq_guard(struct cmdq_item *, const char *, int);
void printflike(2, 3) cmdq_print(struct cmd_q *, const char *, ...); void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
void printflike(2, 3) cmdq_error(struct cmd_q *, const char *, ...); void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
/* cmd-string.c */ /* cmd-string.c */
int cmd_string_parse(const char *, struct cmd_list **, const char *, int cmd_string_parse(const char *, struct cmd_list **, const char *,

View File

@@ -244,9 +244,9 @@ window_choose_data_free(struct window_choose_data *wcd)
void void
window_choose_data_run(struct window_choose_data *cdata) window_choose_data_run(struct window_choose_data *cdata)
{ {
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
char *cause; char *cause;
struct cmd_q *cmdq; struct cmdq_item *item;
/* /*
* The command template will have already been replaced. But if it's * 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; return;
} }
cmdq = cmdq_get_command(cmdlist, NULL, NULL, 0); item = cmdq_get_command(cmdlist, NULL, NULL, 0);
cmdq_append(cdata->start_client, cmdq); cmdq_append(cdata->start_client, item);
cmd_list_free(cmdlist); cmd_list_free(cmdlist);
} }