#! /bin/sh

target=$1

rm -f test.diff core pokusny_subor *.core
for file in *.ci; do
    if test $file = "io.ci" -o $file = "test00.ci"; then
	continue
    fi
    file_out=`echo $file | sed 's/\.ci//'` 
    num=`echo $file_out | egrep test[6-9][0-9]`
    if test -n "$num" -a "$num" != test60; then
	arg="-fno-call-by-reference -fcall-by-value -fhandle-main"
    else
	arg=
    fi
    if test -f "$file_out.in"; then
	$target/clif $file $arg < "$file_out.in" 1>test.diff 2>/dev/null
    elif test -f "$file_out.out"; then 
	$target/clif $file $arg 1>test.diff 2>/dev/null
    else
	$target/clif $file $arg
    fi
    if test $? -ne 0; then
	failed="$failed $file"
    elif test -f core; then
	failed="$failed $file"
    elif test -f *.core; then
	failed="$failed $file"
    elif test -f test.diff; then
	if cmp -s test.diff "$file_out.out"; then
	    if test -f pokusny_subor; then
		if cmp -s pokusny_subor test_file; then
		    :
		else
		    failed="$failed $file"
		fi
	    fi
	else
	    failed="$failed $file"
	fi
    fi
    rm -f core *.core test.diff pokusny_subor
    echo "$file"
done

if test -z "$failed"; then
    echo "All checks successful"
else
    echo "Failed checks were:"
    echo "$failed"
fi
