option specifies an option of an SDTool
%option -char [ arg ] [ usage=oneline-message ] [ %do C-code executed when option is selected ] [ %otherwise C-code executed when option is not selected ]
The option section of a source description file specifies a command line option of an SDTool. There may be any number of option sections in a source description file. If an option is chosen on the command line, then the do C code is executed (if present); otherwise, the otherwise C code is executed (if present). An option char may be any character accepted by the getopt routine (see GETOPT(3) in the UNIX Programmer Reference Manual). If the option has an argument, the keyword arg must be used, and the value of the argument will be stored in the agoptarg array (see VERSION(5) ).
Most options specify generation of products (see PRODUCT(2) ). Some options may not directly relate to generating products, but instead determine some characteristic of a product or preprocessing. Options with single arguments are allowed (in the style of getopt). The BOOLEAN array, agoption, is indexed by option characters and returns TRUE if an option appears on the command line. Option arguments are stored in a STRING array, agoptarg, which is also indexed by the option character. The array values of agoptarg are initialized to NULL. See VERSION(5) for other details.
The options and products of an SDTool are processed in the order in which their option and product sections appear in the source description file, not in the order in which their option characters appear on the command line.
Normally option processing and product generation take place
after the code from the middlecode section is executed, but
before any code in the finalcode section is executed. If
options must cause actions at other times, the agoption and
apoptarg arrays may be accessed directly. In the following
example, the -a option is declared; if the option is
selected then the code in the startcode section code sets a
flag before parsing.
%declare
int aflag;
%option -a
%startcode
aflag = agoption['a'];
The predefined options provided with every SDTool may be redefined for any SDTool. The predefined options are:
The -1 and -2 options may be removed from an SDTool by selecting features 1 and 2 in the features section (see FEATURES(2) ).
%declare
%option -g arg
%option -h usage=do huffman encoding
%product main.c
%option -f arg usage=redirect main.c to file given by arg
%do GEN_m(agoptarg['f']); /* redirect main.c product to file
named by option argument */
%option -p
%do GEN_m(ofile); /* redirect output to ofile */
This example shows how some of the predefined options could
be defined:
%option -d arg usage=put products in directory `arg'
%option -2 usage=output parse tree
%do printtree(top);
FEATURES(2)
FINALCODE(2)
MIDDLECODE(2)
OBJECTS(2)
PRODUCT(2)
STARTCODE(2)
DEBUG(5)
GEN_x(5)
PRINTTREE(5)
VERSION(5)