#!/bin/sh
#
# Address Book startup script.
#
# @(#)showmetvab-o.sh	2.8 98/11/16 Copyright 1993-94 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 ShowTV 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 ShowTV 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

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

        #
        # this is needed for the sake of Help from the Comments
        # window (which is borrowed from ShowMe TV)
        #
        ShowMeTVHelpDir=$UtilsHelpDir ; export ShowMeTVHelpDir

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

	#
	# Add ShowTV executables directory to shell search path
	#
	PATH=${showmeExecDir}:${machDepExecDir}:${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

}

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

GetOSVersion

GetPaths

SetupEnvironment

# Need motif; main will check for it
export motifHome

exec $utilsExecDir/`basename $0` $@

exit 0
