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