#!/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
which=$1
shift
case "$which" in
	WHICH)	loc=`which $1 2>/dev/null`;;
	LOCATE)	loc=`locate "*/$1" 2>/dev/null`;;
	FIND)	path=`echo $PATH | sed 's/:/ /g'`
		for i in $path; do
			loc=`find $i/ -name $1 -type f -print 2>/dev/null \
				| head -1`
			if test "$loc"; then
				break
			fi
		done;;
	*)	echo "fullpath: Cannot find command location with \"$which\"."
		exit;;
esac
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
