#! /bin/sh
# whichall -- find all files in TEXINPUTS that match the given name
#
# 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 ..."

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

for arg
do
	for pd in `echo "$TEXINPUTS" | sed -e 's/^:/. /;s/::/ standard /g;s/:/ /g'`
	do
	    if test "$pd" = 'standard'
	    then
	        for f in /usr/local/teTeX/texmf/tex/latex/*/${arg}*
		do
		    if test -f $f
		    then
			$LISTIT $f
		    fi
		done
            else
		for f in $pd/${arg}*
		do
		    if test -f $f
		    then
			$LISTIT $f
		    fi
		done
	    fi
	done
done
