next up previous contents index
Next: Introduction to Xic Scripts Up: The Macro Preprocessor Previous: Predefined Macros   Contents   Index


Generic Macro Keywords

The following keywords may vary between different contexts where the macro processor is used. The actual keywords are programmable within the macro preprocessor system, so as to better match the syntax of the file format to which the preprocessor is being applied. Here, we will use italicized generic names for these keywords, but the correspondence to actual keyword names (given in the documentation for the specific file formats) should be obvious. The square brackets indicate ``optional''.

$\textstyle \parbox{4in}{\raggedright
{\it DEFINE} [{\tt eval}] {\it token}\\
...
...t arg\/},
{\it arg\/}1, ..., {\it arg\/}n) [{\it text\_containing\_args}]\\
}$
The macro name token may use alphanumeric characters and underscores, and must start with an alpha or underscore character. The name is optionally immediately followed by an argument list in parentheses. The arguments are arbitrary alphanumeric plus underscore tokens that start with an alpha or underscore and are separated by commas. This is the same syntax used in the C language preprocessor for #define lines. The remainder of the line is the substitution string.

If the optional ``eval'' keyword is not included, the replacement text, if any, will replace the macro in lines of text being macro expanded.

If ``eval'' is included (this is verbatim but case-insensitive), the replacement text is assumed to be executable as a single line script. The script will be executed, and the result (or return value) will be converted to a text string (if necessary) and taken as the replacement text.

IF expression
The expression is a constant expression which can contain macros previously defined with DEFINE, predefines, and functions from the script library files or otherwise available in memory. The expression is evaluated numerically, and if the result is nonzero (as an integer), the block that follows until the corresponding ELSE or ENDIF is read. If the result is 0 (as an integer), the block of lines that follow is skipped.

IFDEF token
If token has been defined, either with DEFINE or as a predefined macro, reading resumes at the following line. Otherwise, reading resumes at the line following the next ELSE or ENDIF.

IFNDEF token
If token has not been defined, reading resumes at the following line. Otherwise, reading resumes at the line following the next ELSE or ENDIF.

ELSE Used in conjunction with IF, IFDEF and IFNDEF.

ENDIF
Used to terminate an IF, IFDEF, IFNDEF, or ELSE block.

In various contexts, other special keywords may be recognized. These are described elsewhere.

Examples:

The examples below illustrate some simple constructs that improve portability of input files, using the predefined macros and generic keywords. In real input, the actual keywords appropriate for the type of file should be used.

The IF keyword, and product name and RELEASE predefines, were implemented in release 3.0.5, so use is not compatible with older releases. Nevertheless, files can be made portably version dependent through use of IFDEF and/or IFNDEF.

IFNDEF RELEASE
# old release
text...
ELSE
IF RELEASE == 30050
# release xic-3.0.5
text...
ELSE
# a later release
text...
ENDIF
ENDIF

Often, it is necessary to know what operating system is being used. Usually, there are really only two categories: Windows, and everything else.

IF OSTYPE == "Windows"
# running Windows
text...
ELSE
# not running Windows
text...
ENDIF

It may be necessary to disable certain setup if not running the full Xic feature set, for example, if the same file is used for different Xic feature sets.

IF FEATURESET == "FULL"
# running Xic
text...
ELSE
IF FEATURESET == "EDITOR"
# running XicII
text...
ELSE
IF FEATURESET == "VIEWER"
# running Xiv
text...
ELSE
# impossible!
ENDIF
ENDIF
ENDIF


next up previous contents index
Next: Introduction to Xic Scripts Up: The Macro Preprocessor Previous: Predefined Macros   Contents   Index
Stephen R. Whiteley 2024-09-29