#############################################################################
#
# This script compiles a C test program and generates a pascal main program
# which is needed to run the C test program. It also generates a stream file
# for PAWS. This has to be executed on PAWS after the current script has 
# successfully completed.
# It is assumed that the user inputs the file name without extensions, they
# are generated automatically.
#
# Actions performed:
# $1.c is compiled with the PAWS C compiler, output is $1.s
# $1.s is copied to the SRM system with srmput, output is $1.TEXT
# File main.TEXT is generated on SRM (pascal main program).
# File maketst.TEXT is generated on SRM (stream file).
#
# Author: Angelika Hierath, BCD R&D
#         4-Nov-86
#
#############################################################################

USAGE="usage: gentst <file name without extension> <destination directory>"

CLIBRARY="PCLIB:CLIBRARY"
CCOMP="/users/paws/angelika/CC/src/ccom"
INC="/users/paws/angelika/HEADER"
SRMVOL=${SRMVOL:="bcdrd"}
SRMDEV=${SRMDEV:="/dev/srm"}
SRMHOME=${SRMHOME:="/"}

if [ $# -ne 2 ]
then
	echo $USAGE
	exit 1
fi

echo "#####################################################################"
echo "Started with gentst of $1 at `date`"
echo "#####################################################################"


# compile $1
echo "compile $1"
/lib/cpp -I$INC $1.c $1
$CCOMP -P $1 $1.s


# copy $1.s to SRM $1.TEXT
srmrm -v$SRMVOL $SRMDEV:$SRMHOME/$2/$1.TEXT 2>/dev/null
echo "copy file $1.s to SRM $SRMDEV:$SRMHOME/$2/$1.TEXT"
expand $1.s | srmcp -p -v$SRMVOL - $SRMDEV:$SRMHOME/$2/$1.TEXT

# rm intermediate files
rm $1
rm $1.s

# generate main program and copy it to SRM
echo "copy main program to SRM"
srmrm -v$SRMVOL $SRMDEV:$SRMHOME/$2/main.TEXT 2>/dev/null
{
echo "\$search 'tst','$CLIBRARY'\$"
echo "program tst(input,output);"
echo "import $1,CLIB;"
echo "var x: integer;"
echo "begin x:= main; end."
} | srmcp -p -v$SRMVOL - $SRMDEV:$SRMHOME/$2/main.TEXT

# generate stream file
echo "copy stream file to SRM"
srmrm -v$SRMVOL $SRMDEV:$SRMHOME/$2/maketst.TEXT 2>/dev/null
{
echo "A$1.TEXT"
echo "ntst"
echo "cmain"
echo "n"
echo "lo$1"
echo "limain"
echo "aitst"
echo "ai$CLIBRARY"
echo "alkq"
echo "frtst.CODE"
echo "q"
echo "****************************"
echo "* TEST $1 made"
echo "****************************"
} | srmcp -p -v$SRMVOL - $SRMDEV:$SRMHOME/$2/maketst.TEXT


echo "#####################################################################"
echo "# Done with gentst of $1 at `date`"
echo "# Now run streamfile $SRMHOME/$2/maketst.TEXT on SRM"
echo "######################################################################"
