Source Scripts ============== These are sets of commands that are executed like a dos batch file. White space is ignored in a script file, unless a line starts with a '>'. Comments may be imbedded by starting the line with '#'. A source script is started using the source command. Optional parameters may be specifed: source .. These optional parameters are accessed in the script by using %n. Every occurance of '%n' in the script is replaced by the corrosponding parameter. To access parameter above 9, %(n) must be used (see below). All parameters can be accessed by using '%*'. To allow multiple words in a single parameter, delimit the sequence by '/', eg the command source test.vi /a b c/ d e would pass the parms "a b c", "d", and "e" to the script. Variables are supported. Variables must be preceded by a '%' symbol. Variables with more than one letter must be encased in brackets, eg: %a - references variable named a. %(abc) - references variable named abc. Both local and global variables are supported. They are distinguished by the case of the first letter: Local variables must begin with a lower case letter, and global variables begin with an upper case variable. Global variables are valid for the life of the editing session. There are a number of variables that take on values as the editor runs, use these at your own risk: %C - current column %D - drive of current file (actual path) %(D1) - drive of current file (as typed by user) %E - file name extension of current file %F - current file name (as typed by the user) %H - home directory of a file (directory where edit command was issued) %N - name of current file (without extension) %M - modified status - contains 1 if current file is modified, 0 otherwise %(OS) - what operating system the editor is hosted on (possible values are: nt, unix, os2, os2v2, dos) %(OS386) - is 1 if the host operating system is 386 (or higher) based %P - path of current file (actual path) %(P1) - path of current file (as typed by user) %R - current row (line number) %(SH) - height of screen in characters %(SW) - width of screen in characters %(Sysrc) - return code from last system command The full command line command set (see cmd.hlp) is supported, along with a programming language. Useful Commands --------------- Command line commands (see cmd.hlp) useful for scripts are: compile - compile a script load - make a script resident in memory Hook Scripts ------------ There are several hooks that may be implemented into the editor. If a hook returns a non-zero value, the operation being hooked is cancelled. Read Hook - this hook script is called just after a new file as been read into the editor. The script invoked is whatever file specified by the global variable %(Rdhook). Write Hook - this hook script is called just before a modified file is to be saved and exited. The script invoked is whatever file specified by the global variable %(Wrhook). Command Hook - this hook script is called after the return is pressed from the command line. The global variable %(Com) contains the current command line, and may be modified. The script invoked is whatever file specified by the global variable %(Cmdhook). Mod Hook - Modified hook. This hook script is called whenever a command is about to modify an unmodified file (if it already modifed, the hook is not called). The script invoked is whatever file specified by the global variable %(Modhook). Mouse Columns- this hook script is called whenever a selected column range Sel Hook has been right clicked. The script is invoked with the following parameters: %1 - string selected %2 - line on screen of selected string %3 - column on screen of start of string %4 - column on screen of end of string The script invoked is whatever file is specified by the global variable %(MCselhook) Mouse Lines - this hook script is called whenever a selected line range Sel Hook has been right clicked. The script is invoked with the following parameters: %1 - line on screen where mouse was clicked %2 - column on screen where mouse was clicked %3 - starting line %4 - ending line The script invoked is whatever file is specified by the global variable %(MLselhook) Control Constructs ------------------ loop (expr) until (expr) while (expr) (expr) endloop loop (expr) endloop if (expr) elseif (expr) elseif (expr) else endif Expressions ----------- Where (expr) is specified, an expression may be used. expression : conditional-exp conditional-exp : log-or-exp | log-or-exp ? expression : conditional-exp log-or-exp : log-and-exp | log-or-exp || log-and-exp log-and-exp : bit-or-exp | log-and-exp && bit-or-exp bit-or-exp : bit-xor-exp | bit-or-exp | bit-xor-exp bit-xor-exp : bit-and-exp | bit-xor-exp ^ bit-and-exp bit-and-exp : equality-exp | bit-and-exp & equality-exp equality-exp : relational-exp | equality-exp == relational-exp | equality-exp != relational-exp relational-exp : shift-exp | relational-exp > shift-exp | relational-exp < shift-exp | relational-exp >= shift-exp | relational-exp <= shift-exp shift-exp : additive-exp | shift-exp << additive-exp | shift-exp >> additive-exp additive-exp : multiplicative-exp | additive-exp + multiplicative-exp | additive-exp - multiplicative-exp multiplicative-exp : exponent-exp | multiplicative-exp * exponent-exp | multiplicative-exp / exponent-exp | multiplicative-exp % exponent-exp exponent-exp : unary-exp | exponent-exp ** unary-exp unary-exp : primary-exp | - unary-exp | ~ unary-exp | ! unary-exp primary-exp : INTEGER : STRING | ( expression ) A string is indicated by using quotes. The keyword "lastrc" may be used in an expression. This tests the return code issued by the last command run in the source script. Possible values to compare against are found in error.dat; this values may be used by name (eg ERR_NO_ERR). The keyword "rdonly" may be used in an expression. This tests if the current file is read only or not (1 or 0) The keyword "config" may be used in an expression. This contains the current screen configuration. Its values are: 100 - color mode 10 - black and white mode 1 - monochrome mode This may be used to have different configurations build into your configuaration script Example expressions: if ("%(str)" == "foo") || ("%(str)" == "bar") if (5+%i*3 == 15) if rdonly == 1 Summary ------- [atomic] - causes all editing actions done by the script to all be part of one undo record. This way, the action of the entire script can be eliminated with a single undo [assign] = //(r)($)(@)(x)(l) - assigns string to variable v1. may contain other variables. The /'s around are only needed if there are spaces in , or if one of the special operations r,$ or @ are coded. The /'s must NOT be used if is one of the special operators defined below. may be coded as a string, or as a special operator: strlen - compute the length of string in variable strchr - compute first occurance of character in in variable . substr - compute substring of variable v, using character through of the variable. Locations in strings are based from 1 (not 0, like in C). Note that additional parameters , , may be variables as well. eg: assign foobar to %a - puts "foobar" into variable %a assign strlen %a to %b - puts "6" into variable %b assign strchr %a b to %c - puts "4" into variable %c assign substr %a 2 4 to %d - puts "oob" into variable %d Special flags 'r' - if used, may contain regular expression replacement strings (using the last regular expression searched for). See regexp.hlp for more information. 'x' - if used, is to be treated like an expression, with the result be assigned to . '$' - if used, may be the name of an environment variable. will be given the value of the environment variable. '@' - if used, may be the name of one of the items that are used in the "set" command. will be given the current value of that setting 'l' - if used, is treated as an expression for a line number. The contents of the resulting line are assigned to [break] - unconditionally leave the current looping block [continue] - restart current looping block [endif] - close an if block [endloop] - end a loop block [endwhile] - end a while block [elseif] - an alternate case in an if structure [else] - last case in an if structure [expr] = - assign expression - closes file (where = 1..9) [floatmenu] - activates floating menu (defined using the MENU command) is the length of a string that the menu is around; the floating menu will try to appear around the string. , specify the coordinates of the upper left hand corner of the menu. [fopen] - open file , assigning it file handle ( = 1..9). is one of r,w,a,x for read, write, append, or existance check. Note that for the existance check, ERR_NO_ERR is returned if the file exists. [fread] - read line from file handle into variable [fwrite] - write line to file handle from variable [get] - waits for the user to type a single keystroke, and then assigns the keystroke into variable . [goto]