#!/bin/sh
#
# A hack program intended to massage the source code for various RCCL
# and RCI demo programs to get them ready for verbatim insertion into
# the documenation. This massaging consists of two things:
# 
# (1) deleting code that is special cased on "vxWorks";
# (2) running 'expand' so that tabs will not bother the TeX 'cverbatim'
#     macro.
#
tmpout=
case $# in
	0)	;;
	1)	exec <"$1"
		;;
	2)	tmpout="$2 TEMP $$"
		trap "rm -f '$tmpout'; exit" 0 1 2 15
		exec <"$1" >"$tmpout"
		;;
	*)	echo "usage: $0 [<inputFile> [<outputFile>]]" 1>&2; exit 1
		;;
esac
awk   '/^#if/{lev++};\
	/^#ifdef vxWorks/{if(start==0){start=lev;m=1;next}};\
	/^#ifndef vxWorks/{if(start==0){start=lev;m=0;next}};\
	/^#else/{if(start==lev){m=1-m;next}};\
	/^#endif/{if(start==lev--){start=0;m=0;next}};\
	m==0{print};' | expand
if [ "$tmpout" != "" ]; then
	mv "$tmpout" "$2"
fi

