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

Diff for /src/usr.bin/column/column.c between version 1.13 and 1.14

version 1.13, 2007/05/01 01:26:23 version 1.14, 2007/08/01 13:30:21
Line 56 
Line 56 
   
 void  c_columnate(void);  void  c_columnate(void);
 void *emalloc(size_t);  void *emalloc(size_t);
   void *erealloc(void *, size_t);
 void  input(FILE *);  void  input(FILE *);
 void  maketbl(void);  void  maketbl(void);
 void  print(void);  void  print(void);
Line 218 
Line 219 
         TBL *t;          TBL *t;
         int coloff, cnt;          int coloff, cnt;
         char *p, **lp;          char *p, **lp;
         int *lens, *lens2, maxcols;          int *lens, maxcols;
         TBL *tbl;          TBL *tbl;
         char **cols, **cols2;          char **cols;
   
         t = tbl = emalloc(entries * sizeof(TBL));          t = tbl = emalloc(entries * sizeof(TBL));
         cols = emalloc((maxcols = DEFCOLS) * sizeof(char *));          cols = emalloc((maxcols = DEFCOLS) * sizeof(char *));
Line 229 
Line 230 
                 for (coloff = 0, p = *lp; (cols[coloff] = strtok(p, separator));                  for (coloff = 0, p = *lp; (cols[coloff] = strtok(p, separator));
                     p = NULL)                      p = NULL)
                         if (++coloff == maxcols) {                          if (++coloff == maxcols) {
                                 if (!(cols2 = realloc(cols, (u_int)maxcols +  
                                     DEFCOLS * sizeof(char *))) ||  
                                     !(lens2 = realloc(lens,  
                                     (u_int)maxcols + DEFCOLS * sizeof(int))))  
                                         err(1, NULL);  
                                 cols = cols2;  
                                 lens = lens2;  
                                 memset(lens + maxcols, 0,  
                                     DEFCOLS * sizeof(int));  
                                 maxcols += DEFCOLS;                                  maxcols += DEFCOLS;
                                   cols = erealloc(cols, maxcols * sizeof(char *));
                                   lens = erealloc(lens, maxcols * sizeof(int));
                                   memset(lens + coloff, 0, DEFCOLS * sizeof(int));
                         }                          }
                   if (coloff == 0)
                           continue;
                 t->list = emalloc(coloff * sizeof(char *));                  t->list = emalloc(coloff * sizeof(char *));
                 t->len = emalloc(coloff * sizeof(int));                  t->len = emalloc(coloff * sizeof(int));
                 for (t->cols = coloff; --coloff >= 0;) {                  for (t->cols = coloff; --coloff >= 0;) {
Line 250 
Line 247 
                 }                  }
         }          }
         for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) {          for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) {
                 for (coloff = 0; coloff < t->cols  - 1; ++coloff)                  if (t->cols > 0) {
                         (void)printf("%s%*s", t->list[coloff],                          for (coloff = 0; coloff < t->cols - 1; ++coloff)
                             lens[coloff] - t->len[coloff] + 2, " ");                                  (void)printf("%s%*s", t->list[coloff],
                 (void)printf("%s\n", t->list[coloff]);                                      lens[coloff] - t->len[coloff] + 2, " ");
                           (void)printf("%s\n", t->list[coloff]);
                   }
         }          }
 }  }
   
Line 283 
Line 282 
                 if (maxlength < len)                  if (maxlength < len)
                         maxlength = len;                          maxlength = len;
                 if (entries == maxentry) {                  if (entries == maxentry) {
                         char **nlist;                          maxentry += DEFNUM;
                         size_t nsize = maxentry + DEFNUM;                          list = erealloc(list, maxentry * sizeof(char *));
   
                         if (!(nlist = realloc(list, nsize * sizeof(char *))))  
                                 err(1, NULL);  
                         list = nlist;  
                         maxentry = nsize;  
                 }                  }
                 if (!(list[entries++] = strdup(buf)))                  if (!(list[entries++] = strdup(buf)))
                         err(1, NULL);                          err(1, NULL);
Line 304 
Line 298 
         if (!(p = malloc(size)))          if (!(p = malloc(size)))
                 err(1, NULL);                  err(1, NULL);
         memset(p, 0, size);          memset(p, 0, size);
           return (p);
   }
   
   void *
   erealloc(void *oldp, size_t size)
   {
           void *p;
   
           if (!(p = realloc(oldp, size)))
                   err(1, NULL);
         return (p);          return (p);
 }  }
   

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14