;help {COMMAND or macro}
;
;Type help Name_of_item to get info about a specific command.
;Use apropos topic, to find commands name related to a specific
;topic.
;Use help primer for a first introduction.
;
;see also : apropos


if (!$arg) then
   set comm = primer
else
   set comm = $_
endif


;Test de l'existence du fichier dans
;les directories /usr/local/gifa/help; ./; et 
;ceux definis dans $GIFAPATH 

   set tmpfile = ("/usr/tmp/hgifa" // int(100000*$random))
   set file_out = ("/usr/tmp/gifahelp" // int(100000*$random))
   set path = $GIFAPATH

   sh ("ls  /usr/local/gifa/help/"//$comm//".hlp >";$file_out;" 2> /dev/null")
   sh ("ls ./"//$comm;">>";$file_out;" 2> /dev/null")
   while ($path s! " ")
	set item = (head($path))
        set path = (tail($path))
	sh ("ls ";$item//"/"//$comm;">>";$file_out;" 2> /dev/null")
   endwhile

;creation du fichier help

   open $file_out
   set file = <$file_out
   close  $file_out
   sh ("/bin/rm -f ";$file_out)


   if ( $file s= " " ) then
	dialogbox "Error" \
	" " message \
	("No help available for <";$comm;"> command") message \
	" " message *
	exit 

   elsif ( $file s= ("/usr/local/gifa/help/"//$comm//".hlp") ) then
	sh ("cp ";$file;$tmpfile)
	set orig = help  

   else
	sh ( "awk '/^;/ {print substr($0,2)} /^[^;]/ {exit}'";$file;">"; $tmpfile) 
	set orig = macro 
	set orig_file = $file

   endif

; test de fichier vide

open $tmpfile
set file = <$tmpfile
close  $tmpfile
if ( $file s= " " ) then
   dialogbox "Error" \
   " " message \
   ("No help available for <";$comm;"> command") message \
   " " message *
   exit
endif


; creation formulaire

set title_form = ("Help for:";$comm)
if (($comm s= "help") | ($comm s= "primer") | ($comm s= "contexts")) then 
	set run_comm = DO_NOTHING
else
	set run_comm = $comm
endif
if ($CONFIG_GRAPH==1) then
  if ($orig s= "macro") then
	formbox "HELP" \
        	DO_NOTHING \
         	$title_form  message \
         	$tmpfile text \
		Execute action $run_comm \
		noreturn \
		"Show Macro" action ("formbox Macro DO_NOTHING";$orig_file;" text *") \
       		*
  else
        formbox "HELP" \
                DO_NOTHING \
                $title_form  message \
                $tmpfile text \
                Execute action $run_comm \
                *
  endif
else
	sh ("more";$tmpfile);
endif
sh ("/bin/rm -f ";$tmpfile)
exit

