 	function dix_help(item)
	implicit none
c
c Display help about "item"
c
	include 'dix_def.inc'
	character*(*) item 		!:i: the item for which help is needed
	integer*4 dix_help		!:f: functinr esult
c#
	integer*4 istat,addr,nkar_imag,flag,pagewidth
	integer*4 bpos,epos,nk,ctx
c
	character*(max_filename_length) imagname,helpname
c
	integer*4 lib$find_image_symbol
	integer*4 lbr$output_help
	integer*4 lib$find_file
	external ignore_message
	external dix_help_my_output,dix_help_my_input
	external dix_msg_nohelp
	external dix_help_work
	pointer (p_dix_help_work,dix_help_work)
	integer*4 dix_util_get_len_fu
c
	include '($hlpdef)'
	include '($jpidef)'
	include '($dvidef)'
c
c Definitions for fshelp, if you have it present use the
c  text library
c
c	include 'programs_top:[fshelp]fshelp_lib(fshelp_def)'
	integer*4 fshelp_m_searchwild,fshelp_m_no_down,fshelp_m_nomouse
	parameter (fshelp_m_no_down = 16)
	parameter (fshelp_m_searchwild = 1024)
	parameter (fshelp_m_nomouse = 65536) 
c#	
	integer*4 nlines,pagesize
	logical*4 ansi
	common /my_nlines/ nlines,pagesize,ansi
c
c
c Find the help librrary
c  1. in the image directory
c  2. in sys$help
c  3. the logical dix_help will override
c Find the imagename, and transfer to HLB name
c
	call lib$getjpi(jpi$_imagname,,,,imagname,nkar_imag)
	call dix_util_file_parse(imagname(1:nkar_imag),'D',bpos,epos)
	ctx = 0
	istat = lib$find_file('DIX_HELP',helpname,ctx,
     1                          imagname(1:epos)//'DIX_HELP.HLB')
	call lib$find_file_end(ctx)
c
c Now try again in sys$help
c
	if(.not. istat) then
	  istat = lib$find_file('DIX_HELP',helpname,ctx,
     1                          'SYS$HELP:DIX_HELP.HLB')
	  call lib$find_file_end(ctx)
	endif
c
c
	if(istat) then
	  nk = dix_util_get_len_fu(helpname)
c
c And output help
c
c Try to load fshelp_shr
c
	  call lib$establish(ignore_message)	!to prevent message from find_image_symbol
	  istat = lib$find_image_symbol('fshelp_shr',
     1                     'fshelp_display_help',addr)
	  if(istat) then
c
c Found fshelp_shr, so you can call it now
c
	    p_dix_help_work = addr
	    flag = fshelp_m_searchwild .or. 
     1             fshelp_m_no_down .or.
     1             fshelp_m_nomouse
	    call dix_help_work(helpname(1:nk),item,flag)
	  else
c
c fshelp_shr  not found, so use lbr$output_hlp
c get some terminal data
c
	    call lib$getdvi(dvi$_tt_ansicrt,,'sys$output',ansi)
	    pagesize = 0
	    if(ansi) then
	      call lib$getdvi(dvi$_tt_page,,'sys$output',pagesize)
	      call lib$getdvi(dvi$_devbufsiz,,'sys$output',pagewidth)
	      write(*,1010) ESCAPE,ESCAPE
1010	      format('+',a,'[H',a,'[2J',$)
	    endif
	    flag = hlp$m_prompt .or. hlp$m_help
	    nlines = 0
	    call lbr$output_help(dix_help_my_output,pagewidth,item,
     1              helpname(1:nk),
     1              flag,dix_help_my_input)
	  endif
	else
c
c Signal help file not found
c
	  istat = %loc(dix_msg_nohelp)
	end if
c
	dix_help = istat
	end
	function dix_help_my_input(string,prompt,nkar)
	implicit none
c
	character*(*) string
	character*(*) prompt
	integer*4 nkar
	logical*4 dix_help_my_input
c#
	integer*4 nlines,pagesize
	logical*4 ansi
	common /my_nlines/ nlines,pagesize,ansi
c
	integer*4 lib$get_input
c
	nlines = 0
c
	dix_help_my_input = lib$get_input(string,prompt,nkar)
c
	return
	end

	function dix_help_my_output(string)
	implicit none
c
	include 'dix_def.inc'
c
	character*(*) string
	logical*4 dix_help_my_output
c#
	integer*4 nlines,pagesize
	logical*4 ansi
	common /my_nlines/ nlines,pagesize,ansi
c
	character*(max_line_length) kar
	integer*4 nkar
c
	integer*4 lib$put_output,lib$get_input
c
	nlines = nlines + 1
	if(pagesize .ne. 0 .and. nlines .ge. pagesize-3) then
	  call lib$put_output(' ')
	  call lib$put_output(' ')
	  dix_help_my_output=lib$get_input(kar,'Press RETURN to continue ... ',
     1                      nkar)
	  if(.not. dix_help_my_output) goto 90
	  if(ansi) write(*,1010) ESCAPE,ESCAPE
1010	  format('+',a,'[H',a,'[2J',$)
	  nlines = 0
	end if
	dix_help_my_output = lib$put_output(string)
90	return
	end

	function dix_help_work_ex(rout,line)
	implicit none
	integer*4 rout
	external rout
	character*(*) line
	integer*4 dix_help_work_ex
c
	integer*4 istat
c
c If you have installed FSHELP too, you can use the definition
c from that file, otherwise use the constant
c
c	include 'programs_top:[fshelp]fshelp_lib(fshelp_def)'
	integer*4 fshelp_m_image,fshelp_m_searchwild,fshelp_m_no_down
	integer*4 fshelp_m_nomouse
	parameter (fshelp_m_no_down = 16)
	parameter (fshelp_m_image = 512)
	parameter (fshelp_m_searchwild = 1024)
	parameter (fshelp_m_nomouse = 65536) 
c#	
	istat = rout('DIX_HELP',line,fshelp_m_image .or. 
     1                            fshelp_m_searchwild .or. 
     1                            fshelp_m_no_down .or.
     1                            fshelp_m_nomouse)
	dix_help_work_ex = istat
	return
	end
c
c The floowing routines build up a 
c help string constisting of lines, separated by ;
c
	subroutine help_init(help_des,intro,name_width,topic_width)
	implicit none
c
c Init a variable string, and use str$append to append text to it
c
	include 'dix_def.inc'
	record /dyn_help/ help_des
	character*(*) intro     	!:i: header line
	integer*4 name_width		!:i: topic width (part before :)
	integer*4 topic_width		!:i: topic width (for double cols)
c#	
	call dix_util_clear_descr(help_des.descr,.true.)
c
	help_des.name_width  = name_width
	help_des.topic_width = topic_width
c
c Add intro , name of help page
c
	call str$append(help_des.descr,intro//';')
	help_des.first_part = .true.
	return
	end
	subroutine help_key(control,help_des,dix_function,info,context)
	implicit none
c
c Add the help about a function and its mapping
c
	include 'dix_def.inc'
	record /control/ control	!:i: the control block
	record /dyn_help/ help_des
	integer*4 dix_function
	character*(*) info
	character*(*) context		!:i: screen scontext
c#
	character*(max_line_length) line
	integer*4 nk
c
	if(dix_function .ne. 0) then
	  call keydefs_get_map(dix_function,control,nk,line,context)
	else
	  nk = 0
	endif
	call help_topic_2(help_Des,line(1:nk),info)
	return
	end
	subroutine help_topic_2(help_Des,name,info)
	implicit none
c
c Add key/description
c
	include 'dix_def.inc'
	record /dyn_help/ help_des
c
	character*(*) name
	character*(*) info
c
	character*(max_line_length) line
	integer*4 nk
c
	line = name
	nk = len(name)
	if(nk .lt. help_des.name_width) nk = help_des.name_width
	line(nk+1:) = ': '//info
	nk = nk + 2 + len(info)
c
	if(help_des.topic_width .ne. 0) then
	  help_des.first_part = .not. help_des.first_part
	  if(nk .gt. help_des.topic_width) help_des.first_part = .true.
	endif
	if(help_des.first_part) then
	  nk = nk + 1
	  line(nk:nk) = ';'	!append a ;
	else
	  if(nk .lt. help_des.topic_width) nk = help_des.topic_width
	endif
	call str$append(help_des.descr,line(1:nk))
c
	return
	end
	subroutine help_topic(help_des,topic)
	implicit none
c
c Add a new topic to the help text
c this will be display in bold
c 
	include 'dix_def.inc'
	record /dyn_help/ help_des
	character*(*) topic
c#
	if(.not. help_des.first_part) then
	  call help_text(help_des,' ')
	  help_des.first_part = .true.
	endif
c
	call help_text(help_des,':'//topic)
	return
	end
	subroutine help_text(help_des,text)
	implicit none
c
c Add a text line to the help text (separated by a ;)
c 
	include 'dix_def.inc'
	record /dyn_help/ help_des
	character*(*) text
c#
	call str$append(help_des.descr,text//';')
	return
	end
	subroutine help_exit(help_des)
	implicit none
c
	include 'dix_def.inc'
	record /dyn_help/ help_des
c#
	call dix_util_free_descr(help_des.descr)
	return
	end
	subroutine dix_smg_stack_help(control,lines)
	implicit none
c
c Stack a new help string
c
	character*(*) lines	!:i: help lines spearated by ;
c#
	include 'dix_def.inc'
	record /control/ control
c
	external dix_msg_maxhdep
c
	integer*4 ipos
c
	if(control.help_depth .eq. max_help_depth) then
	  call dix_message(control,dix_msg_maxhdep)
	else
	  control.help_depth = control.help_depth + 1
	  ipos = index(lines,'|')- 1
	  if(ipos .le. 0) ipos = len(lines)
	  control.help_stack(control.help_depth).stack(1) = ipos
	  control.help_stack(control.help_depth).stack(2) = %loc(lines)
	end if
	return
	end
	subroutine dix_smg_unstack_help(control)
	implicit none
c
c Unstack a help string
c
	include 'dix_def.inc'
	record /control/ control
c#
	control.help_depth = max(0,control.help_depth-1)
	return
	end
	subroutine help_init_std(control,help_des,topic,pos,flag,context)
	implicit none
c
c calls help_init and create help lines about the mostly used keys
c depending on flag the following help text will be displayed
c flag is a bit mask
c bit  value   meaning
c   0      1   Left+right
c   1      2   Linup and down
c   2      4   pageUp and pagedown
c   3      8   First and last line
c   4     16   Line editing keys
c
	include 'dix_def.inc'
	record /control/ control
	record /dyn_help/ help_des
	character*(*) topic
	integer*4 pos
	integer*4 flag
	character*(*) context		!:i: context (screen)
c
	call help_init(help_des,topic,pos,0)
c
	if(btest(flag,0)) then
	  call help_key(control,help_des,key_left,
     1            'Move 1 left',context)
	  call help_key(control,help_des,key_right,
     1            'Move 1 right',context)
	endif
c
	if(btest(flag,1)) then
	  call help_key(control,help_des,key_up,
     1            'Move 1 line up',context)
	  call help_key(control,help_des,key_down,
     1            'Move 1 line down',context)
	endif
c
	if(btest(flag,2)) then
	  call help_key(control,help_des,key_prev,
     1            'Move 1 page up',context)
	  call help_key(control,help_des,key_next,
     1            'Move 1 page down',context)
	endif
c
	if(btest(flag,3)) then
	  call help_key(control,help_des,key_top,
     1            'Move to first line',context)
	  call help_key(control,help_des,key_bot,
     1            'Move to last line',context)
	endif
	if(btest(flag,4)) then
	  call help_key(control,help_des,key_first,
     1             'Move to first char',context)
	  call help_key(control,help_des,key_last,
     1             'Move to last char',context)
	  call help_key(control,help_des,key_erase,
     1             'Erase line',context)
	  call help_key(control,help_des,key_toggle,
     1             'Toggle ins/over',context)
	  call help_key(control,help_des,key_delete,
     1             'Delete char',context)
	  call help_key(control,help_des,key_swap_num,
     1             'Input in HEX',context)
	  call help_text(help_des,
     1             '    Enter hex via %DD, %% delivers one %')
	endif
	return

	end
