[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.28 and 1.29

version 1.28, 2020/06/10 21:02:19 version 1.29, 2020/06/10 21:02:33
Line 107 
Line 107 
         infile = stdin;         /* no filenames, so use stdin */          infile = stdin;         /* no filenames, so use stdin */
 }  }
   
   /*
    * POSIX specifies that fields are supposed to be evaluated as if they were
    * split using the value of FS at the time that the record's value ($0) was
    * read.
    *
    * Since field-splitting is done lazily, we save the current value of FS
    * whenever a new record is read in (implicitly or via getline), or when
    * a new value is assigned to $0.
    */
   void savefs(void)
   {
           if (strlen(getsval(fsloc)) >= sizeof (inputFS))
                   FATAL("field separator %.10s... is too long", *FS);
           strlcpy(inputFS, *FS, sizeof(inputFS));
   }
   
 static int firsttime = 1;  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 */
Line 125 
Line 141 
         if (isrecord) {          if (isrecord) {
                 donefld = 0;                  donefld = 0;
                 donerec = 1;                  donerec = 1;
                   savefs();
         }          }
         saveb0 = buf[0];          saveb0 = buf[0];
         buf[0] = 0;          buf[0] = 0;
Line 194 
Line 211 
         int bufsize = *pbufsize;          int bufsize = *pbufsize;
         char *rs = getsval(rsloc);          char *rs = getsval(rsloc);
   
         if (strlen(getsval(fsloc)) >= sizeof (inputFS))  
                 FATAL("field separator %.10s... is too long", *FS);  
         /*fflush(stdout); avoids some buffering problem but makes it 25% slower*/  
         strlcpy(inputFS, *FS, sizeof inputFS);  /* for subsequent field splitting */  
         if ((sep = *rs) == 0) {          if ((sep = *rs) == 0) {
                 sep = '\n';                  sep = '\n';
                 while ((c=getc(inf)) == '\n' && c != EOF)       /* skip leading \n's */                  while ((c=getc(inf)) == '\n' && c != EOF)       /* skip leading \n's */
Line 287 
Line 300 
         }          }
         fr = fields;          fr = fields;
         i = 0;  /* number of fields accumulated here */          i = 0;  /* number of fields accumulated here */
         if (strlen(getsval(fsloc)) >= sizeof (inputFS))  
                 FATAL("field separator %.10s... is too long", *FS);  
         strlcpy(inputFS, *FS, sizeof(inputFS));  
         if (strlen(inputFS) > 1) {      /* it's a regular expression */          if (strlen(inputFS) > 1) {      /* it's a regular expression */
                 i = refldbld(r, inputFS);                  i = refldbld(r, inputFS);
         } else if ((sep = *inputFS) == ' ') {   /* default whitespace */          } else if ((sep = *inputFS) == ' ') {   /* default whitespace */
Line 480 
Line 490 
                         break;                          break;
                 }                  }
         }          }
         return i;          return i;
 }  }
   
 void recbld(void)       /* create $0 from $1..$NF if necessary */  void recbld(void)       /* create $0 from $1..$NF if necessary */
Line 661 
Line 671 
         static int been_here = 0;          static int been_here = 0;
         extern char ebuf[], *ep;          extern char ebuf[], *ep;
   
         if (compile_time == 2 || compile_time == 0 || been_here++ > 0 ||          if (compile_time == 2 || compile_time == 0 || been_here++ > 0 || ebuf == ep)
             ebuf == ep)  
                 return;                  return;
         p = ep - 1;          p = ep - 1;
         if (p > ebuf && *p == '\n')          if (p > ebuf && *p == '\n')

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29