#!/usr/bin/perl
#
# This program gobbles up its input, which should be  one  or  more  C
# case  statements  (plus  all of each case's code); the output is the
# same code surrouded by an #ifdef.  Thus it takes
#      case FOO:
#          ...
#          break;
# and converts it to:
#    #ifdef FOO
#      case FOO:
#          ...
#          break;
#    #endif
# Note that you may feed it more than one case.  Complicated cases may
# take some editing afterwards.  The point of all this is to make code
# more portable, using the  C  preprocessor  to  suppress  cases  that
# aren't defined on a given machine.

while (<>) {
	if (/(\s*)case\s+(\w+)\s*:/) {
		print "#endif\n" if ($sym);
		$sym = $2;
		print "#ifdef$1 $sym\n";
	}
	print;
}
print "#endif\n" if ($sym);
exit 0;
