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