Specifications

CHAPTER 5. IMPLEMENTATION 44
additional arguments, e.g. program -d 3 (program --debug 3) with 3 being the argument
for the command line option -d (--debug).
Parsing of the command line options is realized using getopt long(3). The usage of the
function getopt long() requires the expected command line options to be known at compile
time. Hence, this function can only be used to parse the daemon’s configuration options. Each
command line option is represented by a structure option which is declared as follows:
struct option {
const char *name;
int has_arg;
int *flag;
int val;
};
The member name of the structure is a string representing the name of the long-option.
The value of has arg indicates whether the configuration option requires an argument or not.
If has arg equals 0, the configuration option does not take an argument, if has arg equals
1 the configuration option needs an argument. Optional arguments are specified by setting
has arg to 2. The member flag states how the result of the configuration should be returned.
Usually flag equals NULL which means that getopt long() returns the option’s member
val. The member val is commonly set to a single character which corresponds to the name
of the long-option. All configuration options of the Input Abstraction Layer are stored in the
array long options of option structures. To indicate its end, the last element of the array
has to be set to {0, 0, 0, 0}.
static struct option long_options[] = {
{"debug", 1, NULL, ’d’},
{"foreground", 0, NULL, ’f’},
{"help", 0, NULL, ’h’},
{"list", 0, NULL, ’l’},
{"list-verbose", 0, NULL, ’L’},
{"module-options", 1, NULL, ’m’},
{"version", 0, NULL, ’v’},
{0, 0, 0, 0}
};
For example, running the Input Abstraction Layer daemon with the long-option --help
corresponds to the short command line option -h. Both cases cause the daemon to print its
usage. The command line option debug (short option d) requires an argument which defines
the logging priority (§5.2). If the option foreground (f) is set, the daemon does not detach
itself on start-up. This function is not yet implemented. To get a list of the available modules,
the daemon has to be started using the command line option list (l). Correspondingly, if
the daemon command line option list-verbose (L) is supplied, the daemon prints a verbose
list of the available modules and their configuration options. The configuration options for the
modules are passed by the argument of the configuration option module-options (m). When
called with the command line option version (v), the daemon prints its version number.
For each configuration option the command line parser invokes a corresponding function.