#
# NEED_PARMS format command
#
# HELP: SYNOPSIS:
# HELP:     generic/info/show_man format command
# HELP:
# HELP: DESCRIPTION:
# HELP:     Show the manpage for the given command in the selected format
# HELP:     Format is txt or html
#
DECLARE string $manpage,$version
DECLARE int $try
CECHO ${$version=$argv[1]}
{ CHKVERSION ${ $version!="txt" && $version!="html" }
	CECHO ${$version="txt"}
} CHKVERSION 0 0
CECHO ${$manpage=$argv[2]}
CECHO ${$try=0}
GOTO try

:retry
IF ${$try==3} goto give_up
IF ${$try==2} goto try2
CECHO ${$manpage=$root.func.strings.uppercase($argv[2])}
GOTO try

:try2
CECHO ${$manpage=$root.func.strings.lowercase($argv[2])}

:give_up
ECHO Manpage ${$manpage} not found.
QUIT

:try
CECHO ${$try++}
# ok - we found it on the first attempt.
{ CHKVERSION2 ${$version=="txt"}
	IF ${! $root.func.file.exists($root.global.dir.man+"/"+$version+"/"+$manpage)} GOTO retry
	SPAWNPROCESS xmessage -center -timeout 600 -file ${$root.global.dir.man}/${$version}/${$manpage} &
} CHKVERSION2 0 0
{ CHKVERSION3 ${$version=="html"}
	IF ${! $root.func.file.exists($root.global.dir.man+"/"+$version+"/"+$manpage+".html")} GOTO retry
	SPAWNPROCESS mozilla file://${$root.global.dir.man}/${$version}/${$manpage}.html &
} CHKVERSION3 0 0
QUIT
