#!/bin/sh
:	'(c) Copyright	Empress Software Inc.	1983, 2003'

if test "$EMPRESSPATH" = "" 
then
	echo "EMPRESSPATH not set"
	exit 1

elif test ! -d $EMPRESSPATH
then
	echo "invalid EMPRESSPATH"
	exit 1
else
	RDBMSPATH=$EMPRESSPATH/rdbms
	export RDBMSPATH
fi

PROGNAME=`$EMPRESSPATH/common/sys_bin/basename $0`

USAGE="
*** Usage ***  $PROGNAME  [-frtg] database application [parameter ...] [-p [application ...]] 
				or
*** Usage ***  $PROGNAME  [-c | -l] database [application]
"

. $RDBMSPATH/util_bin/banner

NLSECHO="$EMPRESSPATH/common/nls/nlsecho"
UE_E0_NEEDFULLVER=10001
UE_E0_NOTINENV=10002

LOWER=$EMPRESSPATH/common/sys_bin/lower

. $EMPRESSPATH/config/options

MSTERMSYS=$MSSYS_4GLTERMSYS
export MSTERMSYS

OPTS=
FULL=
GRAPH=
EXEC=

for I
do
	case "$I" in
		-f)		FULL=true
				;;
		-ft | -tf)	FULL=true
				GRAPH=false
				;;
		-fg | -gf)	FULL=true 
				GRAPH=true
				;;
		-r)		FULL=false
				;;
		-rt | -tr)	FULL=false 
				GRAPH=false
				;;
		-rg | -gr)	FULL=false 
				GRAPH=true
				;;
		-t)		GRAPH=false
				;;
		-g)		GRAPH=true
				;;
		-c)		GRAPH=false
				OPTS="c"
				;;
		-l)		GRAPH=false
				OPTS="l"
				;;
		-cl | -lc)	GRAPH=false
				OPTS="cl"
				;;
		-*)		echo "$USAGE"
				exit 1
				;;
		*)		break
				;;
	esac
	shift
done

case "$1" in
 "")	echo "$USAGE";	exit 1;;
esac

case "$OPTS" in
 ?*)
	OPTS="-$OPTS"
	case "$FULL" in
         false)
		$NLSECHO   "option: '%s' requires the full version" \
			$UE_E0_NEEDFULLVER $OPTS
		exit 1;;
	 *)	FULL=true;;
	esac
	;;
esac

case "$FULL" in
 "")
	case "$2" in
	 ""|-p)	FULL=true;;
	 *)	FULL=false;;
	esac
	;;
esac

case "$MSTERM" in
 "")	MSTERM=$TERM ;;
esac

case "$GRAPH" in
 "")
	case "$MSTERM" in
 	 ${MSSYS_4GLGRAPHPREFIX}*)	GRAPH=true ;;
 	 *.${MSSYS_4GLGRAPHPREFIX}*)	GRAPH=true ;;
	esac
	;;
esac

#
# In the event that a machine does not have X11 libraries, but does have
# a xterm (ie HP-UX 64 bit machines) we want to set GRAPH to false
#
test "$MSFEATURE_4GLX11" = "yes" || GRAPH=false

case "$GRAPH" in
 true)
	$RDBMSPATH/exec/ncoldep -s
	case $? in
         0)	
		$NLSECHO  "Not in a Windowing Environment" $UE_E0_NOTINENV
		exit 1
		;;
	 1)	
		case "$MSTERM" in
		 ${MSSYS_4GLGRAPHPREFIX}*mc)	;;
		 *.${MSSYS_4GLGRAPHPREFIX}*mc)	;;
		 ${MSSYS_4GLGRAPHPREFIX}*)	MSTERM="${MSTERM}mc";;
		 *.${MSSYS_4GLGRAPHPREFIX}*)	MSTERM="${MSTERM}mc";;
		esac
		;;
	esac

	case "$FULL" in
	 true)	
		EXEC=emp4fulg
		;;
	 *)	
		if test -f $RDBMSPATH/exec/emp4rtg
		then
			EXEC=emp4rtg
		else
			EXEC=emp4fulg
		fi
		;;
	esac
	;;
 *)
	case "$FULL" in
	 true)	
		EXEC=emp4ful
		;;
	 *)	
		if test -f $RDBMSPATH/exec/emp4rt
		then
			EXEC=emp4rt
		else
			EXEC=emp4ful
		fi
		;;
	esac
	;;
esac

export MSTERM
exec $RDBMSPATH/exec/$EXEC -MSPROGNAME $0 $OPTS "$@"
