#!/bin/sh

PATH="$PATH:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin:/usr/games:/usr/local/lib/emacs/etc:/usr/local/emacs/etc."
export PATH

case $1 in
	-quick)	mode=-quick
		shift;;
	*)	mode=;;
esac

loc=`which $1 2>/dev/null`
case "$loc" in
	# For a Tek:
	"command is /"*)
		loc=`echo $loc | sed 's/command is //'`;;
	# For normal whiches:
	"$1"*|"no $1"*|"command is "*)
		loc=;;
esac

if test ! "$loc" = "" -a "$mode" = "-quick"; then
	echo Assuming $1 is $loc. >&2
else
	echo -n "Where is your \"$1\"? [$loc] " >&2
	read ans

	if test ! "$ans" = ""; then
		loc=$ans
	fi
	if test "$loc" = ""; then
		loc=$1
	fi
	if test -d "$loc"; then
		case "$loc" in
			*"/")	loc=$loc$1;;
			*)	loc=$loc/$1;;
		esac
	fi
	if test ! -f "$loc"; then
		echo Warning: \"$loc\" does not exist. >&2
	fi
fi

echo $loc
