Copyright (C) 2000-2012 |
GNU Info (libc.info)ArgpParsing Program Options with Argp ================================= "Argp" is an interface for parsing unix-style argument vectors. Note: 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. The `argp_parse' Function ------------------------- The main interface to argp is the `argp_parse' function. In many cases, calling `argp_parse' is the only argument-parsing code needed in `main'. Note: Program Arguments. - Function: error_t argp_parse (const struct argp *ARGP, int ARGC, char **ARGV, unsigned FLAGS, int *ARG_INDEX, void *INPUT) The `argp_parse' function parses the arguments in ARGV, of length ARGC, using the argp parser ARGP. Note: Argp Parsers. A value of zero is the same as a `struct argp'containing all zeros. FLAGS is a set of flag bits that modify the parsing behavior. Note: Argp Flags. INPUT is passed through to the argp parser ARGP, and has meaning defined by ARGP. A typical usage is to pass a pointer to a structure which is used for specifying parameters to the parser and passing back the results. Unless the `ARGP_NO_EXIT' or `ARGP_NO_HELP' flags are included in FLAGS, calling `argp_parse' may result in the program exiting. This behavior is true if an error is detected, or when an unknown option is encountered. Note: Program Termination. 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 (Note: Error Codes) if an error is detected. Different argp parsers may return arbitrary error codes, but the standard error codes are: `ENOMEM' if a memory allocation error occurred, or `EINVAL' if an unknown option or option argument is encountered.
automatically generated by info2www version 1.2.2.9 |