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 *);"
121 exec >$objdir/nodes.c.tmp
122 mv -f $objdir/nodes.h.tmp
$objdir/nodes.h ||
exit 1
125 echo " * This file was generated by mknodes.sh"
129 while IFS
=; read -r line
; do
135 echo "static const short nodesize[$tagno] = {"
137 for struct
in $struct_define; do
138 echo " SHELL_ALIGN(sizeof (struct $struct)),"
143 echo " if (n == NULL)"
145 echo " funcblocksize += nodesize[n->type];"
146 echo " switch (n->type) {"
148 for struct
in $struct_list; do
149 eval defines
=\"\
$define_$struct\"
150 for define
in $defines; do
151 echo " case $define:"
153 eval field
=\
$numfld_$struct
157 eval line
=\"\
$field_${struct}_
$field\"
158 field
=$
(($field - 1))
164 nodeptr
) fn
=calcsize
;;
165 nodelist
) fn
=sizenodelist
;;
166 string
) fn
="funcstringsize += strlen"
170 echo " ${fn}(n->$struct.$name${cl};"
177 echo " if (n == NULL)"
179 echo " new = funcblock;"
180 echo " funcblock = (char *) funcblock + nodesize[n->type];"
181 echo " switch (n->type) {"
183 for struct
in $struct_list; do
184 eval defines
=\"\
$define_$struct\"
185 for define
in $defines; do
186 echo " case $define:"
188 eval field
=\
$numfld_$struct
192 eval line
=\"\
$field_${struct}_
$field\"
193 field
=$
(($field - 1))
198 nodeptr
) fn
="copynode(";;
199 nodelist
) fn
="copynodelist(";;
200 string
) fn
="nodesavestr(";;
205 echo " new->$f = ${fn}n->$f${fn:+)};"
210 echo " new->type = n->type;"
217 mv -f $objdir/nodes.c.tmp
$objdir/nodes.c ||
exit 1