Node:Argp Parser Functions, Next:Argp Children, Previous:Argp Option Vectors, Up:Argp Parsers
The function pointed to by the parser
field in a struct
argp
(see Argp Parsers) defines what actions take place in response
to each option or argument that is parsed, and is also used as a hook,
to allow a parser to do something at certain other points during
parsing.
Argp parser functions have the following type signature:
error_t parser (int key, char *arg, struct argp_state *state)where the arguments are as follows:
key
field in the option vector
(see Argp Option Vectors). parser is also called at other
times with special reserved keys, such as ARGP_KEY_ARG
for
non-option arguments. See Argp Special Keys.
arg
field can ever have a value, and those must always have a value,
unless the OPTION_ARG_OPTIONAL
flag was specified (if the input
being parsed specifies a value for an option that doesn't allow one, an
error results before parser ever gets called).
If key is ARGP_KEY_ARG
, arg is a non-option argument;
other special keys always have a zero arg.
struct argp_state
, containing useful
information about the current parsing state for use by parser.
See Argp Parsing State.
0
for success,
ARGP_ERR_UNKNOWN
, if the value of key is not handled by
this parser function, or a unix error code if a real error occurred
(see Error Codes).
int ARGP_ERR_UNKNOWN | Macro |
Argp parser functions should return ARGP_ERR_UNKNOWN for any
key value they do not recognize, or for non-option arguments
(key == ARGP_KEY_ARG ) that they do not wish to handle.
|
error_t parse_opt (int key, char *arg, struct argp_state *state) { switch (key) { case option_key: action break; ... default: return ARGP_ERR_UNKNOWN; } return 0; }