:help system
:base
:


alias chelp {
        ^assign -topics
        for (@i = 1,getitem(chelp $i),@ i++) {
                ^push topics $before(& $getitem(chelp $i))
        }
	if (![$0]) {
		@ topics = sort($topics)
		@ topicn = numwords($topics)
                ^stack push set floating_point_math_var
                ^set floating_point_math_var on
		@ collen = [${topicn / 5}]
		^stack pop set floating_point_math_var
                if (ismatch(. $collen)) {
                        @ collen = before(. $collen)
                        @ collen++
                }   
		echo $fparse(format_header core help)
		for (@i = [0],i < collen,@i++) {
			echo $fparse(format_midbar $(c4)[$(c3)$[11]word($i $topics)$(c4)][$(c3)$[11]word(${i + collen} $topics)$(c4)][$(c3)$[11]word(${i + collen * 2} $topics)$(c4)][$(c3)$[11]word(${i + collen * 3} $topics)$(c4)][$(c3)$[11]word(${i + collen * 4} $topics)$(c4)])
		}
		echo $fparse(format_footer core help)
	}
	{
		if (!match($0 $topics)) {
			xecho -b error: invalid help request
		}
		{
		        for (@i = 1,getitem(chelp $i),@ i++) {       
                		if (before(& $getitem(chelp $i)) == [$0]) {
					xecho -c $fparse(format_usage $before(& $after(& $getitem(chelp $i))))
					xecho -b         $after(& $after(& $getitem(chelp $i)))
				}
			}
		}
	}
        ^restub chelp help.m
}
alias addhelp {
	if (!match($before(& $0) $helplist)) {
		@ setitem(chelp 0 *)
		@ setitem(chelp $numitems(chelp) $0-)
		^push helplist $before(& $0-)
	}
}
alias remhelp {
	@helplist = [$msar(g!$before(& $0)!!  ! !$helplist)]
        for (@i = 1,getitem(chelp $i),@ i++) {
		if (before(& $getitem(chelp $i)) == before(& $0)) {
			@delitem(chelp $i)
		}
	}
}
