#!/usr/bin/sh


## Copyright (c) 1996, Lotus Development Corporation.
## All Rights Reserved.


## UNIX is a registered trademark of X/Open Company Limited.



cdfile() {
    origfile=$1
    if [ -r $origfile ]; then
        echo $origfile
        return
    fi
	
	file=`echo $origfile | tr [A-Z] [a-z]`
	if [ -r $file ]; then
        echo $file
        return
    fi

	file=${file}.
	if [ -r $file ]; then
		echo $file
		return
	fi

    file=`echo $origfile | tr [a-z] [A-Z]`
	upfile=$file
    if [ -r $file ]; then
        echo $file
        return
    fi
	echo $file | grep '\.' >/dev/null 2>&1
	if [ $? -ne 0 ]; then
		file=${file}.
		if [ -r $file ]; then
			echo $file
			return
		fi
	fi
    file=`echo $origfile | tr [a-z] [A-Z]`
	testfile=${file}\;1
	if [ -r $testfile ]; then
		echo ${file}\\\;1
		return
	fi
	
	testfile=${file}\;1
	if [ -r $testfile ]; then
		echo ${file}\\\;1
		return
	fi

    echo $origfile


}

PATH=/usr/bin:/usr/sbin:/bin:${PATH}
export PATH


USERDIR=`pwd`
export USERDIR
thisdir=`dirname $0`
cd $thisdir
thisdir=`pwd`

thisfile=`basename $0`
thisfile=`echo $thisfile | sed -e 's/;1$//'`
torun="tools/lib/${thisfile}.pl"

if [ -z "$LANG" ]; then
	LLANG="C"
else
	LLANG=$LANG
	case ${LLANG} in
		POSIX	|\
		posix	|\
		en_US*	|\
		En_US*	|\
		en_GB*	|\
		En_GB*	)
			LLANG="C"
			;;
	esac
fi

if [ ! -d ${thisdir}/`cdfile tools/nls/${LLANG}` ]; then
	echo ""
	echo "Locale ${LLANG} specified by \$LANG is not directly supported."
	echo "Continuing using English."
	LLANG="C"
fi
export LLANG


eval ". ${thisdir}/`cdfile tools/nls/${LLANG}/${thisfile}.sh`"

echo $INITMSG

if [ -z "$NI_NOTROOT" -a `id | sed -e 's/^[^(]*(//' -e 's/).*$//'` != "root" ];
then
	echo "${NOTROOTMSG}${thisfile}"
	echo ""
	exit 1
fi

while [ "$1" = "-perl" ]; do
	shift
	perlswitch=$1
	shift
done


luname="$thisdir/`cdfile tools/lib/luname`"
thisarch=`eval "$luname -z"`

LUNAME=$luname
export LUNAME

case $thisarch in
	sunspa*)
		LARCH="sunspa"
		;;
	sunx86*)
		LARCH="sunx86"
		;;
	hppa*)
		LARCH="hppa"
		;;
	ibmp*)
		LARCH="ibmpow"
		;;
esac
export LARCH
LARCH_NOREV=$LARCH
export LARCH_NOREV

PERL5LIB="$thisdir/`cdfile tools/lib`:$thisdir/`cdfile tools/lib/perl5`:$thisdir/`cdfile tools/nls/$LLANG`"
export PERL5LIB


DISTDIR=$thisdir
export DISTDIR

PERL=$thisdir/`cdfile tools/bin/$LARCH/Perl`
export PERL

cmd="$PERL $perlswitch $thisdir/`cdfile $torun` $*"
eval $cmd
