#!/bin/sh
#
# A script to launch the JMStudio java application.

#
# If a path name is a symbolic link, resolve it.
#
GetRealPath()
{
	pathName="$1"
	level=1

	while [ -h "$pathName" ] ; do
		level=`/bin/expr $level + 1`
		if [ $level -gt 10 ] ; then
			echo "$pathName: too many levels of symbolic links"
			break;
		fi

		#
		# First, make sure we have an absolute path name.
		#
		if IsRelativePath "$pathName" ; then
			pathName=`/bin/pwd`/"$pathName"
		fi

		#
		# Then determine where the link points (via "ls -l")
		#
		dirName=`/bin/dirname $pathName`
		link=`/bin/ls -l $pathName | sed -e 's,.* -> ,,g'`

		if IsRelativePath "$link" ; then
			pathName="$dirName"/"$link"
		else
			pathName="$link"
		fi
	done

	echo "$pathName"

	return 0
}

#
# Is this a relative path name (i.e., doesn't begin with "/")?
#
IsRelativePath()
{
	pathName="$1"

	if [ `echo "$pathName" | sed -e 's,^/.*,absolute,g'` = "absolute" ] ; then
		return 1
	else
		return 0
	fi
}

#
# Figure out the real path to this shell script and then setup
# the JMFHOME environment
#
PROGPATH=`GetRealPath $0`
TMPDIR=`dirname $PROGPATH`
JMFHOME=`( cd $TMPDIR/.. && /bin/pwd )`; export JMFHOME

CLASSPATH=${JMFHOME}/lib/jmf.jar:${JMFHOME}/lib:${JMFHOME}/lib/sound.jar:${CLASSPATH}; export CLASSPATH

LD_LIBRARY_PATH=.:/usr/openwin/lib:${JMFHOME}/lib:${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH

# Use this to run with native threads:
# THREADS_FLAG=native; export THREADS_FLAG

# If it's running on Solaris 2.6, we are forced to use native threads.
UNAME=`uname -r`
case $UNAME in
5.6) THREADS_FLAG=native; export THREADS_FLAG;;
5.6.*) THREADS_FLAG=native; export THREADS_FLAG;;
5.7) THREADS_FLAG=native; export THREADS_FLAG;;
5.7.*) THREADS_FLAG=native; export THREADS_FLAG;;
5.8) THREADS_FLAG=native; export THREADS_FLAG;;
5.8.*) THREADS_FLAG=native; export THREADS_FLAG;;
esac

if [ $# -gt 0 ]; then
	FILE=$1	
fi
exec java JMStudio $*
