#! /bin/sh
#
#  Demonstration script for how to install cback2.46 to execute after cfront
#  automatically in the CC script.
#
#  1.  Move the actual cfront binary to a different name (cfront.sun).
#
#
#  2.  Modify the following three variables below:
#
#	CFRONT		location of the cfront compiler  
#	CBACK		location of cback2.46
#	RULES		location of rule control file for cback2.46
#
#  3.  Replace the cfront that CC would normally call with this shell script
#      which calls cfront and cback.
#
#  Explanation:
#      
#      This shell script serves as a wrapper that calls both cfront and cback.
#      The above procedure hard links cback into the compile sequence. 
#
#      This shell script also makes sure that cback is run in a fail safe way.
#      If cback has an internal assertion error, and returns a non-zero
#      exit code, then the orginal output of cfront is compiled instead of
#      cback output.  Therefore it will be as if cback was never called.
#
ARCH=sun4
CFRONT=/usr/local/SUNC++/$ARCH/cfront
CBACK=/usr/local/cback/$ARCH/cback2.46
RULES=/usr/local/cback/$ARCH/cback.rc2.46

TMP1=/tmp/cback$$.1
TMP2=/tmp/cback$$.2

trap 'rm -f $TMP1 $TMP2 ; exit 1' 1 2 3 15

if $CFRONT $* >$TMP1
then
  if $CBACK -e -i $TMP1 -o $TMP2 -r $RULES </dev/null >&2
  then
    cat $TMP2
  else
    cat $TMP1
  fi
else
  status=$?
  rm -f $TMP1
  exit $status
fi
      
rm -f $TMP1 $TMP2
