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