📄 vt.doc
字号:
After the above example, base(p)[0] would be "Druid" and base(p)[1]would be 673.You can use the lookup() operator with windows, remotes, andassociation types in addition to plists. "lookup(win, str)" and"lookup(rmt, str)" are short for "lookup(obj(win), str)" and"lookup(obj(rmt), str)" respectively. "lookup(assoc, str)" returnsthe integer offset of <str> for the association type <assoc>. You can"lookup(assoc, str)" to force the order of associations for anassociation type. For instance: world_type = new_assoc(); &world_type->name; &world_type->addr; &world_type->port; world = alloc(3, world_type); acopy(base(world), table("Name", "Addr", 1111), 3);By forcing the order of associations after creating the associationtype, we can initialize new worlds directly by using acopy() andbase(). (The table() function comes from the distribution.) Notethat "&world_type->name" is an abbreviation for "&(*lookup(world_type,"name"))", which is the same as "lookup(world_type, "name")". If youleave out the &, you will be dereferencing an integer, which is anillegal operation.Strings-------Strings are treated in much the same as arrays. They will extend withan attempt to write past their ends using a primitive or an assignmentoperator. Intervening elements are initialized to spaces. That is, [a] a = ""; a[10] = '#'; echo(a);writes a string of ten spaces followed by a '#'. Strings arenull-terminated, so setting a string element to 0 shortens the stringif the string previously stretched being the array element inquestion. Elements past the new end of the string are irretrievablylost. A string constant in VTC code is inviolate. Each reference tothat constant produces a different copy of the string. That is, thefollowing code: [a, i] { a = alloc(2); for (i = 0; i < 2; i++) a[i] = "foobar"; *a[0] = 'g'; echo(a[1]); }will produce the output "foobar," not "goobar." String elementsbeyond the end of a string or before the beginning have the value 0.Assigning to an element before the beginning of a string results in aruntime error.When a primitive takes a string argument, it accepts a string pointer,which is taken to be the beginning of the string.Functions---------You define functions using the parser. You cannot undefine functions,although you can redefine them. Your VTC code can contain a call toan undefined function or a pointer to an undefined function, but thiswill produce a runtime error if you do not define the function beforeexecuting that part of the code.Function declarations contain zero or more parameter variables.Calling a function with fewer arguments than there are parametersresults in a fatal error. You can call a function with more argumentsthan there are parameter variables. The function can use the argc andargv builtins to access these arguments. The argc builtin returns thenumber of arguments passed to the function, and the argv builtinreturns an array that contains all of the arguments, including thedeclared parameters.You can declare some of your function's parameters to be optional, bypreceding them with a '/'. For instance, in the parameter list "(foo,bar / baz, quux)", baz and quux are optional arguments. Theseparameters have the value NULL if you do not specify them in a call tothe function.Functions return a value specified by a return statement, or NULL ifthey exit normally.Many functions have the form: func name(args) { return expr; }where <expr> is a short expression. A shortcut for this is: func name(args) --> exprIf <expr> takes several lines, you must escape each newline explicitlywith a '\', so this construct is best only for short expressions.Windows-------VT divides the screen into two areas: an input window occupyingseveral lines at the bottom of the screen, and an output region, whichis further divided into one or more output windows. Each outputwindow has a divider line below it. When VT starts up, the inputwindow occupies three lines, and the rest of the screen is used forone output window.At all times, one of the output windows is 'active'. This window hasan asterix (*) in the first column of the divider line below it. Tochange the active window, use the ^XO key combination defined by thedistribution VTC code.The input window can be in either VTC mode or text mode. In VTC mode,a line entered in the input window will be parsed, while in text modeit will be passed to the active window. To change modes, use the ESCESC key bombination defined by the distribution.VT checks each character typed against a list of key bindings. If acharacter completes any one of these bindings, VT executes an editingfunction or a VTC function. If the character only partially matches amultiple-character key binding, then VT holds onto it to see iffollowing characters match the rest of the sequence. If they do not,or if a character does not match a key binding at all, then VTdisplays it in the input window.Following is a list of editing functions, along with the bindingsassigned to them by the distribution. The mnemonics are namedconstants in the VTC compiler. To get a list of key bindings fromwith the client, use the command "/list_keys" defined by thedistribution. Mnemonic Keys Description -------- ---- ----------- K_CUP ESC [A Cursor up K_CDOWN ESC [B Cursor down K_CLEFT ESC [C Cursor left K_CRIGHT ESC [D Cursor right K_CHOME ^A or ^[[H Cursor to start of line K_CEND ^E or ^[[K Cursor to end of line K_CWLEFT ESC B Cursor word left K_CWRIGHT ESC F Cursor word right K_BSPC ^H or DEL Delete character left K_BWORD ^W Delete word left K_BHOME ^[K Delete to start of line K_DBUF ^X or ^U Delete input buffer K_DCH ^D Delete character right K_DWORD ESC W Delete word right K_DEND ^K Delete to end of line K_REFRESH ^R Rewrite the input window K_REDRAW ^L Redraw the screen K_MODE ESC ESC Toggle input window mode K_PROCESS newline Process input bufferVTC tasks can intercept keystrokes using the getch() primitive.getch() takes a priority argument to determine whether to check keybindings before returning the keypress, and an optional windowargument specifying which window must be active in order for akeypress to be intercepted. VT dispatches keypresses as follows: Resume task that called getch(HIGH) if any, or Resume task that called getch(HIGH, window) if any, or Execute key binding, if matched, or Hold key, if key partially matched key binding, or Resume task that called getch(LOW) if any, or Resume task that called getch(LOW, window) if any, or Insert in input bufferWhen the user enters a line in text mode, VT "passes" it to the activewindow. A VTC task can also do this with the pass() primitive. VTCtasks can intercept lines passed to a window using the read()primitive. read() with no arguments will intercept a line enteredwhile any window is active; read() with a window argument willintercept a line entered while that window is active. Windows have a"termread" function to handle unintercepted lines. VT dispatches userinput lines as follows: Parse, if the input window is in VTC mode, or Resume task that called read() with no arguments, if any, or Resume task that called read(window), if any, or Run active window's termread function, if it exists, or Send to active window's remote connection, if it exists, or DiscardVT calls the window's termread function with one argument, the linepassed to the window, with no newline character at the end.The builtin variable "prompt" contains a string which VT displays inthe input window. A VTC task can set this prompt using a statementlike: prompt = "> ";The K_PROCESS editing function resets the prompt to an empty string.Remote connections------------------VTC tasks can open connections to remote hosts with the connect()primitive. VT associates three VTC-settable flags with each remote: a"busy" flag signalling that VT should not process any input from thatremote, a "background" flag controlling whether VT should processinput from the remote connection when it is not associated with awindow, and a "raw" flag which determines how VT will process inputfrom the remote host. To set these flags, use the set_busy(),set_back(), and set_raw() primitives. To read them, use thermt_busy(), rmt_back(), and rmt_raw() primitives.A VT connection is said to be in raw mode when the raw flag is on, andin line mode when the raw flag is off. In line mode, VT breaks upincoming server data into lines before dispatching it. In raw mode,VT dispatches the text in blocks. In both modes, VT will dispatch aprompt if it sees a prompt terminator, which is a telnet IAC GAsequence or possibly a telnet IAC EOR sequence.VT supports the telnet protocol and the telnet options ECHO and EOR.Remote connections have two non-user-settable flags, "echo" and "eor".You can check the state of the echo and eor flags with rmt_echo() andrmt_eor().The "echo" flag determines whether VT will display input in the inputwindow, and defaults to on. If the server sends an IAC WILL ECHOwhile the echo flag is set, VT will reply with an IAC DO ECHO andclears the echo flag. While the flag is clear, if the server sends anIAC WONT ECHO, VT responds with an IAC DONT ECHO and sets the echoflag. VT will not display input in the input window while the echoflag is clear.The "eor" flag defaults to off. The remote server can turn it on withan IAC WILL EOR, which VT will respond to with an IAC DO EOR. Whenthe eor flag is on, VT will accept an IAC EOR sequence as a promptterminator. The remote server can turn the flag off with an IAC WONTEOR, which VT will respond to with an IAC DONT EOR. While the flag isoff, or if the connection is in raw mode, VT ignores IAC EOR.VT interprets IAC GA as a prompt terminator regardless of the eorflag.In line mode, VT interprets a newline as a line terminator, andignores carriage returns entirely. In raw mode, VT uses newlines onlyto determine the beginning of a prompt when it encounters a promptterminator.The display() primitive associates a remote connection with a windowand vice versa. You can only associate one remote connection with awindow and vice versa.VTC tasks can intercept lines or blocks from a remote using the read()primitive, but they cannot intercept prompts. Remote connections have"promptread" and "netread" functions to handle prompts andunintercepted lines or blocks.Blocks (in raw mode) and lines (in line mode) are dispatched asfollows: Resume task that called read(remote), if any, or Run remote's netread function, if it exists, or Write to the remote's window, if it exists, or Write to the active window with a "[background] " prefixPrompts are dispatched as follows: Run remote's promptread function, if it exists, or Write to the remote's window, if it exists, or Write to the active window with a "[background] " prefixHooks-----VT has two "hooks", or functions it calls automatically in certainsituations.When VT redraws the screen automatically (that is, after returningfrom a SIGTSTP (^Z) signal or after the screen is resized), if thereis a function redraw_hook(), VT will call that function rather thanredraw the screen. The function can call edfunc(K_REDRAW) to redrawthe screen normally.Second, whenever a remote connection is closed, whether through thedisconnect() primitive or due to a read error or a foreign host, VTwill call disconnect_hook() if it exists.Named constants---------------There are several reserved words in VTC that are translated directlyinto integer constants. These numbers have some meaning to certainprimitives in the compiler. The constants are: Name Value Description ---- ----- ----------- T_INT 0 Data types T_PPTR 1 T_BPTR 2 T_RMT 3 T_WIN 4 T_KEY 5 T_FILE 6 T_SPTR 7 T_APTR 8 T_FPTR 9 T_REG 10 T_ASSOC 11 T_PLIST 12 T_NULL 13 K_CUP 0 Editing functions K_CDOWN 1 K_CLEFT 2 K_CRIGHT 3 K_CHOME 4 K_CEND 5 K_CWLEFT 6 K_CWRIGHT 7 K_BSPC 8 K_BWORD 9 K_BHOME 10 K_DBUF 11 K_DCH 12 K_DWORD 13 K_DEND 14 K_REFRESH 15 K_REDRAW 16 K_MODE 17 K_PROCESS 18 SEEK_SET 0 For fseek(): beginning of file SEEK_CUR 1 current position in file SEEK_END 2 end of file HIGH 0 For getch() primitive LOW 1 INTR 2 EOF -1 For reading files NSUBEXP 10 Max. number of regexp sub-expressionsBuilt-in objects (builtins)---------------------------Most built-in objects act like variables whose values are tied tofunctions of the client. Their values can change automatically. Hereis a complete list: Name Type Description ---- ---- ----------- active WIN Active window prompt SPTR Input window prompt kbuf SPTR Key buffer in input window kpos INT Offset of cursor in key buffer cur_win WIN Current window (see below) cur_rmt RMT Current remote (see below) argc INT Number of arguments to current function argv APTR Current function's argument array time INT Current time (seconds since Jan 1, 1980) wd SPTR Current working directory rnd INT A random integer from 0 to max int value version SPTR Version number errflag INT Error flag (1 or 0) errmsg SPTR Error message for last error NULL NULL Null valueYou can assign to the builtins active, prompt, kbuf, kpos, argc, argv,and wd. Assigning to argc and argv affects only the current functionand is a convenience for functions that traverse their argument array.Assignments to argv also do not affect which arguments the parametervariables refer to. Assigning to other builtins has an immediateeffect. Assigning to the wd builtin will sometimes fail, in whichcase the errflag and errmsg builtins are set as with primitives thatcan fail. Attempting to assign an object of the wrong type to abuiltin, or assigning to a builtin that cannot be written to, resultsin an "Illegal builtin assignment" runtime error. This also occurs ifyou attempt to assign an array pointer to the argv builtin that doesnot point into the current function's parameter array. The & operatorcan be used to get a pointer to a builtin object (of type BPTR), justas with variables.The prompt, kbuf and wd builtins store strings, not pointers tostrings, so that while "kbuf++" is legal, the first character of thekeyboard buffer is lost, and a subsequent "kbuf--" will not allow youto recover it (it will instead clear the keyboard buffer). Also, anynonprintable characters will be stripped from a string you assign tothe kbuf or prompt builtins.The prompt builtin applies to the input window only in text mode, andthe prompt persists only until one line is entered, at which time itreverts to the empty string.Non-fatal errors----------------A number of primitives can fail with a non-fatal error if theirarguments are invalid or some other condition occurs. Theseprimitives return an error code under such conditions. The errflagbuiltin is nonzero if the last error-returning primitive failed. Iferrflag is nonzero, then errmsg contains a string with someinformation as to why the error occurred.errflag and errmsg are also set when the bobj assignment to the wdbuiltin fails, and when VT calls the disconnect_hook() primitive. Inthe latter case, errflag is 0 if the remote was disconnected throughthe disconnect() primitive, and 1 if it was disconnected because of afailed send or receive or a closed connection.Primitives that set the errflag and errmsg builtins are marked with a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -