[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.46 and 1.47

version 1.46, 2010/10/29 20:11:57 version 1.47, 2010/12/21 22:37:59
Line 112 
Line 112 
         NULL          NULL
 };  };
   
 struct session  *cmd_choose_session(struct sessions *);  struct session  *cmd_choose_session_list(struct sessionslist *);
   struct session  *cmd_choose_session(void);
 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(const char *, int *);
Line 316 
Line 317 
         struct msg_command_data *data = ctx->msgdata;          struct msg_command_data *data = ctx->msgdata;
         struct client           *c = ctx->cmdclient;          struct client           *c = ctx->cmdclient;
         struct session          *s;          struct session          *s;
         struct sessions          ss;          struct sessionslist      ss;
         struct winlink          *wl;          struct winlink          *wl;
         struct window_pane      *wp;          struct window_pane      *wp;
         u_int                    i;  
         int                      found;          int                      found;
   
         if (ctx->curclient != NULL && ctx->curclient->session != NULL)          if (ctx->curclient != NULL && ctx->curclient->session != NULL)
Line 332 
Line 332 
          */           */
         if (c != NULL && c->tty.path != NULL) {          if (c != NULL && c->tty.path != NULL) {
                 ARRAY_INIT(&ss);                  ARRAY_INIT(&ss);
                 for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {                  RB_FOREACH(s, sessions, &sessions) {
                         if ((s = ARRAY_ITEM(&sessions, i)) == NULL)  
                                 continue;  
                         found = 0;                          found = 0;
                         RB_FOREACH(wl, winlinks, &s->windows) {                          RB_FOREACH(wl, winlinks, &s->windows) {
                                 TAILQ_FOREACH(wp, &wl->window->panes, entry) {                                  TAILQ_FOREACH(wp, &wl->window->panes, entry) {
Line 350 
Line 348 
                                 ARRAY_ADD(&ss, s);                                  ARRAY_ADD(&ss, s);
                 }                  }
   
                 s = cmd_choose_session(&ss);                  s = cmd_choose_session_list(&ss);
                 ARRAY_FREE(&ss);                  ARRAY_FREE(&ss);
                 if (s != NULL)                  if (s != NULL)
                         return (s);                          return (s);
         }          }
   
         /* Use the session from the TMUX environment variable. */          /* Use the session from the TMUX environment variable. */
         if (data != NULL &&          if (data != NULL && data->pid == getpid()) {
             data->pid == getpid() &&                  s = session_find_by_index(data->idx);
             data->idx <= ARRAY_LENGTH(&sessions) &&                  if (s != NULL)
             (s = ARRAY_ITEM(&sessions, data->idx)) != NULL)                          return (s);
                 return (s);          }
   
         return (cmd_choose_session(&sessions));          return (cmd_choose_session());
 }  }
   
   /* Find the most recently used session. */
   struct session *
   cmd_choose_session(void)
   {
           struct session  *s, *sbest;
           struct timeval  *tv = NULL;
   
           sbest = NULL;
           RB_FOREACH(s, sessions, &sessions) {
                   if (tv == NULL || timercmp(&s->activity_time, tv, >)) {
                           sbest = s;
                           tv = &s->activity_time;
                   }
           }
   
           return (sbest);
   }
   
 /* Find the most recently used session from a list. */  /* Find the most recently used session from a list. */
 struct session *  struct session *
 cmd_choose_session(struct sessions *ss)  cmd_choose_session_list(struct sessionslist *ss)
 {  {
         struct session  *s, *sbest;          struct session  *s, *sbest;
         struct timeval  *tv = NULL;          struct timeval  *tv = NULL;
Line 516 
Line 532 
 cmd_lookup_session(const char *name, int *ambiguous)  cmd_lookup_session(const char *name, int *ambiguous)
 {  {
         struct session  *s, *sfound;          struct session  *s, *sfound;
         u_int            i;  
   
         *ambiguous = 0;          *ambiguous = 0;
   
Line 525 
Line 540 
          * 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
          * returned.           * returned.
          */           */
         for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {          if ((s = session_find(name)) != NULL)
                 if ((s = ARRAY_ITEM(&sessions, i)) == NULL)                  return (s);
                         continue;  
                 if (strcmp(name, s->name) == 0)  
                         return (s);  
         }  
   
         /*          /*
          * Otherwise look for partial matches, returning early if it is found to           * Otherwise look for partial matches, returning early if it is found to
          * be ambiguous.           * be ambiguous.
          */           */
         sfound = NULL;          sfound = NULL;
         for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {          RB_FOREACH(s, sessions, &sessions) {
                 if ((s = ARRAY_ITEM(&sessions, i)) == NULL)  
                         continue;  
                 if (strncmp(name, s->name, strlen(name)) == 0 ||                  if (strncmp(name, s->name, strlen(name)) == 0 ||
                     fnmatch(name, s->name, 0) == 0) {                      fnmatch(name, s->name, 0) == 0) {
                         if (sfound != NULL) {                          if (sfound != NULL) {

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47