=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.96 retrieving revision 1.97 diff -c -r1.96 -r1.97 *** src/usr.bin/tmux/cmd.c 2014/09/25 12:45:35 1.96 --- src/usr.bin/tmux/cmd.c 2014/09/25 12:51:40 1.97 *************** *** 1,4 **** ! /* $OpenBSD: cmd.c,v 1.96 2014/09/25 12:45:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd.c,v 1.97 2014/09/25 12:51:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 121,127 **** struct session *cmd_choose_session(int); struct client *cmd_choose_client(struct clients *); struct client *cmd_lookup_client(const char *); ! struct session *cmd_lookup_session(const char *, int *); struct session *cmd_lookup_session_id(const char *); struct winlink *cmd_lookup_window(struct session *, const char *, int *); int cmd_lookup_index(struct session *, const char *, int *); --- 121,127 ---- struct session *cmd_choose_session(int); struct client *cmd_choose_client(struct clients *); struct client *cmd_lookup_client(const char *); ! struct session *cmd_lookup_session(struct cmd_q *, const char *, int *); struct session *cmd_lookup_session_id(const char *); struct winlink *cmd_lookup_window(struct session *, const char *, int *); int cmd_lookup_index(struct session *, const char *, int *); *************** *** 585,593 **** /* Lookup a session by name. If no session is found, NULL is returned. */ struct session * ! cmd_lookup_session(const char *name, int *ambiguous) { ! struct session *s, *sfound; *ambiguous = 0; --- 585,595 ---- /* Lookup a session by name. If no session is found, NULL is returned. */ struct session * ! cmd_lookup_session(struct cmd_q *cmdq, const char *name, int *ambiguous) { ! struct session *s, *sfound; ! struct window *w; ! struct window_pane *wp; *ambiguous = 0; *************** *** 595,600 **** --- 597,608 ---- if ((s = cmd_lookup_session_id(name)) != NULL) 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 * be unique so an exact match can't be ambigious and can just be *************** *** 630,645 **** struct winlink * cmd_lookup_window(struct session *s, const char *name, int *ambiguous) { ! struct winlink *wl, *wlfound; ! const char *errstr; ! u_int idx; *ambiguous = 0; ! /* Try as a window id. */ if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL) return (wl); /* First see if this is a valid window index in this session. */ idx = strtonum(name, 0, INT_MAX, &errstr); if (errstr == NULL) { --- 638,667 ---- struct winlink * cmd_lookup_window(struct session *s, const char *name, int *ambiguous) { ! struct winlink *wl, *wlfound; ! struct window *w; ! struct window_pane *wp; ! const char *errstr; ! u_int idx; *ambiguous = 0; ! /* Try as pane or window id. */ if ((wl = cmd_lookup_winlink_windowid(s, name)) != NULL) 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. */ idx = strtonum(name, 0, INT_MAX, &errstr); if (errstr == NULL) { *************** *** 786,798 **** struct session * cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) { ! struct session *s; ! struct window_pane *wp; ! struct window *w; ! struct client *c; ! char *tmparg; ! size_t arglen; ! int ambiguous; /* A NULL argument means the current session. */ if (arg == NULL) { --- 808,818 ---- struct session * cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached) { ! struct session *s; ! struct client *c; ! char *tmparg; ! size_t arglen; ! int ambiguous; /* A NULL argument means the current session. */ if (arg == NULL) { *************** *** 801,812 **** 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. */ tmparg = xstrdup(arg); arglen = strlen(tmparg); --- 821,826 ---- *************** *** 822,828 **** } /* Find the session, if any. */ ! s = cmd_lookup_session(tmparg, &ambiguous); /* If it doesn't, try to match it as a client. */ if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL) --- 836,842 ---- } /* Find the session, if any. */ ! s = cmd_lookup_session(cmdq, tmparg, &ambiguous); /* If it doesn't, try to match it as a client. */ if (s == NULL && (c = cmd_lookup_client(tmparg)) != NULL) *************** *** 844,855 **** struct winlink * cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) { ! struct session *s; ! struct winlink *wl; ! struct window_pane *wp; ! const char *winptr; ! char *sessptr = NULL; ! int ambiguous = 0; /* * Find the current session. There must always be a current session, if --- 858,868 ---- struct winlink * cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp) { ! struct session *s; ! struct winlink *wl; ! const char *winptr; ! char *sessptr = NULL; ! int ambiguous = 0; /* * Find the current session. There must always be a current session, if *************** *** 867,880 **** 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. */ if (*arg == '\0') goto not_found; --- 880,885 ---- *************** *** 889,895 **** /* Try to lookup the session if present. */ if (*sessptr != '\0') { ! if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) --- 894,900 ---- /* Try to lookup the session if present. */ if (*sessptr != '\0') { ! if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) *************** *** 940,946 **** lookup_session: if (ambiguous) goto not_found; ! if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL) --- 945,952 ---- lookup_session: if (ambiguous) goto not_found; ! if (*arg != '\0' && ! (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL) *************** *** 1030,1036 **** /* Try to lookup the session if present. */ if (sessptr != NULL && *sessptr != '\0') { ! if ((s = cmd_lookup_session(sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) --- 1036,1042 ---- /* Try to lookup the session if present. */ if (sessptr != NULL && *sessptr != '\0') { ! if ((s = cmd_lookup_session(cmdq, sessptr, &ambiguous)) == NULL) goto no_session; } if (sp != NULL) *************** *** 1078,1084 **** lookup_session: if (ambiguous) goto not_found; ! if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL) --- 1084,1091 ---- lookup_session: if (ambiguous) goto not_found; ! if (*arg != '\0' && ! (s = cmd_lookup_session(cmdq, arg, &ambiguous)) == NULL) goto no_session; if (sp != NULL)