2 # $NetBSD: mknodes.sh,v 1.2 2008/04/29 06:53:00 martin 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.
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
36 exec >$objdir/nodes.h.tmp
39 echo " * This file was generated by mknodes.sh"
44 while IFS
=; read -r line
; do
49 [ -z "$2" ] && continue
53 [ $field = 0 ] && struct_list
="$struct_list $struct"
54 eval field_
${struct}_
$field=\"\$
*\"
55 eval numfld_
$struct=\
$field
61 echo "#define $define $tagno"
63 eval define_
$struct=\"\
$define_$struct \
$define\"
64 struct_define
="$struct_define $struct"
73 for struct
in $struct_list; do
76 echo "struct $struct {"
79 eval line
=\"\
$field_${struct}_
$field\"
87 nodeptr
) type="union node *";;
88 nodelist
) type="struct nodelist *";;
89 string
) type="char *";;
91 * ) name
=; shift 2; type="$*";;
102 for struct
in $struct_list; do
103 echo " struct $struct $struct;"
108 echo "struct nodelist {"
109 echo " struct nodelist *next;"
110 echo " union node *n;"
114 echo "union node *copyfunc(union node *);"
115 echo "void freefunc(union node *);"
117 mv $objdir/nodes.h.tmp
$objdir/nodes.h ||
exit 1
120 exec >$objdir/nodes.c.tmp
123 echo " * This file was generated by mknodes.sh"
127 while IFS
=; read -r line
; do
133 echo "static const short nodesize[$tagno] = {"
135 for struct
in $struct_define; do
136 echo " SHELL_ALIGN(sizeof (struct $struct)),"
141 echo " if (n == NULL)"
143 echo " funcblocksize += nodesize[n->type];"
144 echo " switch (n->type) {"
146 for struct
in $struct_list; do
147 eval defines
=\"\
$define_$struct\"
148 for define
in $defines; do
149 echo " case $define:"
151 eval field
=\
$numfld_$struct
155 eval line
=\"\
$field_${struct}_
$field\"
156 field
=$
(($field - 1))
162 nodeptr
) fn
=calcsize
;;
163 nodelist
) fn
=sizenodelist
;;
164 string
) fn
="funcstringsize += strlen"
168 echo " ${fn}(n->$struct.$name${cl};"
175 echo " if (n == NULL)"
177 echo " new = funcblock;"
178 echo " funcblock = (char *) funcblock + nodesize[n->type];"
179 echo " switch (n->type) {"
181 for struct
in $struct_list; do
182 eval defines
=\"\
$define_$struct\"
183 for define
in $defines; do
184 echo " case $define:"
186 eval field
=\
$numfld_$struct
190 eval line
=\"\
$field_${struct}_
$field\"
191 field
=$
(($field - 1))
196 nodeptr
) fn
="copynode(";;
197 nodelist
) fn
="copynodelist(";;
198 string
) fn
="nodesavestr(";;
203 echo " new->$f = ${fn}n->$f${fn:+)};"
208 echo " new->type = n->type;"
214 mv $objdir/nodes.c.tmp
$objdir/nodes.c ||
exit 1