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


########################################################################
#                                                                      #
# EBM BATCH JOB MACRO :     SETPGMSW                                   #
# Purpose             :     Assign values to Micro Focus runtime       #
#                           switch: COBSW                              #
#                                                                      #
########################################################################
. verify_jobstatus
. beginjob.${EBMSYS}.${JON}
. current_proc_level.${EBMSYS}.${JON}

if [ -f label.${EBMSYS}.${JON}.${PROC_LEVEL} ]
then
   . label.${EBMSYS}.${JON}.${PROC_LEVEL}
fi

if [ "a$BATCH_MODE" = "aMVS" ]
then
   if [ "a$STEPNAME" != a ]
   then
      . check_bypass_step

      if [ "$BYPASS" = "YES" ]
      then
          exit 0
      fi
   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}
else
   cat <$DEVNULL > setparm.${EBMSYS}.${JON}.${PROC_LEVEL}
   chmod 755 setparm.${EBMSYS}.${JON}.${PROC_LEVEL}
fi

print_message_STEPNAME=''
export print_message_STEPNAME

for argument in $*
do
  i=`eval echo $argument`
  case $i in
    value=*)
       VALUE="`eval echo $i|cut -c7-`"
       export VALUE
       ;;
    verbose*)
      VERBOSE=YES
      ;;
    *)
      print_message SETPGMSW "Invalid parameter specified :   $i" 
      . set_jobstatus_abort
      ABORT=YES; export ABORT
       ;;
  esac
done

if [ "a$ABORT" = "aYES" ]
then
   exit 0
fi

if [ "a$VALUE" = "a" ]
then
   print_message SETPGMSW "WARNING: No value specified, SETPGMSW ignored"
else
   bit0='' ; export bit0
   bit1='' ; export bit1
   bit2='' ; export bit2
   bit3='' ; export bit3
   bit4='' ; export bit4
   bit5='' ; export bit5
   bit6='' ; export bit6
   bit7='' ; export bit7
   bit8='' ; export bit8
   bit0=`echo $VALUE | cut -c1 ; export bit0`
   bit1=`echo $VALUE | cut -c2 ; export bit1`
   bit2=`echo $VALUE | cut -c3 ; export bit2`
   bit3=`echo $VALUE | cut -c4 ; export bit3`
   bit4=`echo $VALUE | cut -c5 ; export bit4`
   bit5=`echo $VALUE | cut -c5 ; export bit5`
   bit6=`echo $VALUE | cut -c7 ; export bit6`
   bit7=`echo $VALUE | cut -c8 ; export bit7`
   bit8=`echo $VALUE | cut -c9 ; export bit8`

   if [ "a$bit0" != "a" ]
   then
      case $bit0 in
         0)
           cobsw=$cobsw-0  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+0  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit1" != "a" ]
   then
      case $bit1 in
         0)
           cobsw=$cobsw-1  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+1  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
     esac
   fi
   if [ "a$bit2" != "a" ]
   then
      case $bit2 in
         0)
           cobsw=$cobsw-2  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+2  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit3" != "a" ]
   then
      case $bit3 in
         0)
           cobsw=$cobsw-3  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+3  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit4" != "a" ]
   then
      case $bit4 in
         0)
           cobsw=$cobsw-4  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+4  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit5" != "a" ]
   then
      case $bit5 in
         0)
           cobsw=$cobsw-5  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+5  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit6" != "a" ]
   then
      case $bit6 in
         0)
           cobsw=$cobsw-6  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+6  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit7" != "a" ]
   then
      case $bit7 in
         0)
           cobsw=$cobsw-7  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+7  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
   if [ "a$bit8" != "a" ]
   then
      case $bit8 in
         0)
           cobsw=$cobsw-8  ; export cobsw
         ;;
         1)
           cobsw=$cobsw+8  ; export cobsw
         ;;
         X|x)
         ;;
           *)
              print_message SETPGMSW "invalid syntax: values must be 0,1 or X"
         ;;
        esac
   fi
fi
cat <$DEVNULL > setpgmsw.${EBMSYS}.${JON}
chmod 775       setpgmsw.${EBMSYS}.${JON}
echo "COBSW=$COBSW:$cobsw ; export COBSW" >> setpgmsw.${EBMSYS}.${JON}
if [ "$VERBOSE" = "YES" ]
then
   print_message SETPGMSW "value=$VALUE"
fi
exit 0
