1#! /bin/sh 2 3# $NetBSD: mknodenames.sh,v 1.6 2018/08/18 03:09:37 kre 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 8if [ -z "$1" ]; then 9 echo "Usage: $0 nodes.h" 1>&2 10 exit 1 11fi 12 13NODES=$1 14 15test -t 1 && test -z "$2" && exec > nodenames.h 16 17echo "\ 18/* 19 * Automatically generated by $0 20 * DO NOT EDIT. Do Not 'cvs add'. 21 */ 22" 23echo "#ifndef NODENAMES_H_INCLUDED" 24echo "#define NODENAMES_H_INCLUDED" 25echo 26echo "#ifdef DEBUG" 27 28MAX=$(awk < "$NODES" ' 29 /#define/ { 30 if ($3 > MAX) MAX = $3 31 } 32 END { print MAX } 33') 34 35echo 36echo '#ifdef DEFINE_NODENAMES' 37echo "STATIC const char * const NodeNames[${MAX} + 1] = {" 38 39grep '^#define' "$NODES" | sort -k3n | while read define name number opt_comment 40do 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 )) 49done 50 51echo "};" 52echo '#else' 53echo "extern const char * const NodeNames[${MAX} + 1];" 54echo '#endif' 55echo 56echo '#define NODETYPENAME(type) \' 57echo ' ((unsigned)(type) <= '"${MAX}"' ? NodeNames[(type)] : "??OOR??")' 58echo 59echo '#define NODETYPE(type) NODETYPENAME(type), (type)' 60echo '#define PRIdsNT "s(%d)"' 61echo 62echo '#else /* DEBUG */' 63echo 64echo '#define NODETYPE(type) (type)' 65echo '#define PRIdsNT "d"' 66echo 67echo '#endif /* DEBUG */' 68echo 69echo '#endif /* !NODENAMES_H_INCLUDED */' 70