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