#!/bin/sh

usage() {
	echo `basename $0` \[-V\] \<symbol\>
	echo \- list files containing \<symbol\>
	echo "  -V lists also directories searched"
	echo ""
	echo `basename $0` -h
	echo \- Show this help
	exit 0
}

if [ "$1" == "-V" ]; then
	VERBOSE=1
	shift
else
	VERBOSE=0
fi

if [ "$1" == "-h" ]; then
	usage
fi

if [ "x$1" == "x" ]; then
	usage
fi

LPATH=`echo $LIBRARY_PATH|sed "s|%A/lib:||"`
[ -d ./lib ] && LPATH="./lib:$LPATH" || true
LPATH=`echo $LPATH|sed "s/:/ /g"`
TEMPFILE=/boot/var/tmp/`basename $0`.$PPID
for libdir in `echo $LPATH`; do
	if [ "$VERBOSE" == "1" ]; then
		echo Searching in \"$libdir\"...
	fi
	for lib in $libdir/*.so ; do
		echo "[ $lib ]" > $TEMPFILE
		(nm -D $lib 2>/dev/null)|grep $1 >> $TEMPFILE
		LINES=`wc -l $TEMPFILE | awk '{ print $1; }'`
		if [ "$LINES" != "1" ]; then 
		 	cat $TEMPFILE
		fi
	done
done
rm -f $TEMPFILE
