mknodenames.sh revision 1.4.6.1 1 #! /bin/sh
2
3 # $NetBSD: mknodenames.sh,v 1.4.6.1 2019/06/10 21:41:04 christos Exp $
4
5 # Use this script however you like, but it would be amazing if
6 # it has any purpose other than as part of building the shell...
7
8 if [ -z "$1" ]; then
9 echo "Usage: $0 nodes.h" 1>&2
10 exit 1
11 fi
12
13 NODES=$1
14
15 test -t 1 && test -z "$2" && exec > nodenames.h
16
17 echo "\
18 /*
19 * Automatically generated by $0
20 * DO NOT EDIT. Do Not 'cvs add'.
21 */
22 "
23 echo "#ifndef NODENAMES_H_INCLUDED"
24 echo "#define NODENAMES_H_INCLUDED"
25 echo
26 echo "#ifdef DEBUG"
27
28 MAX=$(awk < "$NODES" '
29 /#define/ {
30 if ($3 > MAX) MAX = $3
31 }
32 END { print MAX }
33 ')
34
35 echo
36 echo '#ifdef DEFINE_NODENAMES'
37 echo "STATIC const char * const NodeNames[${MAX} + 1] = {"
38
39 grep '^#define' "$NODES" | sort -k3n | while read define name number opt_comment
40 do
41 : ${next:=0}
42 while [ "$number" -gt "$next" ]
43 do
44 echo ' "???",'
45 next=$(( next + 1))
46 done
47 echo ' "'"$name"'",'
48 next=$(( number + 1 ))
49 done
50
51 echo "};"
52 echo '#else'
53 echo "extern const char * const NodeNames[${MAX} + 1];"
54 echo '#endif'
55 echo
56 echo '#define NODETYPENAME(type) \'
57 echo ' ((unsigned)(type) <= '"${MAX}"' ? NodeNames[(type)] : "??OOR??")'
58 echo
59 echo '#define NODETYPE(type) NODETYPENAME(type), (type)'
60 echo '#define PRIdsNT "s(%d)"'
61 echo
62 echo '#else /* DEBUG */'
63 echo
64 echo '#define NODETYPE(type) (type)'
65 echo '#define PRIdsNT "d"'
66 echo
67 echo '#endif /* DEBUG */'
68 echo
69 echo '#endif /* !NODENAMES_H_INCLUDED */'
70