#!/bin/sh
#
#	printed-manual
#
#	Produce a printed manual.
#
#	Usage:		% cd /grass4.1/man  (for example)
#			% setenv PRINTER foo
#			% utilities/printed-manual
#
#	Amit Parghi
#	19 January 1992
#
#
PATH=/usr/ucb:/bin:/usr/bin ; export PATH
PRINTER=${PRINTER-oscar} ; export PRINTER
PRINTHOST=${PRINTHOST-zorro}

tempfile1=/tmp/out1.$$
tempfile2=/tmp/out2.$$
rm -f $tempfile1 $tempfile2

outfile=/tmp/soelim.$$
outfile2=$HOME/manual.$$
rm -f $outfile $outfile2

#	First stage:
#	- collect names of all man pages in man1 and man2.
#	- ASSUME and REQUIRE that man page names be unique within these
#	  two chapters, i.e. there is no man1/foo and man2/foo !!!!
#	- sort the names
#	- use dirname etc. to create the first part of our soelim file

echo "Processing sections 1 and 2."

for file in man[12]/*
do
    basename $file >> $tempfile1
done
sort -u $tempfile1 > $tempfile2


#	six blank pages at the very beginning

echo ".pn +7"				>> $outfile
echo ".so utilities/man.version"	>> $outfile
echo ".so utilities/man.header"		>> $outfile

for name in `cat $tempfile2`
do
    file=man[12]/$name
    dir=`dirname $file`

    echo ".so $dir/.class-header"	>> $outfile
    echo ".so" $file			>> $outfile
    echo ".so $dir/.class-notice"	>> $outfile
done

#	Now we're done with the 'main' and 'alpha' man pages, and we
#	can proceed with the remaining sections.

#	Section 3 - shell scripts
echo "Processing section 3."

echo ".pn +3"				>> $outfile
echo ".so man3/.class-header"		>> $outfile

for name in man3/*
do
    echo ".so $name"			>> $outfile
    echo ".so man3/.class-notice"	>> $outfile
done


#	Section 5 - Miscellaneous and File Formats
echo "Processing section 5."

echo ".pn +9"				>> $outfile
echo ".so man5/.class-header"		>> $outfile

for name in man5/*
do
    echo ".so $name"			>> $outfile
    echo ".so man5/.class-notice"	>> $outfile
done

#	Final stage ... run troff on the entire mess."
echo "Starting troff processes."

soelim $outfile | tbl -TX | troff -t > $outfile2

echo "Printing."
rsh $PRINTHOST lpr -r -s -t $outfile2

echo "Done."
rm -f $tempfile1 $tempfile2 $outfile
exit 0
