#! /bin/ksh

#
#  @(#)sdtaudiocontrol.ksh	1.11 02/04/19 SMI
#
# Copyright 1999 Sun Microsystems, Inc. All rights reserved.
# Copyright 1999 Sun Microsystems, Inc. Tous droits r\351serv\351s.
# 4150 Network Circle, Santa Clara, California, 95054, U.S.A.
#
#
# This software is the confidential and proprietary information
# of Sun Microsystems, Inc. ("Confidential Information").  You
# shall not disclose such Confidential Information and shall use
# it only in accordance with the terms of the license agreement
# you entered into with Sun.
#

AUDIODEV=${AUDIODEV:-"/dev/audio"}

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

        case $1 in
		-d )
			if [ "$2X" == "X" ]; then
				print "Argument expected with -d option."
				exit 1
			fi
			shift
			AUDIODEV=$1
			;;

		-ac )
			APP_CONTROLS="-ac"
			;;

                * )
                        print "Unexpected argument: $1"
        esac
        shift

done

# Check if java exists in the user's environment
JAVA_HOME=/usr/java
if [ ! -d $JAVA_HOME ]; then
	print "$JAVA_HOME does not exist - exiting."
	exit 1;
fi

# Set location of packages.
BASE_DIR=/usr/dt
CMD_BASE_DIR=${BASE_DIR}/appconfig/sdtaudiocontrol

# Set the LD_LIBRARY_PATH
LD_LIBRARY_PATH=${CMD_BASE_DIR}/lib:${BASE_DIR}/lib:${LD_LIBRARY_PATH}

# Set the class path to include location of help files for the application.
CLASSPATH=${CMD_BASE_DIR}:${CLASSPATH}

# Set the class path to include location of
# locale data classes for the application.
CLASSPATH=${CMD_BASE_DIR}/classes:${CLASSPATH}

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

# Set xservices (xsession) and java help jars.
CLASSPATH=${BASE_DIR}/classes/xservices.jar:${CLASSPATH}
CLASSPATH=${BASE_DIR}/classes/jhall.jar:${CLASSPATH}
CLASSPATH=${BASE_DIR}/classes/jsearch.jar:${CLASSPATH}

# Set general desktop class path location.
CLASSPATH=${BASE_DIR}/classes:${CLASSPATH}

export LD_LIBRARY_PATH
export CLASSPATH

# Get the java version.
${JAVA_HOME}/bin/java -version 2> /tmp/sdtaudiocontrol.$$

java_ver=`awk -F\" '{ print $2 }' /tmp/sdtaudiocontrol.$$`

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

rm /tmp/sdtaudiocontrol.$$

cd ${CMD_BASE_DIR}
# Start the audiocontrol application, based on the java version.
if (( ${major} != 1 )); then

	# JDK 2.x
	${JAVA_HOME}/bin/java -classpath ${CLASSPATH} com.sun.audiocontrol.SDtAudioControl.AudioControl ${APP_CONTROLS} -d ${AUDIODEV}

else

	# JDK 1.x
	if (( ${minor} >= 2 )); then

		# JDK 1.2 or higher
		${JAVA_HOME}/bin/java -classpath ${CLASSPATH} com.sun.audiocontrol.SDtAudioControl.AudioControl ${APP_CONTROLS} -d ${AUDIODEV}

	else

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