#!/bin/sh
# Find root directory of WorkShop Visual
#
# Copyright Imperial Software Technology Ltd 1996. All Rights Reserved.
# Copyright (c) 1995-1996 Sun Microsystems, Inc. All Rights Reserved.
#
# "@(#)RELEASE VERSION WorkShop Visual 2.0 10/09/96"
# "@(#)SERIAL NUMBER VS-21-100996"

basename=`basename $0`

# The following attempts to determine VISUROOT automatically and compares it
# with any setting inherited from the environment. Warn if the two differ..
# It should work even in the presence of (cursed) symbolic links
#
# First, determine path to apparent executable..
case $0 in 
	*/*)	path=`dirname $0`
		relpath=$path
		;;
	*)	SAVEIFS="$IFS"
		IFS="$IFS:"
		for path in $PATH; do
			if [ -x $path/$0 ]; then
				break
			fi
			# if we ever fall through it must be the current dir..
			path=.
		done
		IFS="$SAVEIFS"
		;;
esac
# Next, follow sym links, if any..
lsout=`ls -l $path/$basename`
while test `expr "$lsout" : "l"` = 1; do
	lpath=`echo $lsout | sed 's/.* //'`
	basename=`basename $lpath`
	case $lpath in
		/*)	path=`dirname $lpath` ;;
		*)	path=$path/`dirname $lpath` ;;
	esac
	lsout=`ls -l $path/$basename`
done
# Expand any sym links to get real path..
realdir=`cd $path; cd ..; pwd | sed -e 's.^/tmp_mnt/./.'`
# Now, compare with VISUROOT if set..
if [ ! -z "$VISUROOT" ]; then
	# Expand any sym links as before (forcing sh to re-eval path)..
	setdir=`cd $VISUROOT/bin/..; pwd | sed -e 's.^/tmp_mnt/./.'`
	if [ "$realdir" != "$setdir" ]; then
		echo "$0: warning: \$VISUROOT set to $VISUROOT" >&2
	fi
else
	VISUROOT=$realdir; export VISUROOT
fi

# if we still haven't determined it, bomb politely...
if [ -z "$VISUROOT" ]; then
	echo "$0: Can't determine location of command so can't set \$VISUROOT appropriately." >&2
	echo "You must set the VISUROOT environment variable to the path of the visu" >&2
	echo "release directory" >&2
	exit 1
fi

# echo computed directory path even if VISUROOT is set..

echo $realdir
