NetBSD/bin/sh/mknodenames.sh
christos ca12a0b88a General KNF and source code cleanups, avoid scattering the
magic string " \t\n" all over the place, slightly improved
syntax error messages, restructured some of the code for
clarity, don't allow IFS to be imported through the environment,
and remove the (never) conditionally compiled ATTY option.
Apart from one or two syntax error messages, and ignoring IFS
if present in the environment, this is intended to have no
user visible changes. (from kre@)
2016-03-27 14:34:46 +00:00

52 lines
879 B
Bash
Executable File

#! /bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 nodes.h" 1>&2
exit 1
fi
NODES=$1
test -t 1 && -z "$2" && exec > nodenames.h
echo "#ifdef DEBUG"
echo '
/*
* Automatically generated by '"$0"'
* DO NOT EDIT. Do Not "cvs add".
*/
'
MAX=$(awk < "$NODES" '
/#define/ {
if ($3 > MAX) MAX = $3
}
END { print MAX }
')
echo
echo '#ifdef DEFINE_NODENAMES'
echo "STATIC const char * const NodeNames[${MAX} + 1] = {"
grep '^#define' "$NODES" | sort -k2n | while read define name number opt_comment
do
: ${next:=0}
while [ "$number" -gt "$next" ]
do
echo ' "???",'
next=$(( next + 1))
done
echo ' "'"$name"'",'
next=$(( number + 1 ))
done
echo "};"
echo '#else'
echo "extern const char * const NodeNames[${MAX} + 1];"
echo '#endif'
echo
echo '#define NODETYPENAME(type) \'
echo ' ((unsigned)(type) <= '"${MAX}"' ? NodeNames[(type)] : "??OOR??")'
echo
echo '#endif'