scripts.gml

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

GML
1,737
字号
:eSUBSECT.

:SECTION.Control Flow Commands
This section gives a brief overview of the control flow commands of the
&edname script language.  For a full description of all
script commands, see the next section
:HDREF refid='scrcmds'.
:PERIOD.
:P.
:SUBSECT.The LOOP Block
The
:KEYWORD.loop
block is similar to the
:HILITE.do-while
construct in C.  The flow of the loop may be modified using the
:HILITE.break
:CONT.,
:HILITE.continue
:CONT.
or
:HILITE.quif
script commands.
:P.
The loop may be set to run until a termination condition is met by using the
:KEYWORD.loop
-
:KEYWORD.until
commands.
:P.
The loop may be set to run without any termination condition by using the
:KEYWORD.loop
-
:KEYWORD.endloop
commands.
:P.
An overview of a loop block is:
:ILLUST.
loop
    break
    continue
    quif <expr>
until <expr>

loop
    break
    continue
    quif <expr>
endloop
:eILLUST.
:eSUBSECT.

:SUBSECT.The WHILE Block
The
:KEYWORD.while
block is similar to the
:HILITE.while
loop construct in C.  The flow of the while loop may be modified using the
:HILITE.break
:CONT.,
:HILITE.continue
:CONT.
or
:HILITE.quif
script commands.
:P.
The while loop is set up using the
:KEYWORD.while
-
:KEYWORD.endwhile
commands.
:P.
An overview of the
:KEYWORD.while
block is:
:ILLUST.
while <expr>
    break
    continue
    quif <expr>
endwhile
:eILLUST.
:eSUBSECT.

:SUBSECT.The IF Block
The
:KEYWORD.if
block is similar to the
:HILITE.if-else
construct in C.
:P.
An overview of the
:KEYWORD.if
block is:
:ILLUST.
if <expr>
elseif <expr>
elseif <expr>
else
endif
:eILLUST.
:eSUBSECT.

:SECTION id='scrcmds'.Script Commands
:INCLUDE file='cmdintro'.
For example, in its syntax model,
the ASSIGN command is specified as "ASSIGN", indicating that all the
letters are required (there are no abbreviations, only "assign" is
accepted as the command).
:P.
The term
:HILITE.<expr>
is used to indicate an expression in the following commands.
Expressions are discussed in full detail in the section
:HDREF refid='screxpr'.
of this chapter.
:P.
Script variables are used by some of the following commands.  Variables
are discussed in full detail in the section
:HDREF refid='scrvars'.
of this chapter.
:P.
When a script command terminates, 
:HILITE.lastrc
is sometimes set to a value.  This value may be tested in an expression.
Script commands that set this have a
:HILITE.Returns
section.
:P.
:FNLIST.Editor Script Commands

:FUNC.ATOMIC
:SYNTAX.* ATOMIC
This command 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
:KEYWORD.undo
command; i.e., it is an atomic action.
:eFUNC.

:FUNC.ASSIGN
:SYNTAX.* ASSIGN <v1> "=" /<val>/"r$@xl"
This command is used to assign the value
:CMDPARM.<val>
to the variable &parm1.
:PERIOD.
:BLANKLINE.
The forward slashes ('/') around
:CMDPARM.<val>
are only need if there are spaces in
:CMDPARM.<val>
:CONT.,
or if one of the special flags
:HILITE.r
:CONT.,
:HILITE.x
:CONT.,
:HILITE.l
:CONT.,
:HILITE.$
or
:HILITE.@
is required at the end.
:BLANKLINE.
The special flags have the following meaning:
:DEFLIST.
:DEFITEM.r
When this flag is used,
:CMDPARM.<val>
may contain regular expression replacement
strings (using the last regular expression searched for). 
For more information on regular expressions, see the chapter
:HDREF refid='rxchap'.
:PERIOD.
:DEFITEM.l
When this flag is used,
:CMDPARM.<val>
is assumed to be an expression that indicates a line number. The expression
is evaluated, and the data on the corresponding line number is assigned
to &parm1
:PERIOD.
:DEFITEM.x
When this flag is used,
:CMDPARM.<val>
is assumed to be an expression, and is evaluated. The result is
assigned to &parm1.
:PERIOD.
For another way of assigning expression results to a variable, see the
:KEYWORD.expr
script command.
:DEFITEM.$ (dollar sign)
When this flag is used,
:CMDPARM.<val>
is assumed to be the name of an operating system environment variable,
and the contents of that environment variable is what is assigned to &parm1.
:PERIOD.
:DEFITEM.@
When this flag is used,
:CMDPARM.<val>
may be the name of one of the
:KEYWORD.set
command parameters. &parm1 will be given the current value of that
parameter.
:eDEFLIST.
:BLANKLINE.
:CMDPARM.<val>
may be coded as a special operator.  If
:CMDPARM.<val>
is coded this way, the forward slashes ('/') must NOT be used.
The special operators are:
:DEFLIST.
:DEFITEM.strlen <v>
Computes the length of the variable
:CMDPARM.<v>
:PERIOD.
This value is assigned to &parm1.
:PERIOD.
:DEFITEM.strchr <v> <c>
Computes the offset of the character
:CMDPARM.<c>
in the variable <v>.
The offset is assigned to &parm1.
:PERIOD.
Note that the character
:CMDPARM.<c>
may be a variable, the value of which will be expanded before offset
is computed.
:PERIOD.
:DEFITEM.substr <v> <n1> <n2>
Computes a substring of the string contained in the variable
:CMDPARM.<v>
:PERIOD.
The substring is composed of characters from offset
:CMDPARM.<n1>
to offset
:CMDPARM.<n2>
:PERIOD.
The substring is assigned to &parm1.
:PERIOD.
Note that the parameters 
:CMDPARM.<n1>
and
:CMDPARM.<n2>
may be variables, the values of which will be expanded before the substring
is computed.
:eDEFLIST.
:EXAMPLE.assign %a = foobar
The variable
:ITALICS.%a
gets the string
:ITALICS.foobar
assigned to it.

:EXAMPLE.assign %(Path) = /path/$
The global variable
:ITALICS.%(Path)
gets the data stored in the
:ITALICS.path
environment variable assigned to it.

:EXAMPLE.assign %b = strlen %a
Assigns the length of the contents of the local variable
:ITALICS.%a
to the local variable
:ITALICS.%b
:PERIOD.
:BLANKLINE.
Assuming the local variable
:ITALICS.%a
has the string
:ITALICS.abcdefg
assigned to it, then
:ITALICS.%b
gets
:ITALICS.7
assigned to it.

:EXAMPLE.assign %b = strchr %a b
Assigns the offset of the letter
:ITALICS.b
in the string contained in the local variable
:ITALICS.%a
to the local variable
:ITALICS.%b
:PERIOD.
:BLANKLINE.
Assuming the local variable
:ITALICS.%a
has the string
:ITALICS.abcdefg
assigned to it, then
:ITALICS.%b
gets
:ITALICS.2
assigned to it.

:EXAMPLE.assign %(Substr) = substr %a 2 4
Assigns the characters from offset 2 to offset 4
in the string contained in the local variable
:ITALICS.%a
to the global variable
:ITALICS.%(Substr)
:PERIOD.
:BLANKLINE.
Assuming the local variable
:ITALICS.%a
has the string
:ITALICS.abcdefg
assigned to it, then
:ITALICS.%b
gets
:ITALICS.bcd
assigned to it.

:EXAMPLE.assign %(res) = /abc %(str) def/
Assuming
:ITALICS.%(str)
has been assigned the value
:ITALICS.xyz
:CONT.,
then the string
:ITALICS.abc xyz def
is assigned to the local variable
:ITALICS.%(res)
:EXAMPLE.assign %(Result) = /100*30+(50-17)*10/x
The value
:ITALICS.3330
is assigned to the global variable
:ITALICS.%(Result)
:PERIOD.

:SEEALSO.
:SEE.expr
:eSEEALSO.
:eFUNC.
      
:FUNC.BREAK
:SYNTAX.* BREAK
Unconditionally exits the current looping block. This breaks out
of
:KEYWORD.loop
-
:KEYWORD.endloop
:CONT.,
:KEYWORD.loop
-
:KEYWORD.until
and
:KEYWORD.while
-
:KEYWORD.endwhile
blocks.
:SEEALSO.
:SEE.continue
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.CONTINUE
:SYNTAX.* CONTINUE
Restarts the current looping block. This causes a jump to the top of
:KEYWORD.loop
-
:KEYWORD.endloop
:CONT.,
:KEYWORD.loop
-
:KEYWORD.until
and
:KEYWORD.while
-
:KEYWORD.endwhile
blocks.
:SEEALSO.
:SEE.break
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.ENDIF
:SYNTAX.* ENDIF
Terminates an
:KEYWORD.if
-
:KEYWORD.elseif
-
:KEYWORD.else
block.
:SEEALSO.
:SEE.if
:SEE.elseif
:SEE.else
:eSEEALSO.
:eFUNC.

:FUNC.ENDLOOP
:SYNTAX.* ENDLOOP
Terminates a loop block.  Control goes to the top of the current loop.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.ENDWHILE
:SYNTAX.* ENDWHILE
Terminates a while block.  Control goes to the top of the current
while loop.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endloop
:SEE.loop
:SEE.quif
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.ELSEIF
:SYNTAX.* ELSEIF <expr>
An alternate case in an
:KEYWORD.if
block.  If the opening
:KEYWORD.if
script command
and none of the
:KEYWORD.elseif
script commands prior to this one were executed, then this
:KEYWORD.elseif
is executed.
:BLANKLINE.
Any variables contained in &parm1 are expanded before the expression
is evaluated.
:BLANKLINE.
If &parm1 is true, then the code following the
:KEYWORD.elseif
is executed.  If &parm1 is false, control goes to the next
:KEYWORD.elseif
:CONT.,
:KEYWORD.else
or
:KEYWORD.endif
command.
:SEEALSO.
:SEE.if
:SEE.else
:SEE.endif
:eSEEALSO.
:eFUNC.

:FUNC.ELSE
:SYNTAX.* ELSE
This is the alternate case in an
:KEYWORD.if
block.  If none of the preceding
:KEYWORD.if
or
:KEYWORD.elseif
statements are true, the code following the
:KEYWORD.else
command is executed.
:SEEALSO.
:SEE.if
:SEE.elseif
:SEE.endif
:eSEEALSO.
:eFUNC.

:FUNC.EXPR
:SYNTAX.* EXPR <v1> "=" <expr>
Assigns the expression &parm3 to the variable &parm1
:PERIOD.
:BLANKLINE.
Any variables contained in &parm3 are expanded before the expression
is evaluated.
:EXAMPLE.expr %(Num) = 100*30+50
Assigns the value
:ITALICS.3050
to the global variable
:ITALICS.%(Num)
:PERIOD.
:EXAMPLE.expr %a = %(SW)-10
Assuming a screen width of 80, then this assigns the value
:ITALICS.70
to the local variable
:ITALICS.%a
:PERIOD.

:SEEALSO.
:SEE.assign
:SEE.eval
:eSEEALSO.
:eFUNC.

:FUNC.FCLOSE
:SYNTAX.FCLOSE <n>
Closes file &parm1 previously opened with a
:KEYWORD.fopen
script command.
:EXAMPLE.fclose 1
Closes file 1.
:SEEALSO.
:SEE.fopen
:SEE.fread
:SEE.fwrite
:eSEEALSO.
:eFUNC.

:FUNC.FOPEN
:SYNTAX.* FOPEN <name> <n> <how>
This command opens file &parm1, assigning it file handle &parm2.
:PERIOD.
:BLANKLINE.
&parm2 may be a value from 1 to 9.  This number is used to identify
the file for future
:KEYWORD.fread
:CONT.,
:KEYWORD.fwrite
or
:KEYWORD.fclose
script commands.
:BLANKLINE.
&parm3 specifies the method that the file is opened. Methods are:
:DEFLIST.
:DEFITEM.a
Opens file for append.
:DEFITEM.r
Opens file for read.
:DEFITEM.w
Opens file for write.
:DEFITEM.x
Checks if the file exists.  This does not actually open the file,
so no
:KEYWORD.fclose
is required.
:eDEFLIST.
:RETURNS.
:RETVAL.ERR_NO_ERR.
The setting of
:KEYWORD.lastrc
if the open/existence check is a success.
:RETVAL.ERR_FILE_NOT_FOUND
The setting of
:KEYWORD.lastrc
if the open/existence check is a fails.
:eRETURNS.
:EXAMPLE.fopen test.dat 1 r
Opens file test.dat for read, and uses file handle 1.
:EXAMPLE.fopen test.dat 2 w
Opens file test.dat for write, and uses file handle 2.
:EXAMPLE.fopen test.dat 1 x
Tests if the file test.dat exists.
:EXAMPLE.fopen test.dat 9 a
Opens file test.dat for append, and uses file handle 9.
:SEEALSO.
:SEE.fclose
:SEE.fread
:SEE.fwrite
:eSEEALSO.
:eFUNC.

:FUNC.FREAD
:SYNTAX.* FREAD <n> <v1>
Reads a line from the file identified by handle &parm1.

⌨️ 快捷键说明

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