#! /bin/bash

filename=/tmp/$$; file_count=0; short=0; long=0

while [ $# -ne 0 ]; do
    case $1 in # 2 kinds of arguments: files and ops ... 
	-*) echo $1 > $filename; opt=`sed 's/-//' $filename`; eval "$opt=1" ;;
	*) ((file_count++)); eval "log$file_count=$1" ;;
    esac; shift;
done

echo "old: $log1
new: $log2
"
# 
if [ $file_count -gt 1 ]; then
    failed_self_test1=`grep "WARNING: Couldn't test self" $log1 | wc -l`
    failed_self_test2=`grep "WARNING: Couldn't test self" $log2 | wc -l`
    if ([ $failed_self_test1 -eq 0 ] && [ $failed_self_test2 -ne 0 ]) || ([ $failed_self_test1 -ne 0 ] && [ $failed_self_test2 -eq 0 ])
	then echo "NOTE: self testing failed in one of these runs - probably because one of the gdb's is a release build.  So gdb test summary numbers for the two runs won't match up."
    fi
fi

if [ $long -eq 1 ]; then
    test_types="KPASS XPASS PASS KFAIL FAIL XFAIL UNRESOLVED UNTESTED UNSUPPORTED"
else test_types="FAIL UNRESOLVED UNTESTED UNSUPPORTED"; fi

for test_type in $test_types; do
    grep "^$test_type:" $log1 > $filename.1
    if [ $file_count -gt 1 ]; then 
	grep "^$test_type:" $log2 > $filename.2
	diff $filename.1 $filename.2 | grep '^>' > $filename.3
    else
	cat $filename.1 > $filename.3
    fi
    count=`cat $filename.3 | wc -l`
    if [ $count -ne  0 ]; then echo "
New $test_type""s: $count
----------------------------------"
	if [ $file_count -gt 1 ]; then 
	    if [ $short -eq 1 ]; then 
		sed "s/^> $test_type: //" $filename.3 | sed "s/:.*$//" | uniq
	    else sed "s/^> $test_type: //" $filename.3; fi
	else 
	    if [ $short -eq 1 ]; then 
		sed "s/^$test_type: //" $filename.3 | sed "s/:.*$//" | uniq
	    else sed "s/^$test_type: //" $filename.3; fi
	fi
    fi
    rm -f $filename.1 $filename.2 $filename.3
done

if [ $long -ne 0 ]; then 
    echo "
ERRORs:`grep ERROR: $log1 | wc -l`
-----------------------"
    grep ERROR: $log1

    echo "
WARNINGs:`grep WARNING: $log1 | wc -l`
-----------------------"
    grep WARNING: $log1
else
    echo "
ERRORs:`grep ERROR: $log1 | wc -l`
-----------------------

WARNINGs:`grep WARNING: $log1 | wc -l`
-----------------------"
fi 