WvStreams
|
00001 /* Hierarchial argument parsing. 00002 Copyright (C) 1995, 96, 97, 98, 99, 2003 Free Software Foundation, Inc. 00003 This file is part of the GNU C Library. 00004 Written by Miles Bader <miles@gnu.ai.mit.edu>. 00005 00006 The GNU C Library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public License as 00008 published by the Free Software Foundation; either version 2 of the 00009 License, or (at your option) any later version. 00010 00011 The GNU C Library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public 00017 License along with the GNU C Library; see the file COPYING.LIB. If not, 00018 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. */ 00020 00021 #ifndef _ARGP_H 00022 #define _ARGP_H 00023 00024 #include <stdio.h> 00025 #include <ctype.h> 00026 00027 #define __need_error_t 00028 #include <errno.h> 00029 00030 #ifndef __THROW 00031 # define __THROW 00032 #endif 00033 00034 #ifndef __const 00035 # define __const const 00036 #endif 00037 00038 #ifndef __error_t_defined 00039 typedef int error_t; 00040 # define __error_t_defined 00041 #endif 00042 00043 /* FIXME: What's the right way to check for __restrict? Sun's cc seems 00044 not to have it. Perhaps it's easiest to just delete the use of 00045 __restrict from the prototypes. */ 00046 #ifndef __restrict 00047 # ifndef __GNUC___ 00048 # define __restrict 00049 # endif 00050 #endif 00051 00052 /* NOTE: We can't use the autoconf tests, since this is supposed to be 00053 an installed header file and argp's config.h is of course not 00054 installed. */ 00055 #ifndef PRINTF_STYLE 00056 # if __GNUC__ >= 2 00057 # define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) 00058 # else 00059 # define PRINTF_STYLE(f, a) 00060 # endif 00061 #endif 00062 00063 00064 #ifdef __cplusplus 00065 extern "C" { 00066 #endif 00067 00068 /* A description of a particular option. A pointer to an array of 00069 these is passed in the OPTIONS field of an argp structure. Each option 00070 entry can correspond to one long option and/or one short option; more 00071 names for the same option can be added by following an entry in an option 00072 array with options having the OPTION_ALIAS flag set. */ 00073 struct argp_option 00074 { 00075 /* The long option name. For more than one name for the same option, you 00076 can use following options with the OPTION_ALIAS flag set. */ 00077 __const char *name; 00078 00079 /* What key is returned for this option. If > 0 and printable, then it's 00080 also accepted as a short option. */ 00081 int key; 00082 00083 /* If non-NULL, this is the name of the argument associated with this 00084 option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */ 00085 __const char *arg; 00086 00087 /* OPTION_ flags. */ 00088 int flags; 00089 00090 /* The doc string for this option. If both NAME and KEY are 0, This string 00091 will be printed outdented from the normal option column, making it 00092 useful as a group header (it will be the first thing printed in its 00093 group); in this usage, it's conventional to end the string with a `:'. */ 00094 __const char *doc; 00095 00096 /* The group this option is in. In a long help message, options are sorted 00097 alphabetically within each group, and the groups presented in the order 00098 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with 00099 if this field 0 will inherit the group number of the previous entry, or 00100 zero if it's the first one, unless its a group header (NAME and KEY both 00101 0), in which case, the previous entry + 1 is the default. Automagic 00102 options such as --help are put into group -1. */ 00103 int group; 00104 }; 00105 00106 /* The argument associated with this option is optional. */ 00107 #define OPTION_ARG_OPTIONAL 0x1 00108 00109 /* This option isn't displayed in any help messages. */ 00110 #define OPTION_HIDDEN 0x2 00111 00112 /* This option is an alias for the closest previous non-alias option. This 00113 means that it will be displayed in the same help entry, and will inherit 00114 fields other than NAME and KEY from the aliased option. */ 00115 #define OPTION_ALIAS 0x4 00116 00117 /* This option isn't actually an option (and so should be ignored by the 00118 actual option parser), but rather an arbitrary piece of documentation that 00119 should be displayed in much the same manner as the options. If this flag 00120 is set, then the option NAME field is displayed unmodified (e.g., no `--' 00121 prefix is added) at the left-margin (where a *short* option would normally 00122 be displayed), and the documentation string in the normal place. For 00123 purposes of sorting, any leading whitespace and puncuation is ignored, 00124 except that if the first non-whitespace character is not `-', this entry 00125 is displayed after all options (and OPTION_DOC entries with a leading `-') 00126 in the same group. */ 00127 #define OPTION_DOC 0x8 00128 00129 /* This option shouldn't be included in `long' usage messages (but is still 00130 included in help messages). This is mainly intended for options that are 00131 completely documented in an argp's ARGS_DOC field, in which case including 00132 the option in the generic usage list would be redundant. For instance, 00133 if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to 00134 distinguish these two cases, -x should probably be marked 00135 OPTION_NO_USAGE. */ 00136 #define OPTION_NO_USAGE 0x10 00137 00138 struct argp; /* fwd declare this type */ 00139 struct argp_state; /* " */ 00140 struct argp_child; /* " */ 00141 00142 /* The type of a pointer to an argp parsing function. */ 00143 typedef error_t (*argp_parser_t) (int key, char *arg, 00144 struct argp_state *state); 00145 00146 /* What to return for unrecognized keys. For special ARGP_KEY_ keys, such 00147 returns will simply be ignored. For user keys, this error will be turned 00148 into EINVAL (if the call to argp_parse is such that errors are propagated 00149 back to the user instead of exiting); returning EINVAL itself would result 00150 in an immediate stop to parsing in *all* cases. */ 00151 #define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */ 00152 00153 /* Special values for the KEY argument to an argument parsing function. 00154 ARGP_ERR_UNKNOWN should be returned if they aren't understood. 00155 00156 The sequence of keys to a parsing function is either (where each 00157 uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key): 00158 00159 INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all 00160 or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed 00161 or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized 00162 00163 The third case is where every parser returned ARGP_KEY_UNKNOWN for an 00164 argument, in which case parsing stops at that argument (returning the 00165 unparsed arguments to the caller of argp_parse if requested, or stopping 00166 with an error message if not). 00167 00168 If an error occurs (either detected by argp, or because the parsing 00169 function returned an error value), then the parser is called with 00170 ARGP_KEY_ERROR, and no further calls are made. */ 00171 00172 /* This is not an option at all, but rather a command line argument. If a 00173 parser receiving this key returns success, the fact is recorded, and the 00174 ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the 00175 argument, a parser function decrements the NEXT field of the state it's 00176 passed, the option won't be considered processed; this is to allow you to 00177 actually modify the argument (perhaps into an option), and have it 00178 processed again. */ 00179 #define ARGP_KEY_ARG 0 00180 /* There are remaining arguments not parsed by any parser, which may be found 00181 starting at (STATE->argv + STATE->next). If success is returned, but 00182 STATE->next left untouched, it's assumed that all arguments were consume, 00183 otherwise, the parser should adjust STATE->next to reflect any arguments 00184 consumed. */ 00185 #define ARGP_KEY_ARGS 0x1000006 00186 /* There are no more command line arguments at all. */ 00187 #define ARGP_KEY_END 0x1000001 00188 /* Because it's common to want to do some special processing if there aren't 00189 any non-option args, user parsers are called with this key if they didn't 00190 successfully process any non-option arguments. Called just before 00191 ARGP_KEY_END (where more general validity checks on previously parsed 00192 arguments can take place). */ 00193 #define ARGP_KEY_NO_ARGS 0x1000002 00194 /* Passed in before any parsing is done. Afterwards, the values of each 00195 element of the CHILD_INPUT field, if any, in the state structure is 00196 copied to each child's state to be the initial value of the INPUT field. */ 00197 #define ARGP_KEY_INIT 0x1000003 00198 /* Use after all other keys, including SUCCESS & END. */ 00199 #define ARGP_KEY_FINI 0x1000007 00200 /* Passed in when parsing has successfully been completed (even if there are 00201 still arguments remaining). */ 00202 #define ARGP_KEY_SUCCESS 0x1000004 00203 /* Passed in if an error occurs. */ 00204 #define ARGP_KEY_ERROR 0x1000005 00205 00206 /* An argp structure contains a set of options declarations, a function to 00207 deal with parsing one, documentation string, a possible vector of child 00208 argp's, and perhaps a function to filter help output. When actually 00209 parsing options, getopt is called with the union of all the argp 00210 structures chained together through their CHILD pointers, with conflicts 00211 being resolved in favor of the first occurrence in the chain. */ 00212 struct argp 00213 { 00214 /* An array of argp_option structures, terminated by an entry with both 00215 NAME and KEY having a value of 0. */ 00216 __const struct argp_option *options; 00217 00218 /* What to do with an option from this structure. KEY is the key 00219 associated with the option, and ARG is any associated argument (NULL if 00220 none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be 00221 returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then 00222 parsing is stopped immediately, and that value is returned from 00223 argp_parse(). For special (non-user-supplied) values of KEY, see the 00224 ARGP_KEY_ definitions below. */ 00225 argp_parser_t parser; 00226 00227 /* A string describing what other arguments are wanted by this program. It 00228 is only used by argp_usage to print the `Usage:' message. If it 00229 contains newlines, the strings separated by them are considered 00230 alternative usage patterns, and printed on separate lines (lines after 00231 the first are prefix by ` or: ' instead of `Usage:'). */ 00232 __const char *args_doc; 00233 00234 /* If non-NULL, a string containing extra text to be printed before and 00235 after the options in a long help message (separated by a vertical tab 00236 `\v' character). */ 00237 __const char *doc; 00238 00239 /* A vector of argp_children structures, terminated by a member with a 0 00240 argp field, pointing to child argps should be parsed with this one. Any 00241 conflicts are resolved in favor of this argp, or early argps in the 00242 CHILDREN list. This field is useful if you use libraries that supply 00243 their own argp structure, which you want to use in conjunction with your 00244 own. */ 00245 __const struct argp_child *children; 00246 00247 /* If non-zero, this should be a function to filter the output of help 00248 messages. KEY is either a key from an option, in which case TEXT is 00249 that option's help text, or a special key from the ARGP_KEY_HELP_ 00250 defines, below, describing which other help text TEXT is. The function 00251 should return either TEXT, if it should be used as-is, a replacement 00252 string, which should be malloced, and will be freed by argp, or NULL, 00253 meaning `print nothing'. The value for TEXT is *after* any translation 00254 has been done, so if any of the replacement text also needs translation, 00255 that should be done by the filter function. INPUT is either the input 00256 supplied to argp_parse, or NULL, if argp_help was called directly. */ 00257 char *(*help_filter) (int __key, __const char *__text, void *__input); 00258 00259 /* If non-zero the strings used in the argp library are translated using 00260 the domain described by this string. Otherwise the currently installed 00261 default domain is used. */ 00262 const char *argp_domain; 00263 }; 00264 00265 /* Possible KEY arguments to a help filter function. */ 00266 #define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */ 00267 #define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */ 00268 #define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */ 00269 #define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation; 00270 TEXT is NULL for this key. */ 00271 /* Explanatory note emitted when duplicate option arguments have been 00272 suppressed. */ 00273 #define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005 00274 #define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */ 00275 00276 /* When an argp has a non-zero CHILDREN field, it should point to a vector of 00277 argp_child structures, each of which describes a subsidiary argp. */ 00278 struct argp_child 00279 { 00280 /* The child parser. */ 00281 __const struct argp *argp; 00282 00283 /* Flags for this child. */ 00284 int flags; 00285 00286 /* If non-zero, an optional header to be printed in help output before the 00287 child options. As a side-effect, a non-zero value forces the child 00288 options to be grouped together; to achieve this effect without actually 00289 printing a header string, use a value of "". */ 00290 __const char *header; 00291 00292 /* Where to group the child options relative to the other (`consolidated') 00293 options in the parent argp; the values are the same as the GROUP field 00294 in argp_option structs, but all child-groupings follow parent options at 00295 a particular group level. If both this field and HEADER are zero, then 00296 they aren't grouped at all, but rather merged with the parent options 00297 (merging the child's grouping levels with the parents). */ 00298 int group; 00299 }; 00300 00301 /* Parsing state. This is provided to parsing functions called by argp, 00302 which may examine and, as noted, modify fields. */ 00303 struct argp_state 00304 { 00305 /* The top level ARGP being parsed. */ 00306 __const struct argp *root_argp; 00307 00308 /* The argument vector being parsed. May be modified. */ 00309 int argc; 00310 char **argv; 00311 00312 /* The index in ARGV of the next arg that to be parsed. May be modified. */ 00313 int next; 00314 00315 /* The flags supplied to argp_parse. May be modified. */ 00316 unsigned flags; 00317 00318 /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the 00319 number of the current arg, starting at zero, and incremented after each 00320 such call returns. At all other times, this is the number of such 00321 arguments that have been processed. */ 00322 unsigned arg_num; 00323 00324 /* If non-zero, the index in ARGV of the first argument following a special 00325 `--' argument (which prevents anything following being interpreted as an 00326 option). Only set once argument parsing has proceeded past this point. */ 00327 int quoted; 00328 00329 /* An arbitrary pointer passed in from the user. */ 00330 void *input; 00331 /* Values to pass to child parsers. This vector will be the same length as 00332 the number of children for the current parser. */ 00333 void **child_inputs; 00334 00335 /* For the parser's use. Initialized to 0. */ 00336 void *hook; 00337 00338 /* The name used when printing messages. This is initialized to ARGV[0], 00339 or PROGRAM_INVOCATION_NAME if that is unavailable. */ 00340 char *name; 00341 00342 /* Streams used when argp prints something. */ 00343 FILE *err_stream; /* For errors; initialized to stderr. */ 00344 FILE *out_stream; /* For information; initialized to stdout. */ 00345 00346 void *pstate; /* Private, for use by argp. */ 00347 }; 00348 00349 /* Flags for argp_parse (note that the defaults are those that are 00350 convenient for program command line parsing): */ 00351 00352 /* Don't ignore the first element of ARGV. Normally (and always unless 00353 ARGP_NO_ERRS is set) the first element of the argument vector is 00354 skipped for option parsing purposes, as it corresponds to the program name 00355 in a command line. */ 00356 #define ARGP_PARSE_ARGV0 0x01 00357 00358 /* Don't print error messages for unknown options to stderr; unless this flag 00359 is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program 00360 name in the error messages. This flag implies ARGP_NO_EXIT (on the 00361 assumption that silent exiting upon errors is bad behaviour). */ 00362 #define ARGP_NO_ERRS 0x02 00363 00364 /* Don't parse any non-option args. Normally non-option args are parsed by 00365 calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg 00366 as the value. Since it's impossible to know which parse function wants to 00367 handle it, each one is called in turn, until one returns 0 or an error 00368 other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the 00369 argp_parse returns prematurely (but with a return value of 0). If all 00370 args have been parsed without error, all parsing functions are called one 00371 last time with a key of ARGP_KEY_END. This flag needn't normally be set, 00372 as the normal behavior is to stop parsing as soon as some argument can't 00373 be handled. */ 00374 #define ARGP_NO_ARGS 0x04 00375 00376 /* Parse options and arguments in the same order they occur on the command 00377 line -- normally they're rearranged so that all options come first. */ 00378 #define ARGP_IN_ORDER 0x08 00379 00380 /* Don't provide the standard long option --help, which causes usage and 00381 option help information to be output to stdout, and exit (0) called. */ 00382 #define ARGP_NO_HELP 0x10 00383 00384 /* Don't exit on errors (they may still result in error messages). */ 00385 #define ARGP_NO_EXIT 0x20 00386 00387 /* Use the gnu getopt `long-only' rules for parsing arguments. */ 00388 #define ARGP_LONG_ONLY 0x40 00389 00390 /* Turns off any message-printing/exiting options. */ 00391 #define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP) 00392 00393 /* Parse the options strings in ARGC & ARGV according to the options in ARGP. 00394 FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the 00395 index in ARGV of the first unparsed option is returned in it. If an 00396 unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser 00397 routine returned a non-zero value, it is returned; otherwise 0 is 00398 returned. This function may also call exit unless the ARGP_NO_HELP flag 00399 is set. INPUT is a pointer to a value to be passed in to the parser. */ 00400 extern error_t argp_parse (__const struct argp *__restrict __argp, 00401 int /*argc*/, char **__restrict /*argv*/, 00402 unsigned __flags, int *__restrict __arg_index, 00403 void *__restrict __input) __THROW; 00404 extern error_t __argp_parse (__const struct argp *__restrict __argp, 00405 int /*argc*/, char **__restrict /*argv*/, 00406 unsigned __flags, int *__restrict __arg_index, 00407 void *__restrict __input) __THROW; 00408 00409 /* Global variables. */ 00410 00411 /* If defined or set by the user program to a non-zero value, then a default 00412 option --version is added (unless the ARGP_NO_HELP flag is used), which 00413 will print this string followed by a newline and exit (unless the 00414 ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ 00415 extern __const char *argp_program_version; 00416 00417 /* If defined or set by the user program to a non-zero value, then a default 00418 option --version is added (unless the ARGP_NO_HELP flag is used), which 00419 calls this function with a stream to print the version to and a pointer to 00420 the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is 00421 used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ 00422 extern void (*argp_program_version_hook) (FILE *__restrict __stream, 00423 struct argp_state *__restrict 00424 __state); 00425 00426 /* If defined or set by the user program, it should point to string that is 00427 the bug-reporting address for the program. It will be printed by 00428 argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various 00429 standard help messages), embedded in a sentence that says something like 00430 `Report bugs to ADDR.'. */ 00431 extern __const char *argp_program_bug_address; 00432 00433 /* The exit status that argp will use when exiting due to a parsing error. 00434 If not defined or set by the user program, this defaults to EX_USAGE from 00435 <sysexits.h>. */ 00436 extern error_t argp_err_exit_status; 00437 00438 /* Flags for argp_help. */ 00439 #define ARGP_HELP_USAGE 0x01 /* a Usage: message. */ 00440 #define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */ 00441 #define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */ 00442 #define ARGP_HELP_LONG 0x08 /* a long help message. */ 00443 #define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */ 00444 #define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */ 00445 #define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC) 00446 #define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */ 00447 #define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to 00448 reflect ARGP_LONG_ONLY mode. */ 00449 00450 /* These ARGP_HELP flags are only understood by argp_state_help. */ 00451 #define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */ 00452 #define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */ 00453 00454 /* The standard thing to do after a program command line parsing error, if an 00455 error message has already been printed. */ 00456 #define ARGP_HELP_STD_ERR \ 00457 (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) 00458 /* The standard thing to do after a program command line parsing error, if no 00459 more specific error message has been printed. */ 00460 #define ARGP_HELP_STD_USAGE \ 00461 (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR) 00462 /* The standard thing to do in response to a --help option. */ 00463 #define ARGP_HELP_STD_HELP \ 00464 (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \ 00465 | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR) 00466 00467 /* Output a usage message for ARGP to STREAM. FLAGS are from the set 00468 ARGP_HELP_*. */ 00469 extern void argp_help (__const struct argp *__restrict __argp, 00470 FILE *__restrict __stream, 00471 unsigned __flags, char *__restrict __name) __THROW; 00472 extern void __argp_help (__const struct argp *__restrict __argp, 00473 FILE *__restrict __stream, unsigned __flags, 00474 char *__name) __THROW; 00475 00476 /* The following routines are intended to be called from within an argp 00477 parsing routine (thus taking an argp_state structure as the first 00478 argument). They may or may not print an error message and exit, depending 00479 on the flags in STATE -- in any case, the caller should be prepared for 00480 them *not* to exit, and should return an appropiate error after calling 00481 them. [argp_usage & argp_error should probably be called argp_state_..., 00482 but they're used often enough that they should be short] */ 00483 00484 /* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are 00485 from the set ARGP_HELP_*. */ 00486 extern void argp_state_help (__const struct argp_state *__restrict __state, 00487 FILE *__restrict __stream, 00488 unsigned int __flags) __THROW; 00489 extern void __argp_state_help (__const struct argp_state *__restrict __state, 00490 FILE *__restrict __stream, 00491 unsigned int __flags) __THROW; 00492 00493 /* Possibly output the standard usage message for ARGP to stderr and exit. */ 00494 extern void argp_usage (__const struct argp_state *__state) __THROW; 00495 extern void __argp_usage (__const struct argp_state *__state) __THROW; 00496 00497 /* If appropriate, print the printf string FMT and following args, preceded 00498 by the program name and `:', to stderr, and followed by a `Try ... --help' 00499 message, then exit (1). */ 00500 extern void argp_error (__const struct argp_state *__restrict __state, 00501 __const char *__restrict __fmt, ...) __THROW 00502 PRINTF_STYLE(2,3); 00503 extern void __argp_error (__const struct argp_state *__restrict __state, 00504 __const char *__restrict __fmt, ...) __THROW 00505 PRINTF_STYLE(2,3); 00506 00507 /* Similar to the standard gnu error-reporting function error(), but will 00508 respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print 00509 to STATE->err_stream. This is useful for argument parsing code that is 00510 shared between program startup (when exiting is desired) and runtime 00511 option parsing (when typically an error code is returned instead). The 00512 difference between this function and argp_error is that the latter is for 00513 *parsing errors*, and the former is for other problems that occur during 00514 parsing but don't reflect a (syntactic) problem with the input. */ 00515 extern void argp_failure (__const struct argp_state *__restrict __state, 00516 int __status, int __errnum, 00517 __const char *__restrict __fmt, ...) __THROW 00518 PRINTF_STYLE(4,5); 00519 extern void __argp_failure (__const struct argp_state *__restrict __state, 00520 int __status, int __errnum, 00521 __const char *__restrict __fmt, ...) __THROW 00522 PRINTF_STYLE(4,5); 00523 00524 /* Returns true if the option OPT is a valid short option. */ 00525 extern int _option_is_short (__const struct argp_option *__opt) __THROW; 00526 extern int __option_is_short (__const struct argp_option *__opt) __THROW; 00527 00528 /* Returns true if the option OPT is in fact the last (unused) entry in an 00529 options array. */ 00530 extern int _option_is_end (__const struct argp_option *__opt) __THROW; 00531 extern int __option_is_end (__const struct argp_option *__opt) __THROW; 00532 00533 /* Return the input field for ARGP in the parser corresponding to STATE; used 00534 by the help routines. */ 00535 extern void *_argp_input (__const struct argp *__restrict __argp, 00536 __const struct argp_state *__restrict __state) 00537 __THROW; 00538 extern void *__argp_input (__const struct argp *__restrict __argp, 00539 __const struct argp_state *__restrict __state) 00540 __THROW; 00541 00542 /* Used for extracting the program name from argv[0] */ 00543 extern char *_argp_basename(char *name) __THROW; 00544 extern char *__argp_basename(char *name) __THROW; 00545 00546 /* Getting the program name given an argp state */ 00547 extern char * 00548 _argp_short_program_name(const struct argp_state *state) __THROW; 00549 extern char * 00550 __argp_short_program_name(const struct argp_state *state) __THROW; 00551 00552 00553 #ifdef __USE_EXTERN_INLINES 00554 00555 # if !_LIBC 00556 # define __argp_usage argp_usage 00557 # define __argp_state_help argp_state_help 00558 # define __option_is_short _option_is_short 00559 # define __option_is_end _option_is_end 00560 # endif 00561 00562 # ifndef ARGP_EI 00563 # define ARGP_EI extern __inline__ 00564 # endif 00565 00566 ARGP_EI void 00567 __argp_usage (__const struct argp_state *__state) 00568 { 00569 __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE); 00570 } 00571 00572 ARGP_EI int 00573 __option_is_short (__const struct argp_option *__opt) 00574 { 00575 if (__opt->flags & OPTION_DOC) 00576 return 0; 00577 else 00578 { 00579 int __key = __opt->key; 00580 return __key > 0 && isprint (__key); 00581 } 00582 } 00583 00584 ARGP_EI int 00585 __option_is_end (__const struct argp_option *__opt) 00586 { 00587 return !__opt->key && !__opt->name && !__opt->doc && !__opt->group; 00588 } 00589 00590 # if !_LIBC 00591 # undef __argp_usage 00592 # undef __argp_state_help 00593 # undef __option_is_short 00594 # undef __option_is_end 00595 # endif 00596 #endif /* Use extern inlines. */ 00597 00598 #ifdef __cplusplus 00599 } 00600 #endif 00601 00602 #endif /* argp.h */