Tfzhelp

Code expands to fit the available ram. I think that is a physical law. My memory (not ram) is failing and I can't recall EVERYTHING I have done. To that end I constructed the Zhelp system. As I write code I put in a
'/test zhelp_add("KEYWORD_SUBKEYWORD","HELP TEXT")'
after the /def I wish to document. Then I can type in any of the following while tf is running:

'/zhelp'
'/zhelp list' to get a list of KEYWORDs
'/zhelp all' to get help on all KEYWORDs
'/zhelp KEYWORD' to get help on just the top level of KEYWORD
'/zhelp KEYWORD list' to get a list of SUBKEYWORDs under KEYWORD
'/zhelp KEYWORD all' to get help on all SUBKEYWORDs under KEYWORD
'/zhelp KEYWORD SUBKEYWORD' to get help on just that SUBKEYWORD of KEYWORD

Note: Take a look at the code for examples of /test zhelp_add(). They are NOT part of the macro and are evaluated when the file loads so there is no real effect on responce and, once the statements are inserted in the file(s) there is no real upkeep unless you want to change the help.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;                                Zhelp.tf                                 ;;;
;;;                              Zorbo on 3k                                ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

/loaded z::zhelp.tf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This is to help with my help.
; Basicly, as you write a script, after the /def or /alias (or whatever you need
; documented in zhelp) put in a statement like:
; /test zhelp_add("zhelp","This the Zhelp system. Type /zhelp <keyword> for help")
; this is now available with /zhelp zhelp
;
; /test zhelp_add("<system>[_subcommand]","<helpstring>")
;
; try /zhelp zhelp all

;;; zhelp_add ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; syntax: /test zhelp_add("<system>[_subcommand]","<helpstring>")
;
; example: /test zhelp_add("zmap_start","Command used to start a new map")
;    will add an entry under the 'zmap' keyword with a second keyword of 'start'
;
/def -i zhelp_add = \
    /set zhelp_%{1}=%{2}%; \
    /return 1
/test zhelp_add("zhelp_add","Adds a help entry into the zhelp system ie /test \
    zhelp_add('<system>[_subcommand]','<helpstring>')")

;;; zhelp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; syntax:    zhelp(keyword,[all])
;        /zhelp keyword [all]
;
; example:    /eval /echo $[zhelp("map_start")
;        /zhelp map all
;
/def -i zhelp = \
    /let tempv=%; \
    /if ({1}=~"") \
        /echo -p @{BCgreen}>>Zhelp:@{n}  Type '@{B}/zhelp <keyword1|all|list> [keyword|all|list]@{n}' for @{B}help@{n}.%; \
        /return 0%; \
    /endif%; \
    /if ({1}=~"all") \
        /echo -p @{BCgreen}>>Zhelp:@{n}  Help for @{BCcyan}ALL@{n} systems Registered in Zhelp...%; \
        /set zhelpjustmajor=1%; \
        /quote -S /zhelp_all `"/listvar zhelp_*"%; \
        /set zhelpjustmajor=0%; \
        /return 1%; \
    /elseif ({1}=~"list") \
        /set showlist=%; \
        /echo -p @{BCgreen}>>Zhelp:@{n} Listing @{B}ALL@{n} systems systems registered in Zhelp...%; \
        /quote -S /zhelp_all_list1 `"/listvar -s zhelp_*"%; \
        /zhelp_display_parser_list %{showlist}%; \
        /return 1%; \
    /endif%; \
    /if (!zhelp_ishelp({1})) \
        /echo -p @{BCred}>>Zhelp:@{n}  No help available for @{BCcyan}%{1}@{n}.%; \
        /return -1%; \
    /endif%; \
    /if ({2}=~"") \
        /eval /test tempv:=zhelp_%{1}%; \
        /test zhelp_display({1},":",{tempv})%; \
        /return 1%; \
    /elseif ({2}=~"all") \
        /echo -p @{BCgreen}>>Zhelp:@{n} Listing @{B}ALL@{n} help for @{BCcyan}%{1}@{n}...%; \
        /quote -S /zhelp_all `"/listvar zhelp_%{1}*"%; \
        /return 1%; \
    /elseif ({2}=~"list") \
        /set showlist=%; \
        /echo -p @{BCgreen}>>Zhelp:@{n} Listing @{B}ALL@{n} entries for @{BCcyan}%{1}@{n}...%; \
        /quote -S /zhelp_all_list2 `"/listvar -s zhelp_%{1}_*"%; \
        /zhelp_display_parser_list %{showlist}%; \
        /return 1%; \
    /else \
        /let lookfor=%{1}_%{2}%; \
        /if (!zhelp_ishelp({lookfor})) \
            /echo -p @{BCred}>>Zhelp:@{n}  No help available for @{BCcyan}%{1} %{2}@{n}.%; \
            /return -1%; \
        /else \
            /quote -S /zhelp_all `"/listvar zhelp_%{1}_%{2}"%; \
        /endif%; \
    /endif
/test zhelp_add("zhelp","This the Zhelp system. Type '/zhelp <keyword1|all|list> [keyword2|all|list]' for help")

;;; zhelp_all ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; syntax:
;
; example:
;
/def -i zhelp_all = \
    /let trial=0%; \
    /if (zhelpjustmajor==0) \
        /test trial:=regmatch("\/set zhelp\_([^\_]*)\_([^\=]*)\=",{*})%; \
        /if (trial>0) \
            /let zhelpkey1=%{P1}%; \
            /let zhelpkey2=%{P2}%; \
            /let zhelpstr=%{PR}%; \
            /test zhelp_display({zhelpkey1},{zhelpkey2},{zhelpstr})%; \
            /return 1%; \
        /endif%; \
    /endif%; \
    /test trial:=regmatch("\/set zhelp\_([^\=]*)=",{*})%; \
    /if (trial>0) \
        /let zhelpkey1=%{P1}%; \
        /if (strstr(zhelpkey1,"_")==-1) \
            /let zhelpkey2=:%; \
            /let zhelpstr=%{PR}%; \
            /test zhelp_display({zhelpkey1},{zhelpkey2},{zhelpstr})%; \
            /return 1%; \
        /endif%; \
    /endif    

;;; zhelp_isvar ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; helper routine to determine if there is help available
; syntax: /if (!zhelp_ishelp({1})) 
;
/def zhelp_ishelp = \
    /test tfclose("o")%; /listvar -msimple -- zhelp_%*

;;; zhelp_display ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; routine to display the help requested
; syntax: /test zhelp_display(zhelpkey1,zhelpkey2,zhelpstr)
;
/def zhelp_display = \
    /let zhelpkey1=%{1}%; \
    /let zhelpkey2=%{2}%; \
    /let zhelpstr=%{-2}%; \
    /echo -p @{BCgreen}>>Zhelp:@{n} @{BCcyan}%{zhelpkey1} %{zhelpkey2}:@{n}%; \
    /zhelp_display_parser %{zhelpstr}

/def zhelp_display_parser = \
    /while ({#}) \
        /let ztemps=$[strcat(ztemps," ",{1})]%; \
        /if (strlen(ztemps)>45) \
            /echo -p @{Cgreen}>>@{n}      @{BCwhite}%{ztemps}@{n}%; \
            /let ztemps=%; \
        /endif%; \
        /shift%; \
    /done%; \
    /if (strlen(ztemps)>0) \
        /echo -p @{Cgreen}>>@{n}      @{BCwhite}%{ztemps}@{n}%; \
    /endif

/def zhelp_all_list1 = \
    /let entry=%*%; \
    /let first=$[strchr(entry,"_")+1]%; \
    /let second=$[strchr(entry,"_",first)]%; \
    /if (second<=0) \
        /let entry=$[substr({entry},first)]%; \
        /test showlist:=strcat(showlist," ",entry)%; \
    /endif

/def zhelp_all_list2 = \
    /let entry=%*%; \
    /let first=$[strchr(entry,"_")+1]%; \
    /let second=$[strchr(entry,"_",first)+1]%; \
    /let entry=$[substr({entry},second)]%; \
    /test showlist:=strcat(showlist," ",entry)

/def zhelp_display_parser_list = \
    /while ({#}) \
        /let ztemps=$[strcat(ztemps," ",pad({1},-12))]%; \
        /if (strlen(ztemps)>55) \
            /echo -p @{Cgreen}>>@{n}      @{BCwhite}%{ztemps}@{n}%; \
            /let ztemps=%; \
        /endif%; \
        /shift%; \
    /done%; \
    /if (strlen(ztemps)>0) \
        /echo -p @{Cgreen}>>@{n}      @{BCwhite}%{ztemps}@{n}%; \
    /endif

/echo -p @{BCgreen}>>Zhelp:@{n}  Type '@{B}/zhelp <keyword1|all|list> [keyword|all|list]@{n}' for @{B}help@{n}.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License