#!/bin/sh
# man2html cgi script - uses /usr/bin/man2html to format man pages
# auxiliary text files in /home/httpd/cgi-aux/man
# aeb@cwi.nl - 980109
MAN2HTML="$DOCUMANCER_HOME/helpers/man2html/man2html"
LL="-H../ -p -M."
CG="../"
# Find the required page - expect to be called with "man2html [sec] page".
# There may a prefixed "-M manpath" option.
if [ $# -ge 2 -a x"$1" = x-M ]; then
MANPATH="$2"
export MANPATH
shift; shift
MP=" using the given MANPATH"
else
MP=""
fi
if [ $# -gt 2 ]; then
"$MAN2HTML" -E "man2html: bad invocation: too many arguments"
exit 0
fi
# A single argument may be an explicitly give path name
# Otherwise, ask man where to find it
if [ $# = 1 ]; then
case "$1" in
/*)
PAGE="$1"
;;
*)
PAGE=`man -w -c "$@" 2>/dev/null`
;;
esac
else
PAGE=`man -w -c "$@" 2>/dev/null`
fi
if [ x"$PAGE" = x ]; then
complaint="man2html: cannot find a page"
if [ $# = 1 ]; then
"$MAN2HTML" -E "$complaint for $1$MP"
else
"$MAN2HTML" -E "$complaint for $2 in section $1$MP"
fi
exit 0
fi
if [ -r "$PAGE" ]
then
case "$PAGE" in
*.bz2)
bzcat "$PAGE" | "$MAN2HTML" $LL -D "$PAGE"
;;
*.gz)
zcat "$PAGE" | "$MAN2HTML" $LL -D "$PAGE"
;;
*)
"$MAN2HTML" $LL "$PAGE"
;;
esac
elif [ -r "$PAGE".gz ]
then
zcat "$PAGE".gz | "$MAN2HTML" $LL -D "$PAGE"
elif [ -r "$PAGE".bz2 ]
then
bzcat "$PAGE".bz2 | "$MAN2HTML" $LL -D "$PAGE"
else
"$MAN2HTML" -E "Strange... Cannot find (or read) $PAGE."
fi
exit 0