17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
237c478bd9Sstevel@tonic-gate /* All Rights Reserved */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate #include "awk.def"
267c478bd9Sstevel@tonic-gate #include "awk.h"
277c478bd9Sstevel@tonic-gate #include "stdio.h"
28*4774dff6SToomas Soome #include "stdint.h"
297c478bd9Sstevel@tonic-gate
nodealloc(int n)30*4774dff6SToomas Soome NODE *nodealloc(int n)
317c478bd9Sstevel@tonic-gate {
32*4774dff6SToomas Soome NODE *x;
33*4774dff6SToomas Soome x = (NODE *) malloc(sizeof (NODE) + n * sizeof (NODE *));
347c478bd9Sstevel@tonic-gate if (x == NULL)
357c478bd9Sstevel@tonic-gate error(FATAL, "out of space in nodealloc");
367c478bd9Sstevel@tonic-gate return (x);
377c478bd9Sstevel@tonic-gate }
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate
exptostat(NODE * a)42*4774dff6SToomas Soome NODE *exptostat(NODE *a)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate a->ntype = NSTAT;
457c478bd9Sstevel@tonic-gate return (a);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate
node0(int a)51*4774dff6SToomas Soome NODE *node0(int a)
527c478bd9Sstevel@tonic-gate {
53*4774dff6SToomas Soome NODE *x;
54*4774dff6SToomas Soome x = nodealloc(0); /* No space for narg */
557c478bd9Sstevel@tonic-gate x->nnext = NULL;
567c478bd9Sstevel@tonic-gate x->nobj = a;
577c478bd9Sstevel@tonic-gate return (x);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate
node1(int a,NODE * b)63*4774dff6SToomas Soome NODE *node1(int a, NODE *b)
647c478bd9Sstevel@tonic-gate {
65*4774dff6SToomas Soome NODE *x;
667c478bd9Sstevel@tonic-gate x = nodealloc(1);
677c478bd9Sstevel@tonic-gate x->nnext = NULL;
687c478bd9Sstevel@tonic-gate x->nobj = a;
697c478bd9Sstevel@tonic-gate x->narg[0]=b;
707c478bd9Sstevel@tonic-gate return (x);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate
node2(int a,NODE * b,NODE * c)76*4774dff6SToomas Soome NODE *node2(int a, NODE *b, NODE *c)
777c478bd9Sstevel@tonic-gate {
78*4774dff6SToomas Soome NODE *x;
797c478bd9Sstevel@tonic-gate x = nodealloc(2);
807c478bd9Sstevel@tonic-gate x->nnext = NULL;
817c478bd9Sstevel@tonic-gate x->nobj = a;
827c478bd9Sstevel@tonic-gate x->narg[0] = b;
837c478bd9Sstevel@tonic-gate x->narg[1] = c;
847c478bd9Sstevel@tonic-gate return (x);
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate
node3(int a,NODE * b,NODE * c,NODE * d)90*4774dff6SToomas Soome NODE *node3(int a, NODE *b, NODE *c, NODE *d)
917c478bd9Sstevel@tonic-gate {
92*4774dff6SToomas Soome NODE *x;
937c478bd9Sstevel@tonic-gate x = nodealloc(3);
947c478bd9Sstevel@tonic-gate x->nnext = NULL;
957c478bd9Sstevel@tonic-gate x->nobj = a;
967c478bd9Sstevel@tonic-gate x->narg[0] = b;
977c478bd9Sstevel@tonic-gate x->narg[1] = c;
987c478bd9Sstevel@tonic-gate x->narg[2] = d;
997c478bd9Sstevel@tonic-gate return (x);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate
node4(int a,NODE * b,NODE * c,NODE * d,NODE * e)105*4774dff6SToomas Soome NODE *node4(int a, NODE *b, NODE *c, NODE *d, NODE *e)
1067c478bd9Sstevel@tonic-gate {
107*4774dff6SToomas Soome NODE *x;
1087c478bd9Sstevel@tonic-gate x = nodealloc(4);
1097c478bd9Sstevel@tonic-gate x->nnext = NULL;
1107c478bd9Sstevel@tonic-gate x->nobj = a;
1117c478bd9Sstevel@tonic-gate x->narg[0] = b;
1127c478bd9Sstevel@tonic-gate x->narg[1] = c;
1137c478bd9Sstevel@tonic-gate x->narg[2] = d;
1147c478bd9Sstevel@tonic-gate x->narg[3] = e;
1157c478bd9Sstevel@tonic-gate return (x);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate
stat3(int a,NODE * b,NODE * c,NODE * d)121*4774dff6SToomas Soome NODE *stat3(int a, NODE *b, NODE *c, NODE *d)
1227c478bd9Sstevel@tonic-gate {
123*4774dff6SToomas Soome NODE *x;
1247c478bd9Sstevel@tonic-gate x = node3(a, b, c, d);
1257c478bd9Sstevel@tonic-gate x->ntype = NSTAT;
1267c478bd9Sstevel@tonic-gate return (x);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate
op2(int a,NODE * b,NODE * c)132*4774dff6SToomas Soome NODE *op2(int a, NODE *b, NODE *c)
1337c478bd9Sstevel@tonic-gate {
134*4774dff6SToomas Soome NODE *x;
1357c478bd9Sstevel@tonic-gate x = node2(a, b, c);
1367c478bd9Sstevel@tonic-gate x->ntype = NEXPR;
1377c478bd9Sstevel@tonic-gate return (x);
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate
op1(int a,NODE * b)143*4774dff6SToomas Soome NODE *op1(int a, NODE *b)
1447c478bd9Sstevel@tonic-gate {
145*4774dff6SToomas Soome NODE *x;
1467c478bd9Sstevel@tonic-gate x = node1(a, b);
1477c478bd9Sstevel@tonic-gate x->ntype = NEXPR;
1487c478bd9Sstevel@tonic-gate return (x);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate
stat1(int a,NODE * b)154*4774dff6SToomas Soome NODE *stat1(int a, NODE *b)
1557c478bd9Sstevel@tonic-gate {
156*4774dff6SToomas Soome NODE *x;
1577c478bd9Sstevel@tonic-gate x = node1(a, b);
1587c478bd9Sstevel@tonic-gate x->ntype = NSTAT;
1597c478bd9Sstevel@tonic-gate return (x);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate
op3(int a,NODE * b,NODE * c,NODE * d)165*4774dff6SToomas Soome NODE *op3(int a, NODE *b, NODE *c, NODE *d)
1667c478bd9Sstevel@tonic-gate {
167*4774dff6SToomas Soome NODE *x;
1687c478bd9Sstevel@tonic-gate x = node3(a, b, c, d);
1697c478bd9Sstevel@tonic-gate x->ntype = NEXPR;
1707c478bd9Sstevel@tonic-gate return (x);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate
1757c478bd9Sstevel@tonic-gate
stat2(int a,NODE * b,NODE * c)176*4774dff6SToomas Soome NODE *stat2(int a, NODE *b, NODE *c)
1777c478bd9Sstevel@tonic-gate {
178*4774dff6SToomas Soome NODE *x;
1797c478bd9Sstevel@tonic-gate x = node2(a, b, c);
1807c478bd9Sstevel@tonic-gate x->ntype = NSTAT;
1817c478bd9Sstevel@tonic-gate return (x);
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate
stat4(int a,NODE * b,NODE * c,NODE * d,NODE * e)187*4774dff6SToomas Soome NODE *stat4(int a, NODE *b, NODE *c, NODE *d, NODE *e)
1887c478bd9Sstevel@tonic-gate {
189*4774dff6SToomas Soome NODE *x;
1907c478bd9Sstevel@tonic-gate x = node4(a, b, c, d, e);
1917c478bd9Sstevel@tonic-gate x->ntype = NSTAT;
1927c478bd9Sstevel@tonic-gate return (x);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate
valtonode(CELL * a,int b)198*4774dff6SToomas Soome NODE *valtonode(CELL *a, int b)
1997c478bd9Sstevel@tonic-gate {
200*4774dff6SToomas Soome NODE *x;
201*4774dff6SToomas Soome x = node0((uintptr_t)a);
2027c478bd9Sstevel@tonic-gate x->ntype = NVALUE;
2037c478bd9Sstevel@tonic-gate x->subtype = b;
2047c478bd9Sstevel@tonic-gate return (x);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate
pa2stat(NODE * a,NODE * b,NODE * c)210*4774dff6SToomas Soome NODE *pa2stat(NODE *a, NODE *b, NODE *c)
2117c478bd9Sstevel@tonic-gate {
212*4774dff6SToomas Soome NODE *x;
2137c478bd9Sstevel@tonic-gate x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
2147c478bd9Sstevel@tonic-gate paircnt++;
2157c478bd9Sstevel@tonic-gate x->ntype = NSTAT;
2167c478bd9Sstevel@tonic-gate return (x);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate
linkum(NODE * a,NODE * b)222*4774dff6SToomas Soome NODE *linkum(NODE *a, NODE *b)
2237c478bd9Sstevel@tonic-gate {
224*4774dff6SToomas Soome NODE *c;
2257c478bd9Sstevel@tonic-gate if (a == NULL) return (b);
2267c478bd9Sstevel@tonic-gate else if (b == NULL) return (a);
2277c478bd9Sstevel@tonic-gate for (c = a; c->nnext != NULL; c=c->nnext)
2287c478bd9Sstevel@tonic-gate ;
2297c478bd9Sstevel@tonic-gate c->nnext = b;
2307c478bd9Sstevel@tonic-gate return (a);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate
genprint(void)236*4774dff6SToomas Soome NODE *genprint(void)
2377c478bd9Sstevel@tonic-gate {
238*4774dff6SToomas Soome NODE *x;
2397c478bd9Sstevel@tonic-gate static wchar_t L_record[] = L"$record";
2407c478bd9Sstevel@tonic-gate x = stat2(PRINT, valtonode(lookup(L_record, symtab, 0), CFLD), NULL);
2417c478bd9Sstevel@tonic-gate return (x);
2427c478bd9Sstevel@tonic-gate }
243