#!/bin/sh
#set -x  # debugging info
# Rob Stone (rob@psych.york.ac.uk)
# Convert the man pages to html and bung em all in the ./man dir.
# convert using man2html [ http://www.oac.uci.edu/indiv/ehood/man2html.html ]

# BUGS
# SECTIONS was worked out manually !
# need to  properly to x-ref up the other pages not just in see also.


# check these carefullly especially SRC directory and Path to man2html
THIS=`which $0`
PREPARE="nroff -man "
CONVERT="/usr/local/bin/man2html -cgiurl ../man\${section}/\${title}.html"
SRC="/var/qmail/src"
IDX="./man/index.html"

head () {
echo "doing header"
# cd $SRC
[ -d ./man ] || mkdir man
cp $THIS ./man

cat <<EOF  > $IDX
<HTML>
<HEAD>
<TITLE> MAN PAGES FOR QMAIL 1.03 </TITLE>
<META REPACKAGER="(Rob Stone) rob@psych.york.ac.uk">
<META AUTHOR="(Dan Bernstein) djb@koobera.math.uic.edu">
</HEAD>
<BODY>
<H1> MAN PAGES FOR QMAIL 1.03 </H1>
<MULTICOL COLS=3>
EOF
}


dosections (){
SECTIONS="1 3 5 7 8 9"
#SECTIONS="7 9"   # test with 7 as very few !

for i in $SECTIONS
do
   echo "doing man section $i"
   echo "<DL> <B>Section $i</B>\n" >> $IDX   
   TO="./man/man$i"
   [ -d $TO ] || mkdir $TO
   for  j in *.$i
   do
     k=`basename $j .$i`
     $PREPARE $j | $CONVERT > $TO/$k.html
     echo "<DT><A HREF=\"man$i/$k.html\">$k</A>($i)" >> $IDX
   done
   echo "</DL><SPACER>\n" >> $IDX
done
}


domisc () {
# mark up the misc documents all at least 3 caps. 
# check for file not directory.
echo "doing misc pages"
TO="./man/misc"
[ -d $TO ] || mkdir $TO
echo "<DL> <B>misc.</B>\n" >> $IDX
for i in [A-Z][A-Z][A-Z]*
do
	if  [ -f $i ] 
	then
	 	cp $i  $TO/$i.txt
     	echo "<DT><A HREF=\"misc/$i.txt\">$i</A>" >> $IDX
    fi
done     
}

tail () {
echo "doing trailer"
cat   <<EOF >> $IDX
</MULTICOL>
</BODY>
</HTML>
EOF
}

head
dosections
domisc
tail
