Expand Multiple Commands

From Gwen Morse's Wiki
Jump to: navigation, search
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Original by Andrew C.M. McClintock <andrewm at tiger dot hsc dot edu>
;;; corrections by Ken Keys <hawkeye at commercewave dot com>

; Here is some tf code Andrew wrote to handle multiple commands inputted at once,
; using the comma as a delimiter, and the ] and > keys as the commands
; trigger:

/require alias.tf

/alias ] /do_expand %{*}

/alias > /eval /do_expand %%{dir_%{1}}%;\
    /if (strlen({-1})) /do_expand %{-1} %; /endif

/def do_expand = \
    /let args=%*%; \
    /let i=0%; \
    /while ((i:=strchr(args, ",")) >= 0) \
        /eval $[substr(args, 0, i)]%; \
        /let args=$[substr(args, i+1)]%; \
    /done%; \
    /eval %args

; so usage would be:
;
; ] s,kill dog,laugh dog,moon dog
;
; the > functionality is for move macros, you have to set these before hand,
; like:
;
; /set dir_temple s,e,n,w
; /set dir_somewhere e,s,w,n
;
; > temple > somewhere
;
; also you can use the move macros bundled with commands at the end:
;
; > temple > somewhere kill dog,laugh dog,moon dog
;
; this may or may not prove useful to you; i do welcome and critiques on the
; code and suggestions as to how i can make it faster...