#!/bin/ksh # $Id: manpage.cgi,v 1.20 2012/04/05 14:39:24 ksb Exp $ # # Display a manual page via http to a browser. Better than some programs # that try a lot harder. --ksb # # Called for example: http://www.sac.fedex.com/cgi-bin/manpage.cgi?chown&2 # to get chown from section 2 rather than perhaps section 8. Note that "1L" # changes the search path to move local first. That lets you get to # install&1L vs install&1. # : ${MANPATH:=/usr/share/man:/usr/local/man:/usr/X11R6/man:/usr/man} : ${manpath:=$MANPATH} export manpath MANPATH PATH set _ `echo ${QUERY_STRING} | tr '&' ' '` shift THEMANPAGE=${1:-intro} THESECTION=$2 if expr "$THESECTION" : '[0-9]*[Ll]' >/dev/null ; then manpath=/usr/local/man:$MANPATH THESECTION=`expr "$THESECTION" : '\([0-9]*\)[Ll]'` fi # bold(\fB) b^Hbo^Hol^Hld^Hd # italic(\fI) _^Hi_^Ht_^Ha_^Hl_^Hi_^Hc # bold italic (\f(BI) _^Hb^Hb_^Ho^Ho_^Hl^Hl_^Hd^Hd _^Hi^Hi_^Ht^Ht_^Ha^Ha... cat <Manpage CGI | $THEMANPAGE Manual page ${THEMANPAGE}${THESECTION:+\($THESECTION\)}
!

Upper=`echo $THEMANPAGE | tr 'a-z' 'A-Z'`
/usr/bin/man -M ${manpath} ${THESECTION:+"$THESECTION"} "${THEMANPAGE}" 2>&1 |
sed -e '/\/\*[  ]*\(<[^>]*>\)[  ]*\*\//{
	s//\1/
	n
}' -e 's/[&][&]/BOLDamp;/g' -e 's!<>!BOLDgt;!g' \
	-e 's/[+]o/AMPoplus;/g' -e 's/o[+]/AMPoplus;/g' \
	-e 's/[&]/AMPamp;/g' -e 's//AMPgt;/g' \
	-e 's@\([^	 (<][^ 	(<]*\)(\([0-9][-a-zA-Z.]*\))@&@g' \
	-e 's/AMPlt;/\</g' -e 's/AMPgt;/\>/g' -e 's/AMPamp;/\&/g' \
	-e 's/AMPoplus;/\⊕/g' \
	-e 's!BOLDlt;!\<!g' -e 's!BOLDgt;!\>!g' \
	-e 's!BOLDamp;!\&!g' |
sed -e 's!_\([^_]\)\1!\1!g' -e 's!!!g' |
sed -e 's!_\([^_]\)!\1!g' -e 's!!!g' |
sed -e 's!\(.\)\1!\1!g' -e 's!\([ 	]*\)!\1!g' |
sed -e 's!!!g' -e 's!!!g' \
	-e 's!!!g' -e 's!!!g' |\
#	-e 's!!!g' -e 's!!!g' |
sed -e 's@\(\([^>]*\)\([^"]*"\)>\([^>]*[^<]*\)@\1\2\3\4@g' \
	-e 's@\(\([^>]*[^<]*\)@\1\2\3\4@g' |
perl -pne 'BEGIN {
		my($last) = undef;
	}
	if (m|(.*)-<.b> *$|o) {
		$last = $1;
		next;
	}
	next unless defined($last);
	$_ =~ s|^(\s*
" exit 0