#!/bin/sh
echo "   This script uses agrep, src for which is in ../../public/agrep"
echo "\n"
grepper='agrep -h -d$$ -i'
oldIFS="$IFS"
IFS=":$IFS"
IFS="$oldIFS"

if [ -f /usr/people/4Dgifts/toolbox/documents/RFC/rfc-index.txt ]; then
	RFC=/CDROM/documents/RFC
fi

case "$RFC" in
"")	echo "   Please set environment variable \"RFC\" to the current location"
	echo "   of your RFC directory.  The Developer Toolbox CD is expecting"
	echo "   this path to be \"/CDROM/documents/RFC\"."
	echo "   To search in this directory using this \"rfc\" script, you will"
	echo "   need to either umount the CD from wherever-it-is currently,"
	echo "   then re-mount it under this mount point, or copy this 54+ MB "
	echo "   dir to a local disk and then run"
	echo "\n"
	echo "setenv RFC \`pwd\`"
	echo "\n"
	echo "   after you cd to the local disk's directory location.  Then the"
	echo "   \"rfc\" script will not bark at you.  An example of what it can"
	echo "   produce wud be:"
	echo "\n"
	echo "< 118 ratmandu /documents/RFC> rfc 'protocol;multicast'"
	echo "   This script uses agrep, src for which is in ../../public/agrep"
       	echo "\n"
	echo "grepping..."
	echo ""
	echo "1458  Braudes, R.; Zabele, S.  Requirements for Multicast Protocols (Not"
	echo "      online)  1993 May; 19 p. (Format: TXT=48107 bytes)"
	echo ""
	echo "1301  Armstrong, S.; Freier, A.; Marzullo, K.  Multicast Transport Protocol."
	echo "      February 1992; 38 p. (Format: TXT=91977 bytes)"
	echo ""
	echo "1075  Waitzman, D.; Partridge, C.; Deering, S.  Distance Vector Multicast"
	echo "      Routing Protocol.  1988 November; 24 p. (Format: TXT=54731 bytes)"
	echo ""
	echo "966   Deering, S.; Cheriton, D.  Host Groups: A Multicast Extension to the"
	echo "      Internet Protocol.  1985 December; 27 p. (Format: TXT=61006 bytes)"
	echo "      (Obsoleted by RFC 988)"
	echo ""
	exit
esac

case "$1" in
"")
	echo 'usage: rfc <number>'
	echo '       will display RFC <number> with "more" (or your $PAGER)'
	echo ''
	echo '       rfc <pattern>'
	echo '       will egrep [agrep] for <pattern> in the file "rfc-index"'
	echo ''
	;;
[0-9]*)
	list=
	for i
	do 
		list="$list $RFC/rfc$i.*"
	done
	exec ${PAGER:-more} $list
	;;
*)
	echo grepping...
	exec sed -e 's/^  *$//' $RFC/rfc-index.txt | $grepper "$@"
esac


