#!/bin/sh
# whichjava -- find where something is in the CLASSPATH
#
# With the -l flag, this also does a ls -l on them
#
# AUTHOR: Gary T. Leavens

[ -n "$echo" ] && set -x

USAGE="Usage: $0 [-l] cmd-name ..."

# paths to the JDK sources
: ${JAVASRCPATH="/usr/local/jdk1.4/src:/opt/java/src"}

LISTIT='echo'

case "$1" in
    -l)
	LISTIT='ls -l'
	shift
	;;
    -*)
        echo "$USAGE" >&2
	exit 1
	;;
esac

# no arguments?
if test $# -eq 0
then
	echo "$USAGE" >&2
	exit 1
fi

CURDIR=`pwd`

for arg
do
	for pd in `echo "$CLASSPATH:$JAVASRCPATH" | sed -e 's/^:/. /;s/:/ /g'`
	do
		
		if test -d $pd
		then
			cd $pd
			find . -name $arg -print | sed -e 's#^\./##' |
			while read filepath
			do
				$LISTIT $pd/$filepath
			done
			cd $CURDIR
		fi
	done
done
