[BACK]Return to cmd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd.c between version 1.40 and 1.41

version 1.40, 2010/05/05 23:24:23 version 1.41, 2010/06/21 01:46:36
Line 538 
Line 538 
 /*  /*
  * Lookup a window or return -1 if not found or ambigious. First try as an   * Lookup a window or return -1 if not found or ambigious. First try as an
  * index and if invalid, use fnmatch or leading prefix. Return NULL but fill in   * index and if invalid, use fnmatch or leading prefix. Return NULL but fill in
  * idx if the window index is a valid number but there is now window with that   * idx if the window index is a valid number but there is no window with that
  * index.   * index.
  */   */
 struct winlink *  struct winlink *
Line 660 
Line 660 
         const char      *winptr;          const char      *winptr;
         char            *sessptr = NULL;          char            *sessptr = NULL;
         int              ambiguous = 0;          int              ambiguous = 0;
           int              n = 1;
   
         /*          /*
          * Find the current session. There must always be a current session, if           * Find the current session. There must always be a current session, if
Line 705 
Line 706 
                 wl = s->curw;                  wl = s->curw;
         else if (winptr[0] == '!' && winptr[1] == '\0')          else if (winptr[0] == '!' && winptr[1] == '\0')
                 wl = TAILQ_FIRST(&s->lastw);                  wl = TAILQ_FIRST(&s->lastw);
         else if (winptr[0] == '+' && winptr[1] == '\0')          else if (winptr[0] == '+' || winptr[0] == '-') {
                 wl = winlink_next(s->curw);                  if (winptr[1] != '\0')
         else if (winptr[0] == '-' && winptr[1] == '\0')                          n = strtonum(winptr + 1, 1, INT_MAX, NULL);
                 wl = winlink_previous(s->curw);                  if (n == 0)
         else                          wl = cmd_lookup_window(s, winptr, &ambiguous);
                   else {
                           if (winptr[0] == '+')
                                   wl = winlink_next_by_number(s->curw, n);
                           else
                                   wl = winlink_previous_by_number(s->curw, n);
                           /* Search by name before giving up. */
                           if (wl == NULL)
                                   wl = cmd_lookup_window(s, winptr, &ambiguous);
                   }
           } else
                 wl = cmd_lookup_window(s, winptr, &ambiguous);                  wl = cmd_lookup_window(s, winptr, &ambiguous);
         if (wl == NULL)          if (wl == NULL)
                 goto not_found;                  goto not_found;
Line 726 
Line 737 
         if (arg[0] == '!' && arg[1] == '\0') {          if (arg[0] == '!' && arg[1] == '\0') {
                 if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)                  if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)
                         goto not_found;                          goto not_found;
         } else if (arg[0] == '+' && arg[1] == '\0') {          } else if (arg[0] == '+' || arg[0] == '-') {
                 if ((wl = winlink_next(s->curw)) == NULL)                  if (arg[1] != '\0')
                         goto not_found;                          n = strtonum(arg + 1, 1, INT_MAX, NULL);
         } else if (arg[0] == '-' && arg[1] == '\0') {                  if (n == 0)
                 if ((wl = winlink_previous(s->curw)) == NULL)                          wl = cmd_lookup_window(s, arg, &ambiguous);
                         goto not_found;                  else {
         } else if ((wl = cmd_lookup_window(s, arg, &ambiguous)) == NULL) {                          if (arg[0] == '+')
                 if (ambiguous)                                  wl = winlink_next_by_number(s->curw, n);
                         goto not_found;                          else
                 if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)                                  wl = winlink_previous_by_number(s->curw, n);
                         goto no_session;                          /* Search by name before giving up. */
                 wl = s->curw;                          if (wl == NULL)
         }                                  wl = cmd_lookup_window(s, arg, &ambiguous);
                   }
                   if (wl == NULL)
                           goto lookup_session;
           } else if ((wl = cmd_lookup_window(s, arg, &ambiguous)) == NULL)
                   goto lookup_session;
   
         if (sp != NULL)          if (sp != NULL)
                 *sp = s;                  *sp = s;
   
         return (wl);          return (wl);
   
   lookup_session:
           if (ambiguous)
                   goto not_found;
           if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
                   goto no_session;
   
           if (sp != NULL)
                   *sp = s;
   
           return (s->curw);
   
 no_session:  no_session:
         if (ambiguous)          if (ambiguous)
                 ctx->error(ctx, "multiple sessions: %s", arg);                  ctx->error(ctx, "multiple sessions: %s", arg);
Line 778 
Line 805 
         const char      *winptr;          const char      *winptr;
         char            *sessptr = NULL;          char            *sessptr = NULL;
         int              idx, ambiguous = 0;          int              idx, ambiguous = 0;
           int              n = 1;
   
         /*          /*
          * Find the current session. There must always be a current session, if           * Find the current session. There must always be a current session, if
Line 825 
Line 853 
                 if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)                  if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)
                         goto not_found;                          goto not_found;
                 idx = wl->idx;                  idx = wl->idx;
         } else if (winptr[0] == '+' && winptr[1] == '\0') {          } else if (winptr[0] == '+' || winptr[0] == '-') {
                 if (s->curw->idx == INT_MAX)                  if (winptr[1] != '\0')
                         goto not_found;                          n = strtonum(winptr + 1, 1, INT_MAX, NULL);
                 idx = s->curw->idx + 1;                  if (winptr[0] == '+' && s->curw->idx == INT_MAX)
         } else if (winptr[0] == '-' && winptr[1] == '\0') {                          idx = cmd_lookup_index(s, winptr, &ambiguous);
                 if (s->curw->idx == 0)                  else if (winptr[0] == '-' && s->curw->idx == 0)
                         goto not_found;                          idx = cmd_lookup_index(s, winptr, &ambiguous);
                 idx = s->curw->idx - 1;                  else if (n == 0)
         } else if ((idx = cmd_lookup_index(s, winptr, &ambiguous)) == -1) {                          idx = cmd_lookup_index(s, winptr, &ambiguous);
                 if (ambiguous)                  else if (winptr[0] == '+')
                         goto not_found;                          idx = s->curw->idx + n;
                 ctx->error(ctx, "invalid index: %s", arg);                  else
                 idx = -2;                          idx = s->curw->idx - n;
         }                  if (idx < 0)
                           goto invalid_index;
           } else if ((idx = cmd_lookup_index(s, winptr, &ambiguous)) == -1)
                   goto invalid_index;
   
         if (sessptr != NULL)          if (sessptr != NULL)
                 xfree(sessptr);                  xfree(sessptr);
Line 853 
Line 884 
                 if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)                  if ((wl = TAILQ_FIRST(&s->lastw)) == NULL)
                         goto not_found;                          goto not_found;
                 idx = wl->idx;                  idx = wl->idx;
         } else if (arg[0] == '+' && arg[1] == '\0') {          } else if (arg[0] == '+' || arg[0] == '-') {
                 if (s->curw->idx == INT_MAX)                  if (arg[1] != '\0')
                         goto not_found;                          n = strtonum(arg + 1, 1, INT_MAX, NULL);
                 idx = s->curw->idx + 1;                  if (arg[0] == '+' && s->curw->idx == INT_MAX)
         } else if (arg[0] == '-' && arg[1] == '\0') {                          idx = cmd_lookup_index(s, arg, &ambiguous);
                 if (s->curw->idx == 0)                  else if (arg[0] == '-' && s->curw->idx == 0)
                         goto not_found;                          idx = cmd_lookup_index(s, arg, &ambiguous);
                 idx = s->curw->idx - 1;                  else if (n == 0)
         } else if ((idx = cmd_lookup_index(s, arg, &ambiguous)) == -1) {                          idx = cmd_lookup_index(s, arg, &ambiguous);
                 if (ambiguous)                  else if (arg[0] == '+')
                         goto not_found;                          idx = s->curw->idx + n;
                 if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)                  else
                         goto no_session;                          idx = s->curw->idx - n;
                 idx = -1;                  if (idx < 0)
         }                          goto lookup_session;
           } else if ((idx = cmd_lookup_index(s, arg, &ambiguous)) == -1)
                   goto lookup_session;
   
         if (sp != NULL)          if (sp != NULL)
                 *sp = s;                  *sp = s;
   
         return (idx);          return (idx);
   
   lookup_session:
           if (ambiguous)
                   goto not_found;
           if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
                   goto no_session;
   
           if (sp != NULL)
                   *sp = s;
   
           return (-1);
   
 no_session:  no_session:
         if (ambiguous)          if (ambiguous)
                 ctx->error(ctx, "multiple sessions: %s", arg);                  ctx->error(ctx, "multiple sessions: %s", arg);
Line 883 
Line 927 
                 xfree(sessptr);                  xfree(sessptr);
         return (-2);          return (-2);
   
   invalid_index:
           if (ambiguous)
                   goto not_found;
           ctx->error(ctx, "invalid index: %s", arg);
   
           if (sessptr != NULL)
                   xfree(sessptr);
           return (-2);
   
 not_found:  not_found:
         if (ambiguous)          if (ambiguous)
                 ctx->error(ctx, "multiple windows: %s", arg);                  ctx->error(ctx, "multiple windows: %s", arg);
Line 907 
Line 960 
         struct layout_cell      *lc;          struct layout_cell      *lc;
         const char              *period, *errstr;          const char              *period, *errstr;
         char                    *winptr, *paneptr;          char                    *winptr, *paneptr;
         u_int                    idx;          u_int                    idx, n = 1;
   
         /* Get the current session. */          /* Get the current session. */
         if ((s = cmd_current_session(ctx)) == NULL) {          if ((s = cmd_current_session(ctx)) == NULL) {
Line 939 
Line 992 
         paneptr = winptr + (period - arg) + 1;          paneptr = winptr + (period - arg) + 1;
         if (*paneptr == '\0')          if (*paneptr == '\0')
                 *wpp = wl->window->active;                  *wpp = wl->window->active;
         else {          else if (paneptr[0] == '+' || paneptr[0] == '-') {
                   if (paneptr[1] != '\0')
                           n = strtonum(paneptr + 1, 1, INT_MAX, NULL);
                   idx = window_pane_index(wl->window, wl->window->active);
                   if (paneptr[0] == '+' && idx == INT_MAX)
                           *wpp = TAILQ_FIRST(&wl->window->panes);
                   else if (paneptr[0] == '-' && idx == 0)
                           *wpp = TAILQ_LAST(&wl->window->panes, window_panes);
                   else if (n == 0)
                           *wpp = wl->window->active;
                   else if (paneptr[0] == '+')
                           *wpp = window_pane_at_index(wl->window, idx + n);
                   else
                           *wpp = window_pane_at_index(wl->window, idx - n);
                   if (paneptr[0] == '+' && *wpp == NULL)
                           *wpp = TAILQ_FIRST(&wl->window->panes);
                   else if (paneptr[0] == '-' && *wpp == NULL)
                           *wpp = TAILQ_LAST(&wl->window->panes, window_panes);
                   else if (*wpp == NULL)
                           goto error;
           } else {
                 idx = strtonum(paneptr, 0, INT_MAX, &errstr);                  idx = strtonum(paneptr, 0, INT_MAX, &errstr);
                 if (errstr != NULL)                  if (errstr != NULL)
                         goto lookup_string;                          goto lookup_string;
Line 952 
Line 1025 
         return (wl);          return (wl);
   
 lookup_string:  lookup_string:
         /* Try as next or previous pane. */  
         if (paneptr[0] == '+' && paneptr[1] == '\0') {  
                 *wpp = TAILQ_NEXT(wl->window->active, entry);  
                 if (*wpp == NULL)  
                         *wpp = TAILQ_FIRST(&wl->window->panes);  
                 return (wl);  
         }  
         if (paneptr[0] == '-' && paneptr[1] == '\0') {  
                 *wpp = TAILQ_PREV(wl->window->active, window_panes, entry);  
                 if (*wpp == NULL)  
                         *wpp = TAILQ_LAST(&wl->window->panes, window_panes);  
                 return (wl);  
         }  
   
         /* Try pane string description. */          /* Try pane string description. */
         if ((lc = layout_find_string(wl->window, paneptr)) == NULL) {          if ((lc = layout_find_string(wl->window, paneptr)) == NULL) {
                 ctx->error(ctx, "can't find pane: %s", paneptr);                  ctx->error(ctx, "can't find pane: %s", paneptr);

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.41