Distribution Internals ---------------------- This file documents some useful functions in the distribution VTC code. It does not document functions and globals that are not intended for outside use, or for functions which are essentially command handlers. avl.vtc ------- Data type: Tree (Ttree) A tree is a data structure for associating keys with values. Insertions, deletions, and searches are performed in O(ln n) time. Because the tree is an AVL tree, there is no problem with inserting pre-sorted data. tree->cfunc Comparison function tree->root Root node PLIST make_tree(FPTR/PPTR compare_func) This returns a new tree, using to compare keys. is expected to act like strcmp(), that is, returning less than zero, zero, or greater than zero depending on the ordering of the two arguments. NULL insert_tree(PLIST tree, ?? key, ?? data) Inserts in , associated with . If is already present in the tree, the data associated with it will be replaced. should not be NULL. ?? find_tree(PLIST tree, ?? key) Searches for in and returns the associated data if it is found. If is not found, find_tree() returns NULL. NULL/1 delete_tree(PLIST tree, ?? key) Deletes the data value associated with in . If delete_tree() is successful, it returns true (1); otherwise, it returns false (NULL). NULL traverse_tree(PLIST tree, FPTR/PPTR map_func, [...]) Applies to each element of . Any arguments beyond the second passed to traverse_tree() will also be passed after the tree element to . bind.vtc -------- It's worth noting that the newline key is bound to accept(), so anything you want to have done every time you press return can go in there. For instance, you might put a call to reset_pager() inside accept(). Commands: /list_keys command.vtc ----------- Data type: Command (Tcommand) command->name command->args Number of args or -1 command->fptr Function to run when invoked command->fmt For /help Commands: /def /help /list_defs /undef ?? efind(FPTR/PPTR fptr, SPTR thing, SPTR s) efind() calls (*fptr)(s) and returns the result, if it is true. If the result is false, indicating a failure to find , efind() displays an error message and aborts the current process. efind() is used for building find functions that can be relied on to return successfully or not at all. For instance: func Find_world(s) { efind(.find_world, "world", s); } NULL add_cmd(SPTR name, INT args, FPTR/PPTR fptr, SPTR fmt) Adds a new command, named by , taking args. If is negative, is called with one string containing the entire argument line. If is nonnegative, is called with one string for each argument on the argument line. The shows up in /help. To make a command that does not show up on the /help list, use add_macro() with a function macro body. PLIST/NULL find_cmd(SPTR name) PLIST Find_cmd(SPTR name) Returns the command with the name . find_cmd() will return NULL if the command is not found; Find_cmd() will display an error message and abort. NULL add_macro(SPTR name, SPTR/FPTR cmd) Adds a new macro. When the macro is invoked, if is a string pointer, it will be evaluated according to the rules in dist.doc. If is a function pointer, it will be called as (*cmd)(line, args), where is the unprocessed argument string and is an array with args[0] == line and args[1..n] are the space-separated arguments in the argument string. SPTR/FPTR/NULL find_macro(SPTR name) SPTR/FPTR Find_macro(SPTR name) Returns the command string of the macro with the name . find_macro() will return NULL if the macro is not found; Find_cmd() will display an error mesage and abort. NULL process_cmdline(SPTR line, [SPTR full, APTR args]) Processes a line according to the rules in dist.doc. If the line is a macro or trigger body, should be the unprocessed argument string and should be a table of arguments for substitution (%0 --> args[0], etc.) hist.vtc -------- Data type: History line (Tline) line->text (*text) is style, (text + 1) is line line->world Globals: lineno Line number of next line to go in history Commands: /recall NULL add_hist(SPTR line, [INT style, ?? PLIST world]) Adds a line to the history.