#!/bin/sh

TMPFILE=/tmp/temp.$$

X=`echo "$MSTESTDB" | sed -e 's;/testwork/_testtmp/testdb;;'`

cat > $TMPFILE <<EOM
s;= "DATABASE";= "$X" //\\
     1  "/testwork/_testtmp/testdb";
s;"DATABASE";"$MSTESTDB";
EOM

if grep SIZE_OF_C_LONG script.ff > /dev/null 2>&1
then
	case $MSSYS_PLATFORM in
	 SYS_OS_UNIX_IRIX_64)	
		cat > sizelong.c <<@
#include <stdio.h>
int main(int argc, char** argv)
{ printf ("%ld %ld\n", sizeof(long), sizeof(short)); return 0; }
@
		;;
	 *)
		cat > sizelong.c <<@
#include <stdio.h>
int main(int argc, char** argv)
{ printf ("%d %d\n", sizeof(long), sizeof(short)); return 0; }
@
		;;
	esac
	$EMPRESSPATH/common/sys_bin/cc -o sizelong sizelong.c

	./sizelong > tmp
	read SIZE_OF_C_LONG SIZE_OF_C_SHORT < tmp

	cat >> $TMPFILE <<EOM
s;SIZE_OF_C_LONG;$SIZE_OF_C_LONG;
s;SIZE_OF_C_SHORT;$SIZE_OF_C_SHORT;
EOM

	rm -f ./sizelong ./tmp
fi

sed -f $TMPFILE < script.ff > script.f
rm -fr $TMPFILE

echo "Calling the precompiler"
empesql -ptr script.f scptout.f scptoutc.c
echo "Compiling the resulting C/Fortran program"
$EMPRESSPATH/common/sys_bin/cc -c -I$EMPRESSPATH/rdbms/include scptoutc.c >> testout 2>&1
empef77 -o script scptout.f scptoutc.o
echo "Running the compiled program"
./script >> testout 2>&1

$MSTSRCMINOR/_strip testout
