=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.59 retrieving revision 1.60 diff -c -r1.59 -r1.60 *** src/usr.bin/tmux/cmd.c 2012/01/20 19:54:07 1.59 --- src/usr.bin/tmux/cmd.c 2012/01/30 09:39:34 1.60 *************** *** 1,4 **** ! /* $OpenBSD: cmd.c,v 1.59 2012/01/20 19:54:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd.c,v 1.60 2012/01/30 09:39:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 120,127 **** struct winlink *cmd_lookup_window(struct session *, const char *, int *); int cmd_lookup_index(struct session *, const char *, int *); struct window_pane *cmd_lookup_paneid(const char *); ! struct session *cmd_pane_session(struct cmd_ctx *, ! struct window_pane *, struct winlink **); struct winlink *cmd_find_window_offset(const char *, struct session *, int *); int cmd_find_index_offset(const char *, struct session *, int *); struct window_pane *cmd_find_pane_offset(const char *, struct winlink *); --- 120,129 ---- struct winlink *cmd_lookup_window(struct session *, const char *, int *); int cmd_lookup_index(struct session *, const char *, int *); struct window_pane *cmd_lookup_paneid(const char *); ! struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *); ! struct window *cmd_lookup_windowid(const char *); ! struct session *cmd_window_session(struct cmd_ctx *, ! struct window *, struct winlink **); struct winlink *cmd_find_window_offset(const char *, struct session *, int *); int cmd_find_index_offset(const char *, struct session *, int *); struct window_pane *cmd_find_pane_offset(const char *, struct winlink *); *************** *** 587,592 **** --- 589,598 ---- *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) { *************** *** 649,658 **** return (-1); } ! /* ! * Lookup pane id. An initial % means a pane id. sp must already point to the ! * current session. ! */ struct window_pane * cmd_lookup_paneid(const char *arg) { --- 655,661 ---- return (-1); } ! /* Lookup pane id. An initial % means a pane id. */ struct window_pane * cmd_lookup_paneid(const char *arg) { *************** *** 668,686 **** return (window_pane_find_by_id(paneid)); } ! /* Find session and winlink for pane. */ struct session * ! cmd_pane_session(struct cmd_ctx *ctx, struct window_pane *wp, ! struct winlink **wlp) { struct session *s; struct sessionslist ss; struct winlink *wl; ! /* If this pane is in the current session, return that winlink. */ s = cmd_current_session(ctx, 0); if (s != NULL) { ! wl = winlink_find_by_window(&s->windows, wp->window); if (wl != NULL) { if (wlp != NULL) *wlp = wl; --- 671,720 ---- return (window_pane_find_by_id(paneid)); } ! /* Lookup window id in a session. An initial @ means a window id. */ ! struct winlink * ! cmd_lookup_winlink_windowid(struct session *s, const char *arg) ! { ! const char *errstr; ! u_int windowid; ! ! if (*arg != '@') ! return (NULL); ! ! windowid = strtonum(arg + 1, 0, UINT_MAX, &errstr); ! if (errstr != NULL) ! return (NULL); ! return (winlink_find_by_window_id(&s->windows, windowid)); ! } ! ! /* Lookup window id. An initial @ means a window id. */ ! struct window * ! cmd_lookup_windowid(const char *arg) ! { ! const char *errstr; ! u_int windowid; ! ! if (*arg != '@') ! return (NULL); ! ! windowid = strtonum(arg + 1, 0, UINT_MAX, &errstr); ! if (errstr != NULL) ! return (NULL); ! return (window_find_by_id(windowid)); ! } ! ! /* Find session and winlink for window. */ struct session * ! cmd_window_session(struct cmd_ctx *ctx, struct window *w, struct winlink **wlp) { struct session *s; struct sessionslist ss; struct winlink *wl; ! /* If this window is in the current session, return that winlink. */ s = cmd_current_session(ctx, 0); if (s != NULL) { ! wl = winlink_find_by_window(&s->windows, w); if (wl != NULL) { if (wlp != NULL) *wlp = wl; *************** *** 688,703 **** } } ! /* Otherwise choose from all sessions with this pane. */ ARRAY_INIT(&ss); RB_FOREACH(s, sessions, &sessions) { ! if (winlink_find_by_window(&s->windows, wp->window) != NULL) ARRAY_ADD(&ss, s); } s = cmd_choose_session_list(&ss); ARRAY_FREE(&ss); if (wlp != NULL) ! *wlp = winlink_find_by_window(&s->windows, wp->window); return (s); } --- 722,737 ---- } } ! /* Otherwise choose from all sessions with this window. */ ARRAY_INIT(&ss); RB_FOREACH(s, sessions, &sessions) { ! if (winlink_find_by_window(&s->windows, w) != NULL) ARRAY_ADD(&ss, s); } s = cmd_choose_session_list(&ss); ARRAY_FREE(&ss); if (wlp != NULL) ! *wlp = winlink_find_by_window(&s->windows, w); return (s); } *************** *** 707,712 **** --- 741,747 ---- { struct session *s; struct window_pane *wp; + struct window *w; struct client *c; char *tmparg; size_t arglen; *************** *** 716,724 **** if (arg == NULL) return (cmd_current_session(ctx, prefer_unattached)); ! /* Lookup as pane id. */ if ((wp = cmd_lookup_paneid(arg)) != NULL) ! return (cmd_pane_session(ctx, wp, NULL)); /* Trim a single trailing colon if any. */ tmparg = xstrdup(arg); --- 751,761 ---- if (arg == NULL) return (cmd_current_session(ctx, prefer_unattached)); ! /* Lookup as pane id or window id. */ if ((wp = cmd_lookup_paneid(arg)) != NULL) ! return (cmd_window_session(ctx, wp->window, NULL)); ! if ((w = cmd_lookup_windowid(arg)) != NULL) ! return (cmd_window_session(ctx, w, NULL)); /* Trim a single trailing colon if any. */ tmparg = xstrdup(arg); *************** *** 780,786 **** /* Lookup as pane id. */ if ((wp = cmd_lookup_paneid(arg)) != NULL) { ! s = cmd_pane_session(ctx, wp, &wl); if (sp != NULL) *sp = s; return (wl); --- 817,823 ---- /* Lookup as pane id. */ if ((wp = cmd_lookup_paneid(arg)) != NULL) { ! s = cmd_window_session(ctx, wp->window, &wl); if (sp != NULL) *sp = s; return (wl); *************** *** 1081,1087 **** /* Lookup as pane id. */ if ((*wpp = cmd_lookup_paneid(arg)) != NULL) { ! s = cmd_pane_session(ctx, *wpp, &wl); if (sp != NULL) *sp = s; return (wl); --- 1118,1124 ---- /* Lookup as pane id. */ if ((*wpp = cmd_lookup_paneid(arg)) != NULL) { ! s = cmd_window_session(ctx, (*wpp)->window, &wl); if (sp != NULL) *sp = s; return (wl);