# help engine
@ a.helpfile = [~/argon/argon.help]

alias ausage {
  ge $(c.hw)usage$(c.hk):$(cl) $getitem(cu_$0 0)}

alias ahelp {
  if ([$*]==[index]|![$*]) {
    ^local ah.
    @ ah.t1 = pattern(ch_* $tolower($getarrays()))
    fe ($ah.t1) ah.f {
      push ah.t $after(_ $ah.f)}
    @ ah.t = sort($ah.t)
    echo $box.head()
    echo $box.echo_head(help is available on the following topics$(c.hk): $(c.lm)\($(cl)/ahelp $(c.hk)[$(cl)topic$(c.hk)]$(c.lm)\)$(cl))
    fe ($ah.t) ah.1 ah.2 ah.3 ah.4 ah.5 {
      switch ($numwords($ah.1 $ah.2 $ah.3 $ah.4 $ah.5)) {
      (5) {
        echo $box.echo($[12]ah.1 $[12]ah.2 $[12]ah.3 $[12]ah.4 $[12]ah.5)}
      (4) {
        echo $box.echo($[12]ah.1 $[12]ah.2              $[12]ah.3 $[12]ah.4)}
      (3) {
        echo $box.echo(             $[12]ah.1 $[12]ah.2 $[12]ah.3)}
      (2) {
        echo $box.echo(             $[12]ah.1              $[12]ah.2)}
      (1) {
        echo $box.echo(                          $[12]ah.1)}}}
    echo $box.footer()} else {
    if (numitems(ch_$0)) {
      echo $box.head()
      echo $box.echo_head(help for "$(c.hw)$0$(cl)"$(c.hk)..$(cl))
      for (@xx=0, xx < numitems(ch_$0), @xx++) {
        echo $box.echo($(cl)$getitem(ch_$0 $xx))}
      echo $box.footer()} else {
      ge no help is available for "$0".. try /ahelp index.}}}

if (fexist($a.helpfile)==1) {
  @ _hfd = open($a.helpfile R) 
  while (!eof($_hfd)) {
    @ _hr = read($_hfd)
    switch ($[1]_hr) {
    (@) {
      @ _htype = after(@ $_hr)
      @ delarray(cu_$_htype)
      @ delarray(ch_$_htype)}
    (&) {
      @ setitem(cu_$_htype $numitems(cu_$_htype) $after(& $_hr))}
    (.) {
      @ setitem(ch_$_htype $numitems(ch_$_htype) $after(. $_hr))}}}
  @ close($_hfd)}
#sjk'97
