#!/bin/sh 

# Get this from environment if available, or use a default working
# when invoked by build-dir.
# Better yet might be generating this file on make check..
#
GPROCESSOR=${GPROCESSOR:=../../utilities/gprocessor}

# NOTE: We're supposed to advance 10 frames.
#	We allow 11 loop-backs (just for fun, we probably can support more)
#
FLAGS="-r11 -f10 -v"

if [ -z "$1" ]; then
	echo "Usage: `basename $0` <swffile> [<flags>]" >&2
	exit 2
fi


in="$1"
shift
FLAGS="$FLAGS $@"
out=`basename "${in}"`.trace-gnash
logout=`basename "${in}"`.out
logerr=`basename "${in}"`.err
logpipe=${logout}.fifo
mknod $logpipe p
exp="${in}.trace"

echo "Running ${GPROCESSOR} ${FLAGS} ${in}" >&2
${GPROCESSOR} ${FLAGS} "$in" > $logpipe 2> $logerr &
cat < $logpipe > $logout
rm $logpipe

grep -a TRACE -A40 ${logout} | sed '/^--$/d; s/.*TRACE: //; /\n*[0-9]:[0-9]*\].*/d; s/^$//;' > $out
diff -u "$exp" "$out"
exit $?
