1*86b64dcbSAndroid Build Coastguard Worker /* Declarations for getopt. 2*86b64dcbSAndroid Build Coastguard Worker Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. 3*86b64dcbSAndroid Build Coastguard Worker This file is part of the GNU C Library. 4*86b64dcbSAndroid Build Coastguard Worker 5*86b64dcbSAndroid Build Coastguard Worker The GNU C Library is free software; you can redistribute it and/or 6*86b64dcbSAndroid Build Coastguard Worker modify it under the terms of the GNU Lesser General Public 7*86b64dcbSAndroid Build Coastguard Worker License as published by the Free Software Foundation; either 8*86b64dcbSAndroid Build Coastguard Worker version 2.1 of the License, or (at your option) any later version. 9*86b64dcbSAndroid Build Coastguard Worker 10*86b64dcbSAndroid Build Coastguard Worker The GNU C Library is distributed in the hope that it will be useful, 11*86b64dcbSAndroid Build Coastguard Worker but WITHOUT ANY WARRANTY; without even the implied warranty of 12*86b64dcbSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13*86b64dcbSAndroid Build Coastguard Worker Lesser General Public License for more details. 14*86b64dcbSAndroid Build Coastguard Worker 15*86b64dcbSAndroid Build Coastguard Worker You should have received a copy of the GNU Lesser General Public 16*86b64dcbSAndroid Build Coastguard Worker License along with the GNU C Library; if not, write to the Free 17*86b64dcbSAndroid Build Coastguard Worker Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18*86b64dcbSAndroid Build Coastguard Worker 02111-1307 USA. */ 19*86b64dcbSAndroid Build Coastguard Worker 20*86b64dcbSAndroid Build Coastguard Worker #ifndef _GETOPT_H 21*86b64dcbSAndroid Build Coastguard Worker 22*86b64dcbSAndroid Build Coastguard Worker #ifndef __need_getopt 23*86b64dcbSAndroid Build Coastguard Worker # define _GETOPT_H 1 24*86b64dcbSAndroid Build Coastguard Worker #endif 25*86b64dcbSAndroid Build Coastguard Worker 26*86b64dcbSAndroid Build Coastguard Worker /* If __GNU_LIBRARY__ is not already defined, either we are being used 27*86b64dcbSAndroid Build Coastguard Worker standalone, or this is the first header included in the source file. 28*86b64dcbSAndroid Build Coastguard Worker If we are being used with glibc, we need to include <features.h>, but 29*86b64dcbSAndroid Build Coastguard Worker that does not exist if we are standalone. So: if __GNU_LIBRARY__ is 30*86b64dcbSAndroid Build Coastguard Worker not defined, include <ctype.h>, which will pull in <features.h> for us 31*86b64dcbSAndroid Build Coastguard Worker if it's from glibc. (Why ctype.h? It's guaranteed to exist and it 32*86b64dcbSAndroid Build Coastguard Worker doesn't flood the namespace with stuff the way some other headers do.) */ 33*86b64dcbSAndroid Build Coastguard Worker #if !defined __GNU_LIBRARY__ 34*86b64dcbSAndroid Build Coastguard Worker # include <ctype.h> 35*86b64dcbSAndroid Build Coastguard Worker #endif 36*86b64dcbSAndroid Build Coastguard Worker 37*86b64dcbSAndroid Build Coastguard Worker #ifdef __cplusplus 38*86b64dcbSAndroid Build Coastguard Worker extern "C" { 39*86b64dcbSAndroid Build Coastguard Worker #endif 40*86b64dcbSAndroid Build Coastguard Worker 41*86b64dcbSAndroid Build Coastguard Worker /* For communication from `getopt' to the caller. 42*86b64dcbSAndroid Build Coastguard Worker When `getopt' finds an option that takes an argument, 43*86b64dcbSAndroid Build Coastguard Worker the argument value is returned here. 44*86b64dcbSAndroid Build Coastguard Worker Also, when `ordering' is RETURN_IN_ORDER, 45*86b64dcbSAndroid Build Coastguard Worker each non-option ARGV-element is returned here. */ 46*86b64dcbSAndroid Build Coastguard Worker 47*86b64dcbSAndroid Build Coastguard Worker extern char *optarg; 48*86b64dcbSAndroid Build Coastguard Worker 49*86b64dcbSAndroid Build Coastguard Worker /* Index in ARGV of the next element to be scanned. 50*86b64dcbSAndroid Build Coastguard Worker This is used for communication to and from the caller 51*86b64dcbSAndroid Build Coastguard Worker and for communication between successive calls to `getopt'. 52*86b64dcbSAndroid Build Coastguard Worker 53*86b64dcbSAndroid Build Coastguard Worker On entry to `getopt', zero means this is the first call; initialize. 54*86b64dcbSAndroid Build Coastguard Worker 55*86b64dcbSAndroid Build Coastguard Worker When `getopt' returns -1, this is the index of the first of the 56*86b64dcbSAndroid Build Coastguard Worker non-option elements that the caller should itself scan. 57*86b64dcbSAndroid Build Coastguard Worker 58*86b64dcbSAndroid Build Coastguard Worker Otherwise, `optind' communicates from one call to the next 59*86b64dcbSAndroid Build Coastguard Worker how much of ARGV has been scanned so far. */ 60*86b64dcbSAndroid Build Coastguard Worker 61*86b64dcbSAndroid Build Coastguard Worker extern int optind; 62*86b64dcbSAndroid Build Coastguard Worker 63*86b64dcbSAndroid Build Coastguard Worker /* Callers store zero here to inhibit the error message `getopt' prints 64*86b64dcbSAndroid Build Coastguard Worker for unrecognized options. */ 65*86b64dcbSAndroid Build Coastguard Worker 66*86b64dcbSAndroid Build Coastguard Worker extern int opterr; 67*86b64dcbSAndroid Build Coastguard Worker 68*86b64dcbSAndroid Build Coastguard Worker /* Set to an option character which was unrecognized. */ 69*86b64dcbSAndroid Build Coastguard Worker 70*86b64dcbSAndroid Build Coastguard Worker extern int optopt; 71*86b64dcbSAndroid Build Coastguard Worker 72*86b64dcbSAndroid Build Coastguard Worker #ifndef __need_getopt 73*86b64dcbSAndroid Build Coastguard Worker /* Describe the long-named options requested by the application. 74*86b64dcbSAndroid Build Coastguard Worker The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 75*86b64dcbSAndroid Build Coastguard Worker of `struct option' terminated by an element containing a name which is 76*86b64dcbSAndroid Build Coastguard Worker zero. 77*86b64dcbSAndroid Build Coastguard Worker 78*86b64dcbSAndroid Build Coastguard Worker The field `has_arg' is: 79*86b64dcbSAndroid Build Coastguard Worker no_argument (or 0) if the option does not take an argument, 80*86b64dcbSAndroid Build Coastguard Worker required_argument (or 1) if the option requires an argument, 81*86b64dcbSAndroid Build Coastguard Worker optional_argument (or 2) if the option takes an optional argument. 82*86b64dcbSAndroid Build Coastguard Worker 83*86b64dcbSAndroid Build Coastguard Worker If the field `flag' is not NULL, it points to a variable that is set 84*86b64dcbSAndroid Build Coastguard Worker to the value given in the field `val' when the option is found, but 85*86b64dcbSAndroid Build Coastguard Worker left unchanged if the option is not found. 86*86b64dcbSAndroid Build Coastguard Worker 87*86b64dcbSAndroid Build Coastguard Worker To have a long-named option do something other than set an `int' to 88*86b64dcbSAndroid Build Coastguard Worker a compiled-in constant, such as set a value from `optarg', set the 89*86b64dcbSAndroid Build Coastguard Worker option's `flag' field to zero and its `val' field to a nonzero 90*86b64dcbSAndroid Build Coastguard Worker value (the equivalent single-letter option character, if there is 91*86b64dcbSAndroid Build Coastguard Worker one). For long options that have a zero `flag' field, `getopt' 92*86b64dcbSAndroid Build Coastguard Worker returns the contents of the `val' field. */ 93*86b64dcbSAndroid Build Coastguard Worker 94*86b64dcbSAndroid Build Coastguard Worker struct option 95*86b64dcbSAndroid Build Coastguard Worker { 96*86b64dcbSAndroid Build Coastguard Worker # if (defined __STDC__ && __STDC__) || defined __cplusplus 97*86b64dcbSAndroid Build Coastguard Worker const char *name; 98*86b64dcbSAndroid Build Coastguard Worker # else 99*86b64dcbSAndroid Build Coastguard Worker char *name; 100*86b64dcbSAndroid Build Coastguard Worker # endif 101*86b64dcbSAndroid Build Coastguard Worker /* has_arg can't be an enum because some compilers complain about 102*86b64dcbSAndroid Build Coastguard Worker type mismatches in all the code that assumes it is an int. */ 103*86b64dcbSAndroid Build Coastguard Worker int has_arg; 104*86b64dcbSAndroid Build Coastguard Worker int *flag; 105*86b64dcbSAndroid Build Coastguard Worker int val; 106*86b64dcbSAndroid Build Coastguard Worker }; 107*86b64dcbSAndroid Build Coastguard Worker 108*86b64dcbSAndroid Build Coastguard Worker /* Names for the values of the `has_arg' field of `struct option'. */ 109*86b64dcbSAndroid Build Coastguard Worker 110*86b64dcbSAndroid Build Coastguard Worker # define no_argument 0 111*86b64dcbSAndroid Build Coastguard Worker # define required_argument 1 112*86b64dcbSAndroid Build Coastguard Worker # define optional_argument 2 113*86b64dcbSAndroid Build Coastguard Worker #endif /* need getopt */ 114*86b64dcbSAndroid Build Coastguard Worker 115*86b64dcbSAndroid Build Coastguard Worker 116*86b64dcbSAndroid Build Coastguard Worker /* Get definitions and prototypes for functions to process the 117*86b64dcbSAndroid Build Coastguard Worker arguments in ARGV (ARGC of them, minus the program name) for 118*86b64dcbSAndroid Build Coastguard Worker options given in OPTS. 119*86b64dcbSAndroid Build Coastguard Worker 120*86b64dcbSAndroid Build Coastguard Worker Return the option character from OPTS just read. Return -1 when 121*86b64dcbSAndroid Build Coastguard Worker there are no more options. For unrecognized options, or options 122*86b64dcbSAndroid Build Coastguard Worker missing arguments, `optopt' is set to the option letter, and '?' is 123*86b64dcbSAndroid Build Coastguard Worker returned. 124*86b64dcbSAndroid Build Coastguard Worker 125*86b64dcbSAndroid Build Coastguard Worker The OPTS string is a list of characters which are recognized option 126*86b64dcbSAndroid Build Coastguard Worker letters, optionally followed by colons, specifying that that letter 127*86b64dcbSAndroid Build Coastguard Worker takes an argument, to be placed in `optarg'. 128*86b64dcbSAndroid Build Coastguard Worker 129*86b64dcbSAndroid Build Coastguard Worker If a letter in OPTS is followed by two colons, its argument is 130*86b64dcbSAndroid Build Coastguard Worker optional. This behavior is specific to the GNU `getopt'. 131*86b64dcbSAndroid Build Coastguard Worker 132*86b64dcbSAndroid Build Coastguard Worker The argument `--' causes premature termination of argument 133*86b64dcbSAndroid Build Coastguard Worker scanning, explicitly telling `getopt' that there are no more 134*86b64dcbSAndroid Build Coastguard Worker options. 135*86b64dcbSAndroid Build Coastguard Worker 136*86b64dcbSAndroid Build Coastguard Worker If OPTS begins with `--', then non-option arguments are treated as 137*86b64dcbSAndroid Build Coastguard Worker arguments to the option '\0'. This behavior is specific to the GNU 138*86b64dcbSAndroid Build Coastguard Worker `getopt'. */ 139*86b64dcbSAndroid Build Coastguard Worker 140*86b64dcbSAndroid Build Coastguard Worker #if (defined __STDC__ && __STDC__) || defined __cplusplus 141*86b64dcbSAndroid Build Coastguard Worker # ifdef __GNU_LIBRARY__ 142*86b64dcbSAndroid Build Coastguard Worker /* Many other libraries have conflicting prototypes for getopt, with 143*86b64dcbSAndroid Build Coastguard Worker differences in the consts, in stdlib.h. To avoid compilation 144*86b64dcbSAndroid Build Coastguard Worker errors, only prototype getopt for the GNU C library. */ 145*86b64dcbSAndroid Build Coastguard Worker extern int getopt (int __argc, char *const *__argv, const char *__shortopts); 146*86b64dcbSAndroid Build Coastguard Worker # else /* not __GNU_LIBRARY__ */ 147*86b64dcbSAndroid Build Coastguard Worker extern int getopt (); 148*86b64dcbSAndroid Build Coastguard Worker # endif /* __GNU_LIBRARY__ */ 149*86b64dcbSAndroid Build Coastguard Worker 150*86b64dcbSAndroid Build Coastguard Worker # ifndef __need_getopt 151*86b64dcbSAndroid Build Coastguard Worker extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 152*86b64dcbSAndroid Build Coastguard Worker const struct option *__longopts, int *__longind); 153*86b64dcbSAndroid Build Coastguard Worker extern int getopt_long_only (int __argc, char *const *__argv, 154*86b64dcbSAndroid Build Coastguard Worker const char *__shortopts, 155*86b64dcbSAndroid Build Coastguard Worker const struct option *__longopts, int *__longind); 156*86b64dcbSAndroid Build Coastguard Worker 157*86b64dcbSAndroid Build Coastguard Worker /* Internal only. Users should not call this directly. */ 158*86b64dcbSAndroid Build Coastguard Worker extern int _getopt_internal (int __argc, char *const *__argv, 159*86b64dcbSAndroid Build Coastguard Worker const char *__shortopts, 160*86b64dcbSAndroid Build Coastguard Worker const struct option *__longopts, int *__longind, 161*86b64dcbSAndroid Build Coastguard Worker int __long_only); 162*86b64dcbSAndroid Build Coastguard Worker # endif 163*86b64dcbSAndroid Build Coastguard Worker #else /* not __STDC__ */ 164*86b64dcbSAndroid Build Coastguard Worker extern int getopt (); 165*86b64dcbSAndroid Build Coastguard Worker # ifndef __need_getopt 166*86b64dcbSAndroid Build Coastguard Worker extern int getopt_long (); 167*86b64dcbSAndroid Build Coastguard Worker extern int getopt_long_only (); 168*86b64dcbSAndroid Build Coastguard Worker 169*86b64dcbSAndroid Build Coastguard Worker extern int _getopt_internal (); 170*86b64dcbSAndroid Build Coastguard Worker # endif 171*86b64dcbSAndroid Build Coastguard Worker #endif /* __STDC__ */ 172*86b64dcbSAndroid Build Coastguard Worker 173*86b64dcbSAndroid Build Coastguard Worker #ifdef __cplusplus 174*86b64dcbSAndroid Build Coastguard Worker } 175*86b64dcbSAndroid Build Coastguard Worker #endif 176*86b64dcbSAndroid Build Coastguard Worker 177*86b64dcbSAndroid Build Coastguard Worker /* Make sure we later can get all the definitions and declarations. */ 178*86b64dcbSAndroid Build Coastguard Worker #undef __need_getopt 179*86b64dcbSAndroid Build Coastguard Worker 180*86b64dcbSAndroid Build Coastguard Worker #endif /* getopt.h */ 181