2
* This file was generated by mknodes.sh
5
/* $NetBSD: nodes.c.pat,v 1.12 2004/06/15 22:57:27 dsl Exp $ */
8
* Copyright (c) 1991, 1993
9
* The Regents of the University of California. All rights reserved.
11
* This code is derived from software contributed to Berkeley by
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
17
* 1. Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
19
* 2. Redistributions in binary form must reproduce the above copyright
20
* notice, this list of conditions and the following disclaimer in the
21
* documentation and/or other materials provided with the distribution.
22
* 3. Neither the name of the University nor the names of its contributors
23
* may be used to endorse or promote products derived from this software
24
* without specific prior written permission.
26
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
* @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95
43
* Routine for dealing with parsed shell commands.
53
int funcblocksize; /* size of structures in function */
54
int funcstringsize; /* size of strings in node */
55
pointer funcblock; /* block to allocate function from */
56
char *funcstring; /* block to allocate strings from */
58
static const short nodesize[26] = {
59
SHELL_ALIGN(sizeof (struct nbinary)),
60
SHELL_ALIGN(sizeof (struct ncmd)),
61
SHELL_ALIGN(sizeof (struct npipe)),
62
SHELL_ALIGN(sizeof (struct nredir)),
63
SHELL_ALIGN(sizeof (struct nredir)),
64
SHELL_ALIGN(sizeof (struct nredir)),
65
SHELL_ALIGN(sizeof (struct nbinary)),
66
SHELL_ALIGN(sizeof (struct nbinary)),
67
SHELL_ALIGN(sizeof (struct nif)),
68
SHELL_ALIGN(sizeof (struct nbinary)),
69
SHELL_ALIGN(sizeof (struct nbinary)),
70
SHELL_ALIGN(sizeof (struct nfor)),
71
SHELL_ALIGN(sizeof (struct ncase)),
72
SHELL_ALIGN(sizeof (struct nclist)),
73
SHELL_ALIGN(sizeof (struct narg)),
74
SHELL_ALIGN(sizeof (struct narg)),
75
SHELL_ALIGN(sizeof (struct nfile)),
76
SHELL_ALIGN(sizeof (struct nfile)),
77
SHELL_ALIGN(sizeof (struct nfile)),
78
SHELL_ALIGN(sizeof (struct nfile)),
79
SHELL_ALIGN(sizeof (struct nfile)),
80
SHELL_ALIGN(sizeof (struct ndup)),
81
SHELL_ALIGN(sizeof (struct ndup)),
82
SHELL_ALIGN(sizeof (struct nhere)),
83
SHELL_ALIGN(sizeof (struct nhere)),
84
SHELL_ALIGN(sizeof (struct nnot)),
88
STATIC void calcsize(union node *);
89
STATIC void sizenodelist(struct nodelist *);
90
STATIC union node *copynode(union node *);
91
STATIC struct nodelist *copynodelist(struct nodelist *);
92
STATIC char *nodesavestr(char *);
97
* Make a copy of a parse tree.
109
funcblock = ckmalloc(funcblocksize + funcstringsize);
110
funcstring = (char *) funcblock + funcblocksize;
122
funcblocksize += nodesize[n->type];
129
calcsize(n->nbinary.ch2);
130
calcsize(n->nbinary.ch1);
133
calcsize(n->ncmd.redirect);
134
calcsize(n->ncmd.args);
137
sizenodelist(n->npipe.cmdlist);
142
calcsize(n->nredir.redirect);
143
calcsize(n->nredir.n);
146
calcsize(n->nif.elsepart);
147
calcsize(n->nif.ifpart);
148
calcsize(n->nif.test);
151
funcstringsize += strlen(n->nfor.var) + 1;
152
calcsize(n->nfor.body);
153
calcsize(n->nfor.args);
156
calcsize(n->ncase.cases);
157
calcsize(n->ncase.expr);
160
calcsize(n->nclist.body);
161
calcsize(n->nclist.pattern);
162
calcsize(n->nclist.next);
166
sizenodelist(n->narg.backquote);
167
funcstringsize += strlen(n->narg.text) + 1;
168
calcsize(n->narg.next);
175
calcsize(n->nfile.fname);
176
calcsize(n->nfile.next);
180
calcsize(n->ndup.vname);
181
calcsize(n->ndup.next);
185
calcsize(n->nhere.doc);
186
calcsize(n->nhere.next);
189
calcsize(n->nnot.com);
201
funcblocksize += SHELL_ALIGN(sizeof(struct nodelist));
218
funcblock = (char *) funcblock + nodesize[n->type];
225
new->nbinary.ch2 = copynode(n->nbinary.ch2);
226
new->nbinary.ch1 = copynode(n->nbinary.ch1);
229
new->ncmd.redirect = copynode(n->ncmd.redirect);
230
new->ncmd.args = copynode(n->ncmd.args);
231
new->ncmd.backgnd = n->ncmd.backgnd;
234
new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
235
new->npipe.backgnd = n->npipe.backgnd;
240
new->nredir.redirect = copynode(n->nredir.redirect);
241
new->nredir.n = copynode(n->nredir.n);
244
new->nif.elsepart = copynode(n->nif.elsepart);
245
new->nif.ifpart = copynode(n->nif.ifpart);
246
new->nif.test = copynode(n->nif.test);
249
new->nfor.var = nodesavestr(n->nfor.var);
250
new->nfor.body = copynode(n->nfor.body);
251
new->nfor.args = copynode(n->nfor.args);
254
new->ncase.cases = copynode(n->ncase.cases);
255
new->ncase.expr = copynode(n->ncase.expr);
258
new->nclist.body = copynode(n->nclist.body);
259
new->nclist.pattern = copynode(n->nclist.pattern);
260
new->nclist.next = copynode(n->nclist.next);
264
new->narg.backquote = copynodelist(n->narg.backquote);
265
new->narg.text = nodesavestr(n->narg.text);
266
new->narg.next = copynode(n->narg.next);
273
new->nfile.fname = copynode(n->nfile.fname);
274
new->nfile.fd = n->nfile.fd;
275
new->nfile.next = copynode(n->nfile.next);
279
new->ndup.vname = copynode(n->ndup.vname);
280
new->ndup.dupfd = n->ndup.dupfd;
281
new->ndup.fd = n->ndup.fd;
282
new->ndup.next = copynode(n->ndup.next);
286
new->nhere.doc = copynode(n->nhere.doc);
287
new->nhere.fd = n->nhere.fd;
288
new->nhere.next = copynode(n->nhere.next);
291
new->nnot.com = copynode(n->nnot.com);
299
STATIC struct nodelist *
303
struct nodelist *start;
304
struct nodelist **lpp;
309
funcblock = (char *) funcblock +
310
SHELL_ALIGN(sizeof(struct nodelist));
311
(*lpp)->n = copynode(lp->n);
325
register char *p = s;
326
register char *q = funcstring;
327
char *rtn = funcstring;
329
while ((*q++ = *p++) != 0)