#! /bin/ksh

#  (c) 1998-1999  Sun Microsystems, Inc.
#
#  @(#)dtpower.ksh	1.3 99/10/05 SMI

# Process arguments
while [[ $1 = -* ]]; do

        case $1 in
                -display )
                        shift
                        DISPLAY=$1
			export DISPLAY
                        ;;

		-e )
			EXPANDED="-e"
			;;

		-res_cmd )
			shift
			RESTART="-res_cmd $1"
			;;

		-geometry )
			shift
			GEOMETRY="-geometry $1"
			;;
			
                * )
                        print "Unexpected argument: $1"
        esac
        shift
done

# Save the current directory.
current_dir=`pwd`

# Check if java exists in the user's environment
if [ -a /usr/java ]; then
	JAVA_HOME=/usr/java
fi

# Change directory to location of packages.
cd /usr/dt/appconfig/dtpower

# Set the LD_LIBRARY_PATH
LD_LIBRARY_PATH=`pwd`/lib:/usr/dt/lib:${LD_LIBRARY_PATH}

# Set the class path to include each and every jar file of the application
CLASSPATH=`pwd`
cd classes
CLASSPATH=`pwd`:${CLASSPATH}
jarfiles=`/bin/ls *.jar`
for i in ${jarfiles}; do
	CLASSPATH=`pwd`/${i}:${CLASSPATH}
done
CLASSPATH=${CLASSPATH}:/usr/dt/classes/jhall.jar
CLASSPATH=${CLASSPATH}:/usr/dt/classes/xservices.jar


export LD_LIBRARY_PATH

# Get the java version.
tmp_file=/tmp/dtpower.version_test`echo $$`
${JAVA_HOME}/bin/java -version 2> $tmp_file

java_ver=`awk -F\" '{ print $2 }' $tmp_file`

# Get the major.minor.subminor java version numbers.
major=`awk -F\" '{ print $2 }' $tmp_file | awk -F\. '{ print $1 }' `
minor=`awk -F\" '{ print $2 }' $tmp_file | awk -F\. '{ print $2 }' `
subminor=`awk -F\" '{ print $2 }' $tmp_file | awk -F\. '{ print $3 }' `

rm $tmp_file

# Start the dtpower application, based on the java version.
if (( ${minor} >= 2 )); then
	# JDK 1.2 or higher
	(cd /usr/dt/appconfig/dtpower; ${JAVA_HOME}/bin/java -classpath ${CLASSPATH} com.sun.dt.dtpower.Dtpower ${RESTART} ${EXPANDED} ${GEOMETRY})

else

	# Less than JDK 1.1.6
	print "Unsupported jdk version - exiting."

fi
cd $current_dir
