run.c revision d09832051bb4b41ce2b3202c09fceedc089678af
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#define DEBUG
#include "awk.def"
#include "math.h"
#include "awk.h"
#include "stdio.h"
#include "ctype.h"
#include "wctype.h"
#include "awktype.h"
#include <stdlib.h>
#define FILENUM 10
struct
{
int type;
#define PA2NUM 29
#define MAXTMP 20
void fldbld(void);
void
{
int i;
execute(a);
/* Wait for children to complete if output to a pipe. */
for (i=0; i<FILENUM; i++)
}
CELL *
{
CELL *x;
NODE *a;
if (u == NULL)
return (true);
for (a = u; /* dummy */; a = a->nnext) {
if (cantexec(a))
return (nodetoobj(a));
if (isfld(x))
fldbld();
if (isexpr(a))
return (x);
/* a statement, goto next statement */
if (isjump(x))
return (x);
return (x);
tempfree(x);
}
}
CELL *
{
CELL *x;
if (a[0] != NULL) {
x = execute(a[0]);
if (isexit(x))
return (true);
if (isjump(x))
tempfree(x);
}
while (getrec()) {
x = execute(a[1]);
if (isexit(x)) {
tempfree(x);
break;
}
tempfree(x);
}
if (a[2] != NULL) {
x = execute(a[2]);
tempfree(x);
}
return (true);
}
CELL *
getline(void)
{
CELL *x;
x = gettemp();
return (x);
}
CELL *
{
CELL *x, *y;
x = execute(a[1]);
y = arrayel(a[0], x);
tempfree(x);
return (y);
}
CELL *
{
wchar_t *s;
CELL *x;
int i;
CELL *y;
s = getsval(b);
x = (CELL *) a;
}
return (y);
}
CELL *
{
CELL *x;
wchar_t *s;
int i;
x = execute(a[0]);
s = getsval(x);
tempfree(x);
i = match(a[1], s);
return (true);
else
return (false);
}
CELL *
{
CELL *x, *y;
int i;
x = execute(a[0]);
i = istrue(x);
tempfree(x);
switch (n) {
case BOR:
if (i) return (true);
y = execute(a[1]);
i = istrue(y);
tempfree(y);
if (i) return (true);
else return (false);
case AND:
if (!i) return (false);
y = execute(a[1]);
i = istrue(y);
tempfree(y);
if (i) return (true);
else return (false);
case NOT:
if (i) return (false);
else return (true);
default:
}
return (false);
}
CELL *
{
int i;
CELL *x, *y;
awkfloat j;
x = execute(a[0]);
y = execute(a[1]);
i = j<0? -1: (j>0? 1: 0);
} else {
else
return (false);
}
tempfree(x);
tempfree(y);
switch (n) {
case LT: if (i<0) return (true);
else return (false);
case LE: if (i<=0) return (true);
else return (false);
case NE: if (i!=0) return (true);
else return (false);
case EQ: if (i == 0) return (true);
else return (false);
case GE: if (i>=0) return (true);
else return (false);
case GT: if (i>0) return (true);
else return (false);
default:
}
return (false);
}
CELL *
gettemp(void)
{
int i;
CELL *x;
for (i=0; i<MAXTMP; i++)
break;
if (i == MAXTMP)
x = &tmps[i];
return (x);
}
CELL *
{
CELL *x;
int m;
x = execute(a[0]);
m = getfval(x);
tempfree(x);
x = fieldadr(m);
return (x);
}
CELL *
{
int k, m, n;
CELL *x, *y;
y = execute(a[0]);
s = getsval(y);
k = wslen(s) + 1;
if (k <= 1) {
x = gettemp();
return (x);
}
x = execute(a[1]);
m = getfval(x);
if (m <= 0)
m = 1;
else if (m > k)
m = k;
tempfree(x);
if (a[2] != 0) {
x = execute(a[2]);
n = getfval(x);
tempfree(x);
}
else
n = k - 1;
if (n < 0)
n = 0;
else if (n > k - m)
n = k - m;
dprintf("substr: m=%d, n=%d, s=%ws\n", m, n, s);
x = gettemp();
temp = s[n+m-1];
setsval(x, s + m - 1);
s[n+m-1] = temp;
tempfree(y);
return (x);
}
CELL *
{
CELL *x;
x = execute(a[0]);
tempfree(x);
x = execute(a[1]);
tempfree(x);
x = gettemp();
;
return (x);
}
}
setfval(x, 0.0);
return (x);
}
wchar_t *
{
wchar_t *p;
char *t;
char fmt[200];
CELL *x;
int flag = 0;
os = s;
if (p == NULL)
while (*s) {
if (*s != '%') {
*p++ = *s++;
continue;
}
if (*(s+1) == '%') {
*p++ = '%';
s += 2;
continue;
}
for (t=fmt; *s != '\0'; s++)
{
if (*s == 's' || *s == 'c')
*t++ = 'w';
*t++ = *s;
if (*s >= 'a' && *s <= 'z' && *s != 'l')
break;
if (*s == '*') {
if (a == NULL) {
"not enough arguments in printf(%ws) or sprintf(%ws)",
}
x = execute(a);
a = a->nnext;
tempfree(x);
}
}
*t = '\0';
switch (*s) {
case 'f': case 'e': case 'g':
flag = 1;
break;
case 'd':
flag = 2;
if (*(s-1) == 'l') break;
*(t-1) = 'l';
*t = 'd';
*++t = '\0';
break;
case 'o': case 'x':
break;
case 'c':
flag = 3;
break;
case 's':
flag = 4;
break;
default:
flag = 0;
break;
}
if (flag == 0) {
p += wslen(p);
continue;
}
if (a == NULL) {
}
x = execute(a);
a = a->nnext;
/*
* Get the string to check length; %s is the usual problem;
* other conversions can cause overrun if they occur when
* the buffer is almost filled.
*/
}
else {
tbuf);
}
/*
* If string overruns the buffer, reallocate;
* consider length of format string
*/
/* Add RECSIZE for additional space */
}
/* Transfer string to buffer */
if (flag == 4)
else
tempfree(x);
p += wslen(p);
if (p >= ep)
s++;
}
*p = '\0';
return (buf);
}
CELL *
{
CELL *x;
NODE *y;
wchar_t *s;
y = a[0]->nnext;
x = execute(a[0]);
tempfree(x);
x = gettemp();
x->sval = s;
return (x);
}
CELL *
{
awkfloat i, j;
CELL *x, *y, *z;
x = execute(a[0]);
i = getfval(x);
tempfree(x);
if (n != UMINUS) {
y = execute(a[1]);
j = getfval(y);
tempfree(y);
}
z = gettemp();
switch (n) {
case ADD:
i += j;
break;
case MINUS:
i -= j;
break;
case MULT:
i *= j;
break;
case DIVIDE:
if (j == 0)
i /= j;
break;
case MOD:
if (j == 0)
i = i - j*(long)(i/j);
break;
case UMINUS:
i = -i;
break;
default:
}
setfval(z, i);
return (z);
}
CELL *
{
CELL *x, *z;
int k;
x = execute(a[0]);
return (x);
}
z = gettemp();
tempfree(x);
return (z);
}
CELL *
{
CELL *x, *y;
x = execute(a[0]);
y = execute(a[1]);
if (n == ASSIGN) { /* ordinary assignment */
tempfree(y);
return (x);
}
switch (n) {
case ADDEQ:
break;
case SUBEQ:
break;
case MULTEQ:
break;
case DIVEQ:
if (yf == 0)
break;
case MODEQ:
if (yf == 0)
break;
default:
break;
}
tempfree(y);
return (x);
}
CELL *
{
CELL *x, *y, *z;
wchar_t *s;
x = execute(a[0]);
y = execute(a[1]);
getsval(x);
getsval(y);
tempfree(y);
z = gettemp();
z->sval = s;
tempfree(x);
return (z);
}
CELL *
{
CELL *x;
if (a[0] == 0)
x = true;
else
x = execute(a[0]);
if (istrue(x)) {
tempfree(x);
x = execute(a[1]);
}
return (x);
}
CELL *
{
CELL *x;
int pair;
pair = (int) a[3];
x = execute(a[0]);
if (istrue(x))
tempfree(x);
}
x = execute(a[1]);
if (istrue(x))
tempfree(x);
x = execute(a[2]);
return (x);
}
return (false);
}
CELL *
{
CELL *x;
x = a_sprintf(a, n);
if (a[1] == NULL) {
tempfree(x);
return (true);
}
return (x);
}
CELL *
{
CELL *x;
wchar_t *s, *p, c;
int n, flag;
x = execute(a[0]);
s = getsval(x);
tempfree(x);
if (a[2] == 0)
else {
x = execute(a[2]);
tempfree(x);
}
freesymtab(ap);
n = 0;
if (sep == ' ')
for (n = 0; /* dummy */; /* dummy */) {
c = *s;
c = *(++s);
if (*s == 0)
break;
n++;
t = s;
do
c = *(++s);
while (! iswblank(c) && c != '\t' &&
c != '\n' && c != '\0');
temp = c;
*s = (wchar_t)0x0;
if (isanumber(t))
else
*s = temp;
if (*s != 0)
s++;
} else if (*s != 0)
for (;;) {
n++;
t = s;
s++;
temp = c;
*s = (wchar_t)0x0;
if (isanumber(t))
else
*s = temp;
if (*s++ == 0)
break;
}
x = gettemp();
x->fval = n;
return (x);
}
CELL *
{
CELL *x;
x = execute(a[0]);
if (istrue(x)) {
tempfree(x);
x = execute(a[1]);
} else if (a[2] != 0) {
tempfree(x);
x = execute(a[2]);
}
return (x);
}
CELL *
{
CELL *x;
for (;;) {
x = execute(a[0]);
if (!istrue(x)) return (x);
tempfree(x);
x = execute(a[1]);
if (isbreak(x)) {
x = true;
return (x);
}
return (x);
tempfree(x);
}
}
CELL *
{
CELL *x;
CELL *z;
z = execute(a[0]);
tempfree(z);
for (;;) {
if (a[1]!=0) {
x = execute(a[1]);
if (!istrue(x)) return (x);
else tempfree(x);
}
x = execute(a[3]);
if (isbreak(x)) { /* turn off break */
x = true;
return (x);
}
return (x);
tempfree(x);
z = execute(a[2]);
tempfree(z);
}
}
CELL *
{
CELL *x;
int i;
for (i = 0; i < MAXSYM; i++) { /* this routine knows too much */
x = execute(a[2]);
if (isbreak(x)) {
x = true;
return (x);
}
return (x);
tempfree(x);
}
}
return (true);
}
CELL *
{
CELL *y;
switch (n) {
case EXIT:
if (a[0] != 0) {
y = execute(a[0]);
}
return (jexit);
case NEXT:
return (jnext);
case BREAK:
return (jbreak);
case CONTINUE:
return (jcont);
default:
}
return (NULL);
}
CELL *
{
CELL *x;
awkfloat u;
int t;
t = (int) a[0];
x = execute(a[1]);
if (t == FLENGTH)
else if (t == FLOG)
else if (t == FINT)
else if (t == FEXP)
else if (t == FSQRT)
else
tempfree(x);
x = gettemp();
setfval(x, u);
return (x);
}
CELL *
{
NODE *x;
CELL *y;
s[0] = '\0';
bp = s;
blen = 0;
y = execute(x);
/* total new length will be */
} else {
}
/* allocate larger buffer if needed */
if (oldbp == s)
if (oldbp == s)
}
tempfree(y);
}
if (a[1] == NULL) {
if (bp != s)
return (true);
}
if (bp != s)
return (false);
}
CELL *
nullproc(void)
{
return (NULL);
}
CELL *
{
CELL *x;
if (isfld(x))
fldbld();
return (x);
}
static void
{
int i;
CELL *x;
x = execute(b);
getsval(x);
for (i=0; i<FILENUM; i++)
goto doit;
for (i=0; i<FILENUM; i++)
break;
if (i >= FILENUM)
if (a == '|') /* a pipe! */
else if (a == APPEND)
else if (a == GT)
else
doit:
#ifndef gcos
#endif
tempfree(x);
}