Home | History | Annotate | Line # | Download | only in sh
mknodenames.sh revision 1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos test -t 1 && test "$#" -eq 0 && exec > nodenames.h
      4  1.1  christos 
      5  1.1  christos echo "#ifdef DEBUG"
      6  1.1  christos echo '
      7  1.1  christos /*
      8  1.1  christos  * Automatically generated by '"$0"'
      9  1.1  christos  * DO NOT EDIT. Do Not "cvs add".
     10  1.1  christos  */
     11  1.1  christos '
     12  1.1  christos 
     13  1.1  christos MAX=$(awk < nodes.h '
     14  1.1  christos 	/#define/ {
     15  1.1  christos 		if ($3 > MAX) MAX = $3
     16  1.1  christos 	}
     17  1.1  christos 	END { print MAX }
     18  1.1  christos ')
     19  1.1  christos 
     20  1.1  christos echo
     21  1.1  christos echo "STATIC const char * const NodeNames[${MAX} + 1] = {"
     22  1.1  christos 
     23  1.1  christos grep '^#define' nodes.h | sort -k2n | while read define name number opt_comment
     24  1.1  christos do
     25  1.1  christos 	: ${next:=0}
     26  1.1  christos 	while [ "$number" -gt "$next" ]
     27  1.1  christos 	do
     28  1.1  christos 		echo '	"???",'
     29  1.1  christos 		next=$(( next + 1))
     30  1.1  christos 	done
     31  1.1  christos 	echo '	"'"$name"'",'
     32  1.1  christos 	next=$(( number + 1 ))
     33  1.1  christos done
     34  1.1  christos 
     35  1.1  christos echo "};"
     36  1.1  christos echo
     37  1.1  christos echo '#define NODETYPENAME(type) \'
     38  1.1  christos echo '	((unsigned)(type) <= '"${MAX}"' ? NodeNames[(type)] : "??OOR??")'
     39  1.1  christos echo
     40  1.1  christos echo '#endif'
     41