diff options
Diffstat (limited to 'man2html/scripts/cgi-bin/man/man2html')
-rwxr-xr-x | man2html/scripts/cgi-bin/man/man2html | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/man2html/scripts/cgi-bin/man/man2html b/man2html/scripts/cgi-bin/man/man2html new file mode 100755 index 0000000..7c515d1 --- /dev/null +++ b/man2html/scripts/cgi-bin/man/man2html @@ -0,0 +1,109 @@ +#!/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="/usr/bin/man2html" +MANX="/home/httpd/cgi-aux/man/man.aux" + +# Do we need lynxcgi URLs? For the moment our criterion is +# 1) HTTP_USER_AGENT=Lynx* and 2) HTTP_HOST is unset. +AGENT="${HTTP_USER_AGENT-unknown}" + +case "$AGENT" in + Lynx*|lynx*) + HH="${HTTP_HOST-nohh}" + SED="s/%lynx //" + ;; + *) + HH=nolynx + SED="/%lynx/d" + ;; +esac + +SERVER="${SERVER_NAME-localhost}" +case "$HH" in + nohh) + LL="-l" + CG="lynxcgi:/home/httpd/cgi-bin/man" + ;; + *) + LL="-H$SERVER" + CG="http://$SERVER/cgi-bin/man" + ;; +esac + +# 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 no arguments given, show a start page. +if [ $# = 0 ]; then + if [ -r $MANX ]; then + cat $MANX | sed "s#%cg#$CG#g; $SED" + else + "$MAN2HTML" -E "man2html: cannot open $MANX" + fi + exit 0 +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 + *.gz) + zcat "$PAGE" | "$MAN2HTML" "$LL" -D "$PAGE" + ;; + *.bz2) + bzcat "$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 |