📄 argp.h
字号:
options in the parent argp; the values are the same as the GROUP field in argp_option structs, but all child-groupings follow parent options at a particular group level. If both this field and HEADER are zero, then they aren't grouped at all, but rather merged with the parent options (merging the child's grouping levels with the parents). */ int group;};/* Parsing state. This is provided to parsing functions called by argp, which may examine and, as noted, modify fields. */struct argp_state{ /* The top level ARGP being parsed. */ __const struct argp *root_argp; /* The argument vector being parsed. May be modified. */ int argc; char **argv; /* The index in ARGV of the next arg that to be parsed. May be modified. */ int next; /* The flags supplied to argp_parse. May be modified. */ unsigned flags; /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the number of the current arg, starting at zero, and incremented after each such call returns. At all other times, this is the number of such arguments that have been processed. */ unsigned arg_num; /* If non-zero, the index in ARGV of the first argument following a special `--' argument (which prevents anything following being interpreted as an option). Only set once argument parsing has proceeded past this point. */ int quoted; /* An arbitrary pointer passed in from the user. */ void *input; /* Values to pass to child parsers. This vector will be the same length as the number of children for the current parser. */ void **child_inputs; /* For the parser's use. Initialized to 0. */ void *hook; /* The name used when printing messages. This is initialized to ARGV[0], or PROGRAM_INVOCATION_NAME if that is unavailable. */ char *name; /* Streams used when argp prints something. */ FILE *err_stream; /* For errors; initialized to stderr. */ FILE *out_stream; /* For information; initialized to stdout. */ void *pstate; /* Private, for use by argp. */};/* Flags for argp_parse (note that the defaults are those that are convenient for program command line parsing): *//* Don't ignore the first element of ARGV. Normally (and always unless ARGP_NO_ERRS is set) the first element of the argument vector is skipped for option parsing purposes, as it corresponds to the program name in a command line. */#define ARGP_PARSE_ARGV0 0x01/* Don't print error messages for unknown options to stderr; unless this flag is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program name in the error messages. This flag implies ARGP_NO_EXIT (on the assumption that silent exiting upon errors is bad behaviour). */#define ARGP_NO_ERRS 0x02/* Don't parse any non-option args. Normally non-option args are parsed by calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg as the value. Since it's impossible to know which parse function wants to handle it, each one is called in turn, until one returns 0 or an error other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the argp_parse returns prematurely (but with a return value of 0). If all args have been parsed without error, all parsing functions are called one last time with a key of ARGP_KEY_END. This flag needn't normally be set, as the normal behavior is to stop parsing as soon as some argument can't be handled. */#define ARGP_NO_ARGS 0x04/* Parse options and arguments in the same order they occur on the command line -- normally they're rearranged so that all options come first. */#define ARGP_IN_ORDER 0x08/* Don't provide the standard long option --help, which causes usage and option help information to be output to stdout, and exit (0) called. */#define ARGP_NO_HELP 0x10/* Don't exit on errors (they may still result in error messages). */#define ARGP_NO_EXIT 0x20/* Use the gnu getopt `long-only' rules for parsing arguments. */#define ARGP_LONG_ONLY 0x40/* Turns off any message-printing/exiting options. */#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)/* Parse the options strings in ARGC & ARGV according to the options in ARGP. FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the index in ARGV of the first unparsed option is returned in it. If an unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser routine returned a non-zero value, it is returned; otherwise 0 is returned. This function may also call exit unless the ARGP_NO_HELP flag is set. INPUT is a pointer to a value to be passed in to the parser. */extern error_t argp_parse (__const struct argp *__restrict __argp, int __argc, char **__restrict __argv, unsigned __flags, int *__restrict __arg_index, void *__restrict __input);extern error_t __argp_parse (__const struct argp *__restrict __argp, int __argc, char **__restrict __argv, unsigned __flags, int *__restrict __arg_index, void *__restrict __input);/* Global variables. *//* If defined or set by the user program to a non-zero value, then a default option --version is added (unless the ARGP_NO_HELP flag is used), which will print this string followed by a newline and exit (unless the ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */extern __const char *argp_program_version;/* If defined or set by the user program to a non-zero value, then a default option --version is added (unless the ARGP_NO_HELP flag is used), which calls this function with a stream to print the version to and a pointer to the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is used). This variable takes precedent over ARGP_PROGRAM_VERSION. */extern void (*argp_program_version_hook) (FILE *__restrict __stream, struct argp_state *__restrict __state);/* If defined or set by the user program, it should point to string that is the bug-reporting address for the program. It will be printed by argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help messages), embedded in a sentence that says something like `Report bugs to ADDR.'. */extern __const char *argp_program_bug_address;/* The exit status that argp will use when exiting due to a parsing error. If not defined or set by the user program, this defaults to EX_USAGE from <sysexits.h>. */extern error_t argp_err_exit_status;/* Flags for argp_help. */#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */#define ARGP_HELP_LONG 0x08 /* a long help message. */#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to reflect ARGP_LONG_ONLY mode. *//* These ARGP_HELP flags are only understood by argp_state_help. */#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. *//* The standard thing to do after a program command line parsing error, if an error message has already been printed. */#define ARGP_HELP_STD_ERR \ (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)/* The standard thing to do after a program command line parsing error, if no more specific error message has been printed. */#define ARGP_HELP_STD_USAGE \ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)/* The standard thing to do in response to a --help option. */#define ARGP_HELP_STD_HELP \ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)/* Output a usage message for ARGP to STREAM. FLAGS are from the set ARGP_HELP_*. */extern void argp_help (__const struct argp *__restrict __argp, FILE *__restrict __stream, unsigned __flags, char *__restrict __name);extern void __argp_help (__const struct argp *__restrict __argp, FILE *__restrict __stream, unsigned __flags, char *__name);/* The following routines are intended to be called from within an argp parsing routine (thus taking an argp_state structure as the first argument). They may or may not print an error message and exit, depending on the flags in STATE -- in any case, the caller should be prepared for them *not* to exit, and should return an appropiate error after calling them. [argp_usage & argp_error should probably be called argp_state_..., but they're used often enough that they should be short] *//* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are from the set ARGP_HELP_*. */extern void argp_state_help (__const struct argp_state *__restrict __state, FILE *__restrict __stream, unsigned int __flags);extern void __argp_state_help (__const struct argp_state *__restrict __state, FILE *__restrict __stream, unsigned int __flags);/* Possibly output the standard usage message for ARGP to stderr and exit. */extern void argp_usage (__const struct argp_state *__state);extern void __argp_usage (__const struct argp_state *__state);/* If appropriate, print the printf string FMT and following args, preceded by the program name and `:', to stderr, and followed by a `Try ... --help' message, then exit (1). */extern void argp_error (__const struct argp_state *__restrict __state, __const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));extern void __argp_error (__const struct argp_state *__restrict __state, __const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3)));/* Similar to the standard gnu error-reporting function error(), but will respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print to STATE->err_stream. This is useful for argument parsing code that is shared between program startup (when exiting is desired) and runtime option parsing (when typically an error code is returned instead). The difference between this function and argp_error is that the latter is for *parsing errors*, and the former is for other problems that occur during parsing but don't reflect a (syntactic) problem with the input. */extern void argp_failure (__const struct argp_state *__restrict __state, int __status, int __errnum, __const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 4, 5)));extern void __argp_failure (__const struct argp_state *__restrict __state, int __status, int __errnum, __const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 4, 5)));/* Returns true if the option OPT is a valid short option. */extern int _option_is_short (__const struct argp_option *__opt) __THROW;extern int __option_is_short (__const struct argp_option *__opt) __THROW;/* Returns true if the option OPT is in fact the last (unused) entry in an options array. */extern int _option_is_end (__const struct argp_option *__opt) __THROW;extern int __option_is_end (__const struct argp_option *__opt) __THROW;/* Return the input field for ARGP in the parser corresponding to STATE; used by the help routines. */extern void *_argp_input (__const struct argp *__restrict __argp, __const struct argp_state *__restrict __state) __THROW;extern void *__argp_input (__const struct argp *__restrict __argp, __const struct argp_state *__restrict __state) __THROW;#ifdef __USE_EXTERN_INLINES# if !_LIBC# define __argp_usage argp_usage# define __argp_state_help argp_state_help# define __option_is_short _option_is_short# define __option_is_end _option_is_end# endif# ifndef ARGP_EI# define ARGP_EI extern __inline__# endifARGP_EI void__NTH (__argp_usage (__const struct argp_state *__state)){ __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);}ARGP_EI int__NTH (__option_is_short (__const struct argp_option *__opt)){ if (__opt->flags & OPTION_DOC) return 0; else { int __key = __opt->key; return __key > 0 && isprint (__key); }}ARGP_EI int__NTH (__option_is_end (__const struct argp_option *__opt)){ return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;}# if !_LIBC# undef __argp_usage# undef __argp_state_help# undef __option_is_short# undef __option_is_end# endif#endif /* Use extern inlines. */#ifdef __cplusplus}#endif#endif /* argp.h */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -