#! /bin/sh

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

if [ "$1" != "-" -a \( ! -f $1 \) ]; then
    echo "File $1 not found!"
    exit 1
fi

beginfile=/tmp/begin.awk

commands='nothing return throw call call1 call2 class selector send send1 send2 send3 send4 send5 cstring cstringdup string mutable_string puts version BREAK break quit'
cmdsno=0

(
echo "BEGIN {"
for cmd in $commands; do
    echo "command[\"$cmd\"] = 1;"
done
echo "}"
) >$beginfile


cat << \EOF >>$beginfile
{
    for(i = 1; i <= 2; i++)
	if($i in command) {
	    for(j = i; j < NF; j++)
		printf $j " "
	    printf $j "\n"
	    next
	}
}
EOF

sed -e 's/
//g' -e 's/%/%%/g' $1 | gawk -f $beginfile
