#!/bin/sh
#
# ShowMe TV startup script.
#
# @(#)showmetv-o.sh	2.11 98/11/16 Copyright 1993-96 Sun Microsystems, Inc.  All Rights Reserved.
#


#
# Where various components of this application live.
#
ShowMeHome=
showmeHome=
utilsHome=
motifHome=

showmeExecDir=
machDepExecDir=

osVersion=


programName=$0


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

	while [ -h "$pathName" ] ; do

#
# NOTE that this is not i18n, but that is OK because it will never
# happen anyway; indeed, it seems to me this is never used; at the
# very very worse, if it ever happens, the message will be in English
#
		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
}


#
# Determine what version of Solaris we're running
#
GetOSVersion()
{
       	OS=`/bin/uname -r`

	case $OS in
	4.*)	osVersion=SUNOS;;
	5.*)	case `/bin/uname -p` in 
		sparc)
			osVersion=SVR4;;
		*86)
			osVersion=I386;;
		esac;;
	A.*)
		osVersion=HPUX;;
	esac

}


#
# Determine where ShowMe TV lives.
# We assume that it's two levels up above the directory containing
# this script.
#
GetPaths()
{
	tmpDir=`GetRealPath $programName`
	tmpDir=`dirname $tmpDir`
	ShowMeHome=`( cd $tmpDir/../.. && /bin/pwd )`

	showmeHome=$ShowMeHome/ShowMeTV
	utilsHome=$ShowMeHome/utilities
	motifHome=/usr/dt/lib
}


#
# Set up ShowMe TV environment.
#
SetupEnvironment()
{
        if [ ! -z "$LC_ALL" ]; then
                HELPLANG=$LC_ALL
        elif [ ! -z "$LC_MESSAGES" ]; then
                HELPLANG=$LC_MESSAGES
        elif [ ! -z "$LANG" ]; then
                HELPLANG=$LANG
        else
                HELPLANG=C
        fi
        if [ "$HELPLANG" = "en_US" ]; then
                HELPLANG=C
        fi
        if [ $HELPLANG != "C" ]; then
            if [ ! -d $ShowMeHome/lib/locale/$HELPLANG/help ]; then
                echo "$0: could not find help directory for $HELPLANG" >&2
                echo "trying to use help for locale C" >&2
                HELPLANG=C
            fi
        else
            if [ ! -d $ShowMeHome/lib/locale/$HELPLANG/help ]; then
                echo "$0: could not find help directory" >&2
                echo "on-line help might not work correctly"
            fi
        fi

        ShowMeTVHelpDir=$ShowMeHome/lib/locale/$HELPLANG/help ; \
            export ShowMeTVHelpDir

	showmeExecDir=$showmeHome/bin
	machDepExecDir=$showmeExecDir/bin-$osVersion
	utilsBinDir=$utilsHome/bin
	utilsExecDir=$utilsHome/bin/bin-$osVersion
	sunsolBinDir=`dirname $0`

	#
	# Add ShowMe TV executable directories to shell search path
	#
	PATH=${showmeExecDir}:${machDepExecDir}:${utilsBinDir}:${utilsExecDir}:${sunsolBinDir}:${PATH}

	export PATH

	#
	# Use our own Motif key_bindings because the built-in ones
	# in the Motif library don't handle all the Sun keys correctly.
	# However, if XMBINDDIR is already set, leave it alone!
	#

	if [ -d ${motifHome}/share/key_bindings ]; then
		XMBINDDIR=${XMBINDDIR:=${motifHome}/share/key_bindings}
		export XMBINDDIR
	fi

	#
	# Needed for demo license and for showmetvh.
	#
	SUNSOL_HOME=${ShowMeHome} ; export SUNSOL_HOME

	#
	# Needed for VIS H261 decoder.
	H261HOME=${ShowMeHome}/lib/lib-SVR4; export H261HOME
}

####################################################

GetOSVersion

GetPaths

SetupEnvironment

case `basename $0` in
	splitmov | mergemov | catmov | showmetvd)
		;;
	showmetv | showmetvt)
		# Need motif; main will check for it
		export motifHome
		;;
esac

case `basename $0` in
    showmetv)
	;;
    showmetvt)
	;;
    splitmov)
	;;
    showmetvd)
	;;
esac

exec $machDepExecDir/`basename $0` $@

exit 0
