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


Specifying Argp Parsers

The first argument to the argp_parse function is a pointer to a struct argp, which known as an argp parser:

Data Type: struct argp
This structure specifies how to parse a given set of options and arguments, perhaps in conjunction with other argp parsers. It has the following fields:

const struct argp_option *options
A pointer to a vector of argp_option structures specifying which options this argp parser understands; it may be zero if there are no options at all. See section Specifying Options in an Argp Parser.
argp_parser_t parser
A pointer to a function that defines actions for this parser; it is called for each option parsed, and at other well-defined points in the parsing process. A value of zero is the same as a pointer to a function that always returns ARGP_ERR_UNKNOWN. See section Argp Parser Functions.
const char *args_doc
If non-zero, a string describing what non-option arguments are wanted by this parser; it is only used to print the `Usage:' message. If it contains newlines, the strings separated by them are considered alternative usage patterns, and printed on separate lines (lines after the first are prefixed by ` or: ' instead of `Usage:').
const char *doc
If non-zero, a string containing extra text to be printed before and after the options in a long help message, with the two sections separated by a vertical tab ('\v', '\013') character. By convention, the documentation before the options is just a short string saying what the program does, and that afterwards is longer, describing the behavior in more detail.
const struct argp_child *children
A pointer to a vector of argp_children structures specifying additional argp parsers that should be combined with this one. See section Combining Multiple Argp Parsers.
char *(*help_filter)(int key, const char *text, void *input)
If non-zero, a pointer to a function to filter the output of help messages. See section Customizing Argp Help Output.
const char *argp_domain
If non-zero, the strings used in the argp library are translated using the domain described by this string. Otherwise the currently installed default domain is used.

The options, parser, args_doc, and doc fields are usually all that are needed. If an argp parser is defined as an initialized C variable, only the used fields need be specified in the initializer--the rest will default to zero due to the way C structure initialization works (this fact is exploited for most argp structures, grouping the most-used fields near the beginning, so that unused fields can simply be left unspecified).


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