#!/bin/sh

if [ $# = 0 ]; then
	echo "usage: `basename $0` files"
	exit 1
fi

for f in $@; do
	echo $f
	bfile=`basename $f .h`
	(prot=__`echo $bfile`__
	echo "#ifndef $prot"
	echo "#define $prot"
	echo
	cat $f
	echo
	echo "#endif /* $prot */"
	) | sed -e 's^import^include^g' -e 's^<foundation^<Foundation^g' -e '/objc-class\.h/s^.*^^g' -e '/@class/,/;/s/<[a-zA-Z, ]*>//g' -e 's^NSException	\*exception^NSException \*localException^g' -e 's^exception = nil^localException = nil^g' >$f.new
	mv $f.new $f
done
