From bf0d297eb5fd1d4558a97868432053598642156e Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 22 Apr 2017 10:22:39 +0000 Subject: [PATCH] Get rid of the extra layer of flags and cmd_prepare() and just store the CMD_FIND_* flags in the cmd_entry and call it for the command. Commands with special requirements call it themselves and update the target for hooks to use. --- usr.bin/tmux/cmd-attach-session.c | 34 ++++-- usr.bin/tmux/cmd-break-pane.c | 21 ++-- usr.bin/tmux/cmd-capture-pane.c | 8 +- usr.bin/tmux/cmd-choose-buffer.c | 8 +- usr.bin/tmux/cmd-choose-client.c | 8 +- usr.bin/tmux/cmd-choose-tree.c | 14 +-- usr.bin/tmux/cmd-command-prompt.c | 9 +- usr.bin/tmux/cmd-confirm-before.c | 9 +- usr.bin/tmux/cmd-copy-mode.c | 8 +- usr.bin/tmux/cmd-detach-client.c | 16 +-- usr.bin/tmux/cmd-display-message.c | 14 +-- usr.bin/tmux/cmd-display-panes.c | 9 +- usr.bin/tmux/cmd-find-window.c | 10 +- usr.bin/tmux/cmd-find.c | 8 +- usr.bin/tmux/cmd-if-shell.c | 12 +- usr.bin/tmux/cmd-join-pane.c | 20 ++-- usr.bin/tmux/cmd-kill-pane.c | 8 +- usr.bin/tmux/cmd-kill-session.c | 6 +- usr.bin/tmux/cmd-kill-window.c | 10 +- usr.bin/tmux/cmd-list-clients.c | 6 +- usr.bin/tmux/cmd-list-panes.c | 8 +- usr.bin/tmux/cmd-list-windows.c | 6 +- usr.bin/tmux/cmd-lock-server.c | 21 ++-- usr.bin/tmux/cmd-move-window.c | 33 ++++-- usr.bin/tmux/cmd-new-session.c | 14 +-- usr.bin/tmux/cmd-new-window.c | 12 +- usr.bin/tmux/cmd-paste-buffer.c | 6 +- usr.bin/tmux/cmd-pipe-pane.c | 12 +- usr.bin/tmux/cmd-queue.c | 44 +++++-- usr.bin/tmux/cmd-refresh-client.c | 9 +- usr.bin/tmux/cmd-rename-session.c | 6 +- usr.bin/tmux/cmd-rename-window.c | 6 +- usr.bin/tmux/cmd-resize-pane.c | 10 +- usr.bin/tmux/cmd-respawn-pane.c | 10 +- usr.bin/tmux/cmd-respawn-window.c | 8 +- usr.bin/tmux/cmd-rotate-window.c | 6 +- usr.bin/tmux/cmd-run-shell.c | 12 +- usr.bin/tmux/cmd-select-layout.c | 10 +- usr.bin/tmux/cmd-select-pane.c | 12 +- usr.bin/tmux/cmd-select-window.c | 14 +-- usr.bin/tmux/cmd-send-keys.c | 12 +- usr.bin/tmux/cmd-set-environment.c | 8 +- usr.bin/tmux/cmd-set-hook.c | 10 +- usr.bin/tmux/cmd-set-option.c | 8 +- usr.bin/tmux/cmd-show-environment.c | 10 +- usr.bin/tmux/cmd-show-messages.c | 9 +- usr.bin/tmux/cmd-show-options.c | 8 +- usr.bin/tmux/cmd-split-window.c | 12 +- usr.bin/tmux/cmd-swap-pane.c | 14 +-- usr.bin/tmux/cmd-swap-window.c | 14 +-- usr.bin/tmux/cmd-switch-client.c | 35 ++++-- usr.bin/tmux/cmd.c | 176 +--------------------------- usr.bin/tmux/tmux.h | 54 +++------ 53 files changed, 376 insertions(+), 491 deletions(-) diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 0ba69f49c65..896c00bfaa4 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $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 @@ -40,21 +40,23 @@ const struct cmd_entry cmd_attach_session_entry = { .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)) { @@ -70,6 +72,19 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, 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); @@ -150,6 +165,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item) { 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'))); } diff --git a/usr.bin/tmux/cmd-break-pane.c b/usr.bin/tmux/cmd-break-pane.c index 6b7d2780f0f..83b83004b6f 100644 --- a/usr.bin/tmux/cmd-break-pane.c +++ b/usr.bin/tmux/cmd-break-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -35,10 +35,11 @@ const struct cmd_entry cmd_break_pane_entry = { .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 @@ -49,14 +50,14 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c index 1ffee4f0ae9..ac66d2fa40a 100644 --- a/usr.bin/tmux/cmd-capture-pane.c +++ b/usr.bin/tmux/cmd-capture-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -43,7 +43,7 @@ const struct cmd_entry cmd_capture_pane_entry = { .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 @@ -56,7 +56,7 @@ const struct cmd_entry cmd_clear_history_entry = { .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 @@ -193,7 +193,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-choose-buffer.c b/usr.bin/tmux/cmd-choose-buffer.c index d8b20eadf98..9f1e9435682 100644 --- a/usr.bin/tmux/cmd-choose-buffer.c +++ b/usr.bin/tmux/cmd-choose-buffer.c @@ -1,4 +1,4 @@ -/* $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 @@ -40,7 +40,7 @@ const struct cmd_entry cmd_choose_buffer_entry = { .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 @@ -50,8 +50,8 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-choose-client.c b/usr.bin/tmux/cmd-choose-client.c index ddef66cf913..6cb91c03594 100644 --- a/usr.bin/tmux/cmd-choose-client.c +++ b/usr.bin/tmux/cmd-choose-client.c @@ -1,4 +1,4 @@ -/* $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 @@ -45,7 +45,7 @@ const struct cmd_entry cmd_choose_client_entry = { .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 @@ -59,10 +59,10 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index 28c1bc6f058..50f882b32bb 100644 --- a/usr.bin/tmux/cmd-choose-tree.c +++ b/usr.bin/tmux/cmd-choose-tree.c @@ -1,4 +1,4 @@ -/* $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 @@ -51,7 +51,7 @@ const struct cmd_entry cmd_choose_tree_entry = { .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 @@ -64,7 +64,7 @@ const struct cmd_entry cmd_choose_session_entry = { .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 @@ -77,7 +77,7 @@ const struct cmd_entry cmd_choose_window_entry = { .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 @@ -87,9 +87,9 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c index 99b274cb7a3..297fa742ec8 100644 --- a/usr.bin/tmux/cmd-command-prompt.c +++ b/usr.bin/tmux/cmd-command-prompt.c @@ -1,4 +1,4 @@ -/* $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 @@ -43,8 +43,6 @@ const struct cmd_entry cmd_command_prompt_entry = { .usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " "[template]", - .tflag = CMD_CLIENT, - .flags = 0, .exec = cmd_command_prompt_exec }; @@ -69,10 +67,13 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item) struct args *args = self->args; const char *inputs, *prompts; struct cmd_command_prompt_cdata *cdata; - struct client *c = 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); diff --git a/usr.bin/tmux/cmd-confirm-before.c b/usr.bin/tmux/cmd-confirm-before.c index cf683645bfb..e7884dae9a8 100644 --- a/usr.bin/tmux/cmd-confirm-before.c +++ b/usr.bin/tmux/cmd-confirm-before.c @@ -1,4 +1,4 @@ -/* $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 @@ -41,8 +41,6 @@ const struct cmd_entry cmd_confirm_before_entry = { .args = { "p:t:", 1, 1 }, .usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command", - .tflag = CMD_CLIENT, - .flags = 0, .exec = cmd_confirm_before_exec }; @@ -57,10 +55,13 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_confirm_before_data *cdata; - struct client *c = 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 { diff --git a/usr.bin/tmux/cmd-copy-mode.c b/usr.bin/tmux/cmd-copy-mode.c index dd0018378bb..ac1a8e78102 100644 --- a/usr.bin/tmux/cmd-copy-mode.c +++ b/usr.bin/tmux/cmd-copy-mode.c @@ -1,4 +1,4 @@ -/* $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 @@ -33,7 +33,7 @@ const struct cmd_entry cmd_copy_mode_entry = { .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 @@ -46,7 +46,7 @@ const struct cmd_entry cmd_clock_mode_entry = { .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 @@ -59,7 +59,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) 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) diff --git a/usr.bin/tmux/cmd-detach-client.c b/usr.bin/tmux/cmd-detach-client.c index 7db1d489b32..025050e5a75 100644 --- a/usr.bin/tmux/cmd-detach-client.c +++ b/usr.bin/tmux/cmd-detach-client.c @@ -1,4 +1,4 @@ -/* $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 @@ -37,8 +37,7 @@ const struct cmd_entry cmd_detach_client_entry = { .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 @@ -51,8 +50,6 @@ const struct cmd_entry cmd_suspend_client_entry = { .args = { "t:", 0, 0 }, .usage = CMD_TARGET_CLIENT_USAGE, - .tflag = CMD_CLIENT, - .flags = 0, .exec = cmd_detach_client_exec }; @@ -61,11 +58,14 @@ static enum cmd_retval 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); @@ -77,7 +77,9 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item) 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) diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c index 3e0c369100b..afb3a4826c5 100644 --- a/usr.bin/tmux/cmd-display-message.c +++ b/usr.bin/tmux/cmd-display-message.c @@ -1,4 +1,4 @@ -/* $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 @@ -43,8 +43,7 @@ const struct cmd_entry cmd_display_message_entry = { .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 @@ -54,10 +53,10 @@ static enum cmd_retval 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; @@ -66,6 +65,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) 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) diff --git a/usr.bin/tmux/cmd-display-panes.c b/usr.bin/tmux/cmd-display-panes.c index b5bdffb97c7..d40a1a0366c 100644 --- a/usr.bin/tmux/cmd-display-panes.c +++ b/usr.bin/tmux/cmd-display-panes.c @@ -1,4 +1,4 @@ -/* $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 @@ -40,8 +40,6 @@ const struct cmd_entry cmd_display_panes_entry = { .args = { "t:", 0, 1 }, .usage = CMD_TARGET_CLIENT_USAGE, - .tflag = CMD_CLIENT, - .flags = CMD_AFTERHOOK, .exec = cmd_display_panes_exec }; @@ -50,7 +48,10 @@ static enum cmd_retval 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); diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c index 0ece6fd8dc3..a117b622042 100644 --- a/usr.bin/tmux/cmd-find-window.c +++ b/usr.bin/tmux/cmd-find-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -54,7 +54,7 @@ const struct cmd_entry cmd_find_window_entry = { .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 @@ -143,10 +143,10 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c index a10464c2cef..533ad7b9846 100644 --- a/usr.bin/tmux/cmd-find.c +++ b/usr.bin/tmux/cmd-find.c @@ -1,4 +1,4 @@ -/* $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 @@ -953,6 +953,10 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, 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); @@ -1190,6 +1194,8 @@ error: log_debug("%s: error", __func__); free(copy); + if (flags & CMD_FIND_CANFAIL) + return (0); return (-1); found: diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c index 1c5696dc726..52c0aefe34a 100644 --- a/usr.bin/tmux/cmd-if-shell.c +++ b/usr.bin/tmux/cmd-if-shell.c @@ -1,4 +1,4 @@ -/* $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 @@ -43,7 +43,7 @@ const struct cmd_entry cmd_if_shell_entry = { .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 @@ -70,10 +70,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) 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) diff --git a/usr.bin/tmux/cmd-join-pane.c b/usr.bin/tmux/cmd-join-pane.c index e1bcc330db4..af8c846cbaa 100644 --- a/usr.bin/tmux/cmd-join-pane.c +++ b/usr.bin/tmux/cmd-join-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -38,8 +38,8 @@ const struct cmd_entry cmd_join_pane_entry = { .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 @@ -52,8 +52,8 @@ const struct cmd_entry cmd_move_pane_entry = { .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 @@ -79,15 +79,15 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) 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); diff --git a/usr.bin/tmux/cmd-kill-pane.c b/usr.bin/tmux/cmd-kill-pane.c index 02e9f08fc98..c2bde0479fa 100644 --- a/usr.bin/tmux/cmd-kill-pane.c +++ b/usr.bin/tmux/cmd-kill-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -35,7 +35,7 @@ const struct cmd_entry cmd_kill_pane_entry = { .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 @@ -44,8 +44,8 @@ const struct cmd_entry cmd_kill_pane_entry = { 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); diff --git a/usr.bin/tmux/cmd-kill-session.c b/usr.bin/tmux/cmd-kill-session.c index 79c500a0cb6..47673625fda 100644 --- a/usr.bin/tmux/cmd-kill-session.c +++ b/usr.bin/tmux/cmd-kill-session.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_kill_session_entry = { .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 @@ -49,7 +49,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item) 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) { diff --git a/usr.bin/tmux/cmd-kill-window.c b/usr.bin/tmux/cmd-kill-window.c index 7a6c5b1738c..eea02f3f5f9 100644 --- a/usr.bin/tmux/cmd-kill-window.c +++ b/usr.bin/tmux/cmd-kill-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_window_entry = { .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 @@ -46,7 +46,7 @@ const struct cmd_entry cmd_unlink_window_entry = { .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 @@ -56,9 +56,9 @@ static enum cmd_retval 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)) { diff --git a/usr.bin/tmux/cmd-list-clients.c b/usr.bin/tmux/cmd-list-clients.c index 4ad5f926b1f..3d489a05b1e 100644 --- a/usr.bin/tmux/cmd-list-clients.c +++ b/usr.bin/tmux/cmd-list-clients.c @@ -1,4 +1,4 @@ -/* $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 @@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_clients_entry = { .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 @@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item) char *line; if (args_has(args, 't')) - s = item->state.tflag.s; + s = item->target.s; else s = NULL; diff --git a/usr.bin/tmux/cmd-list-panes.c b/usr.bin/tmux/cmd-list-panes.c index cf51396eab5..1f81dee1a9f 100644 --- a/usr.bin/tmux/cmd-list-panes.c +++ b/usr.bin/tmux/cmd-list-panes.c @@ -1,4 +1,4 @@ -/* $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 @@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_panes_entry = { .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 @@ -51,8 +51,8 @@ static enum cmd_retval 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); diff --git a/usr.bin/tmux/cmd-list-windows.c b/usr.bin/tmux/cmd-list-windows.c index 1daf04a65a5..fa4572a6321 100644 --- a/usr.bin/tmux/cmd-list-windows.c +++ b/usr.bin/tmux/cmd-list-windows.c @@ -1,4 +1,4 @@ -/* $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 @@ -52,7 +52,7 @@ const struct cmd_entry cmd_list_windows_entry = { .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 @@ -66,7 +66,7 @@ cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item) 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); } diff --git a/usr.bin/tmux/cmd-lock-server.c b/usr.bin/tmux/cmd-lock-server.c index 30969584bc5..bb91aa4b878 100644 --- a/usr.bin/tmux/cmd-lock-server.c +++ b/usr.bin/tmux/cmd-lock-server.c @@ -1,4 +1,4 @@ -/* $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 @@ -44,7 +44,7 @@ const struct cmd_entry cmd_lock_session_entry = { .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 @@ -57,22 +57,25 @@ const struct cmd_entry cmd_lock_client_entry = { .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); diff --git a/usr.bin/tmux/cmd-move-window.c b/usr.bin/tmux/cmd-move-window.c index e21020d511e..55bc32ddfdd 100644 --- a/usr.bin/tmux/cmd-move-window.c +++ b/usr.bin/tmux/cmd-move-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -35,8 +35,8 @@ const struct cmd_entry cmd_move_window_entry = { .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 @@ -49,8 +49,8 @@ const struct cmd_entry cmd_link_window_entry = { .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 @@ -60,18 +60,31 @@ static enum cmd_retval 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'); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index 4cc4eecf86e..502729d4d3e 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $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 @@ -44,7 +44,7 @@ const struct cmd_entry cmd_new_session_entry = { "[-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 @@ -57,7 +57,7 @@ const struct cmd_entry cmd_has_session_entry = { .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 @@ -108,10 +108,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) * 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); @@ -121,7 +121,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* 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); diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index 798aa5c1c03..4bdab690617 100644 --- a/usr.bin/tmux/cmd-new-window.c +++ b/usr.bin/tmux/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -42,7 +42,7 @@ const struct cmd_entry cmd_new_window_entry = { .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 @@ -53,10 +53,10 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c index 0e256108eca..f3fac0bc929 100644 --- a/usr.bin/tmux/cmd-paste-buffer.c +++ b/usr.bin/tmux/cmd-paste-buffer.c @@ -1,4 +1,4 @@ -/* $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 @@ -38,7 +38,7 @@ const struct cmd_entry cmd_paste_buffer_entry = { .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 @@ -48,7 +48,7 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-pipe-pane.c b/usr.bin/tmux/cmd-pipe-pane.c index 4eb6f567eb2..7ed9284ccd2 100644 --- a/usr.bin/tmux/cmd-pipe-pane.c +++ b/usr.bin/tmux/cmd-pipe-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -44,7 +44,7 @@ const struct cmd_entry cmd_pipe_pane_entry = { .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 @@ -54,10 +54,10 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index 639dbe688bc..0abda7b27d3 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $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 @@ -189,14 +189,34 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current, 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; @@ -205,27 +225,27 @@ cmdq_fire_command(struct cmdq_item *item) 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: diff --git a/usr.bin/tmux/cmd-refresh-client.c b/usr.bin/tmux/cmd-refresh-client.c index 371be312fc9..52d3dcb5d1f 100644 --- a/usr.bin/tmux/cmd-refresh-client.c +++ b/usr.bin/tmux/cmd-refresh-client.c @@ -1,4 +1,4 @@ -/* $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 @@ -34,8 +34,6 @@ const struct cmd_entry cmd_refresh_client_entry = { .args = { "C:St:", 0, 0 }, .usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE, - .tflag = CMD_CLIENT, - .flags = CMD_AFTERHOOK, .exec = cmd_refresh_client_exec }; @@ -44,10 +42,13 @@ static enum cmd_retval 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"); diff --git a/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c index 9d5a2eb360e..b5c3876b24d 100644 --- a/usr.bin/tmux/cmd-rename-session.c +++ b/usr.bin/tmux/cmd-rename-session.c @@ -1,4 +1,4 @@ -/* $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 @@ -37,7 +37,7 @@ const struct cmd_entry cmd_rename_session_entry = { .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 @@ -47,7 +47,7 @@ static enum cmd_retval 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]; diff --git a/usr.bin/tmux/cmd-rename-window.c b/usr.bin/tmux/cmd-rename-window.c index 6291564cd8c..52950012755 100644 --- a/usr.bin/tmux/cmd-rename-window.c +++ b/usr.bin/tmux/cmd-rename-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_rename_window_entry = { .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 @@ -46,7 +46,7 @@ static enum cmd_retval 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); diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c index 4dc020e49f4..f151a6e2242 100644 --- a/usr.bin/tmux/cmd-resize-pane.c +++ b/usr.bin/tmux/cmd-resize-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -39,7 +39,7 @@ const struct cmd_entry cmd_resize_pane_entry = { .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 @@ -50,11 +50,11 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index fb16ca41759..7dac2b9fdf7 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -37,7 +37,7 @@ const struct cmd_entry cmd_respawn_pane_entry = { .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 @@ -47,10 +47,10 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index 30aaf5e11c2..d6b3bba55b9 100644 --- a/usr.bin/tmux/cmd-respawn-window.c +++ b/usr.bin/tmux/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -37,7 +37,7 @@ const struct cmd_entry cmd_respawn_window_entry = { .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 @@ -47,8 +47,8 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-rotate-window.c b/usr.bin/tmux/cmd-rotate-window.c index 52fbbfe9561..82a3608e65c 100644 --- a/usr.bin/tmux/cmd-rotate-window.c +++ b/usr.bin/tmux/cmd-rotate-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -34,7 +34,7 @@ const struct cmd_entry cmd_rotate_window_entry = { .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 @@ -43,7 +43,7 @@ const struct cmd_entry cmd_rotate_window_entry = { 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; diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index c1624403509..c85220ce522 100644 --- a/usr.bin/tmux/cmd-run-shell.c +++ b/usr.bin/tmux/cmd-run-shell.c @@ -1,4 +1,4 @@ -/* $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 @@ -42,7 +42,7 @@ const struct cmd_entry cmd_run_shell_entry = { .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 @@ -86,10 +86,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) { 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) diff --git a/usr.bin/tmux/cmd-select-layout.c b/usr.bin/tmux/cmd-select-layout.c index 711fa5e9331..b2d572e442c 100644 --- a/usr.bin/tmux/cmd-select-layout.c +++ b/usr.bin/tmux/cmd-select-layout.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_layout_entry = { .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 @@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_layout_entry = { .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 @@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_layout_entry = { .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 @@ -72,7 +72,7 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c index cebf81f4c9e..d84c13a92a8 100644 --- a/usr.bin/tmux/cmd-select-pane.c +++ b/usr.bin/tmux/cmd-select-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_pane_entry = { .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 @@ -46,7 +46,7 @@ const struct cmd_entry cmd_last_pane_entry = { .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 @@ -57,10 +57,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) { 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')) { diff --git a/usr.bin/tmux/cmd-select-window.c b/usr.bin/tmux/cmd-select-window.c index 5d7d4296abe..cf42d063d1a 100644 --- a/usr.bin/tmux/cmd-select-window.c +++ b/usr.bin/tmux/cmd-select-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_window_entry = { .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 @@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_window_entry = { .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 @@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_window_entry = { .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 @@ -75,7 +75,7 @@ const struct cmd_entry cmd_last_window_entry = { .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 @@ -85,8 +85,8 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-send-keys.c b/usr.bin/tmux/cmd-send-keys.c index 75c6d379879..4b46c45e10c 100644 --- a/usr.bin/tmux/cmd-send-keys.c +++ b/usr.bin/tmux/cmd-send-keys.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_send_keys_entry = { .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 @@ -49,7 +49,7 @@ const struct cmd_entry cmd_send_prefix_entry = { .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 @@ -59,9 +59,9 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-set-environment.c b/usr.bin/tmux/cmd-set-environment.c index 0690384b8ba..400f37393c0 100644 --- a/usr.bin/tmux/cmd-set-environment.c +++ b/usr.bin/tmux/cmd-set-environment.c @@ -1,4 +1,4 @@ -/* $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 @@ -37,7 +37,7 @@ const struct cmd_entry cmd_set_environment_entry = { .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 @@ -68,7 +68,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item) 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); @@ -76,7 +76,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item) 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')) { diff --git a/usr.bin/tmux/cmd-set-hook.c b/usr.bin/tmux/cmd-set-hook.c index 87e1642a6a2..6d6ac127321 100644 --- a/usr.bin/tmux/cmd-set-hook.c +++ b/usr.bin/tmux/cmd-set-hook.c @@ -1,4 +1,4 @@ -/* $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 @@ -36,7 +36,7 @@ const struct cmd_entry cmd_set_hook_entry = { .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 @@ -49,7 +49,7 @@ const struct cmd_entry cmd_show_hooks_entry = { .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 @@ -68,7 +68,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item) 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); @@ -76,7 +76,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item) 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) { diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 02f8b2a6860..d51021430a7 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $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 @@ -45,7 +45,7 @@ const struct cmd_entry cmd_set_option_entry = { .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 @@ -58,7 +58,7 @@ const struct cmd_entry cmd_set_window_option_entry = { .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 @@ -69,7 +69,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-show-environment.c b/usr.bin/tmux/cmd-show-environment.c index 3429f7a3f86..50a53c946e6 100644 --- a/usr.bin/tmux/cmd-show-environment.c +++ b/usr.bin/tmux/cmd-show-environment.c @@ -1,4 +1,4 @@ -/* $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 @@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_environment_entry = { .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 @@ -97,7 +97,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) 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); } @@ -106,7 +106,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) 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); @@ -114,7 +114,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item) 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) { diff --git a/usr.bin/tmux/cmd-show-messages.c b/usr.bin/tmux/cmd-show-messages.c index 9c82675e201..64d481e8013 100644 --- a/usr.bin/tmux/cmd-show-messages.c +++ b/usr.bin/tmux/cmd-show-messages.c @@ -1,4 +1,4 @@ -/* $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 @@ -39,8 +39,6 @@ const struct cmd_entry cmd_show_messages_entry = { .args = { "JTt:", 0, 0 }, .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE, - .tflag = CMD_CLIENT, - .flags = CMD_AFTERHOOK, .exec = cmd_show_messages_exec }; @@ -92,11 +90,14 @@ static enum cmd_retval 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); diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c index 0832e970075..83c668b05d9 100644 --- a/usr.bin/tmux/cmd-show-options.c +++ b/usr.bin/tmux/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $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 @@ -42,7 +42,7 @@ const struct cmd_entry cmd_show_options_entry = { .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 @@ -55,7 +55,7 @@ const struct cmd_entry cmd_show_window_options_entry = { .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 @@ -65,7 +65,7 @@ static enum cmd_retval 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; diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 9a963db3b80..661fd0959c0 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -44,7 +44,7 @@ const struct cmd_entry cmd_split_window_entry = { .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 @@ -55,11 +55,11 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) { 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; diff --git a/usr.bin/tmux/cmd-swap-pane.c b/usr.bin/tmux/cmd-swap-pane.c index 805d306a643..9f6bde7a6de 100644 --- a/usr.bin/tmux/cmd-swap-pane.c +++ b/usr.bin/tmux/cmd-swap-pane.c @@ -1,4 +1,4 @@ -/* $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 @@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_pane_entry = { .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 @@ -50,10 +50,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) 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')) { diff --git a/usr.bin/tmux/cmd-swap-window.c b/usr.bin/tmux/cmd-swap-window.c index 97b19908b42..d7694c71fce 100644 --- a/usr.bin/tmux/cmd-swap-window.c +++ b/usr.bin/tmux/cmd-swap-window.c @@ -1,4 +1,4 @@ -/* $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 @@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_window_entry = { .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 @@ -50,12 +50,12 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item) 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 && diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index 4b5d48a52bc..ef7f2ce3226 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $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 @@ -38,8 +38,7 @@ const struct cmd_entry cmd_switch_client_entry = { .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 @@ -49,13 +48,32 @@ static enum cmd_retval 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; @@ -94,11 +112,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) } 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); } } diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index b2545bd2863..61e5569e7f7 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $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 @@ -448,180 +448,6 @@ usage: 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) { diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 9f6412bf54d..3c7903d57f1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $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 @@ -1162,13 +1162,7 @@ struct cmd_find_state { #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 { @@ -1237,40 +1231,24 @@ struct cmdq_item { #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. */ @@ -1285,16 +1263,15 @@ struct cmd_entry { } 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. */ @@ -1761,7 +1738,6 @@ char **cmd_copy_argv(int, char **); void cmd_free_argv(int, char **); char *cmd_stringify_argv(int, char **); struct cmd *cmd_parse(int, char **, const char *, u_int, char **); -int cmd_prepare_state(struct cmd *, struct cmdq_item *); char *cmd_print(struct cmd *); int cmd_mouse_at(struct window_pane *, struct mouse_event *, u_int *, u_int *, int); @@ -1772,8 +1748,8 @@ char *cmd_template_replace(const char *, const char *, int); extern const struct cmd_entry *cmd_table[]; /* cmd-attach-session.c */ -enum cmd_retval cmd_attach_session(struct 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 **); -- 2.20.1