#!/bin/sh

#
# This is a really ugly hack, but it works.
# If given two arguments, then this script acts as a 'contains',
# returning a TRUE status if $1 (assumed to be a directory)
# contains $2.  This is used below to prune the search made to
# speed the find up a lot.
#
if test -n "$2" ; then
    test -f $1/$2 ;
    exit ;
fi

#
# Otherwise, really do the find
#
string=`launch -m "Please enter search string:" -h echo`

if test -n "$string" ; then
	confirm -t "Please wait, performing search" >/dev/null &
	confirm_pid=$!

#
# This rather complicated command does several things:
# -- It looks for buttonfly files, which it assumes are named .msomething.
#    (this is the first half of the find command)
# -- If a directory doesn't contain a .menu file, it assumes there are no
#    buttonfly files anywhere underneath it, and prunes the search.  This
#    saves a lot of time, since the find doesn't have to search in the
#    binary or data directories.
#    (this is the second half of the find command)
# -- Looks for the string in the buttonfly files found
#    (the xargs fgre part)
# -- Finally, all the filenames that match are passed to the awk script,
#    which gets rid of duplicate files and spits their contents to
#    stdout, where the buttonfly process invoking this script can get them.
#
	find . \( -name .m\* -print \) -o \( -type d ! -exec /usr/demos/bin/flyfind {} .menu \; -prune \) | xargs fgrep -il "$string" | nawk -f /usr/demos/bin/flyfind.nawk

	kill $confirm_pid >/dev/null 2>&1
fi
