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

Diff for /src/usr.bin/awk/lib.c between version 1.14 and 1.15

version 1.14, 2003/12/01 15:34:26 version 1.15, 2004/12/30 01:52:48
Line 105 
Line 105 
         infile = stdin;         /* no filenames, so use stdin */          infile = stdin;         /* no filenames, so use stdin */
 }  }
   
   static int firsttime = 1;
   
 int getrec(char **pbuf, int *pbufsize, int isrecord)    /* get next input record */  int getrec(char **pbuf, int *pbufsize, int isrecord)    /* get next input record */
 {                       /* note: cares whether buf == record */  {                       /* note: cares whether buf == record */
         int c;          int c;
         static int firsttime = 1;  
         char *buf = *pbuf;          char *buf = *pbuf;
         int bufsize = *pbufsize;          int bufsize = *pbufsize;
   
Line 312 
Line 313 
                 }                  }
                 *fr = 0;                  *fr = 0;
         } else if (*r != 0) {   /* if 0, it's a null field */          } else if (*r != 0) {   /* if 0, it's a null field */
                   /* subtlecase : if length(FS) == 1 && length(RS > 0)
                    * \n is NOT a field separator (cf awk book 61,84).
                    * this variable is tested in the inner while loop.
                    */
                   int rtest = '\n';  /* normal case */
                   if (strlen(*RS) > 0)
                           rtest = '\0';
                 for (;;) {                  for (;;) {
                         i++;                          i++;
                         if (i > nfields)                          if (i > nfields)
Line 320 
Line 328 
                                 xfree(fldtab[i]->sval);                                  xfree(fldtab[i]->sval);
                         fldtab[i]->sval = fr;                          fldtab[i]->sval = fr;
                         fldtab[i]->tval = FLD | STR | DONTFREE;                          fldtab[i]->tval = FLD | STR | DONTFREE;
                         while (*r != sep && *r != '\n' && *r != '\0')   /* \n is always a separator */                          while (*r != sep && *r != rtest && *r != '\0')  /* \n is always a separator */
                                 *fr++ = *r++;                                  *fr++ = *r++;
                         *fr++ = 0;                          *fr++ = 0;
                         if (*r++ == 0)                          if (*r++ == 0)
Line 375 
Line 383 
 Cell *fieldadr(int n)   /* get nth field */  Cell *fieldadr(int n)   /* get nth field */
 {  {
         if (n < 0)          if (n < 0)
                 FATAL("trying to access field %d", n);                  FATAL("trying to access out of range field %d", n);
         if (n > nfields)        /* fields after NF are empty */          if (n > nfields)        /* fields after NF are empty */
                 growfldtab(n);  /* but does not increase NF */                  growfldtab(n);  /* but does not increase NF */
         return(fldtab[n]);          return(fldtab[n]);
Line 384 
Line 392 
 void growfldtab(int n)  /* make new fields up to at least $n */  void growfldtab(int n)  /* make new fields up to at least $n */
 {  {
         int nf = 2 * nfields;          int nf = 2 * nfields;
           size_t s;
   
         if (n > nf)          if (n > nf)
                 nf = n;                  nf = n;
         fldtab = (Cell **) realloc(fldtab, (nf+1) * (sizeof (struct Cell *)));          s = (nf+1) * (sizeof (struct Cell *));  /* freebsd: how much do we need? */
           if (s / sizeof(struct Cell *) - 1 == nf) /* didn't overflow */
                   fldtab = (Cell **) realloc(fldtab, s);
           else                                    /* overflow sizeof int */
                   xfree(fldtab);  /* make it null */
         if (fldtab == NULL)          if (fldtab == NULL)
                 FATAL("out of space creating %d fields", nf);                  FATAL("out of space creating %d fields", nf);
         makefields(nfields+1, nf);          makefields(nfields+1, nf);

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