
# UNISRC_ID: @(#)f_sinstr.sh	27.2	85/03/10  
#  ***statement level***
#
#  FILE NAME is 'f_sinstr'
#
#  This script is called by a make file to run the SOFTOOL
#  instrumenter at the statement level on a source file.  The source
#  file is the compiled, and, if errors occur during compilation, the
#  AUDITOR is run on the file.  The original source code remains in a
#  '.f' file, the modified source in a '.f.f' file, the instrumenter
#  listing in a '.sil' file, and the modified object code in a '.o' file.
#  If the AUDITOR is run on a file, that output is in a '.L' file and the
#  modified source listing is in the '.f.f' file.

#  This script runs a compile with the -c and -U options for an '.f.f' file and
#  sends the error output to awk.  The awk file prints the name of the '.f.f'
#  file if errors occurred during compilation.  This output is printed to a file
#  which is the routine name concatenated with '.aud'.  Note that this file
#  is always created, but its size is >0 when the compilation generated errors.

#  The size of the '.aud' file is checked next, and if it is >0, the SOFTOOL
#  AUDITOR is executed on the '.f.f' file.  The AUDITOR output report is put
#  into a file named from the routine name concatenated with '.L' and the status
#  output of the operation is appended to a log file called 'audit.log'.
#  (Status is 0 if the tool executes properly.)
#
#  An AUDITOR control file is also used (aud_cntrl) which supresses all 
#  warning, portability, and documentation messages.

#  Next, the .aud file is removed.

#  Next, if errors were found during compilation, the '.f.f' file is modified
#  so that the SOFTOOL AUDITOR errors are placed before the line causing the
#  error.  In addition, the routine name is written to a file called
#  'compile.err'.

rm -f tmp_srcmod `basename $1 .f`.L audit.log 
/usr/softool/pedir/INSTPREP < $1 >$1.f \
     2>> instr.err /usr/contrib/bin/s_cntrl `basename $1 .f`.sil
awk -f /usr/contrib/bin/awk_soft $1.f | ex $1.f
fc -c -U $1.f 2>&1 | awk -f /usr/contrib/bin/awk_fpe >`basename $1 .f`.aud
echo "compile done"
    if test -s `basename $1 .f`.aud  
      then
	  echo "starting audit"
	  /usr/softool/pedir/AUDITOR <$1.f >`basename $1 .f`.L \
		  2>>audit.log /usr/contrib/bin/aud_cntrl
      fi
    rm `basename $1 .f`.aud
    if test -s `basename $1 .f`.L
      then
	  echo "starting auditor report modifications"
	  echo `basename $1 .f`.L
	  awk -f /usr/contrib/bin/aud.mod `basename $1 .f`.L | ex `basename $1 .f`.L
	  echo "starting source modifications"
	  awk -f /usr/contrib/bin/src.mod tmp_srcmod
	  mv tmp_newsrc $1.f
          echo "compile error in: " $1.f >> compile.err
       fi
    rm -f tmp_srcmod 
if test -s $1.o
  then
    mv $1.o `basename $1 .f`.o
fi
