summaryrefslogtreecommitdiff
path: root/contrib/one-true-awk/run.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/one-true-awk/run.c')
-rw-r--r--contrib/one-true-awk/run.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/contrib/one-true-awk/run.c b/contrib/one-true-awk/run.c
index 5f29a643013f..a9e269cc7155 100644
--- a/contrib/one-true-awk/run.c
+++ b/contrib/one-true-awk/run.c
@@ -49,19 +49,20 @@ void tempfree(Cell *p) {
}
*/
-#ifdef _NFILE
-#ifndef FOPEN_MAX
-#define FOPEN_MAX _NFILE
-#endif
-#endif
-
-#ifndef FOPEN_MAX
-#define FOPEN_MAX 40 /* max number of open files */
-#endif
-
-#ifndef RAND_MAX
-#define RAND_MAX 32767 /* all that ansi guarantees */
-#endif
+/* do we really need these? */
+/* #ifdef _NFILE */
+/* #ifndef FOPEN_MAX */
+/* #define FOPEN_MAX _NFILE */
+/* #endif */
+/* #endif */
+/* */
+/* #ifndef FOPEN_MAX */
+/* #define FOPEN_MAX 40 */ /* max number of open files */
+/* #endif */
+/* */
+/* #ifndef RAND_MAX */
+/* #define RAND_MAX 32767 */ /* all that ansi guarantees */
+/* #endif */
jmp_buf env;
extern int pairstack[];
@@ -110,6 +111,7 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr,
if (rminlen)
minlen += quantum - rminlen;
tbuf = (char *) realloc(*pbuf, minlen);
+ dprintf( ("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, *pbuf, tbuf) );
if (tbuf == NULL) {
if (whatrtn)
FATAL("out of memory in %s", whatrtn);
@@ -463,7 +465,7 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
for (np = a[1]; np; np = np->nnext) {
y = execute(np); /* subscript */
s = getsval(y);
- if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
+ if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "array"))
FATAL("out of memory for %s[%s...]", x->nval, buf);
strcat(buf, s);
if (np->nnext)
@@ -510,7 +512,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts *
for (np = a[1]; np; np = np->nnext) {
y = execute(np); /* subscript */
s = getsval(y);
- if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
+ if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "awkdelete"))
FATAL("out of memory deleting %s[%s...]", x->nval, buf);
strcat(buf, s);
if (np->nnext)
@@ -549,7 +551,7 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */
for (p = a[0]; p; p = p->nnext) {
x = execute(p); /* expr */
s = getsval(x);
- if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0))
+ if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "intest"))
FATAL("out of memory deleting %s[%s...]", x->nval, buf);
strcat(buf, s);
tempfree(x);
@@ -819,7 +821,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
if ((fmt = (char *) malloc(fmtsz)) == NULL)
FATAL("out of memory in format()");
while (*s) {
- adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format");
+ adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1");
if (*s != '%') {
*p++ = *s++;
continue;
@@ -833,9 +835,9 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
fmtwd = atoi(s+1);
if (fmtwd < 0)
fmtwd = -fmtwd;
- adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format");
+ adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format2");
for (t = fmt; (*t++ = *s) != '\0'; s++) {
- if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, 0))
+ if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, "format3"))
FATAL("format item %.30s... ran format() out of memory", os);
if (isalpha((uschar)*s) && *s != 'l' && *s != 'h' && *s != 'L')
break; /* the ansi panoply */
@@ -853,7 +855,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
*t = '\0';
if (fmtwd < 0)
fmtwd = -fmtwd;
- adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format");
+ adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format4");
switch (*s) {
case 'f': case 'e': case 'g': case 'E': case 'G':
@@ -887,14 +889,14 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
n = MAXNUMSIZE;
if (fmtwd > n)
n = fmtwd;
- adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format");
+ adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format5");
switch (flag) {
case '?': sprintf(p, "%s", fmt); /* unknown, so dump it too */
t = getsval(x);
n = strlen(t);
if (fmtwd > n)
n = fmtwd;
- adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format");
+ adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format6");
p += strlen(p);
sprintf(p, "%s", t);
break;
@@ -906,7 +908,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
n = strlen(t);
if (fmtwd > n)
n = fmtwd;
- if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, 0))
+ if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format7"))
FATAL("huge string/format (%d chars) in printf %.30s... ran format() out of memory", n, t);
sprintf(p, fmt, t);
break;