-/* $OpenBSD: cmd-attach-session.c,v 1.72 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.73 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "c:dErt:", 0, 0 },
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION_WITHPANE,
+ /* -t is special */
.flags = CMD_STARTSERVER,
.exec = cmd_attach_session_exec
};
enum cmd_retval
-cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
- const char *cflag, int Eflag)
+cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
+ int rflag, const char *cflag, int Eflag)
{
struct cmd_find_state *current = &item->shared->current;
- struct session *s = item->state.tflag.s;
+ enum cmd_find_type type;
+ int flags;
struct client *c = item->client, *c_loop;
- struct winlink *wl = item->state.tflag.wl;
- struct window_pane *wp = item->state.tflag.wp;
+ struct session *s;
+ struct winlink *wl;
+ struct window_pane *wp;
char *cause;
if (RB_EMPTY(&sessions)) {
return (CMD_RETURN_ERROR);
}
+ if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
+ type = CMD_FIND_PANE;
+ flags = 0;
+ } else {
+ type = CMD_FIND_SESSION;
+ flags = CMD_FIND_PREFER_UNATTACHED;
+ }
+ if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
+ return (CMD_RETURN_ERROR);
+ s = item->target.s;
+ wl = item->target.wl;
+ wp = item->target.wp;
+
if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
{
struct args *args = self->args;
- return (cmd_attach_session(item, args_has(args, 'd'),
- args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E')));
+ return (cmd_attach_session(item, args_get(args, 't'),
+ args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
+ args_has(args, 'E')));
}
-/* $OpenBSD: cmd-break-pane.c,v 1.44 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-break-pane.c,v 1.45 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.alias = "breakp",
.args = { "dPF:n:s:t:", 0, 0 },
- .usage = "[-dP] [-F format] [-n window-name] [-s src-pane] [-t dst-window]",
+ .usage = "[-dP] [-F format] [-n window-name] [-s src-pane] "
+ "[-t dst-window]",
- .sflag = CMD_PANE,
- .tflag = CMD_WINDOW_INDEX,
+ .source = { 's', CMD_FIND_PANE, 0 },
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
.flags = 0,
.exec = cmd_break_pane_exec
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
- struct client *c = item->state.c;
- struct winlink *wl = item->state.sflag.wl;
- struct session *src_s = item->state.sflag.s;
- struct session *dst_s = item->state.tflag.s;
- struct window_pane *wp = item->state.sflag.wp;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct winlink *wl = item->source.wl;
+ struct session *src_s = item->source.s;
+ struct session *dst_s = item->target.s;
+ struct window_pane *wp = item->source.wp;
struct window *w = wl->window;
char *name, *cause;
- int idx = item->state.tflag.idx;
+ int idx = item->target.idx;
const char *template;
char *cp;
-/* $OpenBSD: cmd-capture-pane.c,v 1.43 2017/02/16 12:18:38 nicm Exp $ */
+/* $OpenBSD: cmd-capture-pane.c,v 1.44 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line]" CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_capture_pane_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_capture_pane_exec
{
struct args *args = self->args;
struct client *c;
- struct window_pane *wp = item->state.tflag.wp;
+ struct window_pane *wp = item->target.wp;
char *buf, *cause;
const char *bufname;
size_t len;
-/* $OpenBSD: cmd-choose-buffer.c,v 1.31 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-choose-buffer.c,v 1.32 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_buffer_exec
cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
- struct winlink *wl = item->state.tflag.wl;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct winlink *wl = item->target.wl;
struct window_choose_data *cdata;
struct paste_buffer *pb;
char *action, *action_data;
-/* $OpenBSD: cmd-choose-client.c,v 1.32 2017/04/05 10:49:46 nicm Exp $ */
+/* $OpenBSD: cmd-choose-client.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_client_exec
cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
+ struct client *c = cmd_find_client(item, NULL, 1);
struct client *c1;
struct window_choose_data *cdata;
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
const char *template;
char *action;
u_int idx, cur;
-/* $OpenBSD: cmd-choose-tree.c,v 1.33 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-choose-tree.c,v 1.34 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
.usage = "[-suw] [-b session-template] [-c window template] "
"[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
.args = { "F:t:", 0, 1 },
.usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_choose_tree_exec
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
- struct winlink *wl = item->state.tflag.wl, *wm;
- struct session *s = item->state.tflag.s, *s2;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct winlink *wl = item->target.wl, *wm;
+ struct session *s = item->target.s, *s2;
struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template;
char *final_win_action, *cur_win_template;
-/* $OpenBSD: cmd-command-prompt.c,v 1.42 2017/04/19 12:44:29 nicm Exp $ */
+/* $OpenBSD: cmd-command-prompt.c,v 1.43 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
"[template]",
- .tflag = CMD_CLIENT,
-
.flags = 0,
.exec = cmd_command_prompt_exec
};
struct args *args = self->args;
const char *inputs, *prompts;
struct cmd_command_prompt_cdata *cdata;
- struct client *c = item->state.c;
+ struct client *c;
char *prompt, *ptr, *input = NULL;
size_t n;
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
if (c->prompt_string != NULL)
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: cmd-confirm-before.c,v 1.33 2017/01/15 22:00:56 nicm Exp $ */
+/* $OpenBSD: cmd-confirm-before.c,v 1.34 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.args = { "p:t:", 1, 1 },
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
- .tflag = CMD_CLIENT,
-
.flags = 0,
.exec = cmd_confirm_before_exec
};
{
struct args *args = self->args;
struct cmd_confirm_before_data *cdata;
- struct client *c = item->state.c;
+ struct client *c;
char *cmd, *copy, *new_prompt, *ptr;
const char *prompt;
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt);
else {
-/* $OpenBSD: cmd-copy-mode.c,v 1.32 2017/04/21 14:01:19 nicm Exp $ */
+/* $OpenBSD: cmd-copy-mode.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "Met:u", 0, 0 },
.usage = "[-Mu] " CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_copy_mode_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_copy_mode_exec
struct cmdq_shared *shared = item->shared;
struct client *c = item->client;
struct session *s;
- struct window_pane *wp = item->state.tflag.wp;
+ struct window_pane *wp = item->target.wp;
if (args_has(args, 'M')) {
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)
-/* $OpenBSD: cmd-detach-client.c,v 1.31 2017/04/19 14:00:28 nicm Exp $ */
+/* $OpenBSD: cmd-detach-client.c,v 1.32 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-aP] [-E shell-command] "
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
- .sflag = CMD_SESSION,
- .tflag = CMD_CLIENT,
+ .source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_READONLY,
.exec = cmd_detach_client_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
- .tflag = CMD_CLIENT,
-
.flags = 0,
.exec = cmd_detach_client_exec
};
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c, *cloop;
+ struct client *c, *cloop;
struct session *s;
enum msgtype msgtype;
const char *cmd = args_get(args, 'E');
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
if (self->entry == &cmd_suspend_client_entry) {
server_client_suspend(c);
return (CMD_RETURN_NORMAL);
msgtype = MSG_DETACH;
if (args_has(args, 's')) {
- s = item->state.sflag.s;
+ s = item->source.s;
+ if (s == NULL)
+ return (CMD_RETURN_NORMAL);
TAILQ_FOREACH(cloop, &clients, entry) {
if (cloop->session == s) {
if (cmd != NULL)
-/* $OpenBSD: cmd-display-message.c,v 1.40 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-display-message.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.usage = "[-p] [-c target-client] [-F format] "
CMD_TARGET_PANE_USAGE " [message]",
- .cflag = CMD_CLIENT_CANFAIL,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_display_message_exec
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
- struct window_pane *wp = item->state.tflag.wp;
+ struct client *c;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
+ struct window_pane *wp = item->target.wp;
const char *template;
char *msg;
struct format_tree *ft;
cmdq_error(item, "only one of -F or argument must be given");
return (CMD_RETURN_ERROR);
}
+ c = cmd_find_client(item, args_get(args, 'c'), 1);
template = args_get(args, 'F');
if (args->argc != 0)
-/* $OpenBSD: cmd-display-panes.c,v 1.18 2017/03/09 17:06:35 nicm Exp $ */
+/* $OpenBSD: cmd-display-panes.c,v 1.19 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "t:", 0, 1 },
.usage = CMD_TARGET_CLIENT_USAGE,
- .tflag = CMD_CLIENT,
-
.flags = CMD_AFTERHOOK,
.exec = cmd_display_panes_exec
};
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
+ struct client *c;
+
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
if (c->identify_callback != NULL)
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: cmd-find-window.c,v 1.40 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-find-window.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "F:CNt:T", 1, 4 },
.usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_find_window_exec
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
- struct client *c = item->state.c;
+ struct client *c = cmd_find_client(item, NULL, 1);
struct window_choose_data *cdata;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl, *wm;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl, *wm;
struct cmd_find_window_list find_list;
struct cmd_find_window_data *find_data;
struct cmd_find_window_data *find_data1;
-/* $OpenBSD: cmd-find.c,v 1.50 2017/04/21 22:23:24 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.51 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicholas.marriott@gmail.com>
const char *session, *window, *pane;
int window_only = 0, pane_only = 0;
+ /* Can fail flag implies quiet. */
+ if (flags & CMD_FIND_CANFAIL)
+ flags |= CMD_FIND_QUIET;
+
/* Log the arguments. */
if (target == NULL)
log_debug("%s: target none, type %d", __func__, type);
log_debug("%s: error", __func__);
free(copy);
+ if (flags & CMD_FIND_CANFAIL)
+ return (0);
return (-1);
found:
-/* $OpenBSD: cmd-if-shell.c,v 1.54 2017/04/22 06:27:15 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.55 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
"[command]",
- .tflag = CMD_PANE_CANFAIL,
+ .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
.flags = 0,
.exec = cmd_if_shell_exec
char *shellcmd, *cmd, *cause;
struct cmd_list *cmdlist;
struct cmdq_item *new_item;
- struct client *c = item->state.c;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
- struct window_pane *wp = item->state.tflag.wp;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
+ struct window_pane *wp = item->target.wp;
const char *cwd;
if (item->client != NULL && item->client->session == NULL)
-/* $OpenBSD: cmd-join-pane.c,v 1.31 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-join-pane.c,v 1.32 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2011 George Nachman <tmux@georgester.com>
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
- .sflag = CMD_PANE_MARKED,
- .tflag = CMD_PANE,
+ .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_join_pane_exec
.args = { "bdhvp:l:s:t:", 0, 0 },
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
- .sflag = CMD_PANE,
- .tflag = CMD_PANE,
+ .source = { 's', CMD_FIND_PANE, 0 },
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_join_pane_exec
else
not_same_window = 0;
- dst_s = item->state.tflag.s;
- dst_wl = item->state.tflag.wl;
- dst_wp = item->state.tflag.wp;
+ dst_s = item->target.s;
+ dst_wl = item->target.wl;
+ dst_wp = item->target.wp;
dst_w = dst_wl->window;
dst_idx = dst_wl->idx;
server_unzoom_window(dst_w);
- src_wl = item->state.sflag.wl;
- src_wp = item->state.sflag.wp;
+ src_wl = item->source.wl;
+ src_wp = item->source.wp;
src_w = src_wl->window;
server_unzoom_window(src_w);
-/* $OpenBSD: cmd-kill-pane.c,v 1.24 2017/03/16 20:05:14 nicm Exp $ */
+/* $OpenBSD: cmd-kill-pane.c,v 1.25 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_kill_pane_exec
static enum cmd_retval
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
{
- struct winlink *wl = item->state.tflag.wl;
- struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp;
+ struct winlink *wl = item->target.wl;
+ struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
server_unzoom_window(wl->window);
-/* $OpenBSD: cmd-kill-session.c,v 1.22 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-kill-session.c,v 1.23 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "aCt:", 0, 0 },
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_kill_session_exec
struct session *s, *sloop, *stmp;
struct winlink *wl;
- s = item->state.tflag.s;
+ s = item->target.s;
if (args_has(args, 'C')) {
RB_FOREACH(wl, winlinks, &s->windows) {
-/* $OpenBSD: cmd-kill-window.c,v 1.23 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-kill-window.c,v 1.24 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_kill_window_exec
.args = { "kt:", 0, 0 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_kill_window_exec
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct winlink *wl = item->state.tflag.wl, *wl2, *wl3;
+ struct winlink *wl = item->target.wl, *wl2, *wl3;
struct window *w = wl->window;
- struct session *s = item->state.tflag.s;
+ struct session *s = item->target.s;
if (self->entry == &cmd_unlink_window_entry) {
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
-/* $OpenBSD: cmd-list-clients.c,v 1.32 2017/04/05 10:49:46 nicm Exp $ */
+/* $OpenBSD: cmd-list-clients.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "F:t:", 0, 0 },
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_READONLY|CMD_AFTERHOOK,
.exec = cmd_list_clients_exec
char *line;
if (args_has(args, 't'))
- s = item->state.tflag.s;
+ s = item->target.s;
else
s = NULL;
-/* $OpenBSD: cmd-list-panes.c,v 1.31 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-list-panes.c,v 1.32 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "asF:t:", 0, 0 },
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_list_panes_exec
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
if (args_has(args, 'a'))
cmd_list_panes_server(self, item);
-/* $OpenBSD: cmd-list-windows.c,v 1.41 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-list-windows.c,v 1.42 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "F:at:", 0, 0 },
.usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_list_windows_exec
if (args_has(args, 'a'))
cmd_list_windows_server(self, item);
else
- cmd_list_windows_session(self, item->state.tflag.s, item, 0);
+ cmd_list_windows_session(self, item->target.s, item, 0);
return (CMD_RETURN_NORMAL);
}
-/* $OpenBSD: cmd-lock-server.c,v 1.25 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-lock-server.c,v 1.26 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_lock_server_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_CLIENT_USAGE,
- .tflag = CMD_CLIENT,
-
.flags = CMD_AFTERHOOK,
.exec = cmd_lock_server_exec
};
static enum cmd_retval
-cmd_lock_server_exec(struct cmd *self, __unused struct cmdq_item *item)
+cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
{
+ struct args *args = self->args;
+ struct client *c;
+
if (self->entry == &cmd_lock_server_entry)
server_lock();
else if (self->entry == &cmd_lock_session_entry)
- server_lock_session(item->state.tflag.s);
- else
- server_lock_client(item->state.c);
-
+ server_lock_session(item->target.s);
+ else {
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+ server_lock_client(c);
+ }
recalculate_sizes();
return (CMD_RETURN_NORMAL);
-/* $OpenBSD: cmd-move-window.c,v 1.28 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-move-window.c,v 1.29 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "adkrs:t:", 0, 0 },
.usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
- .sflag = CMD_WINDOW,
- .tflag = CMD_MOVEW_R,
+ .source = { 's', CMD_FIND_WINDOW, 0 },
+ /* -t is special */
.flags = 0,
.exec = cmd_move_window_exec
.args = { "adks:t:", 0, 0 },
.usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
- .sflag = CMD_WINDOW,
- .tflag = CMD_WINDOW_INDEX,
+ .source = { 's', CMD_FIND_WINDOW, 0 },
+ /* -t is special */
.flags = 0,
.exec = cmd_move_window_exec
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct session *src = item->state.sflag.s;
- struct session *dst = item->state.tflag.s;
- struct winlink *wl = item->state.sflag.wl;
+ const char *tflag = args_get(args, 't');
+ struct session *src;
+ struct session *dst;
+ struct winlink *wl;
char *cause;
- int idx = item->state.tflag.idx, kflag, dflag, sflag;
+ int idx, kflag, dflag, sflag;
if (args_has(args, 'r')) {
- session_renumber_windows(dst);
+ if (cmd_find_target(&item->target, item, tflag,
+ CMD_FIND_SESSION, CMD_FIND_QUIET) != 0)
+ return (CMD_RETURN_ERROR);
+
+ session_renumber_windows(item->target.s);
recalculate_sizes();
+ server_status_session(item->target.s);
return (CMD_RETURN_NORMAL);
}
+ if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW,
+ CMD_FIND_WINDOW_INDEX) != 0)
+ return (CMD_RETURN_ERROR);
+ src = item->source.s;
+ dst = item->target.s;
+ wl = item->source.wl;
+ idx = item->target.idx;
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
-/* $OpenBSD: cmd-new-session.c,v 1.104 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.105 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
"[-y height] [command]",
- .tflag = CMD_SESSION_CANFAIL,
+ .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_STARTSERVER,
.exec = cmd_new_session_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_new_session_exec
* have already been prepared, copy this
* session into its tflag so it can be used.
*/
- cmd_find_from_session(&item->state.tflag, as);
+ cmd_find_from_session(&item->target, as);
return (cmd_attach_session(item,
- args_has(args, 'D'), 0, NULL,
- args_has(args, 'E')));
+ args_get(args, 't'), args_has(args, 'D'),
+ 0, NULL, args_has(args, 'E')));
}
cmdq_error(item, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
/* Is this going to be part of a session group? */
group = args_get(args, 't');
if (group != NULL) {
- groupwith = item->state.tflag.s;
+ groupwith = item->target.s;
if (groupwith == NULL) {
if (!session_check_name(group)) {
cmdq_error(item, "bad group name: %s", group);
-/* $OpenBSD: cmd-new-window.c,v 1.69 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.70 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
- .tflag = CMD_WINDOW_INDEX,
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
.flags = 0,
.exec = cmd_new_window_exec
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
- struct client *c = item->state.c;
- int idx = item->state.tflag.idx;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ int idx = item->target.idx;
const char *cmd, *path, *template, *cwd, *to_free;
char **argv, *cause, *cp;
int argc, detached;
-/* $OpenBSD: cmd-paste-buffer.c,v 1.37 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-paste-buffer.c,v 1.38 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_paste_buffer_exec
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct window_pane *wp = item->state.tflag.wp;
+ struct window_pane *wp = item->target.wp;
struct paste_buffer *pb;
const char *sepstr, *bufname, *bufdata, *bufend, *line;
size_t seplen, bufsize;
-/* $OpenBSD: cmd-pipe-pane.c,v 1.40 2017/02/03 11:57:27 nicm Exp $ */
+/* $OpenBSD: cmd-pipe-pane.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "ot:", 0, 1 },
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_pipe_pane_exec
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
- struct window_pane *wp = item->state.tflag.wp;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct window_pane *wp = item->target.wp;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
char *cmd;
int old_fd, pipe_fd[2], null_fd;
struct format_tree *ft;
-/* $OpenBSD: cmd-queue.c,v 1.53 2017/04/21 22:23:24 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.54 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
return (first);
}
+/* Fill in flag for a command. */
+static enum cmd_retval
+cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
+ const struct cmd_entry_flag *flag)
+{
+ const char *value;
+
+ if (flag->flag == 0) {
+ cmd_find_clear_state(fs, 0);
+ return (CMD_RETURN_NORMAL);
+ }
+
+ value = args_get(item->cmd->args, flag->flag);
+ if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
+ cmd_find_clear_state(fs, 0);
+ return (CMD_RETURN_ERROR);
+ }
+ return (CMD_RETURN_NORMAL);
+}
+
/* Fire command on command queue. */
static enum cmd_retval
cmdq_fire_command(struct cmdq_item *item)
{
struct client *c = item->client;
struct cmd *cmd = item->cmd;
+ const struct cmd_entry *entry = cmd->entry;
enum cmd_retval retval;
- const char *name;
struct cmd_find_state *fsp, fs;
int flags;
if (item->client == NULL)
item->client = cmd_find_client(item, NULL, 1);
-
- if (cmd_prepare_state(cmd, item) != 0) {
- retval = CMD_RETURN_ERROR;
+ retval = cmdq_find_flag(item, &item->source, &entry->source);
+ if (retval == CMD_RETURN_ERROR)
+ goto out;
+ retval = cmdq_find_flag(item, &item->target, &entry->target);
+ if (retval == CMD_RETURN_ERROR)
goto out;
- }
- retval = cmd->entry->exec(cmd, item);
+ retval = entry->exec(cmd, item);
if (retval == CMD_RETURN_ERROR)
goto out;
- if (cmd->entry->flags & CMD_AFTERHOOK) {
- name = cmd->entry->name;
- if (cmd_find_valid_state(&item->state.tflag))
- fsp = &item->state.tflag;
+ if (entry->flags & CMD_AFTERHOOK) {
+ if (cmd_find_valid_state(&item->target))
+ fsp = &item->target;
else if (cmd_find_valid_state(&item->shared->current))
fsp = &item->shared->current;
else if (cmd_find_from_client(&fs, item->client) == 0)
fsp = &fs;
else
goto out;
- hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
+ hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
}
out:
-/* $OpenBSD: cmd-refresh-client.c,v 1.23 2017/01/10 19:45:55 nicm Exp $ */
+/* $OpenBSD: cmd-refresh-client.c,v 1.24 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "C:St:", 0, 0 },
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
- .tflag = CMD_CLIENT,
-
.flags = CMD_AFTERHOOK,
.exec = cmd_refresh_client_exec
};
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
+ struct client *c;
const char *size;
u_int w, h;
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
if (args_has(args, 'C')) {
if ((size = args_get(args, 'C')) == NULL) {
cmdq_error(item, "missing size");
-/* $OpenBSD: cmd-rename-session.c,v 1.25 2016/11/16 11:41:17 nicm Exp $ */
+/* $OpenBSD: cmd-rename-session.c,v 1.26 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_SESSION_USAGE " new-name",
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_rename_session_exec
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct session *s = item->state.tflag.s;
+ struct session *s = item->target.s;
const char *newname;
newname = args->argv[0];
-/* $OpenBSD: cmd-rename-window.c,v 1.19 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-rename-window.c,v 1.20 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "t:", 1, 1 },
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_rename_window_exec
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
window_set_name(wl->window, args->argv[0]);
options_set_number(wl->window->options, "automatic-rename", 0);
-/* $OpenBSD: cmd-resize-pane.c,v 1.29 2017/04/21 14:01:19 nicm Exp $ */
+/* $OpenBSD: cmd-resize-pane.c,v 1.30 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
"[adjustment]",
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_resize_pane_exec
{
struct args *args = self->args;
struct cmdq_shared *shared = item->shared;
- struct window_pane *wp = item->state.tflag.wp;
- struct winlink *wl = item->state.tflag.wl;
+ struct window_pane *wp = item->target.wp;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct client *c = item->client;
- struct session *s = item->state.tflag.s;
+ struct session *s = item->target.s;
const char *errstr;
char *cause;
u_int adjust;
-/* $OpenBSD: cmd-respawn-pane.c,v 1.23 2017/03/09 17:02:38 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-pane.c,v 1.24 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_respawn_pane_exec
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
- struct window_pane *wp = item->state.tflag.wp;
- struct session *s = item->state.tflag.s;
+ struct window_pane *wp = item->target.wp;
+ struct session *s = item->target.s;
struct environ *env;
const char *path;
char *cause;
-/* $OpenBSD: cmd-respawn-window.c,v 1.33 2017/03/09 17:02:38 nicm Exp $ */
+/* $OpenBSD: cmd-respawn-window.c,v 1.34 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "kt:", 0, -1 },
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_respawn_window_exec
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp;
struct environ *env;
-/* $OpenBSD: cmd-rotate-window.c,v 1.22 2016/11/14 16:27:12 nicm Exp $ */
+/* $OpenBSD: cmd-rotate-window.c,v 1.23 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "Dt:U", 0, 0 },
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_rotate_window_exec
static enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
{
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
struct window_pane *wp, *wp2;
struct layout_cell *lc;
-/* $OpenBSD: cmd-run-shell.c,v 1.48 2017/04/21 20:26:34 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.49 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
.args = { "bt:", 1, 1 },
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
- .tflag = CMD_PANE_CANFAIL,
+ .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
.flags = 0,
.exec = cmd_run_shell_exec
{
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
- struct client *c = item->state.c;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
- struct window_pane *wp = item->state.tflag.wp;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
+ struct window_pane *wp = item->target.wp;
const char *cwd;
if (item->client != NULL && item->client->session == NULL)
-/* $OpenBSD: cmd-select-layout.c,v 1.32 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-select-layout.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "nopt:", 0, 1 },
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
struct window *w;
const char *layoutname;
char *oldlayout;
-/* $OpenBSD: cmd-select-pane.c,v 1.37 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-select-pane.c,v 1.38 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "DdegLlMmP:Rt:U", 0, 0 },
.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_select_pane_exec
.args = { "det:", 0, 0 },
.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_select_pane_exec
{
struct args *args = self->args;
struct cmd_find_state *current = &item->shared->current;
- struct winlink *wl = item->state.tflag.wl;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
- struct session *s = item->state.tflag.s;
- struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
+ struct session *s = item->target.s;
+ struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
const char *style;
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
-/* $OpenBSD: cmd-select-window.c,v 1.19 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-select-window.c,v 1.20 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "lnpTt:", 0, 0 },
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
- .tflag = CMD_WINDOW,
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_select_window_exec
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
.args = { "at:", 0, 0 },
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
.args = { "t:", 0, 0 },
.usage = CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = 0,
.exec = cmd_select_window_exec
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct cmd_find_state *current = &item->shared->current;
- struct winlink *wl = item->state.tflag.wl;
- struct session *s = item->state.tflag.s;
+ struct winlink *wl = item->target.wl;
+ struct session *s = item->target.s;
int next, previous, last, activity;
next = self->entry == &cmd_next_window_entry;
-/* $OpenBSD: cmd-send-keys.c,v 1.38 2017/04/21 14:01:19 nicm Exp $ */
+/* $OpenBSD: cmd-send-keys.c,v 1.39 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "lXRMN:t:", 0, -1 },
.usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_send_keys_exec
.args = { "2t:", 0, 0 },
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_send_keys_exec
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
- struct window_pane *wp = item->state.tflag.wp;
- struct session *s = item->state.tflag.s;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct window_pane *wp = item->target.wp;
+ struct session *s = item->target.s;
struct mouse_event *m = &item->shared->mouse;
struct utf8_data *ud, *uc;
wchar_t wc;
-/* $OpenBSD: cmd-set-environment.c,v 1.21 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-set-environment.c,v 1.22 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "grt:u", 1, 2 },
.usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
- .tflag = CMD_SESSION_CANFAIL,
+ .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_environment_exec
if (args_has(self->args, 'g'))
env = global_environ;
else {
- if (item->state.tflag.s == NULL) {
+ if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
- env = item->state.tflag.s->environ;
+ env = item->target.s->environ;
}
if (args_has(self->args, 'u')) {
-/* $OpenBSD: cmd-set-hook.c,v 1.10 2017/01/15 22:00:56 nicm Exp $ */
+/* $OpenBSD: cmd-set-hook.c,v 1.11 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
.args = { "gt:u", 1, 2 },
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
- .tflag = CMD_SESSION_CANFAIL,
+ .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_hook_exec
.args = { "gt:", 0, 1 },
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
- .tflag = CMD_SESSION,
+ .target = { 't', CMD_FIND_SESSION, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_hook_exec
if (args_has(args, 'g'))
hooks = global_hooks;
else {
- if (item->state.tflag.s == NULL) {
+ if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
- hooks = item->state.tflag.s->hooks;
+ hooks = item->target.s->hooks;
}
if (self->entry == &cmd_show_hooks_entry) {
-/* $OpenBSD: cmd-set-option.c,v 1.113 2017/04/22 06:13:30 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.114 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "agoqst:uw", 1, 2 },
.usage = "[-agosquw] [-t target-window] option [value]",
- .tflag = CMD_WINDOW_CANFAIL,
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
.args = { "agoqt:u", 1, 2 },
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
- .tflag = CMD_WINDOW_CANFAIL,
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
{
struct args *args = self->args;
int append = args_has(args, 'a');
- struct cmd_find_state *fs = &item->state.tflag;
+ struct cmd_find_state *fs = &item->target;
struct session *s = fs->s;
struct winlink *wl = fs->wl;
struct window *w;
-/* $OpenBSD: cmd-show-environment.c,v 1.22 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-show-environment.c,v 1.23 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "gst:", 0, 1 },
.usage = "[-gs] " CMD_TARGET_SESSION_USAGE " [name]",
- .tflag = CMD_SESSION_CANFAIL,
+ .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_environment_exec
const char *target;
if ((target = args_get(args, 't')) != NULL) {
- if (item->state.tflag.s == NULL) {
+ if (item->target.s == NULL) {
cmdq_error(item, "no such session: %s", target);
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'g'))
env = global_environ;
else {
- if (item->state.tflag.s == NULL) {
+ if (item->target.s == NULL) {
target = args_get(args, 't');
if (target != NULL)
cmdq_error(item, "no such session: %s", target);
cmdq_error(item, "no current session");
return (CMD_RETURN_ERROR);
}
- env = item->state.tflag.s->environ;
+ env = item->target.s->environ;
}
if (args->argc != 0) {
-/* $OpenBSD: cmd-show-messages.c,v 1.26 2017/04/20 09:20:22 nicm Exp $ */
+/* $OpenBSD: cmd-show-messages.c,v 1.27 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "JTt:", 0, 0 },
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
- .tflag = CMD_CLIENT,
-
.flags = CMD_AFTERHOOK,
.exec = cmd_show_messages_exec
};
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct client *c = item->state.c;
+ struct client *c;
struct message_entry *msg;
char *tim;
int done, blank;
+ if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
done = blank = 0;
if (args_has(args, 'T')) {
blank = cmd_show_messages_terminals(item, blank);
-/* $OpenBSD: cmd-show-options.c,v 1.40 2017/01/30 21:41:17 nicm Exp $ */
+/* $OpenBSD: cmd-show-options.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "gqst:vw", 0, 1 },
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
- .tflag = CMD_WINDOW_CANFAIL,
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_options_exec
.args = { "gvt:", 0, 1 },
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
- .tflag = CMD_WINDOW_CANFAIL,
+ .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_show_options_exec
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct cmd_find_state *fs = &item->state.tflag;
+ struct cmd_find_state *fs = &item->target;
struct options *oo;
enum options_table_scope scope;
char *cause;
-/* $OpenBSD: cmd-split-window.c,v 1.82 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.83 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-bdfhvP] [-c start-directory] [-F format] "
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
- .tflag = CMD_PANE,
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_split_window_exec
{
struct cmd_find_state *current = &item->shared->current;
struct args *args = self->args;
- struct client *c = item->state.c;
- struct session *s = item->state.tflag.s;
- struct winlink *wl = item->state.tflag.wl;
+ struct client *c = cmd_find_client(item, NULL, 1);
+ struct session *s = item->target.s;
+ struct winlink *wl = item->target.wl;
struct window *w = wl->window;
- struct window_pane *wp = item->state.tflag.wp, *new_wp = NULL;
+ struct window_pane *wp = item->target.wp, *new_wp = NULL;
struct environ *env;
const char *cmd, *path, *shell, *template, *cwd, *to_free;
char **argv, *cause, *new_cause, *cp;
-/* $OpenBSD: cmd-swap-pane.c,v 1.30 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd-swap-pane.c,v 1.31 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "dDs:t:U", 0, 0 },
.usage = "[-dDU] " CMD_SRCDST_PANE_USAGE,
- .sflag = CMD_PANE_MARKED,
- .tflag = CMD_PANE,
+ .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_swap_pane_exec
struct layout_cell *src_lc, *dst_lc;
u_int sx, sy, xoff, yoff;
- dst_w = item->state.tflag.wl->window;
- dst_wp = item->state.tflag.wp;
- src_w = item->state.sflag.wl->window;
- src_wp = item->state.sflag.wp;
+ dst_w = item->target.wl->window;
+ dst_wp = item->target.wp;
+ src_w = item->source.wl->window;
+ src_wp = item->source.wp;
server_unzoom_window(dst_w);
if (args_has(self->args, 'D')) {
-/* $OpenBSD: cmd-swap-window.c,v 1.22 2017/02/09 15:04:53 nicm Exp $ */
+/* $OpenBSD: cmd-swap-window.c,v 1.23 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.args = { "ds:t:", 0, 0 },
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
- .sflag = CMD_WINDOW_MARKED,
- .tflag = CMD_WINDOW,
+ .source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
+ .target = { 't', CMD_FIND_WINDOW, 0 },
.flags = 0,
.exec = cmd_swap_window_exec
struct winlink *wl_src, *wl_dst;
struct window *w_src, *w_dst;
- wl_src = item->state.sflag.wl;
- src = item->state.sflag.s;
+ wl_src = item->source.wl;
+ src = item->source.s;
sg_src = session_group_contains(src);
- wl_dst = item->state.tflag.wl;
- dst = item->state.tflag.s;
+ wl_dst = item->target.wl;
+ dst = item->target.s;
sg_dst = session_group_contains(dst);
if (src != dst && sg_src != NULL && sg_dst != NULL &&
-/* $OpenBSD: cmd-switch-client.c,v 1.50 2017/04/22 08:56:24 nicm Exp $ */
+/* $OpenBSD: cmd-switch-client.c,v 1.51 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.usage = "[-Elnpr] [-c target-client] [-t target-session] "
"[-T key-table]",
- .cflag = CMD_CLIENT,
- .tflag = CMD_SESSION_WITHPANE,
+ /* -t is special */
.flags = CMD_READONLY,
.exec = cmd_switch_client_exec
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
- struct cmd_state *state = &item->state;
- struct client *c = state->c;
- struct session *s = item->state.tflag.s;
+ const char *tflag = args_get(args, 't');
+ enum cmd_find_type type;
+ int flags;
+ struct client *c;
+ struct session *s;
+ struct winlink *wl;
struct window_pane *wp;
const char *tablename;
struct key_table *table;
+ if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
+ if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
+ type = CMD_FIND_PANE;
+ flags = 0;
+ } else {
+ type = CMD_FIND_SESSION;
+ flags = CMD_FIND_PREFER_UNATTACHED;
+ }
+ if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
+ return (CMD_RETURN_ERROR);
+ s = item->target.s;
+ wl = item->target.wl;
+ wp = item->target.wp;
+
if (args_has(args, 'r'))
c->flags ^= CLIENT_READONLY;
} else {
if (item->client == NULL)
return (CMD_RETURN_NORMAL);
- if (state->tflag.wl != NULL) {
- wp = state->tflag.wp;
+ if (wl != NULL) {
if (wp != NULL)
window_set_active_pane(wp->window, wp);
- session_set_current(s, state->tflag.wl);
+ session_set_current(s, wl);
cmd_find_from_session(&item->shared->current, s);
}
}
-/* $OpenBSD: cmd.c,v 1.137 2017/04/21 20:26:34 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.138 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
return (NULL);
}
-static int
-cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
- struct cmdq_item *item)
-{
- int targetflags, error;
- struct cmd_find_state *fs = NULL;
-
- if (flag == CMD_NONE ||
- flag == CMD_CLIENT ||
- flag == CMD_CLIENT_CANFAIL)
- return (0);
-
- if (c == 't')
- fs = &item->state.tflag;
- else if (c == 's')
- fs = &item->state.sflag;
-
- if (flag == CMD_SESSION_WITHPANE) {
- if (target != NULL && target[strcspn(target, ":.")] != '\0')
- flag = CMD_PANE;
- else
- flag = CMD_SESSION_PREFERUNATTACHED;
- }
-
- targetflags = 0;
- switch (flag) {
- case CMD_SESSION:
- case CMD_SESSION_CANFAIL:
- case CMD_SESSION_PREFERUNATTACHED:
- case CMD_SESSION_WITHPANE:
- if (flag == CMD_SESSION_CANFAIL)
- targetflags |= CMD_FIND_QUIET;
- if (flag == CMD_SESSION_PREFERUNATTACHED)
- targetflags |= CMD_FIND_PREFER_UNATTACHED;
- break;
- case CMD_MOVEW_R:
- flag = CMD_WINDOW_INDEX;
- /* FALLTHROUGH */
- case CMD_WINDOW:
- case CMD_WINDOW_CANFAIL:
- case CMD_WINDOW_MARKED:
- case CMD_WINDOW_INDEX:
- if (flag == CMD_WINDOW_CANFAIL)
- targetflags |= CMD_FIND_QUIET;
- if (flag == CMD_WINDOW_MARKED)
- targetflags |= CMD_FIND_DEFAULT_MARKED;
- if (flag == CMD_WINDOW_INDEX)
- targetflags |= CMD_FIND_WINDOW_INDEX;
- break;
- case CMD_PANE:
- case CMD_PANE_CANFAIL:
- case CMD_PANE_MARKED:
- if (flag == CMD_PANE_CANFAIL)
- targetflags |= CMD_FIND_QUIET;
- if (flag == CMD_PANE_MARKED)
- targetflags |= CMD_FIND_DEFAULT_MARKED;
- break;
- default:
- fatalx("unknown %cflag %d", c, flag);
- }
- log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
-
- switch (flag) {
- case CMD_NONE:
- case CMD_CLIENT:
- case CMD_CLIENT_CANFAIL:
- return (0);
- case CMD_SESSION:
- case CMD_SESSION_CANFAIL:
- case CMD_SESSION_PREFERUNATTACHED:
- case CMD_SESSION_WITHPANE:
- error = cmd_find_target(fs, item, target, CMD_FIND_SESSION,
- targetflags);
- if (error != 0)
- goto error;
- break;
- case CMD_MOVEW_R:
- error = cmd_find_target(fs, item, target, CMD_FIND_SESSION,
- CMD_FIND_QUIET);
- if (error == 0)
- break;
- /* FALLTHROUGH */
- case CMD_WINDOW:
- case CMD_WINDOW_CANFAIL:
- case CMD_WINDOW_MARKED:
- case CMD_WINDOW_INDEX:
- error = cmd_find_target(fs, item, target, CMD_FIND_WINDOW,
- targetflags);
- if (error != 0)
- goto error;
- break;
- case CMD_PANE:
- case CMD_PANE_CANFAIL:
- case CMD_PANE_MARKED:
- error = cmd_find_target(fs, item, target, CMD_FIND_PANE,
- targetflags);
- if (error != 0)
- goto error;
- break;
- default:
- fatalx("unknown %cflag %d", c, flag);
- }
- return (0);
-
-error:
- if (~targetflags & CMD_FIND_QUIET)
- return (-1);
- cmd_find_clear_state(fs, 0);
- return (0);
-}
-
-int
-cmd_prepare_state(struct cmd *cmd, struct cmdq_item *item)
-{
- const struct cmd_entry *entry = cmd->entry;
- struct cmd_state *state = &item->state;
- char *tmp;
- enum cmd_entry_flag flag;
- const char *s;
- int error;
-
- tmp = cmd_print(cmd);
- log_debug("preparing state for %s (client %p)", tmp, item->client);
- free(tmp);
-
- state->c = NULL;
- cmd_find_clear_state(&state->tflag, 0);
- cmd_find_clear_state(&state->sflag, 0);
-
- flag = cmd->entry->cflag;
- if (flag == CMD_NONE) {
- flag = cmd->entry->tflag;
- if (flag == CMD_CLIENT || flag == CMD_CLIENT_CANFAIL)
- s = args_get(cmd->args, 't');
- else
- s = NULL;
- } else
- s = args_get(cmd->args, 'c');
- switch (flag) {
- case CMD_CLIENT:
- state->c = cmd_find_client(item, s, 0);
- if (state->c == NULL)
- return (-1);
- break;
- default:
- state->c = cmd_find_client(item, s, 1);
- break;
- }
- log_debug("using client %p", state->c);
-
- s = args_get(cmd->args, 't');
- log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
-
- error = cmd_prepare_state_flag('t', s, entry->tflag, item);
- if (error != 0)
- return (error);
-
- s = args_get(cmd->args, 's');
- log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
-
- error = cmd_prepare_state_flag('s', s, entry->sflag, item);
- if (error != 0)
- return (error);
-
- if (!cmd_find_empty_state(&state->tflag) &&
- !cmd_find_valid_state(&state->tflag))
- fatalx("invalid -t state");
- if (!cmd_find_empty_state(&state->sflag) &&
- !cmd_find_valid_state(&state->sflag))
- fatalx("invalid -s state");
-
- return (0);
-}
-
char *
cmd_print(struct cmd *cmd)
{
-/* $OpenBSD: tmux.h,v 1.750 2017/04/21 20:26:34 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.751 2017/04/22 10:22:39 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
#define CMD_FIND_DEFAULT_MARKED 0x8
#define CMD_FIND_EXACT_SESSION 0x10
#define CMD_FIND_EXACT_WINDOW 0x20
-
-/* Context for command being executed. */
-struct cmd_state {
- struct client *c;
- struct cmd_find_state tflag;
- struct cmd_find_state sflag;
-};
+#define CMD_FIND_CANFAIL 0x40
/* Command and list of commands. */
struct cmd {
#define CMDQ_NOHOOKS 0x4
struct cmdq_shared *shared;
+ struct cmd_find_state source;
+ struct cmd_find_state target;
+
struct cmd_list *cmdlist;
struct cmd *cmd;
cmdq_cb cb;
void *data;
- struct cmd_state state;
-
TAILQ_ENTRY(cmdq_item) entry;
};
TAILQ_HEAD(cmdq_list, cmdq_item);
-/* Command -c, -t or -s flags. */
-enum cmd_entry_flag {
- CMD_NONE,
-
- CMD_CLIENT,
- CMD_CLIENT_CANFAIL,
-
- CMD_SESSION,
- CMD_SESSION_CANFAIL,
- CMD_SESSION_PREFERUNATTACHED,
- CMD_SESSION_WITHPANE, /* implies PREFERUNATTACHED */
-
- CMD_WINDOW,
- CMD_WINDOW_CANFAIL,
- CMD_WINDOW_MARKED,
- CMD_WINDOW_INDEX,
-
- CMD_PANE,
- CMD_PANE_CANFAIL,
- CMD_PANE_MARKED,
-
- CMD_MOVEW_R,
+/* Command definition flag. */
+struct cmd_entry_flag {
+ char flag;
+ enum cmd_find_type type;
+ int flags;
};
/* Command definition. */
} args;
const char *usage;
- enum cmd_entry_flag tflag;
- enum cmd_entry_flag sflag;
- enum cmd_entry_flag cflag;
+ struct cmd_entry_flag source;
+ struct cmd_entry_flag target;
#define CMD_STARTSERVER 0x1
#define CMD_READONLY 0x2
#define CMD_AFTERHOOK 0x4
int flags;
- enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
+ enum cmd_retval (*exec)(struct cmd *, struct cmdq_item *);
};
/* Client connection. */
void cmd_free_argv(int, char **);
char *cmd_stringify_argv(int, char **);
struct cmd *cmd_parse(int, char **, const char *, u_int, char **);
-int cmd_prepare_state(struct cmd *, struct cmdq_item *);
char *cmd_print(struct cmd *);
int cmd_mouse_at(struct window_pane *, struct mouse_event *,
u_int *, u_int *, int);
extern const struct cmd_entry *cmd_table[];
/* cmd-attach-session.c */
-enum cmd_retval cmd_attach_session(struct cmdq_item *, int, int, const char *,
- int);
+enum cmd_retval cmd_attach_session(struct cmdq_item *, const char *, int, int,
+ const char *, int);
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);