#!/bin/csh -f

switch (`uname -s``uname -r`)
case SunOS5*:
    set HOST = /usr/local/bin/host
	breaksw
case Linux2*:
    set HOST = /usr/bin/host
	breaksw
default:
	exec echo ${0}: does not run on `uname -s` `uname -r`
endsw

set LIST

while($#argv)
	switch ("$1")
	case -v:
		set VERBOSE
		shift
		breaksw
	default:
		set LIST = ( $LIST $1 )
		shift
		breaksw
	endsw
end

if (! $#LIST) exec echo ${0}: usage $0 "user|host"

set TMP = /tmp/wheres.$$

foreach ARG ( $LIST )

	set LOC = "`$HOST -t txt $ARG |& grep Location | sed 's;\..*text;;'`"
	if ($#LOC) then
		echo host: "$LOC"
	else
		set LOC = `ypmatch $ARG passwd |& sed -e 's;:[^:]*:[^:]*:[^:]*:; ";' -e 's;:.*;";'`
		if ($#LOC) then
			if ("$LOC[1]" != "Can't") echo user: $LOC
		else
			set GCNT = `ypcat passwd | grep $ARG | tee $TMP | wc -l`

			if (! $GCNT) set GCNT = `ypcat passwd | grep -i $ARG | tee $TMP | wc -l`

			if ($GCNT) then
				cat $TMP | sed -e 's;:[^:]*:[^:]*:[^:]*:; ";' -e 's;:.*;";' -e 's;\(.\);user: \1;'
			endif
		endif

	endif

end

rm -f $TMP
