xref: /aosp_15_r20/external/pciutils/compat/getopt.h (revision c2e0c6b56a71da9abe8df5c8348fb3eb5c2c9251)
1*c2e0c6b5SAndroid Build Coastguard Worker /* Declarations for getopt.
2*c2e0c6b5SAndroid Build Coastguard Worker    Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3*c2e0c6b5SAndroid Build Coastguard Worker 
4*c2e0c6b5SAndroid Build Coastguard Worker    This program is free software; you can redistribute it and/or modify it
5*c2e0c6b5SAndroid Build Coastguard Worker    under the terms of the GNU General Public License as published by the
6*c2e0c6b5SAndroid Build Coastguard Worker    Free Software Foundation; either version 2, or (at your option) any
7*c2e0c6b5SAndroid Build Coastguard Worker    later version.
8*c2e0c6b5SAndroid Build Coastguard Worker 
9*c2e0c6b5SAndroid Build Coastguard Worker    This program is distributed in the hope that it will be useful,
10*c2e0c6b5SAndroid Build Coastguard Worker    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*c2e0c6b5SAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*c2e0c6b5SAndroid Build Coastguard Worker    GNU General Public License for more details.
13*c2e0c6b5SAndroid Build Coastguard Worker 
14*c2e0c6b5SAndroid Build Coastguard Worker    You should have received a copy of the GNU General Public License
15*c2e0c6b5SAndroid Build Coastguard Worker    along with this program; if not, write to the Free Software
16*c2e0c6b5SAndroid Build Coastguard Worker    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
17*c2e0c6b5SAndroid Build Coastguard Worker 
18*c2e0c6b5SAndroid Build Coastguard Worker #ifndef _GETOPT_H
19*c2e0c6b5SAndroid Build Coastguard Worker #define _GETOPT_H 1
20*c2e0c6b5SAndroid Build Coastguard Worker 
21*c2e0c6b5SAndroid Build Coastguard Worker #ifdef	__cplusplus
22*c2e0c6b5SAndroid Build Coastguard Worker extern "C" {
23*c2e0c6b5SAndroid Build Coastguard Worker #endif
24*c2e0c6b5SAndroid Build Coastguard Worker 
25*c2e0c6b5SAndroid Build Coastguard Worker /* For communication from `getopt' to the caller.
26*c2e0c6b5SAndroid Build Coastguard Worker    When `getopt' finds an option that takes an argument,
27*c2e0c6b5SAndroid Build Coastguard Worker    the argument value is returned here.
28*c2e0c6b5SAndroid Build Coastguard Worker    Also, when `ordering' is RETURN_IN_ORDER,
29*c2e0c6b5SAndroid Build Coastguard Worker    each non-option ARGV-element is returned here.  */
30*c2e0c6b5SAndroid Build Coastguard Worker 
31*c2e0c6b5SAndroid Build Coastguard Worker extern char *optarg;
32*c2e0c6b5SAndroid Build Coastguard Worker 
33*c2e0c6b5SAndroid Build Coastguard Worker /* Index in ARGV of the next element to be scanned.
34*c2e0c6b5SAndroid Build Coastguard Worker    This is used for communication to and from the caller
35*c2e0c6b5SAndroid Build Coastguard Worker    and for communication between successive calls to `getopt'.
36*c2e0c6b5SAndroid Build Coastguard Worker 
37*c2e0c6b5SAndroid Build Coastguard Worker    On entry to `getopt', zero means this is the first call; initialize.
38*c2e0c6b5SAndroid Build Coastguard Worker 
39*c2e0c6b5SAndroid Build Coastguard Worker    When `getopt' returns EOF, this is the index of the first of the
40*c2e0c6b5SAndroid Build Coastguard Worker    non-option elements that the caller should itself scan.
41*c2e0c6b5SAndroid Build Coastguard Worker 
42*c2e0c6b5SAndroid Build Coastguard Worker    Otherwise, `optind' communicates from one call to the next
43*c2e0c6b5SAndroid Build Coastguard Worker    how much of ARGV has been scanned so far.  */
44*c2e0c6b5SAndroid Build Coastguard Worker 
45*c2e0c6b5SAndroid Build Coastguard Worker extern int optind;
46*c2e0c6b5SAndroid Build Coastguard Worker 
47*c2e0c6b5SAndroid Build Coastguard Worker /* Callers store zero here to inhibit the error message `getopt' prints
48*c2e0c6b5SAndroid Build Coastguard Worker    for unrecognized options.  */
49*c2e0c6b5SAndroid Build Coastguard Worker 
50*c2e0c6b5SAndroid Build Coastguard Worker extern int opterr;
51*c2e0c6b5SAndroid Build Coastguard Worker 
52*c2e0c6b5SAndroid Build Coastguard Worker /* Set to an option character which was unrecognized.  */
53*c2e0c6b5SAndroid Build Coastguard Worker 
54*c2e0c6b5SAndroid Build Coastguard Worker extern int optopt;
55*c2e0c6b5SAndroid Build Coastguard Worker 
56*c2e0c6b5SAndroid Build Coastguard Worker /* Describe the long-named options requested by the application.
57*c2e0c6b5SAndroid Build Coastguard Worker    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
58*c2e0c6b5SAndroid Build Coastguard Worker    of `struct option' terminated by an element containing a name which is
59*c2e0c6b5SAndroid Build Coastguard Worker    zero.
60*c2e0c6b5SAndroid Build Coastguard Worker 
61*c2e0c6b5SAndroid Build Coastguard Worker    The field `has_arg' is:
62*c2e0c6b5SAndroid Build Coastguard Worker    no_argument		(or 0) if the option does not take an argument,
63*c2e0c6b5SAndroid Build Coastguard Worker    required_argument	(or 1) if the option requires an argument,
64*c2e0c6b5SAndroid Build Coastguard Worker    optional_argument 	(or 2) if the option takes an optional argument.
65*c2e0c6b5SAndroid Build Coastguard Worker 
66*c2e0c6b5SAndroid Build Coastguard Worker    If the field `flag' is not NULL, it points to a variable that is set
67*c2e0c6b5SAndroid Build Coastguard Worker    to the value given in the field `val' when the option is found, but
68*c2e0c6b5SAndroid Build Coastguard Worker    left unchanged if the option is not found.
69*c2e0c6b5SAndroid Build Coastguard Worker 
70*c2e0c6b5SAndroid Build Coastguard Worker    To have a long-named option do something other than set an `int' to
71*c2e0c6b5SAndroid Build Coastguard Worker    a compiled-in constant, such as set a value from `optarg', set the
72*c2e0c6b5SAndroid Build Coastguard Worker    option's `flag' field to zero and its `val' field to a nonzero
73*c2e0c6b5SAndroid Build Coastguard Worker    value (the equivalent single-letter option character, if there is
74*c2e0c6b5SAndroid Build Coastguard Worker    one).  For long options that have a zero `flag' field, `getopt'
75*c2e0c6b5SAndroid Build Coastguard Worker    returns the contents of the `val' field.  */
76*c2e0c6b5SAndroid Build Coastguard Worker 
77*c2e0c6b5SAndroid Build Coastguard Worker struct option
78*c2e0c6b5SAndroid Build Coastguard Worker {
79*c2e0c6b5SAndroid Build Coastguard Worker #if	__STDC__
80*c2e0c6b5SAndroid Build Coastguard Worker   const char *name;
81*c2e0c6b5SAndroid Build Coastguard Worker #else
82*c2e0c6b5SAndroid Build Coastguard Worker   char *name;
83*c2e0c6b5SAndroid Build Coastguard Worker #endif
84*c2e0c6b5SAndroid Build Coastguard Worker   /* has_arg can't be an enum because some compilers complain about
85*c2e0c6b5SAndroid Build Coastguard Worker      type mismatches in all the code that assumes it is an int.  */
86*c2e0c6b5SAndroid Build Coastguard Worker   int has_arg;
87*c2e0c6b5SAndroid Build Coastguard Worker   int *flag;
88*c2e0c6b5SAndroid Build Coastguard Worker   int val;
89*c2e0c6b5SAndroid Build Coastguard Worker };
90*c2e0c6b5SAndroid Build Coastguard Worker 
91*c2e0c6b5SAndroid Build Coastguard Worker /* Names for the values of the `has_arg' field of `struct option'.  */
92*c2e0c6b5SAndroid Build Coastguard Worker 
93*c2e0c6b5SAndroid Build Coastguard Worker #define	no_argument		0
94*c2e0c6b5SAndroid Build Coastguard Worker #define required_argument	1
95*c2e0c6b5SAndroid Build Coastguard Worker #define optional_argument	2
96*c2e0c6b5SAndroid Build Coastguard Worker 
97*c2e0c6b5SAndroid Build Coastguard Worker #if __STDC__ || defined(PROTO)
98*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt (int argc, char *const *argv, const char *shortopts);
99*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt_long (int argc, char *const *argv, const char *shortopts,
100*c2e0c6b5SAndroid Build Coastguard Worker 		        const struct option *longopts, int *longind);
101*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt_long_only (int argc, char *const *argv,
102*c2e0c6b5SAndroid Build Coastguard Worker 			     const char *shortopts,
103*c2e0c6b5SAndroid Build Coastguard Worker 		             const struct option *longopts, int *longind);
104*c2e0c6b5SAndroid Build Coastguard Worker 
105*c2e0c6b5SAndroid Build Coastguard Worker /* Internal only.  Users should not call this directly.  */
106*c2e0c6b5SAndroid Build Coastguard Worker extern int _getopt_internal (int argc, char *const *argv,
107*c2e0c6b5SAndroid Build Coastguard Worker 			     const char *shortopts,
108*c2e0c6b5SAndroid Build Coastguard Worker 		             const struct option *longopts, int *longind,
109*c2e0c6b5SAndroid Build Coastguard Worker 			     int long_only);
110*c2e0c6b5SAndroid Build Coastguard Worker #else /* not __STDC__ */
111*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt ();
112*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt_long ();
113*c2e0c6b5SAndroid Build Coastguard Worker extern int getopt_long_only ();
114*c2e0c6b5SAndroid Build Coastguard Worker 
115*c2e0c6b5SAndroid Build Coastguard Worker extern int _getopt_internal ();
116*c2e0c6b5SAndroid Build Coastguard Worker #endif /* not __STDC__ */
117*c2e0c6b5SAndroid Build Coastguard Worker 
118*c2e0c6b5SAndroid Build Coastguard Worker #ifdef	__cplusplus
119*c2e0c6b5SAndroid Build Coastguard Worker }
120*c2e0c6b5SAndroid Build Coastguard Worker #endif
121*c2e0c6b5SAndroid Build Coastguard Worker 
122*c2e0c6b5SAndroid Build Coastguard Worker #endif /* _GETOPT_H */
123