1*f0d9efc0Sbeck /* Declarations for getopt. 2*f0d9efc0Sbeck Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3*f0d9efc0Sbeck 4*f0d9efc0Sbeck This program is free software; you can redistribute it and/or 5*f0d9efc0Sbeck modify it under the terms of the GNU Library General Public License 6*f0d9efc0Sbeck as published by the Free Software Foundation; either version 2, or 7*f0d9efc0Sbeck (at your option) any later version. 8*f0d9efc0Sbeck 9*f0d9efc0Sbeck This program is distributed in the hope that it will be useful, 10*f0d9efc0Sbeck but WITHOUT ANY WARRANTY; without even the implied warranty of 11*f0d9efc0Sbeck MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*f0d9efc0Sbeck GNU Library General Public License for more details. 13*f0d9efc0Sbeck 14*f0d9efc0Sbeck You should have received a copy of the GNU Library General Public License 15*f0d9efc0Sbeck along with this program; if not, write to the Free Software 16*f0d9efc0Sbeck Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 17*f0d9efc0Sbeck 18*f0d9efc0Sbeck #ifndef _GETOPT_H 19*f0d9efc0Sbeck #define _GETOPT_H 1 20*f0d9efc0Sbeck 21*f0d9efc0Sbeck #ifdef __cplusplus 22*f0d9efc0Sbeck extern "C" { 23*f0d9efc0Sbeck #endif 24*f0d9efc0Sbeck 25*f0d9efc0Sbeck /* For communication from `getopt' to the caller. 26*f0d9efc0Sbeck When `getopt' finds an option that takes an argument, 27*f0d9efc0Sbeck the argument value is returned here. 28*f0d9efc0Sbeck Also, when `ordering' is RETURN_IN_ORDER, 29*f0d9efc0Sbeck each non-option ARGV-element is returned here. */ 30*f0d9efc0Sbeck 31*f0d9efc0Sbeck extern char *optarg; 32*f0d9efc0Sbeck 33*f0d9efc0Sbeck /* Index in ARGV of the next element to be scanned. 34*f0d9efc0Sbeck This is used for communication to and from the caller 35*f0d9efc0Sbeck and for communication between successive calls to `getopt'. 36*f0d9efc0Sbeck 37*f0d9efc0Sbeck On entry to `getopt', zero means this is the first call; initialize. 38*f0d9efc0Sbeck 39*f0d9efc0Sbeck When `getopt' returns EOF, this is the index of the first of the 40*f0d9efc0Sbeck non-option elements that the caller should itself scan. 41*f0d9efc0Sbeck 42*f0d9efc0Sbeck Otherwise, `optind' communicates from one call to the next 43*f0d9efc0Sbeck how much of ARGV has been scanned so far. */ 44*f0d9efc0Sbeck 45*f0d9efc0Sbeck extern int optind; 46*f0d9efc0Sbeck 47*f0d9efc0Sbeck /* Callers store zero here to inhibit the error message `getopt' prints 48*f0d9efc0Sbeck for unrecognized options. */ 49*f0d9efc0Sbeck 50*f0d9efc0Sbeck extern int opterr; 51*f0d9efc0Sbeck 52*f0d9efc0Sbeck /* Set to an option character which was unrecognized. */ 53*f0d9efc0Sbeck 54*f0d9efc0Sbeck extern int optopt; 55*f0d9efc0Sbeck 56*f0d9efc0Sbeck /* Describe the long-named options requested by the application. 57*f0d9efc0Sbeck The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 58*f0d9efc0Sbeck of `struct option' terminated by an element containing a name which is 59*f0d9efc0Sbeck zero. 60*f0d9efc0Sbeck 61*f0d9efc0Sbeck The field `has_arg' is: 62*f0d9efc0Sbeck no_argument (or 0) if the option does not take an argument, 63*f0d9efc0Sbeck required_argument (or 1) if the option requires an argument, 64*f0d9efc0Sbeck optional_argument (or 2) if the option takes an optional argument. 65*f0d9efc0Sbeck 66*f0d9efc0Sbeck If the field `flag' is not NULL, it points to a variable that is set 67*f0d9efc0Sbeck to the value given in the field `val' when the option is found, but 68*f0d9efc0Sbeck left unchanged if the option is not found. 69*f0d9efc0Sbeck 70*f0d9efc0Sbeck To have a long-named option do something other than set an `int' to 71*f0d9efc0Sbeck a compiled-in constant, such as set a value from `optarg', set the 72*f0d9efc0Sbeck option's `flag' field to zero and its `val' field to a nonzero 73*f0d9efc0Sbeck value (the equivalent single-letter option character, if there is 74*f0d9efc0Sbeck one). For long options that have a zero `flag' field, `getopt' 75*f0d9efc0Sbeck returns the contents of the `val' field. */ 76*f0d9efc0Sbeck 77*f0d9efc0Sbeck struct option 78*f0d9efc0Sbeck { 79*f0d9efc0Sbeck #if __STDC__ 80*f0d9efc0Sbeck const char *name; 81*f0d9efc0Sbeck #else 82*f0d9efc0Sbeck char *name; 83*f0d9efc0Sbeck #endif 84*f0d9efc0Sbeck /* has_arg can't be an enum because some compilers complain about 85*f0d9efc0Sbeck type mismatches in all the code that assumes it is an int. */ 86*f0d9efc0Sbeck int has_arg; 87*f0d9efc0Sbeck int *flag; 88*f0d9efc0Sbeck int val; 89*f0d9efc0Sbeck }; 90*f0d9efc0Sbeck 91*f0d9efc0Sbeck /* Names for the values of the `has_arg' field of `struct option'. */ 92*f0d9efc0Sbeck 93*f0d9efc0Sbeck #define no_argument 0 94*f0d9efc0Sbeck #define required_argument 1 95*f0d9efc0Sbeck #define optional_argument 2 96*f0d9efc0Sbeck 97*f0d9efc0Sbeck #if __STDC__ 98*f0d9efc0Sbeck #if defined(__GNU_LIBRARY__) 99*f0d9efc0Sbeck /* Many other libraries have conflicting prototypes for getopt, with 100*f0d9efc0Sbeck differences in the consts, in stdlib.h. To avoid compilation 101*f0d9efc0Sbeck errors, only prototype getopt for the GNU C library. */ 102*f0d9efc0Sbeck extern int getopt (int argc, char *const *argv, const char *shortopts); 103*f0d9efc0Sbeck #else /* not __GNU_LIBRARY__ */ 104*f0d9efc0Sbeck extern int getopt (); 105*f0d9efc0Sbeck #endif /* not __GNU_LIBRARY__ */ 106*f0d9efc0Sbeck extern int getopt_long (int argc, char *const *argv, const char *shortopts, 107*f0d9efc0Sbeck const struct option *longopts, int *longind); 108*f0d9efc0Sbeck extern int getopt_long_only (int argc, char *const *argv, 109*f0d9efc0Sbeck const char *shortopts, 110*f0d9efc0Sbeck const struct option *longopts, int *longind); 111*f0d9efc0Sbeck 112*f0d9efc0Sbeck /* Internal only. Users should not call this directly. */ 113*f0d9efc0Sbeck extern int _getopt_internal (int argc, char *const *argv, 114*f0d9efc0Sbeck const char *shortopts, 115*f0d9efc0Sbeck const struct option *longopts, int *longind, 116*f0d9efc0Sbeck int long_only); 117*f0d9efc0Sbeck #else /* not __STDC__ */ 118*f0d9efc0Sbeck extern int getopt (); 119*f0d9efc0Sbeck extern int getopt_long (); 120*f0d9efc0Sbeck extern int getopt_long_only (); 121*f0d9efc0Sbeck 122*f0d9efc0Sbeck extern int _getopt_internal (); 123*f0d9efc0Sbeck #endif /* not __STDC__ */ 124*f0d9efc0Sbeck 125*f0d9efc0Sbeck #ifdef __cplusplus 126*f0d9efc0Sbeck } 127*f0d9efc0Sbeck #endif 128*f0d9efc0Sbeck 129*f0d9efc0Sbeck #endif /* _GETOPT_H */ 130