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