.key file/a,section,NoCatArg
.bra {
.ket }

;
; $PROJECT: unix manual page CLI command using MultiView, man.datatype
;           & AmiNet's nroff.lha
;
; $VER: man 2.1 (09.02.00)
; by
;
; Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
; Martin Tauchmann <MartinTauchamnn@bigfoot.com> http://MartinTauchmann.home.pages.de
;
; (C) Copyright 1994 & 2000
; All Rights Reserved !
;
; $FUNCTION: bin:man term [7 nocat]
;
; This command searches for a given string and if it found a entry, it opens
; a MultiView window to display it (The man.datatype have to be installed) !
;
;
; $HISTORY:
;
; 09.02.00 : 002.001 :  support Unix man files (also gziped) for Geek Gadgets
;			requires AmiNet's nroff.lha installed in bin:nroffUnix
; 26.01.00 : 002.000 :  support gzip'ed cat files for Geek Gadgets
; 19.11.94 : 001.002 :  now uses [0-9] pattern as suffix
; 18.11.94 : 001.001 :  initial
;

;not necessary
;set MANPATH /gnu/man:/usr/share/man


if NOT EXISTS GNU:man/mandb
   c:search GNU:man/ #?.[0-9]#? ~(#?/man?/#?) FILE ALL >t:mandb
   c:sort t:mandb TO GNU:man/mandb
   delete t:mandb QUIET
endif

if NOT EXISTS GNU:man/mandb
   Echo "Can't find man database !"
   quit 5
endif

Resident c:search PURE
Resident c:type PURE
if NOT "{section}" EQ ""
   c:search >t:var GNU:man/mandb #?{section}/{file}.[0-9]#? PATTERN NONUM QUICK
   SET MAN `type t:var`
   if "$MAN" EQ ""
	Echo "no manual entry in section {section} found !"
   endif
else
;   SET MAN `bin:locate -d /gg/man/mandb /{file}.[0-9]#?`
;   SET MAN `bin:find Devel:C/gnu/man/cat*/{file}**`

   c:search >t:var GNU:man/mandb /{file}.[0-9]#? PATTERN NONUM QUICK
   SET MAN `type t:var`
   if "$MAN" EQ ""
	Echo "no manual entry found !"
   endif
endif


; if something is found , display it via MultiView
if NOT "$MAN" EQ ""

	type t:var

	c:search >t:var2 t:var /cat?/ PATTERN NONUM QUICK
	SET MAN `type t:var2`
	if NOT "{NoCatArg}" EQ ""
		SET MAN ""
	endif
	if "$MAN" EQ ""
		SET CAT NO
		c:search >t:var2 t:var /man?/ PATTERN NONUM QUICK
	else
		SET CAT YES
	endif

	c:search >t:var t:var2 *.gz PATTERN NONUM QUICK
	SET MAN `type t:var`
	if "$MAN" EQ ""
		SET GZ NO
		SET MAN `type t:var2`
	else
		SET GZ YES
	endif

	if NOT "$MAN" EQ ""

;		echo hope, only one file
;		echo $MAN

		if NOT "$CAT" EQ "YES" 		;AmiNet's nroff.lha
			if "$GZ" EQ "YES"
				;handle Unix man
				FailAt 21
				bin:gunzip >t:man-tmp.0 -c $MAN
				FailAt 10
				bin:nroffUnix >t:man.txt -man t:man-tmp0
				multiview t:man.txt SCREEN
				;handle GNU man
				;gnu:bin/manGNU {file} {section}
			else
				bin:nroffUnix >t:man.txt -man $MAN
				multiview t:man.txt SCREEN
			endif
		else				; man (cat) datatype
			if "$GZ" EQ "YES"
				FailAt 21
				bin:gunzip >t:man-tmp.0 -c $MAN
				FailAt 10
				multiview t:man-tmp.0 SCREEN
			else
				multiview "$MAN" SCREEN
;;				multiview "$MAN" PUBSCREEN PubMultiView
			endif
		endif
	else
		Echo "no cat or man manual entry found !"
	endif
endif

; cleanup
unset MAN
unset CAT
unset GZ
Delete t:var t:var2 t:man-tmp.0 t:man.txt QUIET
Resident c:type REMOVE
Resident c:search REMOVE
