2
# $NetBSD: mknodes.sh,v 1.1 2004/01/16 23:24:38 dsl Exp $
4
# Copyright (c) 2003 The NetBSD Foundation, Inc.
7
# This code is derived from software contributed to The NetBSD Foundation
10
# Redistribution and use in source and binary forms, with or without
11
# modification, are permitted provided that the following conditions
13
# 1. Redistributions of source code must retain the above copyright
14
# notice, this list of conditions and the following disclaimer.
15
# 2. Redistributions in binary form must reproduce the above copyright
16
# notice, this list of conditions and the following disclaimer in the
17
# documentation and/or other materials provided with the distribution.
18
# 3. Neither the name of The NetBSD Foundation nor the names of its
19
# contributors may be used to endorse or promote products derived
20
# from this software without specific prior written permission.
22
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
# POSSIBILITY OF SUCH DAMAGE.
39
exec >$objdir/nodes.h.tmp
42
echo " * This file was generated by mknodes.sh"
47
while IFS=; read -r line; do
52
[ -z "$2" ] && continue
56
[ $field = 0 ] && struct_list="$struct_list $struct"
57
eval field_${struct}_$field=\"\$*\"
58
eval numfld_$struct=\$field
64
echo "#define $define $tagno"
66
eval define_$struct=\"\$define_$struct \$define\"
67
struct_define="$struct_define $struct"
76
for struct in $struct_list; do
79
echo "struct $struct {"
82
eval line=\"\$field_${struct}_$field\"
90
nodeptr ) type="union node *";;
91
nodelist ) type="struct nodelist *";;
92
string ) type="char *";;
94
* ) name=; shift 2; type="$*";;
105
for struct in $struct_list; do
106
echo " struct $struct $struct;"
111
echo "struct nodelist {"
112
echo " struct nodelist *next;"
113
echo " union node *n;"
117
echo "union node *copyfunc(union node *);"
118
echo "void freefunc(union node *);"
120
mv $objdir/nodes.h.tmp $objdir/nodes.h || exit 1
123
exec >$objdir/nodes.c.tmp
126
echo " * This file was generated by mknodes.sh"
130
while IFS=; read -r line; do
136
echo "static const short nodesize[$tagno] = {"
138
for struct in $struct_define; do
139
echo " SHELL_ALIGN(sizeof (struct $struct)),"
144
echo " if (n == NULL)"
146
echo " funcblocksize += nodesize[n->type];"
147
echo " switch (n->type) {"
149
for struct in $struct_list; do
150
eval defines=\"\$define_$struct\"
151
for define in $defines; do
152
echo " case $define:"
154
eval field=\$numfld_$struct
158
eval line=\"\$field_${struct}_$field\"
159
field=$(($field - 1))
165
nodeptr ) fn=calcsize;;
166
nodelist ) fn=sizenodelist;;
167
string ) fn="funcstringsize += strlen"
171
echo " ${fn}(n->$struct.$name${cl};"
178
echo " if (n == NULL)"
180
echo " new = funcblock;"
181
echo " funcblock = (char *) funcblock + nodesize[n->type];"
182
echo " switch (n->type) {"
184
for struct in $struct_list; do
185
eval defines=\"\$define_$struct\"
186
for define in $defines; do
187
echo " case $define:"
189
eval field=\$numfld_$struct
193
eval line=\"\$field_${struct}_$field\"
194
field=$(($field - 1))
199
nodeptr ) fn="copynode(";;
200
nodelist ) fn="copynodelist(";;
201
string ) fn="nodesavestr(";;
206
echo " new->$f = ${fn}n->$f${fn:+)};"
211
echo " new->type = n->type;"
217
mv $objdir/nodes.c.tmp $objdir/nodes.c || exit 1