#!/bin/ksh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


ebm_print_sysout()
{
cat $SysoutListPrint | while read linein
do
   unset FILENAME
   unset DEST
   unset PRIORITY
   unset tmpfile
   FILENAME=`eval echo $linein | cut -f1 -d' '`
   export FILENAME
   for args in $linein
   do
      export args
      case $args in
         copies=*)
	    COPIES=`eval echo $args | cut -f2 -d'='`
	    export COPIES
         ;;
         dest=*)
            DEST=`eval echo $args | cut -f2 -d'='`
            export DEST
         ;;
         priority=*)
            PRIORITY=`eval echo $args | cut -f2 -d'='`
            export PRIORITY
         ;;
      esac
   done
   #
   # see if there are some specific printer control commands
   # associated with the destination printer
   #
   tmpfilecreate=no; export tmpfilecreate
   if [ -d "$PUBLIC/prtctl" ]
   then
      if [ -f "$PUBLIC/prtctl/$DEST" ]
      then
         tmpfile=`ebmsed $EBMTMPDIR/ebm_ow.${EBMSYS}.${JON}.$$`
         tmpfilecreate=yes ; export tmpfilecreate
         cat $PUBLIC/prtctl/$DEST > $tmpfile
         if [ $? -ne 0 ]
         then
            echo "OW: ERROR creating temporary file $tmpfile"
            exit 1
         fi
         cat $FILENAME >> $tmpfile
         if [ $? -ne 0 ]
         then
            echo "OW: ERROR creating temporary file $tmpfile"
            exit 1
         fi
         FILENAME=$tmpfile
         export FILENAME
      fi
   fi
   # invoke the print specification file
   #
   . $printspec
   if [ ${tmpfilecreate} = "yes" ]
   then
      rm $tmpfile
   fi
done

return
}
########################################################################
if [ -f $1 ]
then
    IMPFILE=$1
    cp $IMPFILE $SYSOUTDIR/$IMPFILE
    echo "Report routed to " $SYSOUTDIR/$IMPFILE
    rm -f $IMPFILE
else
    IMPDIR=$1
    if [ -d $IMPDIR ]
    then
      rmdir $IMPDIR >$DEVNULL 2>&1
      if [ $? -eq 0 ]
      then
    	 echo "No files to be printed"
      else
    	 echo "Files to be printed:"
	 case $BATCH_MODE in
	 VSE)
            case $EBM_OS_NAME in
               NT)
                  SysoutListPrint=${SYSOUTDIR}/${JOBNAME}/JOB_${JON}/SysoutListPrint_${JOB_STIME}
               ;;
               *)
                  SysoutListPrint=${SYSOUTDIR}/${JOBNAME}/JOB_${JON}/SysoutListPrint
               ;;
            esac
            export SysoutListPrint
            SysoutListDir=${SYSOUTDIR}/${JOBNAME}/JOB_${JON}
            if [ -f "$SysoutListPrint" ]
            then
               if [ -s "$SysoutListPrint" ]
               then
                  cat $SysoutListPrint
                  ##############################################################
                  #
                  #  printspec.NT or printspec.LP
                  #                a configuration filename containing
                  #                line(s) utilizing the desired print, or
                  #                other, command.  For example, if using
                  #                the UNIX lp command, the line would be:
                  #                lp -d$DEST -n$COPIES $FILENAME
                  #                see the sample file printspec.LP
                  #
                  case $EBM_OS_NAME in
                     NT)
                        printspec=printspec.NT
                        export printspec
                        ;;
                     *)
                        printspec=printspec.LP
                        export printspec
                        ;;
                  esac
                  #
                  ##############################################################
                  # to actually print files, uncomment the following lines
                  #
                  # if [ -s $SysoutListPrint ]
                  # then
                  #    ebm_print_sysout
                  # fi
                  ##############################################################
               else
                  echo "OW: No sysout files to process"
               fi
            else
               echo "OW: No sysout files to process"
            fi
            ###################################################################
            # Comment out the following lines to RETAIN the sysout print list,
            # sysout hold list, and all the sysout files
            ###################################################################
            if [ -f "$SysoutListPrint" ]
            then
               rm -f $SysoutListDir/SysoutListPrint
               rm -f $SysoutListDir/SysoutListHold
               rmdir $SysoutListDir
            fi
	 ;;
	 MVS)
       	    find $IMPDIR -print | egrep "_$JON$" | while read FILE
       	    do
   
            ####################################################################
            # Uncomment the following two lines if you want to rename your
            # report with a date.time suffix
            ####################################################################
            #  mv $FILE $FILE.$JOB_STIME
            #  FILE=${FILE}.${JOB_STIME} ; export FILE
   
       	       if [ $VALIDATE = "y" ]
               then
                  echo $FILE DELETED
                  rm $FILE
               else
                   echo $FILE
               fi
   
            ####################################################################
            # Uncomment the following lines if you want to delete empty 
            # report files.
            ####################################################################
            #  if [ ! -s $FILE ]
            #  then
            #     echo ""
            #     echo "Empty file removed: $FILE "
            #     echo ""
            #     rm -f $FILE
            #  fi
            ####################################################################
   
       	    done
         ;;
      esac
      fi # if [ $? -eq 0 ] (files to be printed
   else
    	 echo "  No  files  to  be  printed"
   fi # if [ -d $IMPDIR ]   argument was not file or directory

fi # if [ -f $1 ]
exit 0
