1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate #ident "%Z%%M% %I% %E% SMI" 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate #include "awk.def" 29*0Sstevel@tonic-gate #include "awk.h" 30*0Sstevel@tonic-gate #include "stdio.h" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate NODE *nodealloc(n) 33*0Sstevel@tonic-gate { 34*0Sstevel@tonic-gate register NODE *x; 35*0Sstevel@tonic-gate x = (NODE *) malloc(sizeof (NODE) + (n-1)*sizeof (NODE *)); 36*0Sstevel@tonic-gate if (x == NULL) 37*0Sstevel@tonic-gate error(FATAL, "out of space in nodealloc"); 38*0Sstevel@tonic-gate return (x); 39*0Sstevel@tonic-gate } 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate NODE *exptostat(a) NODE *a; 45*0Sstevel@tonic-gate { 46*0Sstevel@tonic-gate a->ntype = NSTAT; 47*0Sstevel@tonic-gate return (a); 48*0Sstevel@tonic-gate } 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate NODE *node0(a) 54*0Sstevel@tonic-gate { 55*0Sstevel@tonic-gate register NODE *x; 56*0Sstevel@tonic-gate x = nodealloc(0); 57*0Sstevel@tonic-gate x->nnext = NULL; 58*0Sstevel@tonic-gate x->nobj = a; 59*0Sstevel@tonic-gate return (x); 60*0Sstevel@tonic-gate } 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate NODE *node1(a, b) NODE *b; 66*0Sstevel@tonic-gate { 67*0Sstevel@tonic-gate register NODE *x; 68*0Sstevel@tonic-gate x = nodealloc(1); 69*0Sstevel@tonic-gate x->nnext = NULL; 70*0Sstevel@tonic-gate x->nobj = a; 71*0Sstevel@tonic-gate x->narg[0]=b; 72*0Sstevel@tonic-gate return (x); 73*0Sstevel@tonic-gate } 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate NODE *node2(a, b, c) NODE *b, *c; 79*0Sstevel@tonic-gate { 80*0Sstevel@tonic-gate register NODE *x; 81*0Sstevel@tonic-gate x = nodealloc(2); 82*0Sstevel@tonic-gate x->nnext = NULL; 83*0Sstevel@tonic-gate x->nobj = a; 84*0Sstevel@tonic-gate x->narg[0] = b; 85*0Sstevel@tonic-gate x->narg[1] = c; 86*0Sstevel@tonic-gate return (x); 87*0Sstevel@tonic-gate } 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate NODE *node3(a, b, c, d) NODE *b, *c, *d; 93*0Sstevel@tonic-gate { 94*0Sstevel@tonic-gate register NODE *x; 95*0Sstevel@tonic-gate x = nodealloc(3); 96*0Sstevel@tonic-gate x->nnext = NULL; 97*0Sstevel@tonic-gate x->nobj = a; 98*0Sstevel@tonic-gate x->narg[0] = b; 99*0Sstevel@tonic-gate x->narg[1] = c; 100*0Sstevel@tonic-gate x->narg[2] = d; 101*0Sstevel@tonic-gate return (x); 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate NODE *node4(a, b, c, d, e) NODE *b, *c, *d, *e; 108*0Sstevel@tonic-gate { 109*0Sstevel@tonic-gate register NODE *x; 110*0Sstevel@tonic-gate x = nodealloc(4); 111*0Sstevel@tonic-gate x->nnext = NULL; 112*0Sstevel@tonic-gate x->nobj = a; 113*0Sstevel@tonic-gate x->narg[0] = b; 114*0Sstevel@tonic-gate x->narg[1] = c; 115*0Sstevel@tonic-gate x->narg[2] = d; 116*0Sstevel@tonic-gate x->narg[3] = e; 117*0Sstevel@tonic-gate return (x); 118*0Sstevel@tonic-gate } 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate NODE *stat3(a, b, c, d) NODE *b, *c, *d; 124*0Sstevel@tonic-gate { 125*0Sstevel@tonic-gate register NODE *x; 126*0Sstevel@tonic-gate x = node3(a, b, c, d); 127*0Sstevel@tonic-gate x->ntype = NSTAT; 128*0Sstevel@tonic-gate return (x); 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate NODE *op2(a, b, c) NODE *b, *c; 135*0Sstevel@tonic-gate { 136*0Sstevel@tonic-gate register NODE *x; 137*0Sstevel@tonic-gate x = node2(a, b, c); 138*0Sstevel@tonic-gate x->ntype = NEXPR; 139*0Sstevel@tonic-gate return (x); 140*0Sstevel@tonic-gate } 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate NODE *op1(a, b) NODE *b; 146*0Sstevel@tonic-gate { 147*0Sstevel@tonic-gate register NODE *x; 148*0Sstevel@tonic-gate x = node1(a, b); 149*0Sstevel@tonic-gate x->ntype = NEXPR; 150*0Sstevel@tonic-gate return (x); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate NODE *stat1(a, b) NODE *b; 157*0Sstevel@tonic-gate { 158*0Sstevel@tonic-gate register NODE *x; 159*0Sstevel@tonic-gate x = node1(a, b); 160*0Sstevel@tonic-gate x->ntype = NSTAT; 161*0Sstevel@tonic-gate return (x); 162*0Sstevel@tonic-gate } 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate NODE *op3(a, b, c, d) NODE *b, *c, *d; 168*0Sstevel@tonic-gate { 169*0Sstevel@tonic-gate register NODE *x; 170*0Sstevel@tonic-gate x = node3(a, b, c, d); 171*0Sstevel@tonic-gate x->ntype = NEXPR; 172*0Sstevel@tonic-gate return (x); 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate NODE *stat2(a, b, c) NODE *b, *c; 179*0Sstevel@tonic-gate { 180*0Sstevel@tonic-gate register NODE *x; 181*0Sstevel@tonic-gate x = node2(a, b, c); 182*0Sstevel@tonic-gate x->ntype = NSTAT; 183*0Sstevel@tonic-gate return (x); 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate NODE *stat4(a, b, c, d, e) NODE *b, *c, *d, *e; 190*0Sstevel@tonic-gate { 191*0Sstevel@tonic-gate register NODE *x; 192*0Sstevel@tonic-gate x = node4(a, b, c, d, e); 193*0Sstevel@tonic-gate x->ntype = NSTAT; 194*0Sstevel@tonic-gate return (x); 195*0Sstevel@tonic-gate } 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate NODE *valtonode(a, b) CELL *a; 201*0Sstevel@tonic-gate { 202*0Sstevel@tonic-gate register NODE *x; 203*0Sstevel@tonic-gate x = node0(a); 204*0Sstevel@tonic-gate x->ntype = NVALUE; 205*0Sstevel@tonic-gate x->subtype = b; 206*0Sstevel@tonic-gate return (x); 207*0Sstevel@tonic-gate } 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate NODE *pa2stat(a, b, c) NODE *a, *b, *c; 213*0Sstevel@tonic-gate { 214*0Sstevel@tonic-gate register NODE *x; 215*0Sstevel@tonic-gate x = node4(PASTAT2, a, b, c, (NODE *) paircnt); 216*0Sstevel@tonic-gate paircnt++; 217*0Sstevel@tonic-gate x->ntype = NSTAT; 218*0Sstevel@tonic-gate return (x); 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate NODE *linkum(a, b) NODE *a, *b; 225*0Sstevel@tonic-gate { 226*0Sstevel@tonic-gate register NODE *c; 227*0Sstevel@tonic-gate if (a == NULL) return (b); 228*0Sstevel@tonic-gate else if (b == NULL) return (a); 229*0Sstevel@tonic-gate for (c = a; c->nnext != NULL; c=c->nnext) 230*0Sstevel@tonic-gate ; 231*0Sstevel@tonic-gate c->nnext = b; 232*0Sstevel@tonic-gate return (a); 233*0Sstevel@tonic-gate } 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate NODE *genprint() 239*0Sstevel@tonic-gate { 240*0Sstevel@tonic-gate register NODE *x; 241*0Sstevel@tonic-gate static wchar_t L_record[] = L"$record"; 242*0Sstevel@tonic-gate x = stat2(PRINT, valtonode(lookup(L_record, symtab, 0), CFLD), NULL); 243*0Sstevel@tonic-gate return (x); 244*0Sstevel@tonic-gate } 245