scripts.gml

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

GML
1,737
字号
:PERIOD.
The line is stored in the variable &parm2
:PERIOD.
:RETURNS.
:RETVAL.ERR_NO_ERR
The setting of
:KEYWORD.lastrc
if the read was successful.
:RETVAL.END_OF_FILE
The setting of
:KEYWORD.lastrc
if end of file was encountered.
:RETVAL.ERR_FILE_NOT_OPEN
The setting of
:KEYWORD.lastrc
if the file being read was not opened with
:KEYWORD.fopen
:PERIOD.
:eRETURNS.
:EXAMPLE.fread 1 %(line)
Reads the next line from file handle 1 into the variable
:ITALICS.%(line)
:PERIOD.
:SEEALSO.
:SEE.fclose
:SEE.fopen
:SEE.fwrite
:eSEEALSO.
:eFUNC.

:FUNC.FWRITE
:SYNTAX.* FWRITE <n> <v1>
Writes the contents of the variable &parm2 to the file identified
by handle &parm1.
:PERIOD.
:RETURNS.
:RETVAL.ERR_NO_ERR
The setting of
:KEYWORD.lastrc
if the write was successful.
:RETVAL.ERR_FILE_NOT_OPEN
The setting of
:KEYWORD.lastrc
if the file being written was not opened with
:KEYWORD.fopen
:PERIOD.
:eRETURNS.
:EXAMPLE.fwrite 3 %(line)
Writes the contents of the variable 
:ITALICS.%(line)
to file handle 3
:PERIOD.
:SEEALSO.
:SEE.fclose
:SEE.fopen
:SEE.fread
:eSEEALSO.
:eFUNC.

:FUNC.GET
:SYNTAX.* GET <v1>
Waits for the user to type a single keystroke, and then assigns
the keystroke into variable &parm1
:PERIOD.
:EXAMPLE.get %(ch)
Waits for a key to be pressed, and then assigns the key to the local
variable
:ITALICS.%(ch)
:PERIOD.
:SEEALSO.
:SEE.floatmenu
:SEE.input
:eSEEALSO.
:eFUNC.

:FUNC.GOTO
:SYNTAX.* GOTO <label>
Transfers control to point in script with label &parm1 defined.
:SEEALSO.
:SEE.label
:eSEEALSO.
:eFUNC.

:FUNC.IF
:SYNTAX.* IF <expr>
Starts an
:KEYWORD.if
block.
:BLANKLINE.
Any variables contained in &parm1 are expanded before the expression
is evaluated.
:BLANKLINE.
If &parm1 is true, then the code following the
:KEYWORD.if
is executed.  If &parm1 is false, control goes to the next
:KEYWORD.elseif
:CONT.,
:KEYWORD.else
or
:KEYWORD.endif
command.
:SEEALSO.
:SEE.elseif
:SEE.else
:SEE.endif
:eSEEALSO.
:eFUNC.

:FUNC.INPUT
:SYNTAX.* INPUT <v1>
Open a window (the
:KEYWORD.commandwindow
) and get a string from the user.  The string is assigned to the
variable &parm1.
:PERIOD.
:BLANKLINE.
If &parm1 was assigned a value before the
:KEYWORD.input
script command was executed, then that value is used as a prompt
string in the input window.
:RETURNS.
:RETVAL.ERR_NO_ERR.
The setting of
:KEYWORD.lastrc
if a string was entered.
:RETVAL.NO_VALUE_ENTERED
The setting of
:KEYWORD.lastrc
if the user pressed
:HILITE.ESC
to cancel the input string.
:eRETURNS.
:EXAMPLE.input %(str)
Get a string from the user, placing the result in the local variable
:ITALICS.%(str)
:PERIOD.
If
:ITALICS.%(str)
had no previous value, then the user would be prompted with:
:ILLUST.
Enter Value:
:eILLUST.
However, if
:ITALICS.%(str)
had the value
:ITALICS.Type in a filename:
:CONT.,
then the user would be prompted with:
:ILLUST.
Type in a filename:
:eILLUST.
:SEEALSO.
:SEE.floatmenu
:SEE.get
:eSEEALSO.
:eFUNC.

:FUNC.LABEL
:SYNTAX.* LABEL <name>
Defines the a label with the name &parm1 at the current line in the script.
:SEEALSO.
:SEE.goto
:eSEEALSO.
:eFUNC.

:FUNC.LOOP
:SYNTAX.* LOOP
Start a loop block.  This is the top of the block, after a
:KEYWORD.continue
:CONT.,
:KEYWORD.endloop
or
:KEYWORD.until
control returns to the instruction after the
:KEYWORD.loop
command.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.NEXTWORD
:SYNTAX.* NEXTWORD <srcvar> <resvar>
Remove the next space-delimited word from the variable &parm1
:PERIOD.
The word is placed in the variable specified by &parm1.
:PERIOD.
Both &parm1 and &parm2 must be variables only.
:EXAMPLE.nextword %a %b
If %a has
:MONO.'this is a test'
assigned to it, then after this command
is processed, %a will have
:MONO.'is a test'
assigned to it, and %b will have
:MONO.'this'
assigned to it.
:eFUNC.

:FUNC.QUIF
:SYNTAX.* QUIF <expr>
Conditionally quit current loop or while loop block.
:BLANKLINE.
Any variables contained in &parm1 are expanded before the expression
is evaluated.
:BLANKLINE.
If &parm1 is true, the current looping block is exited and execution
resumes at the line after the end of the current block.
:BLANKLINE.
If &parm1 is false, execution continues at the next line.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.until
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.RETURN
:SYNTAX.* RETURN <rc>
Exit the script, returning &parm1.
:PERIOD.
:BLANKLINE.
If the script was invoked by another script, then this value becomes
:KEYWORD.lastrc
:PERIOD.
:BLANKLINE.
If the script was invoked at the &cmdline, then this return code
is reported as the appropriate error, if &parm1 is not
:HILITE.ERR_NO_ERR
:PERIOD.
:BLANKLINE.
There are symbolic values for various error codes.
These values are described in the appendix
:HDREF refid=errcode.
:PERIOD.
:eFUNC.

:FUNC.UNTIL
:SYNTAX.* UNTIL <expr>
Closes a loop block.
:BLANKLINE.
Any variables contained in &parm1 are expanded before the expression
is evaluated.
:BLANKLINE.
If &parm1 is true, the first line after the loop block
is executed.
:BLANKLINE.
If &parm1 is false, then
control is returned to the top of the loop block, and the loop
executes again.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.while
:eSEEALSO.
:eFUNC.

:FUNC.WHILE
:SYNTAX.* WHILE <expr>
Start a loop block.  If &parm1 is true, the body of the loop
is executed.  If &parm1 is false, execution transfers to the
instruction after the
:KEYWORD.endwhile
command.
:BLANKLINE.
Any variables contained in &parm1 are expanded before the expression
is evaluated.
:BLANKLINE.
This is the top of the block, after a
:KEYWORD.continue
or
:KEYWORD.endwhile
control returns to the
:KEYWORD.while
command.
:SEEALSO.
:SEE.break
:SEE.continue
:SEE.endloop
:SEE.endwhile
:SEE.loop
:SEE.quif
:SEE.until
:eSEEALSO.
:eFUNC.

:eFNLIST.

:SECTION.Script Examples
The following section describes a number of the scripts
that are provided with &edname.. Each script
is discussed in detail.

:SESECT.err.vi
This is a simple script that edits a file that has the exact same
name as the current file, only has the extension .err.
:SEXMP.
:SELINE.edit %D%P%N.err
:eSEXMP.
:SEREF.
:SEREFER.1
The global variable
:ITALICS.%D
contains the drive of the current file.
The global variable
:ITALICS.%P
contains the full path to the current file.
The global variable
:ITALICS.%N
contains the name of the current file (extension removed).
These are combined with the .err extension to create a full path
to an error file.  This file is edited.
:eSEREF.
:eSESECT.

:SESECT.lnum.vi
This script prompts the user for a line number, and
if a line number is entered, goes to that line.
:SEXMP.
:SELINE.assign %a = /Enter Line Number:/
:SELINE.input %a
:SELINE.if lastrc != NO_VALUE_ENTERED
:SELINE.    %a
:SELINE.endif
:eSEXMP.
:SEREF.
:SEREFER.1 2
These lines assigns the string
:ITALICS.Enter Line Number:
to the local variable
:ITALICS.%a
:PERIOD.
This value will be used by the
:KEYWORD.input
command on line 2 to prompt the user.
:SEREFER.3 5
As long as the input was not cancelled by the user
(by pressing the ESC key),
the line the user typed is executed directly.
This assumes that the user will type a number.
:eSEREF.
:eSESECT.

:SESECT.qall.vi
This script
tries to quit each file being edited.  If the file has been modified,
the user is prompted if he wishes to save the file.  If he replies 'y',
the file is saved.  If he replies 'n', the file is discarded.  If
he presses the ESC key and cancels the input, the script is exited.
:SEXMP.
:SELINE.loop
:SELINE.
:SELINE.    quit
:SELINE.    if lastrc == ERR_FILE_MODIFIED
:SELINE.        assign %a = /Save "%F" (y\/n)?/
:SELINE.        input %a
:SELINE.        quif lastrc == NO_VALUE_ENTERED
:SELINE.        if "%a" == y
:SELINE.            write
:SELINE.            quit
:SELINE.        else
:SELINE.            quit!
:SELINE.        endif
:SELINE.    endif
:SELINE.    quif lastrc != ERR_NO_ERR
:SELINE.
:SELINE.endloop
:eSEXMP.
:SEREF.
:SEREFER.1
Starts the loop.
:SEREFER.3 4
Tries to to quit the file.  If the quit command fails, and the
return code is
:HILITE.ERR_FILE_MODIFIED
(the
:KEYWORD.quit
command will fail if the file being abandoned is modified),
then the code from lines 5-14 is executed.
:SEREFER.5 6
Assigns the string
:ITALICS.Save "<filename>" (y/n)?
to the local variable
:ITALICS.%a
:PERIOD.
This value will be used by the
:KEYWORD.input
command on line 6 to prompt the user.
:SEREFER.7
This exits the main loop if the user cancels the input prompt by
pressing the ESC key.
:SEREFER.8 13
If the user typed the letter y, then the edit buffer is saved and
exited, otherwise the contents of the edit buffer are discarded.
:SEREFER.15
This exits the main loop if any of the previous commands did
not return the "everything is OK" return code,
:HILITE.ERR_NO_ERR
:PERIOD.
:SEREFER.17
Ends the loop.  Control is returned to line 3.
:eSEREF.
:eSESECT.

:SESECT.wrme.vi
This example is the default write
:KEYWORD.hook script
:PERIOD.
This is called just before a edit buffer is saved and exited.
If the file has a null name, then the user is prompted for a name. If
he cancels the prompt, then the save is aborted. Otherwise, the
new name is set and the save continues.
:SEXMP.
:SELINE.if "%F" != ""
:SELINE.    return ERR_NO_ERR
:SELINE.endif
:SELINE.assign %a = /Enter file name:/
:SELINE.input %a
:SELINE.if lastrc == NO_VALUE_ENTERED
:SELINE.    return DO_NOT_CLEAR_MESSAGE_WINDOW
:SELINE.endif
:SELINE.echo off
:SELINE.set filename = %a
:SELINE.echo on
:SELINE.return ERR_NO_ERR
:eSEXMP.
:SEREF.
:SEREFER.1 3
Checks if the current file name is the empty string.  If it is not,
then there is a filename and the script returns
:HILITE.ERR_NO_ERR
to indicate that processing is to continue.
:SEREFER.4 8
The user is prompted with
:ITALICS.Enter a file name:
:PERIOD.
If he cancels the
:KEYWORD.input
command by pressing the ESC key, then the script returns
:HILITE.DO_NOT_CLEAR_MESSAGE_WINDOW
:CONT.,
which is not an error condition but causes the save process to abort
(remember, a hook point stops what it is doing if an
non-zero return code is returned from the
:KEYWORD.hook script
).
:SEREFER.9
Echo is disabled so that the setting of the filename will not
cause the normal message to appear in the message window.
:SEREFER.10
The filename is set to whatever the user typed in.
:SEREFER.11
Echo is enabled.
:SEREFER.12
The script returns
:HILITE.ERR_NO_ERR
to indicate that processing is to continue.
:eSEREF.
:eSESECT.


:SESECT.proc.vi
This example prompts the user for a procedure name.  If the user types
one, then a procedure skeleton is added:
:ILLUST.
/*
 * ProcName
 */
void ProcName(  )
{

} /* ProcName */
:eILLUST.
and the user is left in input mode on the space before the
closing bracket (')').
:SEXMP.
:SELINE.assign %a = /Procedure Name:/
:SELINE.input %a
:SELINE.if lastrc == NO_VALUE_ENTERED
:SELINE.    return
:SELINE.endif
:SELINE.atomic
:SELINE.echo off
:SELINE.assign %x = /autoindent/@
:SELINE.set noautoindent
:SELINE.execute \e0o/*\n * %a\n */\n\e0ivoid %a( @ )\n{\n\n} /* %a */\n\e
:SELINE.if %x == 1
:SELINE.    set autoindent
:SELINE.endif
:SELINE. -4
:SELINE.execute \e0f@x
:SELINE.echo on
:SELINE.echo 1 Procedure %a added
:SELINE.echo 2 " "
:SELINE.keyadd i
:eSEXMP.

:SEREF.
:SEREFER.1 5
The user is prompted with
:ITALICS.Procedure Name:
:PERIOD.
If he cancels the
:KEYWORD.input
command by pressing the ESC key, then the script exits.
:SEREFER.6
The script is an
:KEYWORD.atomic
one; so all modifications to the edit buffer can be undone with a
single
:KEYWORD.undo
command.
:SEREFER.7
Disables any output to the message window.
:SEREFER.8
This line gets the current state of the
:KEYWORD.autoindent
setting, and saves it the the local variable
:ITALICS.%x
:PERIOD.
:SEREFER.9
Turns off autoindent, so that the text to be inserted will line up
properly.
:SEREFER.10
This line simulates the typing of a number of keystrokes at the keyboard.
The effect of these keys is to generate the following:
:ILLUST.
/*
 * ProcName
 */
void ProcName( @ )
{

} /* ProcName */
:eILLUST.
:SEREFER.11 13
The local variable
:ITALICS.%x
is set to the previous value of
:KEYWORD.autoindent.
If
:KEYWORD.autoindent
was on before, then this turns it back on.
:SEREFER.14
This backs the cursor up to the line
:ILLUST.
void ProcName( @ )
:eILLUST.
:SEREFER.15
This line simulates the typing of a number of keystrokes at the keyboard.
The effect of these keystrokes is to move forward to the '@' character
and delete it.  This leaves the cursor in the position necessary to
enter procedure parameters.
:SEREFER.16
Enables output to the message window.
:SEREFER.17 18
Displays a message.
:SEREFER.19
Adds the key 'i' to the keyboard buffer.  Once the script exits, &edname
will process this key as if the user had typed it.  Thus, once the
script is done, the user is left inserting text.
:eSEREF.
:eSESECT.

⌨️ 快捷键说明

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