Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2015-12-13 18:01:11 +00:00
commit d37a580085
4 changed files with 110 additions and 98 deletions

View File

@ -788,15 +788,18 @@ cmd_find_clear_state(struct cmd_find_state *fs, struct cmd_q *cmdq, int flags)
fs->idx = -1; fs->idx = -1;
} }
/* Split target into pieces and resolve for the given type. */ /*
struct cmd_find_state * * Split target into pieces and resolve for the given type. Fills in the given
cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type, * state. Returns 0 on success or -1 on error.
int flags) */
int
cmd_find_target(struct cmd_find_state *fs, struct cmd_q *cmdq,
const char *target, enum cmd_find_type type, int flags)
{ {
static struct cmd_find_state fs, current; struct cmd_find_state current;
struct mouse_event *m; struct mouse_event *m;
char *colon, *period, *copy = NULL; char *colon, *period, *copy = NULL;
const char *session, *window, *pane; const char *session, *window, *pane;
/* Log the arguments. */ /* Log the arguments. */
if (target == NULL) if (target == NULL)
@ -821,8 +824,8 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
} }
/* Clear new state. */ /* Clear new state. */
cmd_find_clear_state(&fs, cmdq, flags); cmd_find_clear_state(fs, cmdq, flags);
fs.current = &current; fs->current = &current;
/* An empty or NULL target is the current. */ /* An empty or NULL target is the current. */
if (target == NULL || *target == '\0') if (target == NULL || *target == '\0')
@ -833,20 +836,20 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
m = &cmdq->item->mouse; m = &cmdq->item->mouse;
switch (type) { switch (type) {
case CMD_FIND_PANE: case CMD_FIND_PANE:
fs.wp = cmd_mouse_pane(m, &fs.s, &fs.wl); fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
if (fs.wp != NULL) if (fs->wp != NULL)
fs.w = fs.wl->window; fs->w = fs->wl->window;
break; break;
case CMD_FIND_WINDOW: case CMD_FIND_WINDOW:
case CMD_FIND_SESSION: case CMD_FIND_SESSION:
fs.wl = cmd_mouse_window(m, &fs.s); fs->wl = cmd_mouse_window(m, &fs->s);
if (fs.wl != NULL) { if (fs->wl != NULL) {
fs.w = fs.wl->window; fs->w = fs->wl->window;
fs.wp = fs.w->active; fs->wp = fs->w->active;
} }
break; break;
} }
if (fs.wp == NULL) { if (fs->wp == NULL) {
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)
cmdq_error(cmdq, "no mouse target"); cmdq_error(cmdq, "no mouse target");
goto error; goto error;
@ -861,11 +864,11 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
cmdq_error(cmdq, "no marked target"); cmdq_error(cmdq, "no marked target");
goto error; goto error;
} }
fs.s = marked_session; fs->s = marked_session;
fs.wl = marked_winlink; fs->wl = marked_winlink;
fs.idx = fs.wl->idx; fs->idx = fs->wl->idx;
fs.w = fs.wl->window; fs->w = fs->wl->window;
fs.wp = marked_window_pane; fs->wp = marked_window_pane;
goto found; goto found;
} }
@ -918,11 +921,11 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
/* Set exact match flags. */ /* Set exact match flags. */
if (session != NULL && *session == '=') { if (session != NULL && *session == '=') {
session++; session++;
fs.flags |= CMD_FIND_EXACT_SESSION; fs->flags |= CMD_FIND_EXACT_SESSION;
} }
if (window != NULL && *window == '=') { if (window != NULL && *window == '=') {
window++; window++;
fs.flags |= CMD_FIND_EXACT_WINDOW; fs->flags |= CMD_FIND_EXACT_WINDOW;
} }
/* Empty is the same as NULL. */ /* Empty is the same as NULL. */
@ -955,32 +958,32 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
/* If the session isn't NULL, look it up. */ /* If the session isn't NULL, look it up. */
if (session != NULL) { if (session != NULL) {
/* This will fill in session. */ /* This will fill in session. */
if (cmd_find_get_session(&fs, session) != 0) if (cmd_find_get_session(fs, session) != 0)
goto no_session; goto no_session;
/* If window and pane are NULL, use that session's current. */ /* If window and pane are NULL, use that session's current. */
if (window == NULL && pane == NULL) { if (window == NULL && pane == NULL) {
fs.wl = fs.s->curw; fs->wl = fs->s->curw;
fs.idx = -1; fs->idx = -1;
fs.w = fs.wl->window; fs->w = fs->wl->window;
fs.wp = fs.w->active; fs->wp = fs->w->active;
goto found; goto found;
} }
/* If window is present but pane not, find window in session. */ /* If window is present but pane not, find window in session. */
if (window != NULL && pane == NULL) { if (window != NULL && pane == NULL) {
/* This will fill in winlink and window. */ /* This will fill in winlink and window. */
if (cmd_find_get_window_with_session(&fs, window) != 0) if (cmd_find_get_window_with_session(fs, window) != 0)
goto no_window; goto no_window;
if (~flags & CMD_FIND_WINDOW_INDEX) if (~flags & CMD_FIND_WINDOW_INDEX)
fs.wp = fs.wl->window->active; fs->wp = fs->wl->window->active;
goto found; goto found;
} }
/* If pane is present but window not, find pane. */ /* If pane is present but window not, find pane. */
if (window == NULL && pane != NULL) { if (window == NULL && pane != NULL) {
/* This will fill in winlink and window and pane. */ /* This will fill in winlink and window and pane. */
if (cmd_find_get_pane_with_session(&fs, pane) != 0) if (cmd_find_get_pane_with_session(fs, pane) != 0)
goto no_pane; goto no_pane;
goto found; goto found;
} }
@ -989,10 +992,10 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
* If window and pane are present, find both in session. This * If window and pane are present, find both in session. This
* will fill in winlink and window. * will fill in winlink and window.
*/ */
if (cmd_find_get_window_with_session(&fs, window) != 0) if (cmd_find_get_window_with_session(fs, window) != 0)
goto no_window; goto no_window;
/* This will fill in pane. */ /* This will fill in pane. */
if (cmd_find_get_pane_with_window(&fs, pane) != 0) if (cmd_find_get_pane_with_window(fs, pane) != 0)
goto no_pane; goto no_pane;
goto found; goto found;
} }
@ -1000,10 +1003,10 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
/* No session. If window and pane, try them. */ /* No session. If window and pane, try them. */
if (window != NULL && pane != NULL) { if (window != NULL && pane != NULL) {
/* This will fill in session, winlink and window. */ /* This will fill in session, winlink and window. */
if (cmd_find_get_window(&fs, window) != 0) if (cmd_find_get_window(fs, window) != 0)
goto no_window; goto no_window;
/* This will fill in pane. */ /* This will fill in pane. */
if (cmd_find_get_pane_with_window(&fs, pane) != 0) if (cmd_find_get_pane_with_window(fs, pane) != 0)
goto no_pane; goto no_pane;
goto found; goto found;
} }
@ -1011,38 +1014,41 @@ cmd_find_target(struct cmd_q *cmdq, const char *target, enum cmd_find_type type,
/* If just window is present, try it. */ /* If just window is present, try it. */
if (window != NULL && pane == NULL) { if (window != NULL && pane == NULL) {
/* This will fill in session, winlink and window. */ /* This will fill in session, winlink and window. */
if (cmd_find_get_window(&fs, window) != 0) if (cmd_find_get_window(fs, window) != 0)
goto no_window; goto no_window;
if (~flags & CMD_FIND_WINDOW_INDEX) if (~flags & CMD_FIND_WINDOW_INDEX)
fs.wp = fs.wl->window->active; fs->wp = fs->wl->window->active;
goto found; goto found;
} }
/* If just pane is present, try it. */ /* If just pane is present, try it. */
if (window == NULL && pane != NULL) { if (window == NULL && pane != NULL) {
/* This will fill in session, winlink, window and pane. */ /* This will fill in session, winlink, window and pane. */
if (cmd_find_get_pane(&fs, pane) != 0) if (cmd_find_get_pane(fs, pane) != 0)
goto no_pane; goto no_pane;
goto found; goto found;
} }
current: current:
/* None is the current session. */ /* Use the current session. */
free(copy);
if (flags & CMD_FIND_WINDOW_INDEX) if (flags & CMD_FIND_WINDOW_INDEX)
current.idx = -1; current.idx = -1;
cmd_find_log_state(__func__, &current); memcpy(fs, &current, sizeof *fs);
return (&current); goto found;
error: error:
free(copy); fs->current = NULL;
log_debug(" error"); log_debug(" error");
return (NULL);
free(copy);
return (-1);
found: found:
cmd_find_log_state(__func__, &fs); fs->current = NULL;
cmd_find_log_state(__func__, fs);
free(copy); free(copy);
return (&fs); return (0);
no_session: no_session:
if (~flags & CMD_FIND_QUIET) if (~flags & CMD_FIND_QUIET)

View File

@ -199,6 +199,8 @@ cmdq_continue_one(struct cmd_q *cmdq)
if (cmd_prepare_state(cmd, cmdq) != 0) if (cmd_prepare_state(cmd, cmdq) != 0)
goto error; goto error;
retval = cmd->entry->exec(cmd, cmdq); retval = cmd->entry->exec(cmd, cmdq);
if (retval == CMD_RETURN_ERROR)
goto error;
cmdq_guard(cmdq, "end", flags); cmdq_guard(cmdq, "end", flags);
return (retval); return (retval);

100
cmd.c
View File

@ -432,12 +432,12 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
struct cmd_state_flag *statef = NULL; struct cmd_state_flag *statef = NULL;
const char *flag; const char *flag;
int flags = cmd->entry->flags, everything = 0; int flags = cmd->entry->flags, everything = 0;
int allflags = 0, targetflags; int allflags = 0, targetflags, error;
struct session *s; struct session *s;
struct window *w; struct window *w;
struct winlink *wl; struct winlink *wl;
struct window_pane *wp; struct window_pane *wp;
struct cmd_find_state *fs; struct cmd_find_state fs;
/* Set up state for either -t or -s. */ /* Set up state for either -t or -s. */
if (c == 't') { if (c == 't') {
@ -479,19 +479,19 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
case CMD_SESSION_T|CMD_PANE_T: case CMD_SESSION_T|CMD_PANE_T:
case CMD_SESSION_S|CMD_PANE_S: case CMD_SESSION_S|CMD_PANE_S:
if (flag != NULL && flag[strcspn(flag, ":.")] != '\0') { if (flag != NULL && flag[strcspn(flag, ":.")] != '\0') {
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE, error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE,
targetflags); targetflags);
if (fs == NULL) if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
statef->wl = fs->wl; statef->wl = fs.wl;
statef->wp = fs->wp; statef->wp = fs.wp;
} else { } else {
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION, error = cmd_find_target(&fs, cmdq, flag,
targetflags); CMD_FIND_SESSION, targetflags);
if (fs == NULL) if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
if (flag == NULL) { if (flag == NULL) {
statef->wl = statef->s->curw; statef->wl = statef->s->curw;
@ -515,24 +515,26 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
break; break;
case CMD_MOVEW_R|CMD_INDEX_T: case CMD_MOVEW_R|CMD_INDEX_T:
case CMD_MOVEW_R|CMD_INDEX_S: case CMD_MOVEW_R|CMD_INDEX_S:
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION, targetflags); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_SESSION,
if (fs != NULL) targetflags);
statef->s = fs->s; if (error == 0)
statef->s = fs.s;
else { else {
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, error = cmd_find_target(&fs, cmdq, flag,
CMD_FIND_WINDOW_INDEX); CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX);
if (fs == NULL) if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
statef->idx = fs->idx; statef->idx = fs.idx;
} }
break; break;
case CMD_SESSION_T: case CMD_SESSION_T:
case CMD_SESSION_S: case CMD_SESSION_S:
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION, targetflags); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_SESSION,
if (fs == NULL) targetflags);
if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
break; break;
case CMD_WINDOW_MARKED_T: case CMD_WINDOW_MARKED_T:
case CMD_WINDOW_MARKED_S: case CMD_WINDOW_MARKED_S:
@ -540,11 +542,12 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
/* FALLTHROUGH */ /* FALLTHROUGH */
case CMD_WINDOW_T: case CMD_WINDOW_T:
case CMD_WINDOW_S: case CMD_WINDOW_S:
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, targetflags); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW,
if (fs == NULL) targetflags);
if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
statef->wl = fs->wl; statef->wl = fs.wl;
break; break;
case CMD_PANE_MARKED_T: case CMD_PANE_MARKED_T:
case CMD_PANE_MARKED_S: case CMD_PANE_MARKED_S:
@ -552,21 +555,22 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
/* FALLTHROUGH */ /* FALLTHROUGH */
case CMD_PANE_T: case CMD_PANE_T:
case CMD_PANE_S: case CMD_PANE_S:
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE, targetflags); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE,
if (fs == NULL) targetflags);
if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
statef->wl = fs->wl; statef->wl = fs.wl;
statef->wp = fs->wp; statef->wp = fs.wp;
break; break;
case CMD_INDEX_T: case CMD_INDEX_T:
case CMD_INDEX_S: case CMD_INDEX_S:
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW,
CMD_FIND_WINDOW_INDEX); CMD_FIND_WINDOW_INDEX);
if (fs == NULL) if (error != 0)
return (-1); return (-1);
statef->s = fs->s; statef->s = fs.s;
statef->idx = fs->idx; statef->idx = fs.idx;
break; break;
default: default:
fatalx("too many -%c for %s", c, cmd->entry->name); fatalx("too many -%c for %s", c, cmd->entry->name);
@ -585,10 +589,10 @@ complete_everything:
if (state->c != NULL) if (state->c != NULL)
statef->s = state->c->session; statef->s = state->c->session;
if (statef->s == NULL) { if (statef->s == NULL) {
fs = cmd_find_target(cmdq, NULL, CMD_FIND_SESSION, error = cmd_find_target(&fs, cmdq, NULL,
CMD_FIND_QUIET); CMD_FIND_SESSION, CMD_FIND_QUIET);
if (fs != NULL) if (error == 0)
statef->s = fs->s; statef->s = fs.s;
} }
if (statef->s == NULL) { if (statef->s == NULL) {
if (flags & CMD_CANFAIL) if (flags & CMD_CANFAIL)
@ -598,18 +602,18 @@ complete_everything:
} }
} }
if (statef->wl == NULL) { if (statef->wl == NULL) {
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, 0); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_WINDOW, 0);
if (fs != NULL) { if (error != 0) {
statef->s = fs->s; statef->s = fs.s;
statef->wl = fs->wl; statef->wl = fs.wl;
} }
} }
if (statef->wp == NULL) { if (statef->wp == NULL) {
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE, 0); error = cmd_find_target(&fs, cmdq, flag, CMD_FIND_PANE, 0);
if (fs != NULL) { if (error != 0) {
statef->s = fs->s; statef->s = fs.s;
statef->wl = fs->wl; statef->wl = fs.wl;
statef->wp = fs->wp; statef->wp = fs.wp;
} }
} }
return (0); return (0);

4
tmux.h
View File

@ -1762,8 +1762,8 @@ long long args_strtonum(struct args *, u_char, long long, long long,
char **); char **);
/* cmd-find.c */ /* cmd-find.c */
struct cmd_find_state *cmd_find_target(struct cmd_q *, const char *, int cmd_find_target(struct cmd_find_state *, struct cmd_q *,
enum cmd_find_type, int); const char *, enum cmd_find_type, int);
struct client *cmd_find_client(struct cmd_q *, const char *, int); struct client *cmd_find_client(struct cmd_q *, const char *, int);
/* cmd.c */ /* cmd.c */