[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.17 and 1.18

version 1.17, 2007/09/02 15:19:31 version 1.18, 2008/10/06 20:38:33
Line 44 
Line 44 
 Cell    **fldtab;       /* pointers to Cells */  Cell    **fldtab;       /* pointers to Cells */
 char    inputFS[100] = " ";  char    inputFS[100] = " ";
   
 #define MAXFLD  200  #define MAXFLD  2
 int     nfields = MAXFLD;       /* last allocated slot for $i */  int     nfields = MAXFLD;       /* last allocated slot for $i */
   
 int     donefld;        /* 1 = implies rec broken into fields */  int     donefld;        /* 1 = implies rec broken into fields */
Line 59 
Line 59 
   
 void recinit(unsigned int n)  void recinit(unsigned int n)
 {  {
         record = (char *) malloc(n);          if ( (record = (char *) malloc(n)) == NULL
         fields = (char *) malloc(n);            || (fields = (char *) malloc(n+1)) == NULL
         fldtab = (Cell **) calloc((nfields+1), sizeof(Cell *));            || (fldtab = (Cell **) calloc(nfields+1, sizeof(Cell *))) == NULL
         if (record == NULL || fields == NULL || fldtab == NULL)            || (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL )
                 FATAL("out of space for $0 and fields");                  FATAL("out of space for $0 and fields");
   
         fldtab[0] = (Cell *) malloc(sizeof (Cell));  
         if (fldtab[0] == NULL)  
                 FATAL("out of space for fields");  
         *fldtab[0] = dollar0;          *fldtab[0] = dollar0;
         fldtab[0]->sval = record;          fldtab[0]->sval = record;
         fldtab[0]->nval = tostring("0");          fldtab[0]->nval = tostring("0");
Line 111 
Line 107 
 {                       /* note: cares whether buf == record */  {                       /* note: cares whether buf == record */
         int c;          int c;
         char *buf = *pbuf;          char *buf = *pbuf;
         int bufsize = *pbufsize;          uschar saveb0;
           int bufsize = *pbufsize, savebufsize = bufsize;
   
         if (firsttime) {          if (firsttime) {
                 firsttime = 0;                  firsttime = 0;
Line 123 
Line 120 
                 donefld = 0;                  donefld = 0;
                 donerec = 1;                  donerec = 1;
         }          }
           saveb0 = buf[0];
         buf[0] = 0;          buf[0] = 0;
         while (argno < *ARGC || infile == stdin) {          while (argno < *ARGC || infile == stdin) {
                    dprintf( ("argno=%d, file=|%s|\n", argno, file) );                     dprintf( ("argno=%d, file=|%s|\n", argno, file) );
Line 169 
Line 167 
                 infile = NULL;                  infile = NULL;
                 argno++;                  argno++;
         }          }
           buf[0] = saveb0;
         *pbuf = buf;          *pbuf = buf;
         *pbufsize = bufsize;          *pbufsize = savebufsize;
         return 0;       /* true end of file */          return 0;       /* true end of file */
 }  }
   
 void nextfile(void)  void nextfile(void)
 {  {
         if (infile != stdin && infile != NULL)          if (infile != NULL && infile != stdin)
                 fclose(infile);                  fclose(infile);
         infile = NULL;          infile = NULL;
         argno++;          argno++;

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18