summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-12-13 17:55:15 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-12-13 17:55:15 +0000
commite910c0c0443b8d4be9918d9c6aef5cea12ee8bbc (patch)
tree6fd5042058b96a5cac2109d095c70b0bc85a303a /usr.bin
parentc011496814a44e41197a9b46f1b6d7c588bd463f (diff)
Use struct cmd_find_state directly and remove cmd_state_flag, also
change so that winlink is set even if an index is too.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-find.c22
-rw-r--r--usr.bin/tmux/cmd-new-window.c9
-rw-r--r--usr.bin/tmux/cmd.c88
-rw-r--r--usr.bin/tmux/tmux.h63
4 files changed, 76 insertions, 106 deletions
diff --git a/usr.bin/tmux/cmd-find.c b/usr.bin/tmux/cmd-find.c
index f7d7a3a42f4..cc1891eca68 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.20 2015/12/13 16:44:35 nicm Exp $ */
+/* $OpenBSD: cmd-find.c,v 1.21 2015/12/13 17:55:14 nicm Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -467,11 +467,10 @@ cmd_find_get_window(struct cmd_find_state *fs, const char *window)
/* Otherwise try as a session itself. */
if (cmd_find_get_session(fs, window) == 0) {
- if (~fs->flags & CMD_FIND_WINDOW_INDEX) {
- fs->wl = fs->s->curw;
- fs->w = fs->wl->window;
+ fs->wl = fs->s->curw;
+ fs->w = fs->wl->window;
+ if (~fs->flags & CMD_FIND_WINDOW_INDEX)
fs->idx = fs->wl->idx;
- }
return (0);
}
@@ -493,6 +492,13 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
log_debug("%s: %s", __func__, window);
exact = (fs->flags & CMD_FIND_EXACT_WINDOW);
+ /*
+ * Start with the current window as the default. So if only an index is
+ * found, the window will be the current.
+ */
+ fs->wl = fs->s->curw;
+ fs->w = fs->wl->window;
+
/* Check for window ids starting with @. */
if (*window == '@') {
fs->w = window_find_by_id_str(window);
@@ -976,8 +982,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq,
/* This will fill in winlink and window. */
if (cmd_find_get_window_with_session(fs, window) != 0)
goto no_window;
- if (~flags & CMD_FIND_WINDOW_INDEX)
- fs->wp = fs->wl->window->active;
+ fs->wp = fs->wl->window->active;
goto found;
}
@@ -1017,8 +1022,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq,
/* This will fill in session, winlink and window. */
if (cmd_find_get_window(fs, window) != 0)
goto no_window;
- if (~flags & CMD_FIND_WINDOW_INDEX)
- fs->wp = fs->wl->window->active;
+ fs->wp = fs->wl->window->active;
goto found;
}
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index 579c8e9f44c..38f55307793 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.55 2015/12/13 14:32:38 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.56 2015/12/13 17:55:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,12 +39,7 @@ const struct cmd_entry cmd_new_window_entry = {
"ac:dF:kn:Pt:", 0, -1,
"[-adkP] [-c start-directory] [-F format] [-n window-name] "
CMD_TARGET_WINDOW_USAGE " [command]",
- /*
- * Using PREP_CANFAIL here ensures that the wl is filled in
- * regardless; making PREP_INDEX the thing we want -t to be used for
- * in the specific case.
- */
- CMD_INDEX_T|CMD_CANFAIL,
+ CMD_INDEX_T,
cmd_new_window_exec
};
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 1edfc4f4b89..e34e8a37585 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.111 2015/12/13 16:44:35 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.112 2015/12/13 17:55:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -430,7 +430,7 @@ static int
cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
{
struct cmd_state *state = &cmdq->state;
- struct cmd_state_flag *statef = NULL;
+ struct cmd_find_state *fsf = NULL;
const char *flag;
int flags = cmd->entry->flags, everything = 0;
int allflags = 0, targetflags, error;
@@ -438,14 +438,13 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
struct window *w;
struct winlink *wl;
struct window_pane *wp;
- struct cmd_find_state fs;
/* Set up state for either -t or -s. */
if (c == 't') {
- statef = &cmdq->state.tflag;
+ fsf = &cmdq->state.tflag;
allflags = CMD_ALL_T;
} else if (c == 's') {
- statef = &cmdq->state.sflag;
+ fsf = &cmdq->state.sflag;
allflags = CMD_ALL_S;
}
@@ -480,25 +479,21 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
case CMD_SESSION_T|CMD_PANE_T:
case CMD_SESSION_S|CMD_PANE_S:
if (flag != NULL && flag[strcspn(flag, ":.")] != '\0') {
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE,
targetflags);
if (error != 0)
return (-1);
- statef->s = fs.s;
- statef->wl = fs.wl;
- statef->wp = fs.wp;
} else {
- error = cmd_find_target(&fs, cmdq, flag,
+ error = cmd_find_target(fsf, cmdq, flag,
CMD_FIND_SESSION, targetflags);
if (error != 0)
return (-1);
- statef->s = fs.s;
if (flag == NULL) {
- statef->wl = statef->s->curw;
- statef->wp = statef->s->curw->window->active;
+ fsf->wl = fsf->s->curw;
+ fsf->wp = fsf->s->curw->window->active;
} else {
- s = statef->s;
+ s = fsf->s;
if ((w = window_find_by_id_str(flag)) != NULL)
wp = w->active;
else {
@@ -508,34 +503,29 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
}
wl = winlink_find_by_window(&s->windows, w);
if (wl != NULL) {
- statef->wl = wl;
- statef->wp = wp;
+ fsf->wl = wl;
+ fsf->wp = wp;
}
}
}
break;
case CMD_MOVEW_R|CMD_INDEX_T:
case CMD_MOVEW_R|CMD_INDEX_S:
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_SESSION,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_SESSION,
targetflags);
- if (error == 0)
- statef->s = fs.s;
- else {
- error = cmd_find_target(&fs, cmdq, flag,
+ if (error != 0) {
+ error = cmd_find_target(fsf, cmdq, flag,
CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX);
if (error != 0)
return (-1);
- statef->s = fs.s;
- statef->idx = fs.idx;
}
break;
case CMD_SESSION_T:
case CMD_SESSION_S:
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_SESSION,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_SESSION,
targetflags);
if (error != 0)
return (-1);
- statef->s = fs.s;
break;
case CMD_WINDOW_MARKED_T:
case CMD_WINDOW_MARKED_S:
@@ -543,12 +533,10 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
/* FALLTHROUGH */
case CMD_WINDOW_T:
case CMD_WINDOW_S:
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW,
targetflags);
if (error != 0)
return (-1);
- statef->s = fs.s;
- statef->wl = fs.wl;
break;
case CMD_PANE_MARKED_T:
case CMD_PANE_MARKED_S:
@@ -556,22 +544,17 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
/* FALLTHROUGH */
case CMD_PANE_T:
case CMD_PANE_S:
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE,
targetflags);
if (error != 0)
return (-1);
- statef->s = fs.s;
- statef->wl = fs.wl;
- statef->wp = fs.wp;
break;
case CMD_INDEX_T:
case CMD_INDEX_S:
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW,
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW,
CMD_FIND_WINDOW_INDEX);
if (error != 0)
return (-1);
- statef->s = fs.s;
- statef->idx = fs.idx;
break;
default:
fatalx("too many -%c for %s", c, cmd->entry->name);
@@ -586,36 +569,31 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
return (0);
complete_everything:
- if (statef->s == NULL) {
+ if (fsf->s == NULL) {
if (state->c != NULL)
- statef->s = state->c->session;
- if (statef->s == NULL) {
- error = cmd_find_target(&fs, cmdq, NULL,
+ fsf->s = state->c->session;
+ if (fsf->s == NULL) {
+ error = cmd_find_target(fsf, cmdq, NULL,
CMD_FIND_SESSION, CMD_FIND_QUIET);
- if (error == 0)
- statef->s = fs.s;
+ if (error != 0)
+ fsf->s = NULL;
}
- if (statef->s == NULL) {
+ if (fsf->s == NULL) {
if (flags & CMD_CANFAIL)
return (0);
cmdq_error(cmdq, "no current session");
return (-1);
}
}
- if (statef->wl == NULL) {
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW, 0);
- if (error != 0) {
- statef->s = fs.s;
- statef->wl = fs.wl;
- }
+ if (fsf->wl == NULL) {
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_WINDOW, 0);
+ if (error != 0)
+ return (-1);
}
- if (statef->wp == NULL) {
- error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE, 0);
- if (error != 0) {
- statef->s = fs.s;
- statef->wl = fs.wl;
- statef->wp = fs.wp;
- }
+ if (fsf->wp == NULL) {
+ error = cmd_find_target(fsf, cmdq, flag, CMD_FIND_PANE, 0);
+ if (error != 0)
+ return (-1);
}
return (0);
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 5487b61073d..f8edb5547b4 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.605 2015/12/13 16:44:35 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.606 2015/12/13 17:55:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1293,18 +1293,37 @@ struct args {
char **argv;
};
-/* Context for a command about to be executed. */
-struct cmd_state_flag {
- struct session *s;
- struct winlink *wl;
- struct window_pane *wp;
- int idx;
+/* Command find structures. */
+enum cmd_find_type {
+ CMD_FIND_PANE,
+ CMD_FIND_WINDOW,
+ CMD_FIND_SESSION,
+};
+struct cmd_find_state {
+ struct cmd_q *cmdq;
+ int flags;
+ struct cmd_find_state *current;
+ struct session *s;
+ struct winlink *wl;
+ struct window *w;
+ struct window_pane *wp;
+ int idx;
};
+
+/* Command find flags. */
+#define CMD_FIND_PREFER_UNATTACHED 0x1
+#define CMD_FIND_QUIET 0x2
+#define CMD_FIND_WINDOW_INDEX 0x4
+#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_state_flag tflag;
- struct cmd_state_flag sflag;
+ struct cmd_find_state tflag;
+ struct cmd_find_state sflag;
};
/* Command and list of commands. */
@@ -1407,32 +1426,6 @@ struct cmd_entry {
#define CMD_ALL_S (CMD_SESSION_S|CMD_WINDOW_S|CMD_PANE_S|CMD_INDEX_S| \
CMD_PANE_MARKED_S|CMD_WINDOW_MARKED_S)
-/* Command find structures. */
-enum cmd_find_type {
- CMD_FIND_PANE,
- CMD_FIND_WINDOW,
- CMD_FIND_SESSION,
-};
-struct cmd_find_state {
- struct cmd_q *cmdq;
- int flags;
- struct cmd_find_state *current;
-
- struct session *s;
- struct winlink *wl;
- struct window *w;
- struct window_pane *wp;
- int idx;
-};
-
-/* Command fine flags. */
-#define CMD_FIND_PREFER_UNATTACHED 0x1
-#define CMD_FIND_QUIET 0x2
-#define CMD_FIND_WINDOW_INDEX 0x4
-#define CMD_FIND_DEFAULT_MARKED 0x8
-#define CMD_FIND_EXACT_SESSION 0x10
-#define CMD_FIND_EXACT_WINDOW 0x20
-
/* Key binding and key table. */
struct key_binding {
key_code key;