version 1.96, 2014/09/25 12:45:35 |
version 1.97, 2014/09/25 12:51:40 |
|
|
struct session *cmd_choose_session(int); |
struct session *cmd_choose_session(int); |
struct client *cmd_choose_client(struct clients *); |
struct client *cmd_choose_client(struct clients *); |
struct client *cmd_lookup_client(const char *); |
struct client *cmd_lookup_client(const char *); |
struct session *cmd_lookup_session(const char *, int *); |
struct session *cmd_lookup_session(struct cmd_q *, const char *, int *); |
struct session *cmd_lookup_session_id(const char *); |
struct session *cmd_lookup_session_id(const char *); |
struct winlink *cmd_lookup_window(struct session *, const char *, int *); |
struct winlink *cmd_lookup_window(struct session *, const char *, int *); |
int cmd_lookup_index(struct session *, const char *, int *); |
int cmd_lookup_index(struct session *, const char *, int *); |
|
|
|
|
/* Lookup a session by name. If no session is found, NULL is returned. */ |
/* Lookup a session by name. If no session is found, NULL is returned. */ |
struct session * |
struct session * |
cmd_lookup_session(const char *name, int *ambiguous) |
cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous) |
{ |
{ |
struct session *s, *sfound; |
struct session *s, *sfound; |
|
struct window *w; |
|
struct window_pane *wp; |
|
|
*ambiguous = 0; |
*ambiguous = 0; |
|
|
|
|
if ((s = cmd_lookup_session_id(name)) != NULL) |
if ((s = cmd_lookup_session_id(name)) != NULL) |
return (s); |
return (s); |
|
|
|
/* Try as pane or window id. */ |
|
if ((wp = cmd_lookup_paneid(name)) != NULL) |
|
return (cmd_window_session(cmdq, wp->window, NULL)); |
|
if ((w = cmd_lookup_windowid(name)) != NULL) |
|
return (cmd_window_session(cmdq, w, NULL)); |
|
|
/* |
/* |
* Look for matches. First look for exact matches - session names must |
* Look for matches. First look for exact matches - session names must |
* be unique so an exact match can't be ambigious and can just be |
* be unique so an exact match can't be ambigious and can just be |
|
|
struct winlink * |
struct winlink * |
cmd_lookup_window(struct session *s, const char *name, int *ambiguous) |
cmd_lookup_window(struct session *s, const char *name, int *ambiguous) |
{ |
{ |
struct winlink *wl, *wlfound; |
struct winlink *wl, *wlfound; |
const char *errstr; |
struct window *w; |
u_int idx; |
struct window_pane *wp; |
|
const char *errstr; |
|
u_int idx; |
|
|
*ambiguous = 0; |
*ambiguous = 0; |
|
|
/* Try as a window id. */ |
/* Try as pane or window id. */ |
if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL) |
if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL) |
return (wl); |
return (wl); |
|
|
|
/* Lookup as pane or window id. */ |
|
if ((wp = cmd_lookup_paneid(name)) != NULL) { |
|
wl = winlink_find_by_window(&s->windows, wp->window); |
|
if (wl != NULL) |
|
return (wl); |
|
} |
|
if ((w = cmd_lookup_windowid(name)) != NULL) { |
|
wl = winlink_find_by_window(&s->windows, w); |
|
if (wl != NULL) |
|
return (wl); |
|
} |
|
|
/* First see if this is a valid window index in this session. */ |
/* First see if this is a valid window index in this session. */ |
idx = strtonum(name, 0, INT_MAX, &errstr); |
idx = strtonum(name, 0, INT_MAX, &errstr); |
if (errstr == NULL) { |
if (errstr == NULL) { |
|
|
struct session * |
struct session * |
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) |
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) |
{ |
{ |
struct session *s; |
struct session *s; |
struct window_pane *wp; |
struct client *c; |
struct window *w; |
char *tmparg; |
struct client *c; |
size_t arglen; |
char *tmparg; |
int ambiguous; |
size_t arglen; |
|
int ambiguous; |
|
|
|
/* A NULL argument means the current session. */ |
/* A NULL argument means the current session. */ |
if (arg == NULL) { |
if (arg == NULL) { |
|
|
return (s); |
return (s); |
} |
} |
|
|
/* Lookup as pane id or window id. */ |
|
if ((wp = cmd_lookup_paneid(arg)) != NULL) |
|
return (cmd_window_session(cmdq, wp->window, NULL)); |
|
if ((w = cmd_lookup_windowid(arg)) != NULL) |
|
return (cmd_window_session(cmdq, w, NULL)); |
|
|
|
/* Trim a single trailing colon if any. */ |
/* Trim a single trailing colon if any. */ |
tmparg = xstrdup(arg); |
tmparg = xstrdup(arg); |
arglen = strlen(tmparg); |
arglen = strlen(tmparg); |
|
|
} |
} |
|
|
/* Find the session, if any. */ |
/* Find the session, if any. */ |
s = cmd_lookup_session(tmparg, &ambiguous); |
s = cmd_lookup_session(cmdq, tmparg, &ambiguous); |
|
|
/* If it doesn't, try to match it as a client. */ |
/* If it doesn't, try to match it as a client. */ |
if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL) |
if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL) |
|
|
struct winlink * |
struct winlink * |
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) |
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) |
{ |
{ |
struct session *s; |
struct session *s; |
struct winlink *wl; |
struct winlink *wl; |
struct window_pane *wp; |
const char *winptr; |
const char *winptr; |
char *sessptr = NULL; |
char *sessptr = NULL; |
int ambiguous = 0; |
int ambiguous = 0; |
|
|
|
/* |
/* |
* Find the current session. There must always be a current session, if |
* Find the current session. There must always be a current session, if |
|
|
return (s->curw); |
return (s->curw); |
} |
} |
|
|
/* Lookup as pane id. */ |
|
if ((wp = cmd_lookup_paneid(arg)) != NULL) { |
|
s = cmd_window_session(cmdq, wp->window, &wl); |
|
if (sp != NULL) |
|
*sp = s; |
|
return (wl); |
|
} |
|
|
|
/* Time to look at the argument. If it is empty, that is an error. */ |
/* Time to look at the argument. If it is empty, that is an error. */ |
if (*arg == '\0') |
if (*arg == '\0') |
goto not_found; |
goto not_found; |
|
|
|
|
/* Try to lookup the session if present. */ |
/* Try to lookup the session if present. */ |
if (*sessptr != '\0') { |
if (*sessptr != '\0') { |
if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) |
if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) |
goto no_session; |
goto no_session; |
} |
} |
if (sp != NULL) |
if (sp != NULL) |
|
|
lookup_session: |
lookup_session: |
if (ambiguous) |
if (ambiguous) |
goto not_found; |
goto not_found; |
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) |
if (*arg != '\0' && |
|
(s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) |
goto no_session; |
goto no_session; |
|
|
if (sp != NULL) |
if (sp != NULL) |
|
|
|
|
/* Try to lookup the session if present. */ |
/* Try to lookup the session if present. */ |
if (sessptr != NULL && *sessptr != '\0') { |
if (sessptr != NULL && *sessptr != '\0') { |
if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) |
if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) |
goto no_session; |
goto no_session; |
} |
} |
if (sp != NULL) |
if (sp != NULL) |
|
|
lookup_session: |
lookup_session: |
if (ambiguous) |
if (ambiguous) |
goto not_found; |
goto not_found; |
if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) |
if (*arg != '\0' && |
|
(s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) |
goto no_session; |
goto no_session; |
|
|
if (sp != NULL) |
if (sp != NULL) |