mirror of
https://github.com/tmux/tmux.git
synced 2025-01-15 05:09:04 +00:00
Remove the cmd_find_{session,window,pane,index} functions (which are
just wrappers around cmd_find_target) and just use cmd_find_target directly.
This commit is contained in:
parent
9d191a6093
commit
ff599f4004
149
cmd-find.c
149
cmd-find.c
@ -27,31 +27,6 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct session *cmd_find_try_TMUX(struct client *, struct window *);
|
struct session *cmd_find_try_TMUX(struct client *, struct window *);
|
||||||
int cmd_find_client_better(struct client *, struct client *);
|
int cmd_find_client_better(struct client *, struct client *);
|
||||||
struct client *cmd_find_best_client(struct client **, u_int);
|
struct client *cmd_find_best_client(struct client **, u_int);
|
||||||
@ -78,9 +53,6 @@ int cmd_find_get_pane_with_window(struct cmd_find_state *, const char *);
|
|||||||
void cmd_find_clear_state(struct cmd_find_state *, struct cmd_q *, int);
|
void cmd_find_clear_state(struct cmd_find_state *, struct cmd_q *, int);
|
||||||
void cmd_find_log_state(const char *, struct cmd_find_state *);
|
void cmd_find_log_state(const char *, struct cmd_find_state *);
|
||||||
|
|
||||||
struct cmd_find_state *cmd_find_target(struct cmd_q *, const char *,
|
|
||||||
enum cmd_find_type, int);
|
|
||||||
|
|
||||||
const char *cmd_find_session_table[][2] = {
|
const char *cmd_find_session_table[][2] = {
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
@ -1112,106 +1084,6 @@ cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
|
|||||||
log_debug("%s: idx=none", prefix);
|
log_debug("%s: idx=none", prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the current session. */
|
|
||||||
struct session *
|
|
||||||
cmd_find_current(struct cmd_q *cmdq)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
int flags = CMD_FIND_QUIET;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, NULL, CMD_FIND_SESSION, flags);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
return (fs->s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target session or report an error and return NULL. */
|
|
||||||
struct session *
|
|
||||||
cmd_find_session(struct cmd_q *cmdq, const char *target, int prefer_unattached)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
if (prefer_unattached)
|
|
||||||
flags |= CMD_FIND_PREFER_UNATTACHED;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_SESSION, flags);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
return (fs->s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target window or report an error and return NULL. */
|
|
||||||
struct winlink *
|
|
||||||
cmd_find_window(struct cmd_q *cmdq, const char *target, struct session **sp)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_WINDOW, 0);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
*sp = fs->s;
|
|
||||||
return (fs->wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target window, defaulting to marked rather than current. */
|
|
||||||
struct winlink *
|
|
||||||
cmd_find_window_marked(struct cmd_q *cmdq, const char *target,
|
|
||||||
struct session **sp)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
int flags = CMD_FIND_DEFAULT_MARKED;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_WINDOW, flags);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
*sp = fs->s;
|
|
||||||
return (fs->wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target pane and report an error and return NULL. */
|
|
||||||
struct winlink *
|
|
||||||
cmd_find_pane(struct cmd_q *cmdq, const char *target, struct session **sp,
|
|
||||||
struct window_pane **wpp)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_PANE, 0);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
*sp = fs->s;
|
|
||||||
if (wpp != NULL)
|
|
||||||
*wpp = fs->wp;
|
|
||||||
return (fs->wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target pane, defaulting to marked rather than current. */
|
|
||||||
struct winlink *
|
|
||||||
cmd_find_pane_marked(struct cmd_q *cmdq, const char *target,
|
|
||||||
struct session **sp, struct window_pane **wpp)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
int flags = CMD_FIND_DEFAULT_MARKED;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_PANE, flags);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (NULL);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
*sp = fs->s;
|
|
||||||
if (wpp != NULL)
|
|
||||||
*wpp = fs->wp;
|
|
||||||
return (fs->wl);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the target client or report an error and return NULL. */
|
/* Find the target client or report an error and return NULL. */
|
||||||
struct client *
|
struct client *
|
||||||
cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
|
cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
|
||||||
@ -1261,24 +1133,3 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
|
|||||||
log_debug("%s: target %s, return %p", __func__, target, c);
|
log_debug("%s: target %s, return %p", __func__, target, c);
|
||||||
return (c);
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Find the target session and window index, whether or not it exists in the
|
|
||||||
* session. Return -2 on error or -1 if no window index is specified. This is
|
|
||||||
* used when parsing an argument for a window target that may not exist (for
|
|
||||||
* example if it is going to be created).
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
cmd_find_index(struct cmd_q *cmdq, const char *target, struct session **sp)
|
|
||||||
{
|
|
||||||
struct cmd_find_state *fs;
|
|
||||||
int flags = CMD_FIND_WINDOW_INDEX;
|
|
||||||
|
|
||||||
fs = cmd_find_target(cmdq, target, CMD_FIND_WINDOW, flags);
|
|
||||||
if (fs == NULL)
|
|
||||||
return (-2);
|
|
||||||
|
|
||||||
if (sp != NULL)
|
|
||||||
*sp = fs->s;
|
|
||||||
return (fs->idx);
|
|
||||||
}
|
|
||||||
|
119
cmd.c
119
cmd.c
@ -433,13 +433,14 @@ 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;
|
int allflags = 0, targetflags;
|
||||||
int prefer = !!(flags & CMD_PREFERUNATTACHED);
|
|
||||||
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;
|
||||||
|
|
||||||
|
/* Set up state for either -t or -s. */
|
||||||
if (c == 't') {
|
if (c == 't') {
|
||||||
statef = &cmdq->state.tflag;
|
statef = &cmdq->state.tflag;
|
||||||
allflags = CMD_ALL_T;
|
allflags = CMD_ALL_T;
|
||||||
@ -469,26 +470,35 @@ cmd_set_state_flag(struct cmd *cmd, struct cmd_q *cmdq, char c)
|
|||||||
goto complete_everything;
|
goto complete_everything;
|
||||||
|
|
||||||
/* Fill in state using command (current or base) flags. */
|
/* Fill in state using command (current or base) flags. */
|
||||||
|
if (flags & CMD_PREFERUNATTACHED)
|
||||||
|
targetflags = CMD_FIND_PREFER_UNATTACHED;
|
||||||
|
else
|
||||||
|
targetflags = 0;
|
||||||
switch (cmd->entry->flags & allflags) {
|
switch (cmd->entry->flags & allflags) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
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') {
|
||||||
statef->wl = cmd_find_pane(cmdq, flag, &statef->s,
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE,
|
||||||
&statef->wp);
|
targetflags);
|
||||||
if (statef->wl == NULL)
|
if (fs == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
statef->wl = fs->wl;
|
||||||
|
statef->wp = fs->wp;
|
||||||
} else {
|
} else {
|
||||||
statef->s = cmd_find_session(cmdq, flag, prefer);
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION,
|
||||||
if (statef->s == NULL)
|
targetflags);
|
||||||
|
if (fs == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
|
||||||
s = statef->s;
|
|
||||||
if (flag == NULL) {
|
if (flag == NULL) {
|
||||||
statef->wl = s->curw;
|
statef->wl = statef->s->curw;
|
||||||
statef->wp = s->curw->window->active;
|
statef->wp = statef->s->curw->window->active;
|
||||||
} else {
|
} else {
|
||||||
|
s = statef->s;
|
||||||
if ((w = window_find_by_id_str(flag)) != NULL)
|
if ((w = window_find_by_id_str(flag)) != NULL)
|
||||||
wp = w->active;
|
wp = w->active;
|
||||||
else {
|
else {
|
||||||
@ -506,50 +516,58 @@ 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:
|
||||||
statef->s = cmd_find_session(cmdq, flag, prefer);
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION, targetflags);
|
||||||
if (statef->s == NULL) {
|
if (fs != NULL)
|
||||||
statef->idx = cmd_find_index(cmdq, flag, &statef->s);
|
statef->s = fs->s;
|
||||||
if (statef->idx == -2)
|
else {
|
||||||
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW,
|
||||||
|
CMD_FIND_WINDOW_INDEX);
|
||||||
|
if (fs == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
statef->idx = fs->idx;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_SESSION_T:
|
case CMD_SESSION_T:
|
||||||
case CMD_SESSION_S:
|
case CMD_SESSION_S:
|
||||||
statef->s = cmd_find_session(cmdq, flag, prefer);
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_SESSION, targetflags);
|
||||||
if (statef->s == NULL)
|
if (fs == NULL)
|
||||||
return (-1);
|
|
||||||
break;
|
|
||||||
case CMD_WINDOW_T:
|
|
||||||
case CMD_WINDOW_S:
|
|
||||||
statef->wl = cmd_find_window(cmdq, flag, &statef->s);
|
|
||||||
if (statef->wl == NULL)
|
|
||||||
return (-1);
|
return (-1);
|
||||||
|
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:
|
||||||
statef->wl = cmd_find_window_marked(cmdq, flag, &statef->s);
|
targetflags |= CMD_FIND_DEFAULT_MARKED;
|
||||||
if (statef->wl == NULL)
|
/* FALLTHROUGH */
|
||||||
return (-1);
|
case CMD_WINDOW_T:
|
||||||
break;
|
case CMD_WINDOW_S:
|
||||||
case CMD_PANE_T:
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, targetflags);
|
||||||
case CMD_PANE_S:
|
if (fs == NULL)
|
||||||
statef->wl = cmd_find_pane(cmdq, flag, &statef->s,
|
|
||||||
&statef->wp);
|
|
||||||
if (statef->wl == NULL)
|
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
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:
|
||||||
statef->wl = cmd_find_pane_marked(cmdq, flag, &statef->s,
|
targetflags |= CMD_FIND_DEFAULT_MARKED;
|
||||||
&statef->wp);
|
/* FALLTHROUGH */
|
||||||
if (statef->wl == NULL)
|
case CMD_PANE_T:
|
||||||
|
case CMD_PANE_S:
|
||||||
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE, targetflags);
|
||||||
|
if (fs == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
statef->wl = fs->wl;
|
||||||
|
statef->wp = fs->wp;
|
||||||
break;
|
break;
|
||||||
case CMD_INDEX_T:
|
case CMD_INDEX_T:
|
||||||
case CMD_INDEX_S:
|
case CMD_INDEX_S:
|
||||||
statef->idx = cmd_find_index(cmdq, flag, &statef->s);
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW,
|
||||||
if (statef->idx == -2)
|
CMD_FIND_WINDOW_INDEX);
|
||||||
|
if (fs == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
statef->s = fs->s;
|
||||||
|
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);
|
||||||
@ -567,21 +585,34 @@ complete_everything:
|
|||||||
if (statef->s == NULL) {
|
if (statef->s == NULL) {
|
||||||
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) {
|
||||||
statef->s = cmd_find_current(cmdq);
|
fs = cmd_find_target(cmdq, NULL, CMD_FIND_SESSION,
|
||||||
|
CMD_FIND_QUIET);
|
||||||
|
if (fs != NULL)
|
||||||
|
statef->s = fs->s;
|
||||||
|
}
|
||||||
if (statef->s == NULL) {
|
if (statef->s == NULL) {
|
||||||
if (flags & CMD_CANFAIL)
|
if (flags & CMD_CANFAIL)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
cmdq_error(cmdq, "no current session");
|
cmdq_error(cmdq, "no current session");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (statef->wl == NULL)
|
if (statef->wl == NULL) {
|
||||||
statef->wl = cmd_find_window(cmdq, flag, &statef->s);
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_WINDOW, 0);
|
||||||
if (statef->wp == NULL)
|
if (fs != NULL) {
|
||||||
statef->wl = cmd_find_pane(cmdq, flag, &statef->s, &statef->wp);
|
statef->s = fs->s;
|
||||||
|
statef->wl = fs->wl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (statef->wp == NULL) {
|
||||||
|
fs = cmd_find_target(cmdq, flag, CMD_FIND_PANE, 0);
|
||||||
|
if (fs != NULL) {
|
||||||
|
statef->s = fs->s;
|
||||||
|
statef->wl = fs->wl;
|
||||||
|
statef->wp = fs->wp;
|
||||||
|
}
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
tmux.h
40
tmux.h
@ -1407,6 +1407,32 @@ struct cmd_entry {
|
|||||||
#define CMD_ALL_S (CMD_SESSION_S|CMD_WINDOW_S|CMD_PANE_S|CMD_INDEX_S| \
|
#define CMD_ALL_S (CMD_SESSION_S|CMD_WINDOW_S|CMD_PANE_S|CMD_INDEX_S| \
|
||||||
CMD_PANE_MARKED_S|CMD_WINDOW_MARKED_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. */
|
/* Key binding and key table. */
|
||||||
struct key_binding {
|
struct key_binding {
|
||||||
key_code key;
|
key_code key;
|
||||||
@ -1734,19 +1760,9 @@ long long args_strtonum(struct args *, u_char, long long, long long,
|
|||||||
char **);
|
char **);
|
||||||
|
|
||||||
/* cmd-find.c */
|
/* cmd-find.c */
|
||||||
struct session *cmd_find_current(struct cmd_q *);
|
struct cmd_find_state *cmd_find_target(struct cmd_q *, const char *,
|
||||||
struct session *cmd_find_session(struct cmd_q *, const char *, int);
|
enum cmd_find_type, int);
|
||||||
struct winlink *cmd_find_window(struct cmd_q *, const char *,
|
|
||||||
struct session **);
|
|
||||||
struct winlink *cmd_find_window_marked(struct cmd_q *, const char *,
|
|
||||||
struct session **);
|
|
||||||
struct winlink *cmd_find_pane(struct cmd_q *, const char *, struct session **,
|
|
||||||
struct window_pane **);
|
|
||||||
struct winlink *cmd_find_pane_marked(struct cmd_q *, const char *,
|
|
||||||
struct session **, struct window_pane **);
|
|
||||||
struct client *cmd_find_client(struct cmd_q *, const char *, int);
|
struct client *cmd_find_client(struct cmd_q *, const char *, int);
|
||||||
int cmd_find_index(struct cmd_q *, const char *,
|
|
||||||
struct session **);
|
|
||||||
|
|
||||||
/* cmd.c */
|
/* cmd.c */
|
||||||
int cmd_pack_argv(int, char **, char *, size_t);
|
int cmd_pack_argv(int, char **, char *, size_t);
|
||||||
|
Loading…
Reference in New Issue
Block a user