previous next top contents index framed top this page unframed
The MODULE IFX reads lines from cmdFile until it encounters a line reading THENX. It evaluates the condition specified by the lines; if it is TRUE, it exits, but if it is FALSE, it reads (and discards) lines until it encounters a line reading ELSEX or ENDX (it also skips nested IFX-ENDX sequences).
The MODULE ELSEX skips lines until it reaches a line reading ENDX (it also skips nested IFX-ENDX sequences).
The MODULE ENDX does nothing.
The result of these behaviors is that IFX, ELSEX, and ENDX implement conditional commands when invoked from MAINEX. The syntax is:
ifx
lines specifying a conditional expression
thenx
MODULEs to invoke if conditional expression is TRUE
endx
or:
ifx
lines specifying a conditional expression
thenx
MODULEs to invoke if conditional expression is TRUE
elsex
MODULEs to invoke if conditional expression is FALSE
endx
where the MODULEs to invoke may also contain properly nested IFX-ENDX sequences.
The conditional expression has the syntax:
conditionalExpression
::= term { OR conditionalExpression }
term
::= factor { AND term }
factor
::= { NOT } primary
primary
::= ( conditionalExpression )
::= BINDABLE ( module name )
::= FILEEXISTS ( file name )
where ::= means “is defined as”, and curly brackets indicate an optional part of an expression.
The primary BINDABLE(m), where m is a MODULE name, is TRUE if m can be bound (i.e., $canFindModule("m") is TRUE). Otherwise it is FALSE. m is not quoted.
The primary FILEEXISTS(f), where f is a file name, is TRUE if f can be opened for input. Otherwise it is FALSE. f is a quoted STRING constant, in which double quotes must be doubled.
Primaries are combined with AND, OR, NOT, and parentheses with the same precedence as those operators have in MAINSAIL.
The case of the letters in MODULE names and keywords is unimportant.
Example 16–1. Use of IFX, ELSEX, and ENDX
| The following MAINEX script:
ifx checks whether the file data.file exists. If not, it checks whether the MODULE MKFILE exists; if not, the MODULE is compiled. MKFILE is then invoked to create data.file. The MAINEX script:
ifx runs the MODULE FOO if FOO, BAR, and BAZ are bindable; otherwise, it exits MAINEX (since a blank line causes MAINEX to exit). |
MAINSAIL Utilities User's Guide, Chapter 16