#!/bin/sh
if test $# -eq 0 -o $# -ge 3 -o "$1" = "-help"
then
	echo "usage: $0 <expression> [<ugmodule>]";
	exit 1;
fi

if test "x$UGROOT" = "x"
then 
	echo "$0: to use $0 set shell environment variable UGROOT!";
	exit 1;
fi

if test -x /bin/uname
then
case `/bin/uname | cut -f1 -d ' ' ` in
	AIX | Paragon)
		FOLLOW_LINKS=
		echo "not following symbolic links"
		;;
	*)
		FOLLOW_LINKS=-follow
		;;
esac;
else
	FOLLOW_LINKS=
	echo "not following symbolic links"
fi


# if one parameter is specified search all ug modules for $1
if test $# -eq 1
then
	find ${UGROOT} \
			-type d -name include -prune -o \
			-type d -name doc -prune -o \
			-type d -name man -prune -o \
			\( -name '*.h' -o -name '*.c' -o -name '*.cc' -o -name '*.hh' \) \
			${FOLLOW_LINKS} -exec egrep "$1" {} \; -print
fi

# if two parameters are specified search the specific module for $1
if test $# -eq 2
then
	find ${UGROOT}/$2 \
		\( -name '*.h' -o -name '*.c' \) \
		${FOLLOW_LINKS} -exec egrep "$1" {} \; -print
fi

