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