#! /bin/sh
# Some machines weren't able to complete the x11perf tests, or missed
# some tests. Fills in lines with a 0.0 average rate for the missing lines.
# Mark Moraes, University of Toronto
f=$1
label=$2
awk '$2 == "reps" || $2 == "trep" {
	print $0;
	next;
    }
' $f | sed 's/^.*: //' | uniq > /tmp/f1.$$
diff -e /tmp/f1.$$ $label > /tmp/f2.$$
others=`sed -n -e ':start' \
	-e '/^[0-9]*,[0-9]*d$/b pnext' \
	-e '/^[0-9]*[ac]$/b skpdot' \
	-e '/^[0-9]*,[0-9]*c$/b skpdot' \
	-e x -e 's/.*/bad pattern in diff output/' -e p -e n -e 'b start' \
	-e :skpdot -e p -e :skip -e n -e '/^\.$/b next' -e 'b skip' \
	-e :pnext -e p -e :next -e n -e 'b start' \
/tmp/f2.$$ | grep -v '^[0-9]*a'`
case "$others" in
'')	;;
*)	echo "$0: label file $label is incomplete or out of date," >& 2
	echo "   or you are trying to use old (pre-1.2) x11perf results." >& 2
	exit 1
	;;
esac
(sed 	-e :start -e '/^[0-9]*[ac]$/b skpdot' \
	-e :skpdot -e :skip -e n -e '/^\.$/b next' \
		-e 's,.*,     0 reps @  0.0    msec (0.0/sec): &,' \
		-e 'b skip' \
	-e :next -e n -e 'b start' \
	/tmp/f2.$$; echo '1,$p') | ed - $f > /tmp/f1.$$
cat /tmp/f1.$$
rm -f /tmp/f1.$$ /tmp/f2.$$
