Diff for /rpl/rplawk/lib.c between versions 1.1 and 1.2

version 1.1, 2010/09/07 12:53:05 version 1.2, 2013/06/12 09:47:52
Line 89  void initgetrec(void) Line 89  void initgetrec(void)
     char *p;      char *p;
   
     for (i = 1; i < *ARGC; i++) {      for (i = 1; i < *ARGC; i++) {
         if (!isclvar(p = getargv(i))) { /* find 1st real filename */          p = getargv(i); /* find 1st real filename */
             setsval(lookup("FILENAME", symtab), getargv(i));          if (p == NULL || *p == '\0') {  /* deleted or zapped */
               argno++;
               continue;
           }
           if (!isclvar(p)) {
               setsval(lookup("FILENAME", symtab), p);
             return;              return;
         }          }
         setclvar(p);    /* a commandline assignment before filename */          setclvar(p);    /* a commandline assignment before filename */
Line 124  int getrec(char **pbuf, int *pbufsize, i Line 129  int getrec(char **pbuf, int *pbufsize, i
            dprintf( ("argno=%d, file=|%s|\n", argno, file) );             dprintf( ("argno=%d, file=|%s|\n", argno, file) );
         if (infile == NULL) {   /* have to open a new file */          if (infile == NULL) {   /* have to open a new file */
             file = getargv(argno);              file = getargv(argno);
             if (*file == '\0') {    /* it's been zapped */              if (file == NULL || *file == '\0') {    /* deleted or zapped */
                 argno++;                  argno++;
                 continue;                  continue;
             }              }
Line 187  int readrec(char **pbuf, int *pbufsize, Line 192  int readrec(char **pbuf, int *pbufsize,
   
     if (strlen(*FS) >= sizeof(inputFS))      if (strlen(*FS) >= sizeof(inputFS))
         FATAL("field separator %.10s... is too long", *FS);          FATAL("field separator %.10s... is too long", *FS);
       /*fflush(stdout); avoids some buffering problem but makes it 25% slower*/
     strcpy(inputFS, *FS);   /* for subsequent field splitting */      strcpy(inputFS, *FS);   /* for subsequent field splitting */
     if ((sep = **RS) == 0) {      if ((sep = **RS) == 0) {
         sep = '\n';          sep = '\n';
Line 227  char *getargv(int n) /* get ARGV[n] */ Line 233  char *getargv(int n) /* get ARGV[n] */
     extern Array *ARGVtab;      extern Array *ARGVtab;
   
     sprintf(temp, "%d", n);      sprintf(temp, "%d", n);
       if (lookup(temp, ARGVtab) == NULL)
           return NULL;
     x = setsymtab(temp, "", 0.0, STR, ARGVtab);      x = setsymtab(temp, "", 0.0, STR, ARGVtab);
     s = getsval(x);      s = getsval(x);
        dprintf( ("getargv(%d) returns |%s|\n", n, s) );         dprintf( ("getargv(%d) returns |%s|\n", n, s) );
Line 256  void fldbld(void) /* create fields from Line 264  void fldbld(void) /* create fields from
 {  {
     /* this relies on having fields[] the same length as $0 */      /* this relies on having fields[] the same length as $0 */
     /* the fields are all stored in this one array with \0's */      /* the fields are all stored in this one array with \0's */
       /* possibly with a final trailing \0 not associated with any field */
     char *r, *fr, sep;      char *r, *fr, sep;
     Cell *p;      Cell *p;
     int i, j, n;      int i, j, n;
Line 268  void fldbld(void) /* create fields from Line 277  void fldbld(void) /* create fields from
     n = strlen(r);      n = strlen(r);
     if (n > fieldssize) {      if (n > fieldssize) {
         xfree(fields);          xfree(fields);
         if ((fields = (char *) malloc(n+1)) == NULL)          if ((fields = (char *) malloc(n+2)) == NULL) /* possibly 2 final \0s */
             FATAL("out of space for fields in fldbld %d", n);              FATAL("out of space for fields in fldbld %d", n);
         fieldssize = n;          fieldssize = n;
     }      }
Line 476  void recbld(void) /* create $0 from $1.. Line 485  void recbld(void) /* create $0 from $1..
     if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3"))      if (!adjbuf(&record, &recsize, 2+r-record, recsize, &r, "recbld 3"))
         FATAL("built giant record `%.30s...'", record);          FATAL("built giant record `%.30s...'", record);
     *r = '\0';      *r = '\0';
        dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );         dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
   
     if (freeable(fldtab[0]))      if (freeable(fldtab[0]))
         xfree(fldtab[0]->sval);          xfree(fldtab[0]->sval);
     fldtab[0]->tval = REC | STR | DONTFREE;      fldtab[0]->tval = REC | STR | DONTFREE;
     fldtab[0]->sval = record;      fldtab[0]->sval = record;
   
        dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, fldtab[0]) );         dprintf( ("in recbld inputFS=%s, fldtab[0]=%p\n", inputFS, (void*)fldtab[0]) );
        dprintf( ("recbld = |%s|\n", record) );         dprintf( ("recbld = |%s|\n", record) );
     donerec = 1;      donerec = 1;
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.2


CVSweb interface <joel.bertrand@systella.fr>