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

Diff for /src/usr.bin/tmux/grid.c between version 1.25 and 1.26

version 1.25, 2013/03/22 15:53:58 version 1.26, 2013/03/22 15:56:11
Line 77 
Line 77 
 size_t  grid_string_cells_fg(const struct grid_cell *, int *);  size_t  grid_string_cells_fg(const struct grid_cell *, int *);
 size_t  grid_string_cells_bg(const struct grid_cell *, int *);  size_t  grid_string_cells_bg(const struct grid_cell *, int *);
 void    grid_string_cells_code(const struct grid_cell *,  void    grid_string_cells_code(const struct grid_cell *,
             const struct grid_cell *, char *, size_t);              const struct grid_cell *, char *, size_t, int);
   
 /* Create a new grid. */  /* Create a new grid. */
 struct grid *  struct grid *
Line 234 
Line 234 
         gl->cellsize = sx;          gl->cellsize = sx;
 }  }
   
   /* Peek at grid line. */
   const struct grid_line *
   grid_peek_line(struct grid *gd, u_int py)
   {
           if (grid_check_y(gd, py) != 0)
                   return (NULL);
           return (&gd->linedata[py]);
   }
   
 /* Get cell for reading. */  /* Get cell for reading. */
 const struct grid_cell *  const struct grid_cell *
 grid_peek_cell(struct grid *gd, u_int px, u_int py)  grid_peek_cell(struct grid *gd, u_int px, u_int py)
Line 485 
Line 494 
  */   */
 void  void
 grid_string_cells_code(const struct grid_cell *lastgc,  grid_string_cells_code(const struct grid_cell *lastgc,
     const struct grid_cell *gc, char *buf, size_t len)      const struct grid_cell *gc, char *buf, size_t len, int escape_c0)
 {  {
         int     oldc[16], newc[16], s[32];          int     oldc[16], newc[16], s[32];
         size_t  noldc, nnewc, n, i;          size_t  noldc, nnewc, n, i;
Line 542 
Line 551 
         /* If there are any parameters, append an SGR code. */          /* If there are any parameters, append an SGR code. */
         *buf = '\0';          *buf = '\0';
         if (n > 0) {          if (n > 0) {
                 strlcat(buf, "\033[", len);                  if (escape_c0)
                           strlcat(buf, "\\033[", len);
                   else
                           strlcat(buf, "\033[", len);
                 for (i = 0; i < n; i++) {                  for (i = 0; i < n; i++) {
                         if (i + 1 < n)                          if (i + 1 < n)
                                 xsnprintf(tmp, sizeof tmp, "%d;", s[i]);                                  xsnprintf(tmp, sizeof tmp, "%d;", s[i]);
Line 554 
Line 566 
         }          }
   
         /* Append shift in/shift out if needed. */          /* Append shift in/shift out if needed. */
         if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET))          if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
                 strlcat(buf, "\016", len);  /* SO */                  if (escape_c0)
         if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET))                          strlcat(buf, "\\016", len);  /* SO */
                 strlcat(buf, "\017", len);  /* SI */                  else
                           strlcat(buf, "\016", len);  /* SO */
           }
           if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
                   if (escape_c0)
                           strlcat(buf, "\\017", len);  /* SI */
                   else
                           strlcat(buf, "\017", len);  /* SI */
           }
 }  }
   
 /* Convert cells into a string. */  /* Convert cells into a string. */
 char *  char *
 grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,  grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
     struct grid_cell **lastgc, int with_codes)      struct grid_cell **lastgc, int with_codes, int escape_c0)
 {  {
         const struct grid_cell  *gc;          const struct grid_cell  *gc;
         static struct grid_cell  lastgc1;          static struct grid_cell  lastgc1;
         struct utf8_data         ud;          struct utf8_data         ud;
           const char*              data;
         char                    *buf, code[128];          char                    *buf, code[128];
         size_t                   len, off, codelen;          size_t                   len, off, size, codelen;
         u_int                    xx;          u_int                    xx;
   
         GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);          GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
Line 590 
Line 611 
                 grid_cell_get(gc, &ud);                  grid_cell_get(gc, &ud);
   
                 if (with_codes) {                  if (with_codes) {
                         grid_string_cells_code(*lastgc, gc, code, sizeof code);                          grid_string_cells_code(*lastgc, gc, code, sizeof code,
                               escape_c0);
                         codelen = strlen(code);                          codelen = strlen(code);
                         memcpy(*lastgc, gc, sizeof *gc);                          memcpy(*lastgc, gc, sizeof *gc);
                 } else                  } else
                         codelen = 0;                          codelen = 0;
   
                 while (len < off + ud.size + codelen + 1) {                  data = ud.data;
                   size = ud.size;
                   if (escape_c0 && size == 1 && *data == '\\') {
                           data = "\\";
                           size = 2;
                   }
   
                   while (len < off + size + codelen + 1) {
                         buf = xrealloc(buf, 2, len);                          buf = xrealloc(buf, 2, len);
                         len *= 2;                          len *= 2;
                 }                  }
Line 605 
Line 634 
                         memcpy(buf + off, code, codelen);                          memcpy(buf + off, code, codelen);
                         off += codelen;                          off += codelen;
                 }                  }
                 memcpy(buf + off, ud.data, ud.size);                  memcpy(buf + off, data, size);
                 off += ud.size;                  off += size;
         }          }
   
         while (off > 0 && buf[off - 1] == ' ')          while (off > 0 && buf[off - 1] == ' ')
                 off--;                  off--;
         buf[off] = '\0';          buf[off] = '\0';
   
         return (buf);          return (buf);
 }  }
   

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26