#!/bin/bash ######################################################################## # Converts a man page to very simple html, basically a page with # A and PRE tags. Takes 1 arguments: path to the non-compressed man # page. This expects the man page to be named PAGE_NAME.SECTION_NUMBER; # like `PQgetf.3' or `printf.1'. # # FEATURES # 1. Any some_man(3), no spaces before '(', is substituted for an # A tag linking to http://libpqtypes.esilo.com/man3/$man.html # # 2. All '<' and '>' are replaced with HTML codes # # 3. Mans referencing other mans, via .so macro, are converted # to symlinks in the output directory. # # ISSUES # Hyperlinks are not 100% substitued into resulting html page. # The only time there are issues is when the link text in the # man page was broken across lines. No work-around at this time # for this issue other than manually ensuring line breaks don't # occur on `some_man(3)'. # # Man pages that reference other man pages, using the .so macro, # must have the .so command in the first 'head' lines. The # .so 'path_to_man' cannot include spaces. ###################################################################### DOCTYPE="" # adjust these to your web server BASEURL="http:\/\/libpqtypes.esilo.com" INC_BASEURL="$BASEURL\/include" MAN_BASEURL="$BASEURL\/man" OUTDIR=/esilo/www/libpqtypes.esilo.com/man HEAD_SECTION="" HEADER="libpqtypes home page

" FOOTER="

libpqtypes home page" if [ $# = 0 ] ; then echo "Must supply man page to convert" exit fi # ignore non-existent files if test ! -f $1 ; then exit fi manpage=`basename $1` section=`echo "$manpage" | awk -F . '{print $NF}'` manpage=${manpage%.[^.]*} OUTDIR="${OUTDIR}${section}" mkdir -p $OUTDIR # If a .so reference, create a symlink solink=`head $1 | grep '.so .*' | cut -d ' ' -f 2` if test ! -z $solink ; then target=`basename $solink` target=${target%.[^.]*} echo "$OUTDIR/$manpage.html => $OUTDIR/$target.html" # remove existing symlink rm -f $OUTDIR/$manpage.html ln -s $OUTDIR/$target.html $OUTDIR/$manpage.html exit fi echo $OUTDIR/$manpage.html >$OUTDIR/$manpage.html # doctype if test ! -z "$DOCTYPE" ; then echo $DOCTYPE >>$OUTDIR/$manpage.html fi # add stadard html tags, include a title echo -e "\n\n$HEAD_SECTION\nman $manpage\n\n" >>$OUTDIR/$manpage.html if test ! -z "$HEADER" ; then echo $HEADER >>$OUTDIR/$manpage.html fi echo "

" >>$OUTDIR/$manpage.html

# 1. output man in ascii
# 2. post-process with col removing backspaces and tabs
# 3. do some html code replacement 
# 4. replace some_man(3) with A tags
groff -t -e -mandoc -Tascii $1 2>/dev/null | col -bx | \
sed 's//\>/g' | \
sed "s/\<\([a-ZA-Z0-9_\-]*\.h\)\>/\<\1<\/a>\>/g" | \
sed "s/\b\([a-zA-Z0-9_\-]\+\)(\([0-9]\))/\1(\2)<\/a>/g" \
>>$OUTDIR/$manpage.html

echo -e "
\n" >>$OUTDIR/$manpage.html if test ! -z "$FOOTER" ; then echo $FOOTER >>$OUTDIR/$manpage.html fi # html closing tags echo -e "\n" >>$OUTDIR/$manpage.html chown apache:apache $OUTDIR/$manpage.html