#!/bin/sh

# Note:  use sed to strip blanks because not all systems have same version
# of diff.

if [ "x$GCTLIB" = "x" ]
then
  GCTLIB=`pwd`/../../../
  PATH=.:`pwd`/../../..:$PATH
  export PATH
fi


# Note that we flush all the header crud GCT puts on.  What exactly
# goes there is rather in flux.
doit()
{
	echo "$INDENT" " $1"
	gct-init $GCTLIB
	gct-ansi -B$GCTLIB $1.c
	sed -e "1,/#line 1/d" -e "s/ //g" T$1.c > /tmp/T$1.N
	sed -e "1,/#line 1/d" -e "s/ //g" $1.ref > /tmp/$1.N
	if diff /tmp/T$1.N /tmp/$1.N
	then
		rm /tmp/T$1.N /tmp/$1.N
	fi
}

make clean
gct-init $GCTLIB

doit pragma 2> pragma.2log; diff pragma.2log pragma.2ref
if [ "$GCT_UNPORTABLE_OK" = "true" ]
then
  # Have to use GCC; cc may not understand pragmas.
  # For some reason, /bin/sh now dumps core when a.out is used
  # as outfile.  Probably memory leak style bug - changing a.out
  # to EXEC fixes it.  Good grief.
  gcc -g -o EXEC Tpragma.c gct-write.c gct-ps-defs.c
  ./EXEC > GMERGE; diff GMERGE pragma.oref
  greport -all GLOG > GMERGE; diff GMERGE pragma.mref
else
  echo $INDENT "Skipping rest of pragma test (not portable)"
fi

echo "$INDENT " wide
gct-init $GCTLIB
gct -c -B$GCTLIB wide.c 2> wide.log
diff wide.log wide.ref

doit annotation
doit bugs
doit characters
doit functions
doit expr
doit test-unary
doit test-ref
doit typecrud
doit test-if
doit loops
doit misc-stmt
doit ambiguity
doit strings
doit strings2
doit sizeof
doit sizeof2


exit 0
