
# UNISRC_ID: @(#)f_rinstr.sh	27.2	85/03/10  
#  ***routine level***
#
#  FILE NAME is 'f_rinstr'
#
#  This script is called by make to do SOFTOOL instrumentation at the routine
#  level.  It also compiles the resulting modified source file, and produces 
#  an AUDITOR modified source listing if there are compiler errors.
#  NOTE: This should not happen since a program will be instrumented for
#  optimization purposes only.  The original source remains in a '.f' file,
#  the modified source in a '.f.f' file, the instrument listing in a '.ril'
#  file and the new object code in a '.o' file.  If an AUDITOR listing is
#  generated, it is found in a '.L' 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 (/usr/contrib/bin/aud_cntrl) which
#  supresses all warning, portability, and documentation messages.

#  Next, the .audit file is removed.
#
#  If the AUDITOR was run on the file, its error messages are put in the 
#  source before the line which caused 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/r_cntrl `basename $1 .f`.ril
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
