Node:Argp, Next:Suboptions, Previous:Getopt, Up:Parsing Program Arguments
Argp is an interface for parsing unix-style argument vectors. See Program Arguments.
Argp provides features unavailable in the more commonly used
getopt
interface. These features include automatically producing
output in response to the --help
and --version
options, as
described in the GNU coding standards. Using argp makes it less likely
that programmers will neglect to implement these additional options or
keep them up to date.
Argp also provides the ability to merge several independently defined option parsers into one, mediating conflicts between them and making the result appear seamless. A library can export an argp option parser that user programs might employ in conjunction with their own option parsers, resulting in less work for the user programs. Some programs may use only argument parsers exported by libraries, thereby achieving consistent and efficient option-parsing for abstractions implemented by the libraries.
The header file <argp.h>
should be included to use argp.
argp_parse
FunctionThe main interface to argp is the argp_parse
function. In many
cases, calling argp_parse
is the only argument-parsing code
needed in main
.
See Program Arguments.
error_t argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags, int *arg_index, void *input) | Function |
The argp_parse function parses the arguments in argv, of
length argc, using the argp parser argp. See Argp Parsers.
A value of zero is the same as a Unless the If arg_index is non-null, the index of the first unparsed option in argv is returned as a value. The return value is zero for successful parsing, or an error code
(see Error Codes) if an error is detected. Different argp parsers
may return arbitrary error codes, but the standard error codes are:
|