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

Diff for /src/usr.bin/awk/run.c between version 1.68 and 1.69

version 1.68, 2020/08/28 16:29:16 version 1.69, 2020/12/09 20:00:11
Line 119 
Line 119 
                 /* round up to next multiple of quantum */                  /* round up to next multiple of quantum */
                 if (rminlen)                  if (rminlen)
                         minlen += quantum - rminlen;                          minlen += quantum - rminlen;
                 tbuf = realloc(*pbuf, minlen);                  tbuf = (char *) realloc(*pbuf, minlen);
                 DPRINTF("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, (void*)*pbuf, (void*)tbuf);                  DPRINTF("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, (void*)*pbuf, (void*)tbuf);
                 if (tbuf == NULL) {                  if (tbuf == NULL) {
                         if (whatrtn)                          if (whatrtn)
Line 241 
Line 241 
         if (!isfcn(fcn))          if (!isfcn(fcn))
                 FATAL("calling undefined function %s", s);                  FATAL("calling undefined function %s", s);
         if (frame == NULL) {          if (frame == NULL) {
                 frp = frame = calloc(nframe += 100, sizeof(*frame));                  frp = frame = (struct Frame *) calloc(nframe += 100, sizeof(*frame));
                 if (frame == NULL)                  if (frame == NULL)
                         FATAL("out of space for stack frames calling %s", s);                          FATAL("out of space for stack frames calling %s", s);
         }          }
Line 275 
Line 275 
         frp++;  /* now ok to up frame */          frp++;  /* now ok to up frame */
         if (frp >= frame + nframe) {          if (frp >= frame + nframe) {
                 int dfp = frp - frame;  /* old index */                  int dfp = frp - frame;  /* old index */
                 frame = reallocarray(frame, (nframe += 100), sizeof(*frame));                  frame = (struct Frame *) reallocarray(frame, (nframe += 100), sizeof(*frame));
                 if (frame == NULL)                  if (frame == NULL)
                         FATAL("out of space for stack frames in %s", s);                          FATAL("out of space for stack frames in %s", s);
                 frp = frame + dfp;                  frp = frame + dfp;
Line 408 
Line 408 
         int bufsize = recsize;          int bufsize = recsize;
         int mode;          int mode;
         bool newflag;          bool newflag;
           double result;
   
         if ((buf = malloc(bufsize)) == NULL)          if ((buf = (char *) malloc(bufsize)) == NULL)
                 FATAL("out of memory in getline");                  FATAL("out of memory in getline");
   
         fflush(stdout); /* in case someone is waiting for a prompt */          fflush(stdout); /* in case someone is waiting for a prompt */
Line 430 
Line 431 
                 } else if (a[0] != NULL) {      /* getline var <file */                  } else if (a[0] != NULL) {      /* getline var <file */
                         x = execute(a[0]);                          x = execute(a[0]);
                         setsval(x, buf);                          setsval(x, buf);
                         if (is_number(x->sval)) {                          if (is_number(x->sval, & result)) {
                                 x->fval = atof(x->sval);                                  x->fval = result;
                                 x->tval |= NUM;                                  x->tval |= NUM;
                         }                          }
                         tempfree(x);                          tempfree(x);
                 } else {                        /* getline <file */                  } else {                        /* getline <file */
                         setsval(fldtab[0], buf);                          setsval(fldtab[0], buf);
                         if (is_number(fldtab[0]->sval)) {                          if (is_number(fldtab[0]->sval, & result)) {
                                 fldtab[0]->fval = atof(fldtab[0]->sval);                                  fldtab[0]->fval = result;
                                 fldtab[0]->tval |= NUM;                                  fldtab[0]->tval |= NUM;
                         }                          }
                 }                  }
Line 449 
Line 450 
                         n = getrec(&buf, &bufsize, false);                          n = getrec(&buf, &bufsize, false);
                         x = execute(a[0]);                          x = execute(a[0]);
                         setsval(x, buf);                          setsval(x, buf);
                         if (is_number(x->sval)) {                          if (is_number(x->sval, & result)) {
                                 x->fval = atof(x->sval);                                  x->fval = result;
                                 x->tval |= NUM;                                  x->tval |= NUM;
                         }                          }
                         tempfree(x);                          tempfree(x);
Line 475 
Line 476 
         int bufsz = recsize;          int bufsz = recsize;
         size_t blen;          size_t blen;
   
         if ((buf = malloc(bufsz)) == NULL) {          if ((buf = (char *) malloc(bufsz)) == NULL) {
                 FATAL("%s: out of memory", func);                  FATAL("%s: out of memory", func);
         }          }
   
Line 702 
Line 703 
         Cell *x;          Cell *x;
   
         if (!tmps) {          if (!tmps) {
                 tmps = calloc(100, sizeof(*tmps));                  tmps = (Cell *) calloc(100, sizeof(*tmps));
                 if (!tmps)                  if (!tmps)
                         FATAL("out of space for temporaries");                          FATAL("out of space for temporaries");
                 for (i = 1; i < 100; i++)                  for (i = 1; i < 100; i++)
Line 727 
Line 728 
         if ((Awkfloat)INT_MAX < val)          if ((Awkfloat)INT_MAX < val)
                 FATAL("trying to access out of range field %s", x->nval);                  FATAL("trying to access out of range field %s", x->nval);
         m = (int) val;          m = (int) val;
         if (m == 0 && !is_number(s = getsval(x)))       /* suspicion! */          if (m == 0 && !is_number(s = getsval(x), NULL)) /* suspicion! */
                 FATAL("illegal field $(%s), name \"%s\"", s, x->nval);                  FATAL("illegal field $(%s), name \"%s\"", s, x->nval);
                 /* BUG: can x->nval ever be null??? */                  /* BUG: can x->nval ever be null??? */
         tempfree(x);          tempfree(x);
Line 840 
Line 841 
   
         os = s;          os = s;
         p = buf;          p = buf;
         if ((fmt = malloc(fmtsz)) == NULL)          if ((fmt = (char *) malloc(fmtsz)) == NULL)
                 FATAL("out of memory in format()");                  FATAL("out of memory in format()");
         while (*s) {          while (*s) {
                 adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1");                  adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1");
Line 983 
Line 984 
         char *buf;          char *buf;
         int bufsz=3*recsize;          int bufsz=3*recsize;
   
         if ((buf = malloc(bufsz)) == NULL)          if ((buf = (char *) malloc(bufsz)) == NULL)
                 FATAL("out of memory in awksprintf");                  FATAL("out of memory in awksprintf");
         y = a[0]->nnext;          y = a[0]->nnext;
         x = execute(a[0]);          x = execute(a[0]);
Line 1006 
Line 1007 
         int len;          int len;
         int bufsz=3*recsize;          int bufsz=3*recsize;
   
         if ((buf = malloc(bufsz)) == NULL)          if ((buf = (char *) malloc(bufsz)) == NULL)
                 FATAL("out of memory in awkprintf");                  FATAL("out of memory in awkprintf");
         y = a[0]->nnext;          y = a[0]->nnext;
         x = execute(a[0]);          x = execute(a[0]);
Line 1260 
Line 1261 
         int sep;          int sep;
         char temp, num[50];          char temp, num[50];
         int n, tempstat, arg3type;          int n, tempstat, arg3type;
           double result;
   
         y = execute(a[0]);      /* source string */          y = execute(a[0]);      /* source string */
         origs = s = strdup(getsval(y));          origs = s = strdup(getsval(y));
Line 1308 
Line 1310 
                                 snprintf(num, sizeof(num), "%d", n);                                  snprintf(num, sizeof(num), "%d", n);
                                 temp = *patbeg;                                  temp = *patbeg;
                                 setptr(patbeg, '\0');                                  setptr(patbeg, '\0');
                                 if (is_number(s))                                  if (is_number(s, & result))
                                         setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);                                          setsymtab(num, s, result, STR|NUM, (Array *) ap->sval);
                                 else                                  else
                                         setsymtab(num, s, 0.0, STR, (Array *) ap->sval);                                          setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
                                 setptr(patbeg, temp);                                  setptr(patbeg, temp);
Line 1327 
Line 1329 
                 }                  }
                 n++;                  n++;
                 snprintf(num, sizeof(num), "%d", n);                  snprintf(num, sizeof(num), "%d", n);
                 if (is_number(s))                  if (is_number(s, & result))
                         setsymtab(num, s, atof(s), STR|NUM, (Array *) ap->sval);                          setsymtab(num, s, result, STR|NUM, (Array *) ap->sval);
                 else                  else
                         setsymtab(num, s, 0.0, STR, (Array *) ap->sval);                          setsymtab(num, s, 0.0, STR, (Array *) ap->sval);
   spdone:    spdone:
Line 1348 
Line 1350 
                         temp = *s;                          temp = *s;
                         setptr(s, '\0');                          setptr(s, '\0');
                         snprintf(num, sizeof(num), "%d", n);                          snprintf(num, sizeof(num), "%d", n);
                         if (is_number(t))                          if (is_number(t, & result))
                                 setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);                                  setsymtab(num, t, result, STR|NUM, (Array *) ap->sval);
                         else                          else
                                 setsymtab(num, t, 0.0, STR, (Array *) ap->sval);                                  setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
                         setptr(s, temp);                          setptr(s, temp);
Line 1377 
Line 1379 
                         temp = *s;                          temp = *s;
                         setptr(s, '\0');                          setptr(s, '\0');
                         snprintf(num, sizeof(num), "%d", n);                          snprintf(num, sizeof(num), "%d", n);
                         if (is_number(t))                          if (is_number(t, & result))
                                 setsymtab(num, t, atof(t), STR|NUM, (Array *) ap->sval);                                  setsymtab(num, t, result, STR|NUM, (Array *) ap->sval);
                         else                          else
                                 setsymtab(num, t, 0.0, STR, (Array *) ap->sval);                                  setsymtab(num, t, 0.0, STR, (Array *) ap->sval);
                         setptr(s, temp);                          setptr(s, temp);
Line 1573 
Line 1575 
         }          }
 }  }
   
   #ifdef __DJGPP__
   static wint_t towupper(wint_t wc)
   {
           if (wc >= 0 && wc < 256)
                   return toupper(wc & 0xFF);
   
           return wc;
   }
   
   static wint_t towlower(wint_t wc)
   {
           if (wc >= 0 && wc < 256)
                   return tolower(wc & 0xFF);
   
           return wc;
   }
   #endif
   
 static char *nawk_toupper(const char *s)  static char *nawk_toupper(const char *s)
 {  {
         return nawk_convert(s, toupper, towupper);          return nawk_convert(s, toupper, towupper);
Line 1794 
Line 1814 
                 sz = 32;                  sz = 32;
                 buf = NULL;                  buf = NULL;
                 do {                  do {
                         if ((buf = reallocarray(buf, 2, sz)) == NULL)                          if ((buf = (char *) reallocarray(buf, 2, sz)) == NULL)
                                 FATAL("out of memory in strftime");                                  FATAL("out of memory in strftime");
                         sz *= 2;                          sz *= 2;
                 } while (strftime(buf, sz, fmt, tm) == 0 && fmt[0] != '\0');                  } while (strftime(buf, sz, fmt, tm) == 0 && fmt[0] != '\0');
Line 1878 
Line 1898 
 static void stdinit(void)       /* in case stdin, etc., are not constants */  static void stdinit(void)       /* in case stdin, etc., are not constants */
 {  {
         nfiles = FOPEN_MAX;          nfiles = FOPEN_MAX;
         files = calloc(nfiles, sizeof(*files));          files = (struct files *) calloc(nfiles, sizeof(*files));
         if (files == NULL)          if (files == NULL)
                 FATAL("can't allocate file memory for %zu files", nfiles);                  FATAL("can't allocate file memory for %zu files", nfiles);
         files[0].fp = stdin;          files[0].fp = stdin;
Line 1918 
Line 1938 
         if (i >= nfiles) {          if (i >= nfiles) {
                 struct files *nf;                  struct files *nf;
                 size_t nnf = nfiles + FOPEN_MAX;                  size_t nnf = nfiles + FOPEN_MAX;
                 nf = reallocarray(files, nnf, sizeof(*nf));                  nf = (struct files *) reallocarray(files, nnf, sizeof(*nf));
                 if (nf == NULL)                  if (nf == NULL)
                         FATAL("cannot grow files for %s and %zu files", s, nnf);                          FATAL("cannot grow files for %s and %zu files", s, nnf);
                 memset(&nf[nfiles], 0, FOPEN_MAX * sizeof(*nf));                  memset(&nf[nfiles], 0, FOPEN_MAX * sizeof(*nf));
Line 2039 
Line 2059 
         fa *pfa;          fa *pfa;
         int bufsz = recsize;          int bufsz = recsize;
   
         if ((buf = malloc(bufsz)) == NULL)          if ((buf = (char *) malloc(bufsz)) == NULL)
                 FATAL("out of memory in sub");                  FATAL("out of memory in sub");
         x = execute(a[3]);      /* target string */          x = execute(a[3]);      /* target string */
         t = getsval(x);          t = getsval(x);
Line 2101 
Line 2121 
         int mflag, tempstat, num;          int mflag, tempstat, num;
         int bufsz = recsize;          int bufsz = recsize;
   
         if ((buf = malloc(bufsz)) == NULL)          if ((buf = (char *) malloc(bufsz)) == NULL)
                 FATAL("out of memory in gsub");                  FATAL("out of memory in gsub");
         mflag = 0;      /* if mflag == 0, can replace empty string */          mflag = 0;      /* if mflag == 0, can replace empty string */
         num = 0;          num = 0;

Legend:
Removed from v.1.68  
changed lines
  Added in v.1.69