#!/bin/sh
#############################################################################
##  APPX_SUBMIT
##
##  This script will submit the Appx background job specified on the 
##  the command line to be executed.
##
##  The format of the command line is expected to be:
##
##	<script-name> <options>
##
##  Where <options> will be a list of the following options
##
##	-image=<image_name>
##	-session=<session_name>		
##	-notify=<notify_user> 
##	-date=<submit_date> 
##	-priority=<submit_priority>
##	-queue=<submit_queue>
##	-user=<submitting_user>
##
#############################################################################

PROCESS_ARGS ()
{
    while test "$1"
    do
 	case $1 in
	    -image*)
		#	-image=<image_name>
		#	
		#  	This argument contains the full pathname
		# 	of the Appx executable used to submit the
		#	the background process
	
		COMMAND=`echo $1 | cut -f 2 -d =`
		;;

	    -session*)
		#	-session=<session_file_name>
		#	
		# 	This argument must given to the Appx background
		# 	process when it is invoked.  It is the eight-
		#	character name of a file which contains all of
		#       the context information necessary to restart the
		#       submitted process

		COMMAND="$COMMAND $1"
		;;		

	    -priority*)		
		#	-priority=<priority_value>
		#
		#	This argument contains the value of the
		#	"SUBMIT PRIORITY" PDF.
		#
		#	The -priority option (if non-blank) is used to 
		# 	specify the "nice" value of the background process.  
		#	It should be a value suitable for the Unix "nice"
		# 	command.

		NICENESS=`echo $1 | cut -f 2 -d =`
		if test "$NICENESS"
		then
		    COMMAND="nice -$NICENESS $COMMAND"
		fi
		;;

	    -notify*)
		#	-notify="Yes"|"No"|""
		#	
		# 	This argument is an interpretation of the 
		#       "SUBMIT NOTIFY USER" PDF.  It will contain 
		#	either "Yes", "No", or blank.
		#
		#	This script ignores the -notify option
		;;
		
	    -date*)
		#	-date=CCYYMMhhmmddhhssth
		#	
		#	This argument is an interpretation of the
		#	"SUBMIT DATE" PDF.  It will contain a date
		# 	in the indicated format or blank.
		#
		#	This script ignores -date option.
		;;

  	    -queue*)
		#	-queue=<queue_name>
		#
		#	This argument contains the value of the
		#	"SUBMIT QUEUE" PDF.
		#
		#	This script ignores the -queue option.
		;;

	    -user*)
		#	-user=<user_name>
		#
		#	This argument contains the Unix user name
		# 	of the submitter.
		#
		#	This script ignore the -user option
		;;
	esac
	
	shift
    done

}


PROCESS_ARGS $*

$COMMAND < /dev/null > /dev/null 2>&1 &

echo "$COMMAND - $!" >> /tmp/submit.log

#############################################################################
##  Modification History
##
##  DATE      BY   Description
##  --------  ---  ----------------------------------------------------------
##  10/31/93  KAD  Initial Creation
##  07/26/93  BHW  Modified to run under Bourne shell (instead of Korn
##		   Shell) for portability.  No loss of functionality, but
##		   some of the readability was sacrificed.  Many external
##		   utilities had to be used to compensate for the shell
##		   "downgrade."
##
#############################################################################
