version 1.11, 1997/04/06 06:31:51 |
version 1.12, 1997/04/07 15:59:56 |
|
|
jmp_buf env; |
jmp_buf env; |
|
|
#define PA2NUM 29 /* max number of pat,pat patterns allowed */ |
#define PA2NUM 29 /* max number of pat,pat patterns allowed */ |
long paircnt; /* number of them in use */ |
int paircnt; /* number of them in use */ |
long pairstack[PA2NUM]; /* state of each pat,pat */ |
int pairstack[PA2NUM]; /* state of each pat,pat */ |
|
|
Node *winner = NULL; /* root of parse tree */ |
Node *winner = NULL; /* root of parse tree */ |
Cell *tmps; /* free temporary cells for execution */ |
Cell *tmps; /* free temporary cells for execution */ |
|
|
} |
} |
for (ncall = 0, x = a[1]; x != NULL; x = x->nnext) /* args in call */ |
for (ncall = 0, x = a[1]; x != NULL; x = x->nnext) /* args in call */ |
ncall++; |
ncall++; |
ndef = (long) fcn->fval; /* args in defn */ |
ndef = (int) fcn->fval; /* args in defn */ |
dprintf( ("calling %s, %d args (%d in defn), fp=%d\n", s, ncall, ndef, fp-frame) ); |
dprintf( ("calling %s, %d args (%d in defn), fp=%d\n", s, ncall, ndef, fp-frame) ); |
if (ncall > ndef) |
if (ncall > ndef) |
ERROR "function %s called with %d args, uses only %d", |
ERROR "function %s called with %d args, uses only %d", |
|
|
Cell *arg(Node **a, int n) /* nth argument of a function */ |
Cell *arg(Node **a, int n) /* nth argument of a function */ |
{ |
{ |
|
|
n = (long) a[0]; /* argument number, counting from 0 */ |
n = (int) a[0]; /* argument number, counting from 0 */ |
dprintf( ("arg(%d), fp->nargs=%d\n", n, fp->nargs) ); |
dprintf( ("arg(%d), fp->nargs=%d\n", n, fp->nargs) ); |
if (n+1 > fp->nargs) |
if (n+1 > fp->nargs) |
ERROR "argument #%d of function %s was not supplied", |
ERROR "argument #%d of function %s was not supplied", |
|
|
r = gettemp(); |
r = gettemp(); |
if (a[1] != NULL) { /* getline < file */ |
if (a[1] != NULL) { /* getline < file */ |
x = execute(a[2]); /* filename */ |
x = execute(a[2]); /* filename */ |
if ((long) a[1] == '|') /* input pipe */ |
if ((int) a[1] == '|') /* input pipe */ |
a[1] = (Node *) LE; /* arbitrary flag */ |
a[1] = (Node *) LE; /* arbitrary flag */ |
fp = openfile((long) a[1], getsval(x)); |
fp = openfile((int) a[1], getsval(x)); |
tempfree(x); |
tempfree(x); |
if (fp == NULL) |
if (fp == NULL) |
n = -1; |
n = -1; |
|
|
if (*s == '*') { |
if (*s == '*') { |
x = execute(a); |
x = execute(a); |
a = a->nnext; |
a = a->nnext; |
sprintf((char *)t-1, "%ld", (long) getfval(x)); |
sprintf((char *)t-1, "%d", (int) getfval(x)); |
t = fmt + strlen(fmt); |
t = fmt + strlen(fmt); |
tempfree(x); |
tempfree(x); |
} |
} |
|
|
break; |
break; |
case 1: sprintf((char *)p, (char *)fmt, getfval(x)); break; |
case 1: sprintf((char *)p, (char *)fmt, getfval(x)); break; |
case 2: sprintf((char *)p, (char *)fmt, (long) getfval(x)); break; |
case 2: sprintf((char *)p, (char *)fmt, (long) getfval(x)); break; |
case 3: sprintf((char *)p, (char *)fmt, (long) getfval(x)); break; |
case 3: sprintf((char *)p, (char *)fmt, (int) getfval(x)); break; |
case 4: |
case 4: |
t = getsval(x); |
t = getsval(x); |
n = strlen(t); |
n = strlen(t); |
|
|
case 5: |
case 5: |
isnum(x) ? |
isnum(x) ? |
(getfval(x) ? |
(getfval(x) ? |
sprintf((char *)p, (char *)fmt, (long) getfval(x)) |
sprintf((char *)p, (char *)fmt, (int) getfval(x)) |
: (*p++ = '\0')) |
: (*p++ = '\0')) |
: sprintf((char *)p, (char *)fmt, getsval(x)[0]); |
: sprintf((char *)p, (char *)fmt, getsval(x)[0]); |
break; |
break; |
|
|
*p = '\0'; |
*p = '\0'; |
for ( ; a; a = a->nnext) /* evaluate any remaining args */ |
for ( ; a; a = a->nnext) /* evaluate any remaining args */ |
execute(a); |
execute(a); |
return ((long)(p - buf)); |
return ((int)(p - buf)); |
} |
} |
|
|
Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ |
Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */ |
|
|
if (ferror(stdout)) |
if (ferror(stdout)) |
ERROR "write error on stdout" FATAL; |
ERROR "write error on stdout" FATAL; |
} else { |
} else { |
fp = redirect((long)a[1], a[2]); |
fp = redirect((int)a[1], a[2]); |
fwrite(buf, len, 1, fp); |
fwrite(buf, len, 1, fp); |
fflush(fp); |
fflush(fp); |
if (ferror(fp)) |
if (ferror(fp)) |
|
|
break; |
break; |
case POWER: |
case POWER: |
if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ |
if (j >= 0 && modf(j, &v) == 0.0) /* pos integer exponent */ |
i = ipow(i, (long) j); |
i = ipow(i, (int) j); |
else |
else |
i = errcheck(pow(i, j), "pow"); |
i = errcheck(pow(i, j), "pow"); |
break; |
break; |
|
|
break; |
break; |
case POWEQ: |
case POWEQ: |
if (yf >= 0 && modf(yf, &v) == 0.0) /* pos integer exponent */ |
if (yf >= 0 && modf(yf, &v) == 0.0) /* pos integer exponent */ |
xf = ipow(xf, (long) yf); |
xf = ipow(xf, (int) yf); |
else |
else |
xf = errcheck(pow(xf, yf), "pow"); |
xf = errcheck(pow(xf, yf), "pow"); |
break; |
break; |
|
|
Cell *x; |
Cell *x; |
int pair; |
int pair; |
|
|
pair = (long) a[3]; |
pair = (int) a[3]; |
if (pairstack[pair] == 0) { |
if (pairstack[pair] == 0) { |
x = execute(a[0]); |
x = execute(a[0]); |
if (istrue(x)) |
if (istrue(x)) |
|
|
s = getsval(y); |
s = getsval(y); |
if (a[2] == 0) /* fs string */ |
if (a[2] == 0) /* fs string */ |
fs = *FS; |
fs = *FS; |
else if ((long) a[3] == STRING) { /* split(str,arr,"string") */ |
else if ((int) a[3] == STRING) { /* split(str,arr,"string") */ |
x = execute(a[2]); |
x = execute(a[2]); |
fs = getsval(x); |
fs = getsval(x); |
} else if ((long) a[3] == REGEXPR) |
} else if ((int) a[3] == REGEXPR) |
fs = (char*) "(regexpr)"; /* split(str,arr,/regexpr/) */ |
fs = (char*) "(regexpr)"; /* split(str,arr,/regexpr/) */ |
else |
else |
ERROR "illegal type of split()" FATAL; |
ERROR "illegal type of split()" FATAL; |
|
|
ap->sval = (char *) makesymtab(NSYMTAB); |
ap->sval = (char *) makesymtab(NSYMTAB); |
|
|
n = 0; |
n = 0; |
if ((*s != '\0' && strlen(fs) > 1) || (long) a[3] == REGEXPR) { /* reg expr */ |
if ((*s != '\0' && strlen(fs) > 1) || (int) a[3] == REGEXPR) { /* reg expr */ |
fa *pfa; |
fa *pfa; |
if ((long) a[3] == REGEXPR) { /* it's ready already */ |
if ((int) a[3] == REGEXPR) { /* it's ready already */ |
pfa = (fa *) a[2]; |
pfa = (fa *) a[2]; |
} else { |
} else { |
pfa = makedfa(fs, 1); |
pfa = makedfa(fs, 1); |
|
|
} |
} |
tempfree(ap); |
tempfree(ap); |
tempfree(y); |
tempfree(y); |
if (a[2] != 0 && (long) a[3] == STRING) |
if (a[2] != 0 && (int) a[3] == STRING) |
tempfree(x); |
tempfree(x); |
x = gettemp(); |
x = gettemp(); |
x->tval = NUM; |
x->tval = NUM; |
|
|
Node *nextarg; |
Node *nextarg; |
FILE *fp; |
FILE *fp; |
|
|
t = (long) a[0]; |
t = (int) a[0]; |
x = execute(a[1]); |
x = execute(a[1]); |
nextarg = a[1]->nnext; |
nextarg = a[1]->nnext; |
switch (t) { |
switch (t) { |
|
|
u = time((time_t *)0); |
u = time((time_t *)0); |
else |
else |
u = getfval(x); |
u = getfval(x); |
srand((long) u); u = (long) u; |
srand((int) u); u = (int) u; |
break; |
break; |
case FTOUPPER: |
case FTOUPPER: |
case FTOLOWER: |
case FTOLOWER: |
|
|
if (a[1] == 0) /* a[1] is redirection operator, a[2] is file */ |
if (a[1] == 0) /* a[1] is redirection operator, a[2] is file */ |
fp = stdout; |
fp = stdout; |
else |
else |
fp = redirect((long)a[1], a[2]); |
fp = redirect((int)a[1], a[2]); |
for (x = a[0]; x != NULL; x = x->nnext) { |
for (x = a[0]; x != NULL; x = x->nnext) { |
y = execute(x); |
y = execute(x); |
fputs((char *)getsval(y), fp); |
fputs((char *)getsval(y), fp); |