Eli   Documents Get Eli: Translator Construction Made Easy at SourceForge.net.
    Fast, secure and Free Open Source software downloads

General Information

 o Eli: Translator Construction Made Easy
 o Global Index
 o Frequently Asked Questions
 o Typical Eli Usage Errors

Tutorials

 o Quick Reference Card
 o Guide For new Eli Users
 o Release Notes of Eli
 o Tutorial on Name Analysis
 o Tutorial on Type Analysis
 o Typical Eli Usage Errors

Reference Manuals

 o User Interface
 o Eli products and parameters
 o LIDO Reference Manual
 o Typical Eli Usage Errors

Libraries

 o Eli library routines
 o Specification Module Library

Translation Tasks

 o Lexical analysis specification
 o Syntactic Analysis Manual
 o Computation in Trees

Tools

 o LIGA Control Language
 o Debugging Information for LIDO
 o Graphical ORder TOol

 o FunnelWeb User's Manual

 o Pattern-based Text Generator
 o Property Definition Language
 o Operator Identification Language
 o Tree Grammar Specification Language
 o Command Line Processing
 o COLA Options Reference Manual

 o Generating Unparsing Code

 o Monitoring a Processor's Execution

Administration

 o System Administration Guide

Mail Home

Command Line Processing

Previous Chapter Next Chapter Table of Contents


Accessing the command line

A CLP specification is turned into code that arranges for command line information to be stored in C variables or a simple database. This code is automatically run by the processor startup code generated by Eli. During attribution of a structure tree you can access the variables or use access functions to obtain the command-line information.

The header file `clp.h' will contain extern declarations for all values defined by the CLP-generated code. It should be included wherever these values must be accessed.

Accessing boolean options

Since boolean options do not have value information associated with them, all that is needed to represent them is a simple flag rather than a database object. We store the flag as a C integer variable whose name is the option name.

For example, given the specification:

GenAssembly "-S" boolean;
CLP will generate a variable called GenAssembly. Typical C code to test for this option would look like:

if (GenAssembly)
  printf ("GenAssembly specified\n");
else
  printf ("GenAssembly not specified\n");

Accessing options with integer values

To provide access to integer value options, CLP generates a database object which has the appropriate value as a property. The object is referred to by a key-valued variable named after the option. For example, given the specification:

NumCopies "-#" int;
CLP will generate a variable called NumCopies. The value of the variable can be used to access the option value using the GetClpValue property access function.

printf ("NumCopies value is %d\n", GetClpValue (NumCopies, 0));
Here 0 will be printed if the option was not specified by the user.

Alternatively, presence of the option can be tested for explicitly by testing the key:

if (NumCopies == NoKey)
  printf ("NumCopies not specified\n");
else
  printf ("NumCopies value is %d\n", GetClpValue (NumCopies, 0));
In this case the default value parameter in the GetClpValue call will never be used.

Accessing options with string values

Access to string value options is provided via a database object which has the appropriate value as a property. The object is referred to by a key-value variable named after the option. For example, given the specification:

TmpFile "-temp=" joinedto string;
CLP will generate a variable called TmpFile. GetClpValue is used to obtain the value which should be interpreted as a string table index (see Arbitrary-length character strings of Library Reference).

#include "csm.h"

if (TmpFile == NoKey)
  printf ("TmpFile not specified\n");
else
  printf ("TmpFile value is '%s'\n", StringTable (GetClpValue (TmpFile, 0)));

Accessing options that appear more than once

The mechanisms described in the previous three sections only apply to options that can appear at most once on the command line. More complicated mechanisms are needed to access values associated with repeated options.

CLP uses linked lists of definition table keys to provide multiple value access. The lists are implemented using Eli's List module. See list of Specification Module Library: Abstract Data Types.

Given the specification:

MacroPackage "-m" joinedto strings;
the list module lets you print the multiple values (via keys) as follows:

#include "csm.h"
#include "clp.h"

DefTableKey printkey (DefTableKey k)
{
    printf ("%s", StringTable (GetClpValue (k, 0)));
}

(void) MapDefTableKeyList (MacroPackage, printkey);

Boolean repeated options are an exception to this list approach. Since no value is associated with the option there is little point in having a list of keys. For this reason, boolean repeated options are implemented as a single integer whose value is the number of times the option appeared.

Accessing positional parameters

For each singular positional parameter specification line CLP generates a variable of the appropriate name holding the key to a database object that has the string value of the positional parameter as a property. The value can be accessed as for string value options (see Accessing options with string values).

CLP will always make sure that a positional parameter is specified and will arrange for a usage message to be printed otherwise. Thus there is no need to test that the database object described in the previous paragraph is defined. For example, given the specification line:

FileName positional;
the following code can be used to print the specified value:

#include "csm.h"

printf ("Filename given was '%s'\n", StringTable (GetClpValue (FileName, 0)));

When a plural positional parameter specification line is given the mechanisms used for repeated option values are used (see Accessing options that appear more than once). For example, if a processor can take multiple input files a specification like the following might be used:

FileNames positionals;
The following code can be used to print these parameters See Linear Lists of Any Type of Specification Module Library: Abstract Data Types.

#include "csm.h"
#include "clp.h"

DefTableKey printkey (DefTableKey k)
{
    printf ("%s", StringTable (GetClpValue (k, 0)));
}

(void) MapDefTableKeyList (FileNames, printkey);

Accessing input parameters

Since an input parameter is just a special kind of positional parameter, its value (which is the name of the input file) can be accessed as shown in Accessing positional parameters.

The input parameter may also be accessed via the standard name CLP_InputFile.

Reporting open errors

CLP defines the text of an error report that a program can write to standard error when a file cannot be opened (see Options that affect usage messages). The program writes this error report by invoking the ClpOpenError routine:

void ClpOpenError(const char *filename, const char *errtext)
/* On entry-
 *   filename points to the string to replace any %f escape in the report
 *   errtext points to the string to replace any %t escape in the report
 * On exit-
 *   The modified report has been written to stderr
 */

Although the role of the argument strings is completely arbitrary, the usual practice is to use the name of the file being opened as the value of filename and the string corresponding to the system error as the value of errtext. Here is a code fragment illustrating the typical usage:

#include <errno.h>
#include <string.h>
...
  int infile = open(infilename, 0);
  if (infile == -1) {
    ClpOpenError(infilename, strerror(errno));
    exit(2);
  }
...


Previous Chapter Next Chapter Table of Contents