spec
Software for Diffraction
2.4.4.1. - Built-In Commands
def name string
-
Defines a macro named
name
to be
string
.
Each time
name
occurs on input,
it is replaced with
string
.
The definition is made immediately, so the macro
can be used later in the same statement block in which
it is defined and can be redefined within the same statement block.
Note that the macro definition is made regardless of any surrounding
flow control
statements, since the enclosing mini-program is not yet completely
parsed and is not executing.
rdef name expression
-
Defines a macro named
name
to be
expression
,
which is almost always a string constant.
Each time
name
occurs on input,
the value
expression
is substituted.
Unlike
def
, described above,
the macro definition is not made until all the encompassing
statement blocks are parsed and the resulting mini-program is executed.
Consider the following example.
if (flag == 1)
rdef plot "onp;offt;lp_plot;ont;plot_res;offp"
else if (flag == 2)
rdef plot "splot;onp;offt;lp_plot;plot_res;ont;offp"
else if (flag == 3)
rdef plot "onp;plot_res;offp"
else
rdef plot "
Clearly, it is necessary for the mini-program
to be parsed and executed to decide which is the appropriate definition
to assign to the
plot
macro.
prdef
-
Displays all macro definitions.
The displayed definitions are prepended
with
def name \'
and terminated with
\'
so if saved to a file, the definitions can be read back.
(See the standard macro
savmac
3.3.4
prdef pattern ...
-
As above, except only macro names matching
pattern
are listed, where
pattern
may contain the metacharacters
?
or
*
,
which have the usual meaning:
?
matches any single character and
*
matches any string.
lsdef
-
Lists the name and the number of characters in each macro definition.
lsdef pattern ...
-
As above, except only macro names matching
pattern
are listed, where
pattern
may contain the metacharacters
?
or
*
.
undef name ...
-
Removes the named macros, which can be ordinary macros, macro functions
or
cdef()
macros.
cdef("name", string [, "key" [, flags ]])
-
Defines parts of
chained
macros.
A chained macro definition is maintained in pieces
that can be selectively included to form the complete macro definition.
The argument
name
is the name of the macro.
The argument
string
contains a piece to add to the macro.
The chained macro can have three parts: a beginning, a middle and an end.
Pieces included in each of the parts of the macros are sorted
lexicographically
by the keys when putting together the macro definition.
Pieces without a key are placed in the middle in the order in which they
were added, but after any middle pieces that
include a key.
The
key
argument allows a piece to be
selectively replaced or deleted, and also controls the order in which
the piece is placed into the macro definition.
The
flags
argument controls whether the pieces are
added to the beginning or to the end of the macro, and also whether the pieces
should be selectively
included in the definition depending on whether
key
is the mnemonic of a configured motor or counter.
The bit meanings for
flags
are as follows:
0x01 - only include if key is a motor mnemonic
0x02 - only include if key is a counter mnemonic
0x10 - place in the beginning part of the macro
0x20 - place in the end part of the macro
If
flag
is the string
"delete"
, the piece associated with
key
is deleted from the named macro, or
if name is the null string,
from all the chained macros.
If
key
is the null string, the
flags
have no effect.
If
flags
is the string
"enable"
, the parts of the named macro
associated with
key
are enabled, and if
flags
is the string
"disable"
, the associated parts are disabled.
If
name
is the null string
""
, then all chained macros that have parts associated with
key
will have those parts enabled or disabled.
If
key
is the null string, the
flags
have no effect.
The
cdef()
function will remove any existing macro defined using
def
or
rdef
. However, the commands
lsdef
, prdef
and
undef
will function with chained macros.
When spec starts and when the
reconfig
command is run (or the
config
macro is invoked),
all the chained macros are adjusted for the currently configured motors
and counters.
cdef("?")
-
Lists all the pieces of all the chained macros.
cdef("name", "", "?")
-
Lists the pieces of the macro named
name
.
clone(destination, source)
-
Duplicates the macro
source
as a new macro named
destination
.
A clone of a chained macro becomes an ordinary macro.
strdef("name" [, arr])
-
Returns a string containing the macro definition of
name
.
If
name
is not a defined macro, returns the string
name
itself.
If an associative array
arr
is included as an argument and if the macro
name
is a macro function, elements of
arr
indexed starting at 0 will be assigned the string
names of the arguments to the macro function.
The element
arr["file"]
will be assigned the name of file where the macro was defined or
"tty"
if the macro was defined at the keyboard.
strdef("name", key [, arr])
-
If
name
is a chained macro, returns
a string containing only the definition segment associated
with
key
.
If
name
is not a defined macro, returns the string
name
itself.
If
name
is a macro, but not a chained macro, returns the definition.
If
name
is a chained macro, but doesn't contain a segment associated
with
key
,
returns the null string.
If an associative array
arr
is included as an argument and if the macro
name
is a macro function, elements of
arr
indexed starting at 0 will be assigned the string
names of the arguments to the macro function.
The element
arr["file"]
will be assigned the name of file where the macro was defined or
"tty"
if the macro was defined at the keyboard.