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

Diff for /src/usr.bin/tmux/status.c between version 1.37 and 1.38

version 1.37, 2009/10/10 10:02:48 version 1.38, 2009/10/10 15:03:01
Line 29 
Line 29 
   
 #include "tmux.h"  #include "tmux.h"
   
 char   *status_replace_popen(char **);  char   *status_job(struct client *, char **);
   void    status_job_callback(struct job *);
 size_t  status_width(struct winlink *);  size_t  status_width(struct winlink *);
 char   *status_print(struct session *, struct winlink *, struct grid_cell *);  char   *status_print(struct session *, struct winlink *, struct grid_cell *);
   
Line 104 
Line 105 
         utf8flag = options_get_number(&s->options, "status-utf8");          utf8flag = options_get_number(&s->options, "status-utf8");
   
         /* Work out the left and right strings. */          /* Work out the left and right strings. */
         left = status_replace(s, options_get_string(          left = status_replace(c, options_get_string(
             &s->options, "status-left"), c->status_timer.tv_sec);              &s->options, "status-left"), c->status_timer.tv_sec);
         llen = options_get_number(&s->options, "status-left-length");          llen = options_get_number(&s->options, "status-left-length");
         llen2 = screen_write_cstrlen(utf8flag, "%s", left);          llen2 = screen_write_cstrlen(utf8flag, "%s", left);
         if (llen2 < llen)          if (llen2 < llen)
                 llen = llen2;                  llen = llen2;
   
         right = status_replace(s, options_get_string(          right = status_replace(c, options_get_string(
             &s->options, "status-right"), c->status_timer.tv_sec);              &s->options, "status-right"), c->status_timer.tv_sec);
         rlen = options_get_number(&s->options, "status-right-length");          rlen = options_get_number(&s->options, "status-right-length");
         rlen2 = screen_write_cstrlen(utf8flag, "%s", right);          rlen2 = screen_write_cstrlen(utf8flag, "%s", right);
Line 317 
Line 318 
 }  }
   
 char *  char *
 status_replace(struct session *s, const char *fmt, time_t t)  status_replace(struct client *c, const char *fmt, time_t t)
 {  {
           struct session *s = c->session;
         struct winlink *wl = s->curw;          struct winlink *wl = s->curw;
         static char     out[BUFSIZ];          static char     out[BUFSIZ];
         char            in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr;          char            in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr;
         char           *savedptr;          char           *savedptr;       /* freed at end of each loop */
         size_t          len;          size_t          len;
         long            n;          long            n;
   
   
         strftime(in, sizeof in, fmt, localtime(&t));          strftime(in, sizeof in, fmt, localtime(&t));
         in[(sizeof in) - 1] = '\0';          in[(sizeof in) - 1] = '\0';
   
Line 352 
Line 355 
                         switch (*iptr++) {                          switch (*iptr++) {
                         case '(':                          case '(':
                                 if (ptr == NULL) {                                  if (ptr == NULL) {
                                         ptr = status_replace_popen(&iptr);                                          ptr = status_job(c, &iptr);
                                         if (ptr == NULL)                                          if (ptr == NULL)
                                                 break;                                                  break;
                                         savedptr = ptr;                                          savedptr = ptr;
Line 374 
Line 377 
                         case 'P':                          case 'P':
                                 if (ptr == NULL) {                                  if (ptr == NULL) {
                                         xsnprintf(tmp, sizeof tmp, "%u",                                          xsnprintf(tmp, sizeof tmp, "%u",
                                                   window_pane_index(wl->window,                                              window_pane_index(wl->window,
                                                   wl->window->active));                                              wl->window->active));
                                         ptr = tmp;                                          ptr = tmp;
                                 }                                  }
                                 /* FALLTHROUGH */                                  /* FALLTHROUGH */
Line 434 
Line 437 
 }  }
   
 char *  char *
 status_replace_popen(char **iptr)  status_job(struct client *c, char **iptr)
 {  {
         FILE    *f;          struct job      *job;
         char    *buf, *cmd, *ptr;          char            *buf, *cmd;
         int     lastesc;          int              lastesc;
         size_t  len;          size_t           len;
   
         if (**iptr == '\0')          if (**iptr == '\0')
                 return (NULL);                  return (NULL);
Line 464 
Line 467 
                 lastesc = 0;                  lastesc = 0;
                 cmd[len++] = **iptr;                  cmd[len++] = **iptr;
         }          }
         if (**iptr == '\0')             /* no terminating ) */          if (**iptr == '\0')             /* no terminating ) */ {
                 goto out;                  xfree(cmd);
                   return (NULL);
           }
         (*iptr)++;                      /* skip final ) */          (*iptr)++;                      /* skip final ) */
         cmd[len] = '\0';          cmd[len] = '\0';
   
         if ((f = popen(cmd, "r")) == NULL)          job = job_get(&c->status_jobs, cmd);
                 goto out;          if (job == NULL) {
                   job = job_add(
         if ((buf = fgetln(f, &len)) == NULL) {                      &c->status_jobs, c, cmd, status_job_callback, xfree, NULL);
                 pclose(f);                  job_run(job);
                 goto out;  
         }          }
         if (buf[len - 1] == '\n') {          if (job->data == NULL)
                 buf[len - 1] = '\0';                  return (xstrdup(""));
                 buf = xstrdup(buf);          return (xstrdup(job->data));
         } else {  }
                 ptr = xmalloc(len + 1);  
                 memcpy(ptr, buf, len);  
                 ptr[len] = '\0';  
                 buf = ptr;  
         }  
         pclose(f);  
   
 out:  void
         xfree(cmd);  status_job_callback(struct job *job)
         return (buf);  {
           char    *buf;
           size_t   len;
   
           len = BUFFER_USED(job->out);
           buf = xmalloc(len + 1);
           if (len != 0)
                   buffer_read(job->out, buf, len);
           buf[len] = '\0';
           buf[strcspn(buf, "\n")] = '\0';
   
           if (job->data != NULL)
                   xfree(job->data);
           else
                   server_redraw_client(job->client);
           job->data = xstrdup(buf);
   
           xfree(buf);
 }  }
   
 size_t  size_t

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38