1*86d7f5d3SJohn Marino /* Internal declarations for getopt. 2*86d7f5d3SJohn Marino Copyright (C) 1989-1994,1996-1999,2001,2003,2004 3*86d7f5d3SJohn Marino Free Software Foundation, Inc. 4*86d7f5d3SJohn Marino This file is part of the GNU C Library. 5*86d7f5d3SJohn Marino 6*86d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify 7*86d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by 8*86d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option) 9*86d7f5d3SJohn Marino any later version. 10*86d7f5d3SJohn Marino 11*86d7f5d3SJohn Marino This program is distributed in the hope that it will be useful, 12*86d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 13*86d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*86d7f5d3SJohn Marino GNU General Public License for more details. 15*86d7f5d3SJohn Marino 16*86d7f5d3SJohn Marino You should have received a copy of the GNU General Public License along 17*86d7f5d3SJohn Marino with this program; if not, write to the Free Software Foundation, 18*86d7f5d3SJohn Marino Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 19*86d7f5d3SJohn Marino 20*86d7f5d3SJohn Marino #ifndef _GETOPT_INT_H 21*86d7f5d3SJohn Marino #define _GETOPT_INT_H 1 22*86d7f5d3SJohn Marino 23*86d7f5d3SJohn Marino extern int _getopt_internal (int ___argc, char **___argv, 24*86d7f5d3SJohn Marino const char *__shortopts, 25*86d7f5d3SJohn Marino const struct option *__longopts, int *__longind, 26*86d7f5d3SJohn Marino int __long_only, int __posixly_correct); 27*86d7f5d3SJohn Marino 28*86d7f5d3SJohn Marino 29*86d7f5d3SJohn Marino /* Reentrant versions which can handle parsing multiple argument 30*86d7f5d3SJohn Marino vectors at the same time. */ 31*86d7f5d3SJohn Marino 32*86d7f5d3SJohn Marino /* Data type for reentrant functions. */ 33*86d7f5d3SJohn Marino struct _getopt_data 34*86d7f5d3SJohn Marino { 35*86d7f5d3SJohn Marino /* These have exactly the same meaning as the corresponding global 36*86d7f5d3SJohn Marino variables, except that they are used for the reentrant 37*86d7f5d3SJohn Marino versions of getopt. */ 38*86d7f5d3SJohn Marino int optind; 39*86d7f5d3SJohn Marino int opterr; 40*86d7f5d3SJohn Marino int optopt; 41*86d7f5d3SJohn Marino char *optarg; 42*86d7f5d3SJohn Marino 43*86d7f5d3SJohn Marino /* Internal members. */ 44*86d7f5d3SJohn Marino 45*86d7f5d3SJohn Marino /* True if the internal members have been initialized. */ 46*86d7f5d3SJohn Marino int __initialized; 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino /* The next char to be scanned in the option-element 49*86d7f5d3SJohn Marino in which the last option character we returned was found. 50*86d7f5d3SJohn Marino This allows us to pick up the scan where we left off. 51*86d7f5d3SJohn Marino 52*86d7f5d3SJohn Marino If this is zero, or a null string, it means resume the scan 53*86d7f5d3SJohn Marino by advancing to the next ARGV-element. */ 54*86d7f5d3SJohn Marino char *__nextchar; 55*86d7f5d3SJohn Marino 56*86d7f5d3SJohn Marino /* Describe how to deal with options that follow non-option ARGV-elements. 57*86d7f5d3SJohn Marino 58*86d7f5d3SJohn Marino If the caller did not specify anything, 59*86d7f5d3SJohn Marino the default is REQUIRE_ORDER if the environment variable 60*86d7f5d3SJohn Marino POSIXLY_CORRECT is defined, PERMUTE otherwise. 61*86d7f5d3SJohn Marino 62*86d7f5d3SJohn Marino REQUIRE_ORDER means don't recognize them as options; 63*86d7f5d3SJohn Marino stop option processing when the first non-option is seen. 64*86d7f5d3SJohn Marino This is what Unix does. 65*86d7f5d3SJohn Marino This mode of operation is selected by either setting the environment 66*86d7f5d3SJohn Marino variable POSIXLY_CORRECT, or using `+' as the first character 67*86d7f5d3SJohn Marino of the list of option characters, or by calling getopt. 68*86d7f5d3SJohn Marino 69*86d7f5d3SJohn Marino PERMUTE is the default. We permute the contents of ARGV as we 70*86d7f5d3SJohn Marino scan, so that eventually all the non-options are at the end. 71*86d7f5d3SJohn Marino This allows options to be given in any order, even with programs 72*86d7f5d3SJohn Marino that were not written to expect this. 73*86d7f5d3SJohn Marino 74*86d7f5d3SJohn Marino RETURN_IN_ORDER is an option available to programs that were 75*86d7f5d3SJohn Marino written to expect options and other ARGV-elements in any order 76*86d7f5d3SJohn Marino and that care about the ordering of the two. We describe each 77*86d7f5d3SJohn Marino non-option ARGV-element as if it were the argument of an option 78*86d7f5d3SJohn Marino with character code 1. Using `-' as the first character of the 79*86d7f5d3SJohn Marino list of option characters selects this mode of operation. 80*86d7f5d3SJohn Marino 81*86d7f5d3SJohn Marino The special argument `--' forces an end of option-scanning regardless 82*86d7f5d3SJohn Marino of the value of `ordering'. In the case of RETURN_IN_ORDER, only 83*86d7f5d3SJohn Marino `--' can cause `getopt' to return -1 with `optind' != ARGC. */ 84*86d7f5d3SJohn Marino 85*86d7f5d3SJohn Marino enum 86*86d7f5d3SJohn Marino { 87*86d7f5d3SJohn Marino REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER 88*86d7f5d3SJohn Marino } __ordering; 89*86d7f5d3SJohn Marino 90*86d7f5d3SJohn Marino /* If the POSIXLY_CORRECT environment variable is set 91*86d7f5d3SJohn Marino or getopt was called. */ 92*86d7f5d3SJohn Marino int __posixly_correct; 93*86d7f5d3SJohn Marino 94*86d7f5d3SJohn Marino 95*86d7f5d3SJohn Marino /* Handle permutation of arguments. */ 96*86d7f5d3SJohn Marino 97*86d7f5d3SJohn Marino /* Describe the part of ARGV that contains non-options that have 98*86d7f5d3SJohn Marino been skipped. `first_nonopt' is the index in ARGV of the first 99*86d7f5d3SJohn Marino of them; `last_nonopt' is the index after the last of them. */ 100*86d7f5d3SJohn Marino 101*86d7f5d3SJohn Marino int __first_nonopt; 102*86d7f5d3SJohn Marino int __last_nonopt; 103*86d7f5d3SJohn Marino 104*86d7f5d3SJohn Marino #if defined _LIBC && defined USE_NONOPTION_FLAGS 105*86d7f5d3SJohn Marino int __nonoption_flags_max_len; 106*86d7f5d3SJohn Marino int __nonoption_flags_len; 107*86d7f5d3SJohn Marino # endif 108*86d7f5d3SJohn Marino }; 109*86d7f5d3SJohn Marino 110*86d7f5d3SJohn Marino /* The initializer is necessary to set OPTIND and OPTERR to their 111*86d7f5d3SJohn Marino default values and to clear the initialization flag. */ 112*86d7f5d3SJohn Marino #define _GETOPT_DATA_INITIALIZER { 1, 1 } 113*86d7f5d3SJohn Marino 114*86d7f5d3SJohn Marino extern int _getopt_internal_r (int ___argc, char **___argv, 115*86d7f5d3SJohn Marino const char *__shortopts, 116*86d7f5d3SJohn Marino const struct option *__longopts, int *__longind, 117*86d7f5d3SJohn Marino int __long_only, int __posixly_correct, 118*86d7f5d3SJohn Marino struct _getopt_data *__data); 119*86d7f5d3SJohn Marino 120*86d7f5d3SJohn Marino extern int _getopt_long_r (int ___argc, char **___argv, 121*86d7f5d3SJohn Marino const char *__shortopts, 122*86d7f5d3SJohn Marino const struct option *__longopts, int *__longind, 123*86d7f5d3SJohn Marino struct _getopt_data *__data); 124*86d7f5d3SJohn Marino 125*86d7f5d3SJohn Marino extern int _getopt_long_only_r (int ___argc, char **___argv, 126*86d7f5d3SJohn Marino const char *__shortopts, 127*86d7f5d3SJohn Marino const struct option *__longopts, 128*86d7f5d3SJohn Marino int *__longind, 129*86d7f5d3SJohn Marino struct _getopt_data *__data); 130*86d7f5d3SJohn Marino 131*86d7f5d3SJohn Marino #endif /* getopt_int.h */ 132