OPTION(2)

Table of Contents

Name

option specifies an option of an SDTool

Synopsis

%option -char [ arg ] [ usage=oneline-message ] [ %do C-code executed when option is selected ] [ %otherwise C-code executed when option is not selected ]

Description

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:

-?
Print the list of all valid options and a one line explanation of each.
-1
Print a trace of yacc grammar rule reductions while parsing the specification file.
-2
Print the parse tree of the specification file (see PRINTTREE(5) ).
-3
Generate all products unconditionally, whether or not they are out of date.
-4
Print statistics on internal operations.
-5
Print a trace of each token as it is read from the specification file.
-V
Output version information.
-d dirname
Generate all products in directory dirname (default is the current directory).
-D flags
Turn on debug options specified in flags (see DEBUG(5) ).
-S
Generate the source code of the SDTool but do not issue the make command to build the executable.

The -1 and -2 options may be removed from an SDTool by selecting features 1 and 2 in the features section (see FEATURES(2) ).

Example

%declare

STRING ofile;
/* name of output file */

%option -g arg

%do
ofile = agoptarg['g']; /* override default value */
%otherwise ofile = «output";
/* default output file name */

%option -h usage=do huffman encoding

%do huffman();
/* 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 */

Example

This example shows how some of the predefined options could be defined:
%option -d arg usage=put products in directory `arg'

%do
productdir = agoptarg['d']; %otherwise productdir = «.";

%option -2 usage=output parse tree
%do printtree(top);

See Also

FEATURES(2)
FINALCODE(2)
MIDDLECODE(2)
OBJECTS(2)
PRODUCT(2)
STARTCODE(2)
DEBUG(5)
GEN_x(5)
PRINTTREE(5)
VERSION(5)


© 1990 Lucent Technologies, Inc
© 1998 Harmony Software, Inc