# This script converts dos header files into header files
# that are compatible with the WIZARD compiler
#
DOSINCLUDE=/msc/include
UNIXINCLUDE=/opus/oplib/include

echo "Directory of the DOS header files? [$DOSINCLUDE] \c"
read DOSDIR
if [ "$DOSDIR" = "" ]; then
	DOSDIR=$DOSINCLUDE
fi
echo "Directory of the translated header files? [$UNIXINCLUDE] \c"
read UNIXDIR
if [ "$UNIXDIR" = "" ]; then
	UNIXDIR=$UNIXINCLUDE
fi
while :; do
echo "header file name (RETURN to quit)? \c"
read FILE
if [ "$FILE" = "" ]; then
	break
fi
if [ ! -f $DOSDIR/$FILE ]; then
	echo "$DOSDIR/$FILE not found"
	continue
fi
awk 'BEGIN { printf("#ifndef NO_EXT_KEYS\n");
		printf("#define NO_EXT_KEYS\n");
		printf("#endif\n");
		printf("#ifndef far\n");
		printf("#define far\n");
		printf("#define near\n");
		printf("#endif\n");
		printf("#ifndef cdecl\n");
		printf("#define cdecl\n");
		printf("#endif\n");
}
/\);/ { if ( $1 !~ /#define/ )
		if (index($0,"(")) {
			end = index($0,"(");
			string=substr($0,0,end);
		}
		gotit = 1;
		print string");"
}
/^[ 	]*#define/ {end = index($0,"#define");
	string=substr($0,end,1000);
	gotit = 1;
	print string 
}
{ if ( gotit == 0 )  print $0; gotit = 0 }
' @$DOSDIR/$FILE > $UNIXDIR/$FILE
done
