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


########################################################################
#                                                                      #
# EBM BATCH JOB MACRO :     LABEL                                      #
# Purpose             :     Defines a point in the jobstream that can  #
#                           be used as a target of a GOTO statement.   #
#                                                                      #
########################################################################

. verify_jobstatus
. beginjob.${EBMSYS}.${JON}
. current_proc_level.${EBMSYS}.${JON}

if [ "${PROC_LEVEL}" -gt 0 ]
then
   prior_level=`expr ${PROC_LEVEL} - 1`
   if [ -f label.${EBMSYS}.${JON}.${prior_level} ]
   then
      . label.${EBMSYS}.${JON}.${prior_level}
   fi
fi

if [ -f beginproc.setparms.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . beginproc.setparms.${EBMSYS}.${JON}.${PROC_LEVEL}
fi
if [ -f setparm.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . setparm.${EBMSYS}.${JON}.${PROC_LEVEL}
fi


for argument in $*
do
   i=`eval echo $argument`
   case $i in 
      name=*)
         NAME="`eval echo $i|cut -f2 -d'='`" ; export NAME
      ;;
      verbose*)
         VERBOSE=YES ; export VERBOSE
       ;;

      *)
         NAME=$i ; export NAME
      ;;
  esac
done   

# 
# if we are in a procedure, we need to keep a running
# form of the stepnames, starting from the job level
# i.e. jobstep_procstep_procstep
# we use this running step name to keep create unique names
#
if [ "${PROC_LEVEL}" -gt 0 ]
then
   RUNNINGSN=${RUNNINGSN}_$NAME
else
   RUNNINGSN=$NAME
fi
export RUNNINGSN

if [ "a$NAME" != "a" ]
then
   STEPNAME=$NAME ; export STEPNAME

   cat <$DEVNULL > label.${EBMSYS}.${JON}.${PROC_LEVEL} 
   chmod 755 label.${EBMSYS}.${JON}.${PROC_LEVEL} 

   echo "STEPNAME=$NAME; export STEPNAME" >> label.${EBMSYS}.${JON}.${PROC_LEVEL}
   echo "RUNNINGSN=$RUNNINGSN; export RUNNINGSN" >> label.${EBMSYS}.${JON}.${PROC_LEVEL}
   if [ "a$VERBOSE" = aYES ]
   then
      echo " "
      print_message LABEL "$NAME"
   fi

else
   print_message LABEL "ERROR   invalid syntax: name is required"
   . set_jobstatus_abort
fi

#
# In either mode of processing, MVS / VSE, we
# need to know immediately if we have reached
# a target label or not if a goto is in effect.
# This is also done for performance enhancements.
#
# However, if we are in the middle of an IF/THEN/ELSE/ENDIF
# series, we bypass this check if we have BOTH a bypassfile
# and an ifbypassfile.  Having both of these means the current
# bypassfile was set because of the IF result and we want
# to keep it until the corresponding ELSE or ENDIF (and a GOTO
# within the scope of if/then/else/endif is currently not valid).
#
# there will always be at least ifbypassfile.1, regardless of the nesting
#
if [ ! -f bypassfile.${EBMSYS}.${JON} -o ! -f ifcodeseg.1.${EBMSYS}.${JON} ]
then
    . check_bypass_step
fi

exit 0
