version 1.7, 2015/05/07 11:42:56 |
version 1.8, 2015/06/04 11:43:51 |
|
|
#define CMD_FIND_PREFER_UNATTACHED 0x1 |
#define CMD_FIND_PREFER_UNATTACHED 0x1 |
#define CMD_FIND_QUIET 0x2 |
#define CMD_FIND_QUIET 0x2 |
#define CMD_FIND_WINDOW_INDEX 0x4 |
#define CMD_FIND_WINDOW_INDEX 0x4 |
|
#define CMD_FIND_DEFAULT_MARKED 0x8 |
|
|
enum cmd_find_type { |
enum cmd_find_type { |
CMD_FIND_PANE, |
CMD_FIND_PANE, |
|
|
|
|
/* Find current state. */ |
/* Find current state. */ |
cmd_find_clear_state(¤t, cmdq, flags); |
cmd_find_clear_state(¤t, cmdq, flags); |
if (cmd_find_current_session(¤t) != 0) { |
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) { |
|
current.s = marked_session; |
|
current.wl = marked_winlink; |
|
current.idx = current.wl->idx; |
|
current.w = current.wl->window; |
|
current.wp = marked_window_pane; |
|
} |
|
if (current.s == NULL && cmd_find_current_session(¤t) != 0) { |
if (~flags & CMD_FIND_QUIET) |
if (~flags & CMD_FIND_QUIET) |
cmdq_error(cmdq, "no current session"); |
cmdq_error(cmdq, "no current session"); |
goto error; |
goto error; |
|
|
} |
} |
return (&fs); |
return (&fs); |
} |
} |
copy = xstrdup(target); |
|
|
|
|
/* Marked target is a plain ~ or {marked}. */ |
|
if (strcmp(target, "~") == 0 || strcmp(target, "{marked}") == 0) { |
|
if (!server_check_marked()) { |
|
if (~flags & CMD_FIND_QUIET) |
|
cmdq_error(cmdq, "no marked target"); |
|
goto error; |
|
} |
|
fs.s = marked_session; |
|
fs.wl = marked_winlink; |
|
fs.idx = fs.wl->idx; |
|
fs.w = fs.wl->window; |
|
fs.wp = marked_window_pane; |
|
return (&fs); |
|
} |
|
|
/* Find separators if they exist. */ |
/* Find separators if they exist. */ |
|
copy = xstrdup(target); |
colon = strchr(copy, ':'); |
colon = strchr(copy, ':'); |
if (colon != NULL) |
if (colon != NULL) |
*colon++ = '\0'; |
*colon++ = '\0'; |
|
|
return (fs->wl); |
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); |
|
cmd_find_log_state(__func__, target, fs); |
|
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. */ |
/* Find the target pane and report an error and return NULL. */ |
struct winlink * |
struct winlink * |
cmd_find_pane(struct cmd_q *cmdq, const char *target, struct session **sp, |
cmd_find_pane(struct cmd_q *cmdq, const char *target, struct session **sp, |
|
|
struct cmd_find_state *fs; |
struct cmd_find_state *fs; |
|
|
fs = cmd_find_target(cmdq, target, CMD_FIND_PANE, 0); |
fs = cmd_find_target(cmdq, target, CMD_FIND_PANE, 0); |
|
cmd_find_log_state(__func__, target, fs); |
|
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); |
cmd_find_log_state(__func__, target, fs); |
cmd_find_log_state(__func__, target, fs); |
if (fs == NULL) |
if (fs == NULL) |
return (NULL); |
return (NULL); |