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

Diff for /src/usr.bin/tmux/cmd-find.c between version 1.8 and 1.9

version 1.8, 2015/06/04 11:43:51 version 1.9, 2015/06/05 08:14:16
Line 30 
Line 30 
 #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  #define CMD_FIND_DEFAULT_MARKED 0x8
   #define CMD_FIND_EXACT_SESSION 0x10
   #define CMD_FIND_EXACT_WINDOW 0x20
   
 enum cmd_find_type {  enum cmd_find_type {
         CMD_FIND_PANE,          CMD_FIND_PANE,
Line 381 
Line 383 
         if (fs->s != NULL)          if (fs->s != NULL)
                 return (0);                  return (0);
   
           /* Stop now if exact only. */
           if (fs->flags & CMD_FIND_EXACT_SESSION)
                   return (-1);
   
         /* Otherwise look for prefix. */          /* Otherwise look for prefix. */
         s = NULL;          s = NULL;
         RB_FOREACH(s_loop, sessions, &sessions) {          RB_FOREACH(s_loop, sessions, &sessions) {
Line 455 
Line 461 
 {  {
         struct winlink  *wl;          struct winlink  *wl;
         const char      *errstr;          const char      *errstr;
         int              idx, n;          int              idx, n, exact;
         struct session  *s;          struct session  *s;
   
         log_debug("%s: %s", __func__, window);          log_debug("%s: %s", __func__, window);
           exact = (fs->flags & CMD_FIND_EXACT_WINDOW);
   
         /* Check for window ids starting with @. */          /* Check for window ids starting with @. */
         if (*window == '@') {          if (*window == '@') {
Line 469 
Line 476 
         }          }
   
         /* Try as an offset. */          /* Try as an offset. */
         if (window[0] == '+' || window[0] == '-') {          if (!exact && window[0] == '+' || window[0] == '-') {
                 if (window[1] != '\0')                  if (window[1] != '\0')
                         n = strtonum(window + 1, 1, INT_MAX, NULL);                          n = strtonum(window + 1, 1, INT_MAX, NULL);
                 else                  else
Line 499 
Line 506 
         }          }
   
         /* Try special characters. */          /* Try special characters. */
         if (strcmp(window, "!") == 0) {          if (!exact) {
                 fs->wl = TAILQ_FIRST(&fs->s->lastw);                  if (strcmp(window, "!") == 0) {
                 if (fs->wl == NULL)                          fs->wl = TAILQ_FIRST(&fs->s->lastw);
                         return (-1);                          if (fs->wl == NULL)
                 fs->idx = fs->wl->idx;                                  return (-1);
                 fs->w = fs->wl->window;                          fs->idx = fs->wl->idx;
                 return (0);                          fs->w = fs->wl->window;
         } else if (strcmp(window, "^") == 0) {  
                 fs->wl = RB_MIN(winlinks, &fs->s->windows);  
                 if (fs->wl == NULL)  
                         return (-1);  
                 fs->idx = fs->wl->idx;  
                 fs->w = fs->wl->window;  
                 return (0);  
         } else if (strcmp(window, "$") == 0) {  
                 fs->wl = RB_MAX(winlinks, &fs->s->windows);  
                 if (fs->wl == NULL)  
                         return (-1);  
                 fs->idx = fs->wl->idx;  
                 fs->w = fs->wl->window;  
                 return (0);  
         }  
   
         /* First see if this is a valid window index in this session. */  
         idx = strtonum(window, 0, INT_MAX, &errstr);  
         if (errstr == NULL) {  
                 if (fs->flags & CMD_FIND_WINDOW_INDEX) {  
                         fs->idx = idx;  
                         return (0);                          return (0);
                 }                  } else if (strcmp(window, "^") == 0) {
                 fs->wl = winlink_find_by_index(&fs->s->windows, idx);                          fs->wl = RB_MIN(winlinks, &fs->s->windows);
                 if (fs->wl != NULL) {                          if (fs->wl == NULL)
                                   return (-1);
                           fs->idx = fs->wl->idx;
                         fs->w = fs->wl->window;                          fs->w = fs->wl->window;
                         return (0);                          return (0);
                   } else if (strcmp(window, "$") == 0) {
                           fs->wl = RB_MAX(winlinks, &fs->s->windows);
                           if (fs->wl == NULL)
                                   return (-1);
                           fs->idx = fs->wl->idx;
                           fs->w = fs->wl->window;
                           return (0);
                 }                  }
         }          }
   
           /* First see if this is a valid window index in this session. */
           if (window[0] != '+' && window[0] != '-') {
                   idx = strtonum(window, 0, INT_MAX, &errstr);
                   if (errstr == NULL) {
                           if (fs->flags & CMD_FIND_WINDOW_INDEX) {
                                   fs->idx = idx;
                                   return (0);
                           }
                           fs->wl = winlink_find_by_index(&fs->s->windows, idx);
                           if (fs->wl != NULL) {
                                   fs->w = fs->wl->window;
                                   return (0);
                           }
                   }
           }
   
         /* Look for exact matches, error if more than one. */          /* Look for exact matches, error if more than one. */
         fs->wl = NULL;          fs->wl = NULL;
         RB_FOREACH(wl, winlinks, &fs->s->windows) {          RB_FOREACH(wl, winlinks, &fs->s->windows) {
Line 551 
Line 562 
                 return (0);                  return (0);
         }          }
   
   
           /* Stop now if exact only. */
           if (exact)
                   return (-1);
   
         /* Try as the start of a window name, error if multiple. */          /* Try as the start of a window name, error if multiple. */
         fs->wl = NULL;          fs->wl = NULL;
         RB_FOREACH(wl, winlinks, &fs->s->windows) {          RB_FOREACH(wl, winlinks, &fs->s->windows) {
Line 866 
Line 882 
                                 break;                                  break;
                         }                          }
                 }                  }
           }
   
           /* Set exact match flags. */
           if (session != NULL && *session == '=') {
                   session++;
                   fs.flags |= CMD_FIND_EXACT_SESSION;
           }
           if (window != NULL && *window == '=') {
                   window++;
                   fs.flags |= CMD_FIND_EXACT_WINDOW;
         }          }
   
         /* Empty is the same as NULL. */          /* Empty is the same as NULL. */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9