scripts.gml

来自「开放源码的编译器open watcom 1.6.0版的源代码」· GML 代码 · 共 1,737 行 · 第 1/3 页

GML
1,737
字号
.*
.* (c) Copyright 1992 by WATCOM International Corp.
.*
.* All rights reserved. No part of this publication may be reproduced or
.* used in any form or by any means - graphic, electronic, or mechanical,
.* including photocopying, recording, taping or information storage and
.* retrieval systems - without written permission of WATCOM Publications
.* Limited.
.*
.* Date		By		Reason
.* ----		--		------
.* 06-aug-92	Craig Eisler	initial draft
.*
:CHAPTER id='scripts'.Editor Script Language
:CMT :SECTION.Introduction
&edname supports a powerful command language.  In a script,
you may use any &cmdline command, along with a number of special commands
explicitly for the script environment.
:P.
White space is ignored in a script file, unless a line starts with a
right angle bracket ('>'). Comments may be imbedded in a script file
by starting the line with pound sign ('#').
:P.
A script is invoked using the &cmdline command
:KEYWORD.source
:PERIOD.
Examples are:
:P.
:ILLUST.
source test2.vi
:eILLUST.
:ILLUST.
source test.vi parm1 parm2 parm3 parm4
:eILLUST.
:P.
A script may be invoked with a set of optional parameters.
These optional parameters are accessed in the script by using
:HILITE.%n
:PERIOD.
Every occurrence of
:HILITE.%n
in the script is replaced by the corresponding parameter.
To access parameter above 9, brackets must surround the number.  This
is because:
:ILLUST.
%10
:eILLUST.
cannot be distinguished from the variable
:HILITE.%1
followed by a 0, and
the variable
:HILITE.%10
:PERIOD.
To remove the ambiguity, brackets are used:
:ILLUST.
%(10)
:eILLUST.
All parameters can be accessed by using
:HILITE.%*
:PERIOD.
:P.
To allow multiple words
in a single parameter, delimit the sequence by forward slashes ('/') or
double quotes ('"').  For example, the line
:ILLUST.
source test.vi "a b c" d e
:eILLUST.
would cause the script test.vi to have the following variables defined:
:ILLUST.
%* = a b c d e
%1 = a b c
%2 = d
%3 = e
:eILLUST.
:P.
General variables, both local and global, are also supported in the
editor script language. Any line in a script
that is not one of the script commands
has all the variables on it expanded before the line is processed.
Script commands can manipulate the variables. For more information, see
the section
:HDREF refid='scrvars'.
of this chapter.
:P.
There are several useful &cmdline
commands dealing with &edname scripts, they are:
:DEFLIST.
:DEFITEM.compile
Used to compile a script.
This allows much faster execution of the script
by &edname.
:PERIOD.
:DEFITEM.load
Used to make a script resident in &edname.
:PERIOD.
This allows much faster invocation of the script,
since &edname does not have to search for it or parse it.
:eDEFLIST.
:P.
If a system command is spawned from a script (using the exclamation point ('!')
command), then &edname does not
pause after the system command is finished running.  However, if
you set
:KEYWORD.pauseonspawnerr
:CONT.,
then &edname will pause after a system command is executed from a script
if the system command returned an error.
:SECTION id='scrvars'.Script Variables
General variables are supported in a &edname script.
Variables are preceded by a percent symbol ('%').
Variables with more than one letter must be enclosed by brackets, for
example:
:ILLUST.
%a     - references variable named a.
%(abc) - references variable named abc.
:eILLUST.
The brackets are required to disambiguate single letter variables followed
by text from multiple letter variables.
:P.
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.  Example variables:
:ILLUST.
%A     - global variable named A.
%a     - local variable named a.
%(AbC) - global variable named AbC.
%(abC) - local variable named abC.
:eILLUST.
Global variables are valid for the life of the editing
session.
:P.
Local variables are only valid for the life of the script that they
are used in.
:P.
:SUBSECT.Pre-defined Global Variables
There are a number of global variables that take on values as the
editor runs, they are:
:DEFLIST.
:DEFITEM.%C   	 
Contains the current column number in the current edit buffer.
:DEFITEM.%D   	 
Drive of current file, based on the actual path.
:DEFITEM.%(D1)  	 
Drive of current file, as typed by the user.  This could have no value.
:DEFITEM.%E   	 
File name extension of current file.
:DEFITEM.%F   	 
Current file name (including name and extension).
:DEFITEM.%H   	 
Home directory of a file. This is the directory where the edit command
was issued.
:DEFITEM.%N   	 
Name of the current file, extension removed.
:DEFITEM.%M   	 
Modified status of the current file - set to 1 if the file
has been modified, and a 0 otherwise.
:DEFITEM.%(OS)    
What operating system the editor is hosted on. Possible values are:
:UL compact.
:LI.dos (protect and real mode).
:LI.unix (QNX, Linux or other Unix-based systems)
:LI.os2
:LI.os2v2
:LI.nt
:eUL.
:DEFITEM.%(OS386) 
This variable is set to 1 is the host operating system is 386
(or higher) based.  The possible 386 environments are:
:UL compact.
:LI.dos (protect mode).
:LI.os2v2
:LI.nt
:LI.unix (when running on a 386)
:eUL.
:DEFITEM.%P   	 
Path of current file (no extension, name, or drive) based on the actual
full path to the file.
:DEFITEM.%(P1)	 
Path of current file (no extension, name, or drive) based on the name
typed by the user.  This could have no value.
:DEFITEM.%R   	 
Contains the current row (line number) in the current edit buffer.
:DEFITEM.%(SH)	 
Height of entire screen in characters.
:DEFITEM.%(SW)	 
Width of entire screen in characters.
:DEFITEM.%(Sysrc)
Return code from last system command.
:eDEFLIST.
:eSUBSECT.
:SECTION.Hook Scripts
&edname has several hook points where a script,
if defined by the user, is invoked.  This allows you to
intercept the editor at key points
to change its behaviour.  A script
that is invoked at a hook point
is referred to as a
:KEYWORD.hook script
:PERIOD.
:P.
Each
:KEYWORD.hook script
is identified by a particular global variable.  Whenever &edname
reaches a hook point, it checks if the global variable is defined,
and if it is, the global variables contents are treated like a script
name, and that script is invoked.
:P.
The hook points are:
:UL.
:LI.after a new file has been read.
:LI.before a modified file is saved and exited.
:LI.after return is pressed on the &cmdline
:PERIOD.
:LI.whenever an unmodified file is modified.
:LI.whenever a selected (highlighted) column range is
chosen (via mouse click or keyboard).
:LI.whenever a selected (highlighted) line range
is chosen (via mouse click or keyboard).
:eUL.
:DEFLIST.
:DEFITEM.Read Hook
The
:KEYWORD.hook script
is called just after a new file has been read into the editor.
:BLANKLINE.
The script invoked is the file specified by the global variable
:HILITE.%(Rdhook)
:PERIOD.

:DEFITEM.Write Hook
The
:KEYWORD.hook script
is called just before a modified file
is to be saved and exited.
:BLANKLINE.
The script invoked is the file specified by the global variable
:HILITE.%(Wrhook).

:DEFITEM.Command Hook
The
:KEYWORD.hook script
is called after the return is pressed from the &cmdline
:PERIOD.
The global variable
:HILITE.%(Com)
contains the current command string, and may be modified.
Whatever it is modified to is what will be processed by the &cmdline
processor.
:BLANKLINE.
The script invoked is the file specified by the global variable
:HILITE.%(Cmdhook)
:PERIOD.

:DEFITEM.Modified Hook
The
:KEYWORD.hook script
is called whenever
a command is about to modify an unmodified file.  If the file is
modified, the hook is not called.
:BLANKLINE.
The script invoked is the file specified by the global variable
:HILITE.%(Modhook)
:PERIOD.

:DEFITEM.Mouse Columns Sel Hook
The
:KEYWORD.hook script
is called whenever a selected column range
has been picked.  Picking a selected region is done by
right-clicking the region with the mouse, or by double clicking
the region with the mouse, or by using the underscore ('_') &cmdmode
keystroke.
:BLANKLINE.
The script is invoked with the following parameters:
:DEFLIST.
:DEFITEM.%1
The selected string.
:DEFITEM.%2
Line on screen of selected string.
:DEFITEM.%3
Column on screen of start of selected string.
:DEFITEM.%4
Column on screen of end of selected string.
:eDEFLIST.
The script invoked is the file is specified by the global variable
:HILITE.%(MCselhook)
:PERIOD.

:DEFITEM.Mouse Lines Sel Hook
The
:KEYWORD.hook script
is called whenever a selected line range
has been picked.  Picking a selected region is done by
right-clicking the region with the mouse, or by double clicking
the region with the mouse, or by using the underscore ('_')
&cmdmode keystroke.
:BLANKLINE.
:DEFLIST.
:DEFITEM.%1
Line on screen where selection request occurred.
:DEFITEM.%2
Column on screen where selection request occurred.
:DEFITEM.%3
First line of selected region.
:DEFITEM.%4
Last line of selected region.
:eDEFLIST.
The script invoked is the file specified by the global
variable
:HILITE.%(MLselhook)
:PERIOD.
:eDEFLIST.

:SECTION id='screxpr'.Expressions
&edname allows the use of constant expressions in its script
language. Long integers and strings may be used in an expression.
Some sample expressions are:
:ILLUST.
5*3+12
(7*7)+10*((3+5)*8+9)
5 >= %(var)
("%(str)" == "foo") || ("%(str)" == "bar")
(5+%i*3 == 15)
rdonly == 1
:eILLUST.
:P.
An expression is composed of operators and tokens.  Operators act
on the tokens to give a final result.
:P.
A token in an expression may be a special keyword, a boolean setting
value, an integer, or
a string.
:P.
A string is indicated by surrounding the string with double quotes (").
A token is an integer if it starts with a numeric
digit (0 to 9).
:P.
If a token starts with a dot ('.'), then the remainder of the token
is assumed to be a setting token.  This token evaluates to be
1 or 0 for a boolean setting, or to the actual value of the setting
for all others.
:ILLUST.
 .autoindent - 1 if autoindent is true, 0 otherwise
 .ai         - 1 if autoindent is true, 0 otherwise
 .autosave   - current value of autosave
 .tmpdir     - current tmpdir string
:eILLUST.
:P.
If a token is not surrounded by double quotes, and is not a keyword and
is not an integer, then that token is assumed to be a string.
:P.
If an expression contains conditional operators, then the result of the
expression is a boolean value (1 or 0). The following script language
control flow commands expect boolean results:
:UL compact.
:LI.:KEYWORD.if
:LI.:KEYWORD.elseif
:LI.:KEYWORD.quif
:LI.:KEYWORD.while
:LI.:KEYWORD.until
:eUL.
:P.
The following are conditional operators in an expression:
:UL compact.
:LI.== (equal to)
:LI.!= (not equal to)
:LI.> (greater than)
:LI.>= (greater than or equal to)
:LI.< (less than)
:LI.<= (less than or equal to)
:LI.&& (boolean AND)
:LI.|| (boolean OR)
:eUL.
An expression may also operate on its token using various mathematical
operators, these operators are
:UL compact.
:LI.+ (plus)
:LI.- (minus)
:LI.* (multiply)
:LI./ (divide)
:LI.** (exponentiation)
:LI.^ (bitwise NOT)
:LI.| (bitwise OR)
:LI.& (bitwise AND)
:LI.>> (bit shift down)
:LI.<< (bit shift up)
:eUL.
:P.
Special keyword tokens are:
:DEFLIST.
:DEFITEM.ERR_???
These are symbolic representations of all possible errors while
executing in &edname..  These values are found in
:KEYWORD.error.dat
:PERIOD.
These values are described in the appendix
:HDREF refid=errcode.
:PERIOD.

:DEFITEM.lastrc
This keyword evaluates to the return code issued by the last command run
in the script. Possible values to compare against are found in
:KEYWORD.error.dat
These values may are described in the appendix
:HDREF refid=errcode.
:PERIOD.

:DEFITEM.rdonly
This keyword evaluates to 1 if the current file is read only, and
0 if it is not read only.

:DEFITEM.config
This keyword evalutes to a number representing the current mode
the screen is configured to. Possible values are:
:DEFLIST.
:DEFITEM.100
Screen is in color mode.
:DEFITEM.10
Screen is in black and white mode.
:DEFITEM.1
Screen is in monochrome mode.
:eDEFLIST.
This may be used to have different configurations built into
your
:KEYWORD.configuration script
:KEYWORD.ed.cfg
:PERIOD.
:DEFITEM.black
This keyword evalutes to the integer representing the color black (0).

:DEFITEM.blue
This keyword evalutes to the integer representing the color blue (1).

:DEFITEM.green
This keyword evalutes to the integer representing the color green (2).

:DEFITEM.cyan
This keyword evalutes to the integer representing the color cyan (3).

:DEFITEM.red
This keyword evalutes to the integer representing the color red (4).

:DEFITEM.magenta
This keyword evalutes to the integer representing the color magenta (5).

:DEFITEM.brown
This keyword evalutes to the integer representing the color brown (6).

:DEFITEM.white
This keyword evalutes to the integer representing the color white (7).

:DEFITEM.dark_gray
This keyword evalutes to the integer representing the color dark_gray (8).

:DEFITEM.light_blue
This keyword evalutes to the integer representing the color light_blue (9).

:DEFITEM.light_green
This keyword evalutes to the integer representing the color light_green (10).

:DEFITEM.light_cyan
This keyword evalutes to the integer representing the color light_cyan (11).

:DEFITEM.light_red
This keyword evalutes to the integer representing the color light_red (12).

:DEFITEM.light_magenta
This keyword evalutes to the integer representing the color light_magenta (13).

:DEFITEM.yellow
This keyword evalutes to the integer representing the color yellow (14).

:DEFITEM.bright_white
This keyword evalutes to the integer representing the color bright_white (15).

:eDEFLIST.
:SUBSECT.Expression BNF
This section describes a BNF for the construction of constant expressions.
:DEFLIST.break
:DEFITEM.expression
: conditional-exp
:DEFITEM. conditional-exp
: log-or-exp
:BREAK.
| log-or-exp ? expression : conditional-exp

:DEFITEM.log-or-exp
: log-and-exp
:BREAK.
| log-or-exp || log-and-exp

:DEFITEM.log-and-exp
: bit-or-exp
:BREAK.
| log-and-exp && bit-or-exp

:DEFITEM.bit-or-exp
: bit-xor-exp
:BREAK.
| bit-or-exp | bit-xor-exp

:DEFITEM.bit-xor-exp
: bit-and-exp
:BREAK.
| bit-xor-exp ^ bit-and-exp

:DEFITEM.bit-and-exp
: equality-exp
:BREAK.
| bit-and-exp & equality-exp

:DEFITEM.equality-exp
: relational-exp
:BREAK.
| equality-exp == relational-exp
:BREAK.
| equality-exp != relational-exp

:DEFITEM.relational-exp
: shift-exp
:BREAK.
| relational-exp > shift-exp
:BREAK.
| relational-exp < shift-exp
:BREAK.
| relational-exp >= shift-exp
:BREAK.
| relational-exp <= shift-exp

:DEFITEM.shift-exp
: additive-exp
:BREAK.
| shift-exp << additive-exp
:BREAK.
| shift-exp >> additive-exp

:DEFITEM.additive-exp
: multiplicative-exp
:BREAK.
| additive-exp + multiplicative-exp
:BREAK.
| additive-exp - multiplicative-exp

:DEFITEM.multiplicative-exp
: exponent-exp
:BREAK.
| multiplicative-exp * exponent-exp
:BREAK.
| multiplicative-exp / exponent-exp
:BREAK.
| multiplicative-exp % exponent-exp

:DEFITEM.exponent-exp
: unary-exp
:BREAK.
| exponent-exp ** unary-exp

:DEFITEM.unary-exp
: primary-exp
:BREAK.
| - unary-exp
:BREAK.
| ~~ unary-exp
:BREAK.
| ! unary-exp

:DEFITEM.primary-exp
: token
:BREAK.
| ( expression )

:DEFITEM.token
: INTEGER
:BREAK.
| STRING
:BREAK.
| KEYWORD
:eDEFLIST.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?