groke6@381: /* from http://www.pwilson.net/getopt.html */ groke6@381: groke6@381: /* getopt.h */ groke6@381: /* Declarations for getopt. groke6@381: Copyright (C) 1989-1994, 1996-1999, 2001 Free Software groke6@381: Foundation, Inc. This file is part of the GNU C Library. groke6@381: groke6@381: The GNU C Library is free software; you can redistribute groke6@381: it and/or modify it under the terms of the GNU Lesser groke6@381: General Public License as published by the Free Software groke6@381: Foundation; either version 2.1 of the License, or groke6@381: (at your option) any later version. groke6@381: groke6@381: The GNU C Library is distributed in the hope that it will groke6@381: be useful, but WITHOUT ANY WARRANTY; without even the groke6@381: implied warranty of MERCHANTABILITY or FITNESS FOR A groke6@381: PARTICULAR PURPOSE. See the GNU Lesser General Public groke6@381: License for more details. groke6@381: groke6@381: You should have received a copy of the GNU Lesser General groke6@381: Public License along with the GNU C Library; if not, write groke6@381: to the Free Software Foundation, Inc., 59 Temple Place, groke6@381: Suite 330, Boston, MA 02111-1307 USA. */ groke6@381: groke6@381: groke6@381: groke6@381: groke6@381: groke6@381: #ifndef _GETOPT_H groke6@381: groke6@381: #ifndef __need_getopt groke6@381: # define _GETOPT_H 1 groke6@381: #endif groke6@381: groke6@381: /* If __GNU_LIBRARY__ is not already defined, either we are being used groke6@381: standalone, or this is the first header included in the source file. groke6@381: If we are being used with glibc, we need to include , but groke6@381: that does not exist if we are standalone. So: if __GNU_LIBRARY__ is groke6@381: not defined, include , which will pull in for us groke6@381: if it's from glibc. (Why ctype.h? It's guaranteed to exist and it groke6@381: doesn't flood the namespace with stuff the way some other headers do.) */ groke6@381: #if !defined __GNU_LIBRARY__ groke6@381: # include groke6@381: #endif groke6@381: groke6@381: #ifdef __cplusplus groke6@381: extern "C" { groke6@381: #endif groke6@381: groke6@381: /* For communication from `getopt' to the caller. groke6@381: When `getopt' finds an option that takes an argument, groke6@381: the argument value is returned here. groke6@381: Also, when `ordering' is RETURN_IN_ORDER, groke6@381: each non-option ARGV-element is returned here. */ groke6@381: groke6@381: extern char *optarg; groke6@381: groke6@381: /* Index in ARGV of the next element to be scanned. groke6@381: This is used for communication to and from the caller groke6@381: and for communication between successive calls to `getopt'. groke6@381: groke6@381: On entry to `getopt', zero means this is the first call; initialize. groke6@381: groke6@381: When `getopt' returns -1, this is the index of the first of the groke6@381: non-option elements that the caller should itself scan. groke6@381: groke6@381: Otherwise, `optind' communicates from one call to the next groke6@381: how much of ARGV has been scanned so far. */ groke6@381: groke6@381: extern int optind; groke6@381: groke6@381: /* Callers store zero here to inhibit the error message `getopt' prints groke6@381: for unrecognized options. */ groke6@381: groke6@381: extern int opterr; groke6@381: groke6@381: /* Set to an option character which was unrecognized. */ groke6@381: groke6@381: extern int optopt; groke6@381: groke6@381: #ifndef __need_getopt groke6@381: /* Describe the long-named options requested by the application. groke6@381: The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector groke6@381: of `struct option' terminated by an element containing a name which is groke6@381: zero. groke6@381: groke6@381: The field `has_arg' is: groke6@381: no_argument (or 0) if the option does not take an argument, groke6@381: required_argument (or 1) if the option requires an argument, groke6@381: optional_argument (or 2) if the option takes an optional argument. groke6@381: groke6@381: If the field `flag' is not NULL, it points to a variable that is set groke6@381: to the value given in the field `val' when the option is found, but groke6@381: left unchanged if the option is not found. groke6@381: groke6@381: To have a long-named option do something other than set an `int' to groke6@381: a compiled-in constant, such as set a value from `optarg', set the groke6@381: option's `flag' field to zero and its `val' field to a nonzero groke6@381: value (the equivalent single-letter option character, if there is groke6@381: one). For long options that have a zero `flag' field, `getopt' groke6@381: returns the contents of the `val' field. */ groke6@381: groke6@381: struct option groke6@381: { groke6@381: # if (defined __STDC__ && __STDC__) || defined __cplusplus groke6@381: const char *name; groke6@381: # else groke6@381: char *name; groke6@381: # endif groke6@381: /* has_arg can't be an enum because some compilers complain about groke6@381: type mismatches in all the code that assumes it is an int. */ groke6@381: int has_arg; groke6@381: int *flag; groke6@381: int val; groke6@381: }; groke6@381: groke6@381: /* Names for the values of the `has_arg' field of `struct option'. */ groke6@381: groke6@381: # define no_argument 0 groke6@381: # define required_argument 1 groke6@381: # define optional_argument 2 groke6@381: #endif /* need getopt */ groke6@381: groke6@381: groke6@381: /* Get definitions and prototypes for functions to process the groke6@381: arguments in ARGV (ARGC of them, minus the program name) for groke6@381: options given in OPTS. groke6@381: groke6@381: Return the option character from OPTS just read. Return -1 when groke6@381: there are no more options. For unrecognized options, or options groke6@381: missing arguments, `optopt' is set to the option letter, and '?' is groke6@381: returned. groke6@381: groke6@381: The OPTS string is a list of characters which are recognized option groke6@381: letters, optionally followed by colons, specifying that that letter groke6@381: takes an argument, to be placed in `optarg'. groke6@381: groke6@381: If a letter in OPTS is followed by two colons, its argument is groke6@381: optional. This behavior is specific to the GNU `getopt'. groke6@381: groke6@381: The argument `--' causes premature termination of argument groke6@381: scanning, explicitly telling `getopt' that there are no more groke6@381: options. groke6@381: groke6@381: If OPTS begins with `--', then non-option arguments are treated as groke6@381: arguments to the option '\0'. This behavior is specific to the GNU groke6@381: `getopt'. */ groke6@381: groke6@381: #if (defined __STDC__ && __STDC__) || defined __cplusplus groke6@381: # ifdef __GNU_LIBRARY__ groke6@381: /* Many other libraries have conflicting prototypes for getopt, with groke6@381: differences in the consts, in stdlib.h. To avoid compilation groke6@381: errors, only prototype getopt for the GNU C library. */ groke6@381: extern int getopt (int ___argc, char *const *___argv, const char *__shortopts); groke6@381: # else /* not __GNU_LIBRARY__ */ groke6@381: extern int getopt (); groke6@381: # endif /* __GNU_LIBRARY__ */ groke6@381: groke6@381: # ifndef __need_getopt groke6@381: extern int getopt_long (int ___argc, char *const *___argv, groke6@381: const char *__shortopts, groke6@381: const struct option *__longopts, int *__longind); groke6@381: extern int getopt_long_only (int ___argc, char *const *___argv, groke6@381: const char *__shortopts, groke6@381: const struct option *__longopts, int *__longind); groke6@381: groke6@381: /* Internal only. Users should not call this directly. */ groke6@381: extern int _getopt_internal (int ___argc, char *const *___argv, groke6@381: const char *__shortopts, groke6@381: const struct option *__longopts, int *__longind, groke6@381: int __long_only); groke6@381: # endif groke6@381: #else /* not __STDC__ */ groke6@381: extern int getopt (); groke6@381: # ifndef __need_getopt groke6@381: extern int getopt_long (); groke6@381: extern int getopt_long_only (); groke6@381: groke6@381: extern int _getopt_internal (); groke6@381: # endif groke6@381: #endif /* __STDC__ */ groke6@381: groke6@381: #ifdef __cplusplus groke6@381: } groke6@381: #endif groke6@381: groke6@381: /* Make sure we later can get all the definitions and declarations. */ groke6@381: #undef __need_getopt groke6@381: groke6@381: #endif /* getopt.h */ groke6@381: