#!/bin/sh
#
# Man2hmtl interface to a live (already running) netscape browser.
# 
# Michael Hamilton <michael@actrix.gen.nz>, Apr 1996
#
# Usage examples:
#        man 1                  - section 1 index
#        man 3 intro            - section 3 name+description index
#        man 1 lpr              - man page for lpr
#        man -k editor          - search
#
function nsfunc () {
	if ( /bin/ps -xc | grep -q 'netscape$' ) ; then
		if [ -x  netscape-remote ] ; then
			exec netscape-remote  -remote "openURL($1,new_window)"
		else
			exec netscape -remote "openURL($1,new_window)"
		fi
	else
		netscape $1 &
	fi
}

if [ $# = 2 ] ; then
	case "$1" in
	  -k)
	      nsfunc "http:/cgi-bin/mansearch?$2"
	      ;;
	  *)
	      if [ $2 = 'intro' ] ; then
		nsfunc "http:/cgi-bin/manwhatis?$1"
	      else
		nsfunc "http:/cgi-bin/man2html?$2+$1"
	      fi
	      ;;
	esac
else
	case "$1" in
	  1|2|3|4|5|6|7|8)
	      nsfunc "http:/cgi-bin/mansec?$1"
	      ;;
	  *)
	      nsfunc "http:/cgi-bin/man2html?$1"
	      ;;
	esac
fi
	
