1#!/bin/sh
2#
3# hman - interface to the man2html scripts
4#
5# Michael Hamilton <michael@actrix.gen.nz>, Apr 1996
6# Andries Brouwer <aeb@cwi.nl>, Jan 1998.
7#
8# Usage examples:
9#        hman                    - get start page
10#        hman man2html           - get man page for man2html
11#        hman 7 locale           - get section 7 man page for locale 
12#        hman 1                  - section 1 index of names only
13#        hman 3 index            - section 3 index names+descriptions
14#        hman -k editor          - search all man pages for some string
15#	 hman -P arena ./twm.man - specify browser; specify man page
16#
17# hman from %version%
18#
19
20if [ x"$1" = x"-v" -o x"$1" = x"-V" ]; then
21	echo "`basename $0` from %version%"
22	exit 0
23fi
24
25# The user has to set MANHTMLPAGER (or he will get httpd-free lynx).
26# Pick your favorite browser: lynx, xmosaic, netscape, arena, amaya, grail, ...
27BROWSER=${MANHTMLPAGER-lynxcgi}
28#
29# If the man pages are on a remote host, specify it in MANHTMLHOST.
30HOST=${MANHTMLHOST-localhost}
31
32# Perhaps the browser was specified on the command line?
33if [ $# -gt 1 -a "$1" = "-P" ]; then
34    BROWSER="$2"
35    shift; shift
36fi
37
38# Perhaps the host was specified on the command line?
39if [ $# -gt 1 -a "$1" = "-H" ]; then
40    HOST="$2"
41    shift; shift
42fi
43
44# Interface to a live (already running) netscape browser.
45function nsfunc () {
46	if ( /bin/ps xc | grep -q 'netscape$' ) ; then
47		if [ -x  netscape-remote ] ; then
48			exec netscape-remote  -remote "openURL($1,new_window)"
49		else
50			exec netscape -remote "openURL($1,new_window)"
51		fi
52	else
53		netscape $1 &
54	fi
55}
56
57case $BROWSER in
58     lynxcgi)
59	BROWSER=lynx
60	CG="lynxcgi:/home/httpd/cgi-bin/man"
61	;;
62     netscape)
63        BROWSER=nsfunc
64        CG="http://$HOST/cgi-bin/man"
65	;;
66     *)
67	CG="http://$HOST/cgi-bin/man"
68	;;
69esac
70
71  case $# in
72     0)   $BROWSER $CG/man2html ;;
73     1)   case "$1" in
74	    1|2|3|4|5|6|7|8|l|n)
75		$BROWSER "$CG/mansec?$CG+$1" ;;
76	    /*)
77		$BROWSER "$CG/man2html?$1" ;;
78	    */*)
79		$BROWSER "$CG/man2html?$PWD/$1" ;;
80	    *)
81		$BROWSER "$CG/man2html?$1" ;;
82          esac ;;
83     2)   case "$1" in
84            -k)
85                $BROWSER "$CG/mansearch?$2" ;;
86            *)
87		if [ "$2" = index ]; then
88		    $BROWSER "$CG/manwhatis?$CG+$1"
89                else
90		    $BROWSER "$CG/man2html?$1+$2"
91                fi ;;
92          esac ;;
93     *)   echo "bad number of args" ;;
94  esac
95
96exit 0
97