Go to the first, previous, next, last section, table of contents.

Command-Line Parser

The SUIF library provides a generic interface for a command line parser. The parser is defined and implemented in the files `cmdparse.h' and `cmdparse.cc'. The SUIF program can provide a structure that contains a list of command line options, the type of arguments these options can handle, and pointers to data where the argument values will be stored. The data locations will be initialized to default values specified in the options table before parsing begins. The parse_cmd_line function is called with argc, argv, the options table, and the number of options in the table. If the parser finds one of the options on the command line, the option (and its argument, if any) are removed from argv and argc is appropriately adjusted. Thus when parsing is finished, argv contains only unrecognized options (such as file names).

The following types of arguments are supported:

CLO_NOARG
No argument is expected. The default value is 0. If the argument is present, the value becomes 1.
CLO_INT
A single integer is expected.
CLO_STRING
A single string is expected.
CLO_MULTI_STRING
A single string is expected for each occurrence of this option, but the option can be repeated with different arguments.

For example:

static boolean quiet;
static int size;
static cmd_line_option my_options[] = {
    { CLO_NOARG, "-quiet", "", &quiet },
    { CLO_INT, "-size", "8", &size }
};

parse_cmd_line(argc, argv, my_options,
               sizeof(my_options)/sizeof(cmd_line_option));

Go to the first, previous, next, last section, table of contents.