Processing Arguments
Developing TACL Routines
3–12
107365 Tandem Computers Incorporated
The syntax for
getargs
is:
getargs
triplet [ triplet ]...
where
triplet
contains three parts:
{
}
REQUIRED
OPTIONAL
type variable
REQUIRED or OPTIONAL specifies whether the corresponding argument is
required or optional.
Type
is an #ARGUMENT alternative such as FILENAME. The specified type
must not permit spaces. The KEYWORD alternative, for example, cannot be used
because it requires the WORDLIST alternative, which allows spaces in its syntax.
Variable
is a name for the argument.
Getargs
stores the argument value in a
variable with this name.
Getargs
pushes
variable
and sets it if a matching
argument is found; otherwise,
variable
is empty.
The following statement asks
getargs
to search for two arguments—one required
number and one optional text constant:
getargs REQUIRED NUMBER numvar OPTIONAL TEXT datavar
If
getargs
finds a numeric argument, it pushes
num
and stores the argument into
num
. If
getargs
finds a text argument, it pushes
data
and stores the argument in
data
.
Figure 3-7. Assigning Values to Arguments (Page 1 of 2)
?SECTION getargs MACRO
== Loop through all triplets
[#IF [#EMPTY %1%] |THEN|
== No more triplets; routine must have no more arguments
SINK [#ARGUMENT END] == Only valid if called by a routine
|ELSE|
#PUSH %3% == Push the variable
== Check first word of triplet for REQUIRED or OPTIONAL
[#CASE %1%
|optional|
[#IF [#EMPTY %4%] |THEN| == Check for more triplets
== No more triplets; argument cannot be followed by
== a comma
[#CASE [#ARGUMENT/TEXT %3%/ %2% END]
|1|
SINK [#ARGUMENT END]
|2|
#SET %3%
|3|
]