2016-02-24 17:51:20 +03:00
|
|
|
#! /bin/sh
|
|
|
|
|
In the older debug code (not using the new macros added in the
previous rev) the two values (node name, and node number) were
arbitrarily printed in different formats and orders (depending
upon my mood at the time I guess...) The new macros will standardise
that usage (in the debug output) once some use of them actually begins.
When the macros were added, I arbitrarily copied the format of one
use I was looking at at that instant (the one which inspired the change),
but after gazing at DEBUG mode output over the intervening time, I
have concluded that I did not pick the easiest to read/follow format.
So, even before they are used, change the style... Also, conform
to standard PRIxxxx macro style by omitting the leading '%'.
NFC (since they aren't used at all, anywhere, yet, not even the
possibility of anything changing!)
2018-08-18 06:09:37 +03:00
|
|
|
# $NetBSD: mknodenames.sh,v 1.6 2018/08/18 03:09:37 kre Exp $
|
2018-08-16 18:02:05 +03:00
|
|
|
|
|
|
|
# Use this script however you like, but it would be amazing if
|
|
|
|
# it has any purpose other than as part of building the shell...
|
|
|
|
|
2016-02-27 21:34:12 +03:00
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Usage: $0 nodes.h" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
NODES=$1
|
|
|
|
|
2017-06-19 14:55:07 +03:00
|
|
|
test -t 1 && test -z "$2" && exec > nodenames.h
|
2016-02-24 17:51:20 +03:00
|
|
|
|
2018-08-16 18:02:05 +03:00
|
|
|
echo "\
|
2016-02-24 17:51:20 +03:00
|
|
|
/*
|
2018-08-16 18:02:05 +03:00
|
|
|
* Automatically generated by $0
|
|
|
|
* DO NOT EDIT. Do Not 'cvs add'.
|
2016-02-24 17:51:20 +03:00
|
|
|
*/
|
2018-08-16 18:02:05 +03:00
|
|
|
"
|
|
|
|
echo "#ifndef NODENAMES_H_INCLUDED"
|
|
|
|
echo "#define NODENAMES_H_INCLUDED"
|
|
|
|
echo
|
|
|
|
echo "#ifdef DEBUG"
|
2016-02-24 17:51:20 +03:00
|
|
|
|
2016-02-27 21:34:12 +03:00
|
|
|
MAX=$(awk < "$NODES" '
|
2016-02-24 17:51:20 +03:00
|
|
|
/#define/ {
|
|
|
|
if ($3 > MAX) MAX = $3
|
|
|
|
}
|
|
|
|
END { print MAX }
|
|
|
|
')
|
|
|
|
|
|
|
|
echo
|
2016-02-27 21:34:12 +03:00
|
|
|
echo '#ifdef DEFINE_NODENAMES'
|
2016-02-24 17:51:20 +03:00
|
|
|
echo "STATIC const char * const NodeNames[${MAX} + 1] = {"
|
|
|
|
|
2017-06-19 14:55:07 +03:00
|
|
|
grep '^#define' "$NODES" | sort -k3n | while read define name number opt_comment
|
2016-02-24 17:51:20 +03:00
|
|
|
do
|
|
|
|
: ${next:=0}
|
|
|
|
while [ "$number" -gt "$next" ]
|
|
|
|
do
|
|
|
|
echo ' "???",'
|
|
|
|
next=$(( next + 1))
|
|
|
|
done
|
|
|
|
echo ' "'"$name"'",'
|
|
|
|
next=$(( number + 1 ))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "};"
|
2016-02-27 21:34:12 +03:00
|
|
|
echo '#else'
|
|
|
|
echo "extern const char * const NodeNames[${MAX} + 1];"
|
|
|
|
echo '#endif'
|
2016-02-24 17:51:20 +03:00
|
|
|
echo
|
|
|
|
echo '#define NODETYPENAME(type) \'
|
|
|
|
echo ' ((unsigned)(type) <= '"${MAX}"' ? NodeNames[(type)] : "??OOR??")'
|
|
|
|
echo
|
In the older debug code (not using the new macros added in the
previous rev) the two values (node name, and node number) were
arbitrarily printed in different formats and orders (depending
upon my mood at the time I guess...) The new macros will standardise
that usage (in the debug output) once some use of them actually begins.
When the macros were added, I arbitrarily copied the format of one
use I was looking at at that instant (the one which inspired the change),
but after gazing at DEBUG mode output over the intervening time, I
have concluded that I did not pick the easiest to read/follow format.
So, even before they are used, change the style... Also, conform
to standard PRIxxxx macro style by omitting the leading '%'.
NFC (since they aren't used at all, anywhere, yet, not even the
possibility of anything changing!)
2018-08-18 06:09:37 +03:00
|
|
|
echo '#define NODETYPE(type) NODETYPENAME(type), (type)'
|
|
|
|
echo '#define PRIdsNT "s(%d)"'
|
2018-08-16 18:02:05 +03:00
|
|
|
echo
|
|
|
|
echo '#else /* DEBUG */'
|
|
|
|
echo
|
|
|
|
echo '#define NODETYPE(type) (type)'
|
In the older debug code (not using the new macros added in the
previous rev) the two values (node name, and node number) were
arbitrarily printed in different formats and orders (depending
upon my mood at the time I guess...) The new macros will standardise
that usage (in the debug output) once some use of them actually begins.
When the macros were added, I arbitrarily copied the format of one
use I was looking at at that instant (the one which inspired the change),
but after gazing at DEBUG mode output over the intervening time, I
have concluded that I did not pick the easiest to read/follow format.
So, even before they are used, change the style... Also, conform
to standard PRIxxxx macro style by omitting the leading '%'.
NFC (since they aren't used at all, anywhere, yet, not even the
possibility of anything changing!)
2018-08-18 06:09:37 +03:00
|
|
|
echo '#define PRIdsNT "d"'
|
2018-08-16 18:02:05 +03:00
|
|
|
echo
|
|
|
|
echo '#endif /* DEBUG */'
|
|
|
|
echo
|
|
|
|
echo '#endif /* !NODENAMES_H_INCLUDED */'
|