.key FILE/A,SECTION
.bra {
.ket }

;
; $PROJECT: unix manual page CLI command using MultiView and man.datatype
;
; $VER: man 40.2 (29.08.96)
; by
;
; Stefan Ruppert , Windthorststrasse 5 , 65439 Floersheim , GERMANY
;
; (C) Copyright 1994-1996
; All Rights Reserved !
;
; $FUNCTION:
;
; 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) !
;
; Set the MANPATH environment variable to the root directory for the man pages.
;
;
; $HISTORY:
;
; 29.08.96 : 040.002 : fixed a bug in List command
; 01.03.96 : 040.001 : some cleanup and a date check for mandb added
; 19.11.94 : 001.002 : now uses [0-9] pattern as suffix
; 18.11.94 : 001.001 : initial
;

Set MANDB mandb
GetEnv >NIL: MANPATH
If WARN
	Set MPATH man:
Else
	set MPATH $MANPATH
Endif

;
; little date check and if something is newer than the $MANDB delete MANDB.
; So that it is generated new.
;

SetEnv MANCHECK X
Set MANDATE `List $MPATH$MANDB LFORMAT "%d"`
List $MPATH P=~($MANDB) SINCE $MANDATE LFORMAT "%s" >>ENV:MANCHECK
If NOT "$MANCHECK" EQ "X"
	; only generate one new $MANDB per day
	GetEnv >NIL: MANCHECKED
	If WARN
		Delete >NIL: $MPATH$MANDB
		SetEnv MANCHECKED TRUE
	Endif
Endif

If NOT EXISTS $MPATH$MANDB
	Set OLDDIR `cd`
	cd $MPATH
	list #? P=#?.[0-9] ALL FILES LFORMAT "%s%s" >$MANDB
	cd $OLDDIR
endif

if NOT EXISTS $MPATH$MANDB
	Echo "Can't find man database !"
	quit 10
endif

if NOT "{section}" EQ ""
	search $MPATH$MANDB #?{section}/{file}.[0-9] PATTERN NONUM >ENV:MAN
	if "$MAN" EQ ""
		Echo "no manual entry in section {section} found !"
	endif
else
	search $MPATH$MANDB /{file}.[0-9] PATTERN NONUM >ENV:MAN
	if "$MAN" EQ ""
		Echo "no manual entry found !"
	endif
endif

; if something is found , display it via MultiView
if NOT "$MAN" EQ ""
	run >NIL: <NIL: MultiView $MPATH$MAN PUBSCREEN `GetPubName`
endif

; cleanup
unsetenv MAN
unsetenv MANCHECK
unset MPATH
unset MANDB
unset MANDATE
unset OLDDIR

