;mtest17
 $f3='-adobe-courier-bold-r-normal--12*'
 $f4='-adobe-helvetica-bold-r-normal--14*'

subr help_tog
 ;4 cases, each calls a selection box
 $help_top = $option_value
 ty,'$help_top =', $help_top
 ncase $option_value
 { load_help_from_file, '/hosts/umbra/usr1/people/shine/auto/instructions.ana_command'
 }
 { $help_label = 'subroutines'
   $help_topic = 'list of subroutines'
   help_list,0
 }
 { $help_label = 'functions'
   $help_topic = 'list of functions'
   help_list,1 }
 { load_help_from_file, '/hosts/umbra/usr1/people/shine/auto/instructions.sorry'
 }
 { load_help_from_file, '/hosts/umbra/usr1/shine/auto/instructions.sorry'
 }
 {
 ;here we try to dismiss all the help widgets
 dismiss_ana_help
 }
 endcase

 endsubr
 ;===============================================================================
subr dismiss_ana_help
 if defined($ana_help_widget) eq 1 then xtunmanage, $ana_help_widget
 if defined($ana_help_widget2) eq 1 then xtunmanage, $ana_help_widget2
 endsubr
 ;===============================================================================
subr help_list, mode
 if defined($ana_help_widget) eq 0 then {
 $ana_help_widget = xmdialog_board(0,0,0, 'Help Keywords')
 $ana_help_label = xmlabel($ana_help_widget, $help_topic, $f4)
 xmposition, $ana_help_label, 20, 10
 $ana_help_list = xmlist($ana_help_widget, 'help_list_cb', 20, $f3, 'white')
 xmposition, xtparent($ana_help_list), 10, 45
 } else xtunmanage, $ana_help_widget
 ;that defines the widget if it wasn't already, now fill it with
 ;requested information
 xmsetlabel, $ana_help_label, $help_topic
 xmlistdeleteall, $ana_help_list
 if mode eq 0 then xmlistsubr, $ana_help_list else xmlistfunc, $ana_help_list
 xmlistselect, $ana_help_list, 1, 0
 xtmanage, $ana_help_widget
 xmposition, $ana_help_widget, 500, 400
 endsubr
 ;===============================================================================
subr load_help_from_file, name
 help_widget2	;checks if defined
 xmtexterase, $ana_help_text
 lun = get_lun()
 openr, lun, name
 s=''
 nlines = 0
 while readf(lun, s) eq 1 do { xmtextappend, $ana_help_text, s, 1  nlines+=1 }
 close, lun
 xmtextsetrowcolumnsize, $ana_help_text, nlines<30, 80
 xmtextsetposition, $ana_help_text, 0
 xtmanage, $ana_help_widget2	;just in case
 endsubr
 ;===============================================================================
subr help_widget2
 if defined($ana_help_widget2) eq 0 then {
 $ana_help_widget2 = xmdialog_board(0,0,0, 'Help Text')
 $ana_help_text = xmtext($ana_help_widget2, 6, 80, $f3,'white')
 xmposition, xtparent($ana_help_text), 0, 0
 xtmanage, $ana_help_widget2
 xmposition, $ana_help_widget2, 500, 500
 }
 endsubr
 ;===============================================================================
subr help_list_cb
 help_widget2	;checks if defined
 text=upper($list_item
 k = strpos(text, ' ')
 if k gt 0 then text=text(0:(k-1))

 ;ty,'choosen item = ', text
 lun = get_lun()
 openr, lun, '/hosts/umbra/usr1/people/shine/auto/ana_subroutines.txt.desc'
 ;we read the file, checking header lines for a match to "text"
 s=''
 found_match = 0
 xmtexterase, $ana_help_text
 nlines = 1
 while readf(lun, s) eq 1 do {
  if num_elem(s) ge 1 then {
  c=s(0)
  if c ne  ' ' and c ne '*' and c ne '.' then {
  ;have a header, check for a match
  ;ty,'header: ', s
  sq = upper(s)
  k = strpos(sq, '(')  if k gt 0 then sq = sq(0:(k-1))
  k = strpos(sq, ',')  if k gt 0 then sq = sq(0:(k-1))
  if strpos(sq, text) eq 0 then {
  ;ty,'found a match'
  found_match = 1
  ;got a match, now get the header plus text and put in a text widget
  xmtextappend, $ana_help_text, s, 1
  flag = 1
  repeat {
  readf, lun, s
  c = s(0)
  if c eq ' ' or c eq '.' then {
  xmtextappend, $ana_help_text, s, 1
  nlines += 1
  } else flag = 0
  } until flag eq 0
  break
  }
  } }
 }
 ;did we actually find a match?
 if found_match eq 0 then {
 s='Nothing seems to be available on this topic.'
 nlines = 2
 xmtextappend, $ana_help_text, s, 1
 }
 xmtextsetrowcolumnsize, $ana_help_text, nlines<30, 80
 xmtextsetposition, $ana_help_text, 0
 xtmanage, $ana_help_widget2	;just in case
 close, lun
 endsubr
 ;=========================================================
subr ana_dismiss_cb
 ;just exit for this test
 exit
 ;dismiss the command widget and all the help widgets
 dismiss_ana_help
 if defined($ana_command_widget) eq 1 then xtunmanage, $ana_command_widget
 endsubr
 ;=========================================================
subr echo_check_cb
 !motif_echo = xmtogglegetstate($echo_check(1))
 endsubr
 ;=========================================================
func ana_command_widget(dummy)
 if defined($ana_command_widget) eq 0 then {
 b1= xmdialog_board(0,0,0,'ANA Command Widget',0,0,10,10)
 $ana_command_widget = b1
 s1 = 'Help'
 bar = xmmenubar($ana_command_widget,  $f4, 'yellow', s1)
 ix = 10	iy = 10
 xmposition, bar(0), ix, iy, 60, 40
 s0 = 'this dialog'
 s1 = 'subroutines'
 s2 = 'functions'
 s3 = 'system variables'
 s4 = 'language'
 s5 = 'dismiss help widgets'
 pd1=xmpulldownmenu(bar(0), bar(1), 'help_tog', $f4, 'green', s0, s1, s2,s3,s4, -
 s5)

 ;a check button for echo
 $echo_check = xmcheckbox(b1,'echo_check_cb',$f4,'','echo commands in output')
 xmposition,$echo_check(0), 160, 10
 xmselectcolor,$echo_check(1),'red'
 ;a dismiss button
 xmposition, xmbutton(b1,'Dismiss', 'ana_dismiss_cb', $f4,'red'), 80, 10, 64, 40

 $text_out = xmtext(b1, 20, 80, $f3, 'white')
 xmposition, xtparent($text_out), 20, 60
 xmposition,xmlabel(b1,'command history:',$f4, ''), 20, 380
 cm = motif_input(b1, 612, 10, 100, $f3, 'white')
 xmfont, cm(2), $f4
 xmposition, cm(0), 10, 392
 }
 return, $ana_command_widget
 endfunc
 ;=========================================================
;main
 $ana_command_widget = ana_command_widget()
 xtmanage, $ana_command_widget
 xmposition, $ana_command_widget, 500, 500
 xtloop, 1
 
