4.14.5 User Interaction |
This section briefly discusses libavl's data structures and functions for parsing command-line arguments. For more information on the command-line arguments accepted by the testing program, refer to the libavl reference manual.
The main way that the test program receives instructions from the user is through the set of arguments passed to main(). The program assumes that these arguments can be controlled easily by the user, presumably through some kind of command-based “shell” program. It allows for two kinds of options: traditional UNIX “short options” that take the form `-o' and GNU-style “long options” of the form `--option'. Either kind of option may take an argument.
Options are specified using an array of struct option, terminated by an all-zero structure:
134. <Test declarations 122> += /* A single command-line option. */ struct option
{ const char *long_name; /* Long name ("-name"). */ int short_name; /* Short name ("n"); value returned. */ int has_arg; /* Has a required argument? */ };
There are two public functions in the option parser:
These functions' implementation are not too interesting for our purposes, so they are relegated to an appendix. See Option Parser, for the full story.
The option parser provides a lot of support for parsing the command line, but of course the individual options have to be handled once they are retrieved by option_get(). The parse_command_line() function takes care of the whole process:
See Command-Line Parser, for source code. The struct test_options initialized by parse_command_line() is described in detail below.