
:

# callpc     compiles a call-interface program
# Usage :    callpc {-compiler_options} name.suffix
# Inputfile is     name.p   for pascal
# Inputfile is     name.c   for c
# Inputfile is     name.cob for cobol
# Inputfile is     name.f   for fortran
# Compiler - Errors are written to name.lst
# vpx15.m

FORTRAN=f77
FORTOPT="-c"

PASCAL="pc"

#  set -x


anz=$#
all=$*
shift `expr $# - 1`
case $1 in
     *.cob ) suf=cob ;;
     *.cbl ) suf=cbl ;;
     *.p   ) suf=p   ;;
     *.c   ) suf=c   ;;
     *.C   ) suf=C   ;;
     *.f   ) suf=f   ;;
esac


bas="`basename $1 .${suf}`"
dir="`dirname $1`"
if [ ! -f ${dir}/${bas}.${suf} ]
then
   echo ${dir}/${bas}.${suf} not found
   exit
fi
if [ -f ${bas}.o ]
then
   rm ${bas}.o
fi
if [ -f ${bas}.lst ]
then
   rm ${bas}.lst
fi


ret=0
if [ $anz -eq 1 ]
then
   case ${suf} in
        p   )
              cp $DBROOT/incl/sqcp* .
              $PASCAL -c            ${all} > ${bas}.lst
              rm sqcp*
              cat ${bas}.lst
              if [ ! -s ${bas}.lst ]
              then
                 rm ${bas}.lst
              fi
              ;;
        c   )
              cc -c -I $DBROOT/incl ${all} > ${bas}.lst
              cat ${bas}.lst
	      if [ ! -f ${bas}.o ]
	      then
	      	 ret=1;
	      fi
              ;;
        C   )
              CC -c -I $DBROOT/incl ${all} > ${bas}.lst
              cat ${bas}.lst
              ;;
        f   )
              cp $DBROOT/incl/sqcf* .
              $FORTRAN $FORTOPT     ${all} > ${bas}.lst
              rm  sqcf*
              cat ${bas}.lst
              ;;
        cbl )
              cobolpc ${all}
              ;;
        cob )
              cobolpc ${all}
              ;;
        *   )
              echo not implemented
              exit
              ;;
   esac
   if [ ${ret} = 0 ]
   then
      ret=$?
   fi
else
   case ${suf} in
        p   )
              cp $DBROOT/incl/sqcp* .
              $PASCAL  ${all} > ${bas}.lst
              rm sqcp*
              cat ${bas}.lst
              if [ ! -s ${bas}.lst ]
              then
                 rm ${bas}.lst
              fi
              ;;
        c   )
              cc       ${all} > ${bas}.lst
              cat ${bas}.lst
	      if [ ! -f ${bas}.o ]
	      then
	      	 ret=1;
	      fi
              ;;
        C   )
              CC       ${all} > ${bas}.lst
              cat ${bas}.lst
              ;;
        f   )
              cp $DBROOT/incl/sqcf* .
              $FORTRAN ${all} > ${bas}.lst
              rm  sqcf*
              cat ${bas}.lst
              ;;
        cbl )
              cobolpc ${all}
              ;;
        cob )
              cobolpc ${all}
              ;;
        *   )
              echo not implemented
              exit
              ;;
   esac
   if [ ${ret} = 0 ]
   then
      ret=$?
   fi
fi
exit $ret
