#!/bin/sh
#ifdef __USAGE
#%C topic
#
#
#%C looks up the reference page for topic and displays it using less if
#its available.  If multiple pages match topic then they are all
#displayed.  
#
#%C expects an index in /usr/help/ref.index and will cache any
#generated pages in /usr/thelp/...
#endif
FUB=`grep -E ^$1[[:space:],] /usr/help/ref.index | cut -f2`
for i in $FUB
do
	FOB=/usr/thelp${i##/usr/help}
	FOB=${FOB%.html}.man
	#the following check comes out right if $FOB doesn't exist
	if test $FOB -nt $FUB
	then
		:
	else
		printf "Converting page(s)...\n"
		mkdir -p ${FOB%/*.man}
		html2man -s $i >$FOB
	fi
	gtbl $FOB 2>/dev/null | gtroff -man -Tascii 2>/dev/null | grotty 2>/dev/null | less
done
