xref: /aosp_15_r20/external/flac/include/share/getopt.h (revision 600f14f40d737144c998e2ec7a483122d3776fbc)
1*600f14f4SXin Li /*
2*600f14f4SXin Li 	NOTE:
3*600f14f4SXin Li 	I cannot get the vanilla getopt code to work (i.e. compile only what
4*600f14f4SXin Li 	is needed and not duplicate symbols found in the standard library)
5*600f14f4SXin Li 	on all the platforms that FLAC supports.  In particular the gating
6*600f14f4SXin Li 	of code with the ELIDE_CODE #define is not accurate enough on systems
7*600f14f4SXin Li 	that are POSIX but not glibc.  If someone has a patch that works on
8*600f14f4SXin Li 	GNU/Linux, Darwin, AND Solaris please submit it on the project page:
9*600f14f4SXin Li 		https://sourceforge.net/p/flac/patches/
10*600f14f4SXin Li 
11*600f14f4SXin Li 	In the meantime I have munged the global symbols and removed gates
12*600f14f4SXin Li 	around code, while at the same time trying to touch the original as
13*600f14f4SXin Li 	little as possible.
14*600f14f4SXin Li */
15*600f14f4SXin Li /* Declarations for getopt.
16*600f14f4SXin Li    Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc.
17*600f14f4SXin Li    This file is part of the GNU C Library.
18*600f14f4SXin Li 
19*600f14f4SXin Li    The GNU C Library is free software; you can redistribute it and/or
20*600f14f4SXin Li    modify it under the terms of the GNU Library General Public License as
21*600f14f4SXin Li    published by the Free Software Foundation; either version 2 of the
22*600f14f4SXin Li    License, or (at your option) any later version.
23*600f14f4SXin Li 
24*600f14f4SXin Li    The GNU C Library is distributed in the hope that it will be useful,
25*600f14f4SXin Li    but WITHOUT ANY WARRANTY; without even the implied warranty of
26*600f14f4SXin Li    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27*600f14f4SXin Li    Library General Public License for more details.
28*600f14f4SXin Li 
29*600f14f4SXin Li    You should have received a copy of the GNU Library General Public
30*600f14f4SXin Li    License along with the GNU C Library; see the file COPYING.LIB.  If not,
31*600f14f4SXin Li    write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32*600f14f4SXin Li    Boston, MA 02110-1301, USA.  */
33*600f14f4SXin Li 
34*600f14f4SXin Li #ifndef SHARE__GETOPT_H
35*600f14f4SXin Li #define SHARE__GETOPT_H
36*600f14f4SXin Li 
37*600f14f4SXin Li /*[JEC] was:#ifndef __need_getopt*/
38*600f14f4SXin Li /*[JEC] was:# define _GETOPT_H 1*/
39*600f14f4SXin Li /*[JEC] was:#endif*/
40*600f14f4SXin Li 
41*600f14f4SXin Li #ifdef	__cplusplus
42*600f14f4SXin Li extern "C" {
43*600f14f4SXin Li #endif
44*600f14f4SXin Li 
45*600f14f4SXin Li /* For communication from `share__getopt' to the caller.
46*600f14f4SXin Li    When `share__getopt' finds an option that takes an argument,
47*600f14f4SXin Li    the argument value is returned here.
48*600f14f4SXin Li    Also, when `ordering' is RETURN_IN_ORDER,
49*600f14f4SXin Li    each non-option ARGV-element is returned here.  */
50*600f14f4SXin Li 
51*600f14f4SXin Li extern char *share__optarg;
52*600f14f4SXin Li 
53*600f14f4SXin Li /* Index in ARGV of the next element to be scanned.
54*600f14f4SXin Li    This is used for communication to and from the caller
55*600f14f4SXin Li    and for communication between successive calls to `share__getopt'.
56*600f14f4SXin Li 
57*600f14f4SXin Li    On entry to `share__getopt', zero means this is the first call; initialize.
58*600f14f4SXin Li 
59*600f14f4SXin Li    When `share__getopt' returns -1, this is the index of the first of the
60*600f14f4SXin Li    non-option elements that the caller should itself scan.
61*600f14f4SXin Li 
62*600f14f4SXin Li    Otherwise, `share__optind' communicates from one call to the next
63*600f14f4SXin Li    how much of ARGV has been scanned so far.  */
64*600f14f4SXin Li 
65*600f14f4SXin Li extern int share__optind;
66*600f14f4SXin Li 
67*600f14f4SXin Li /* Callers store zero here to inhibit the error message `share__getopt' prints
68*600f14f4SXin Li    for unrecognized options.  */
69*600f14f4SXin Li 
70*600f14f4SXin Li extern int share__opterr;
71*600f14f4SXin Li 
72*600f14f4SXin Li /* Set to an option character which was unrecognized.  */
73*600f14f4SXin Li 
74*600f14f4SXin Li extern int share__optopt;
75*600f14f4SXin Li 
76*600f14f4SXin Li /*[JEC] was:#ifndef __need_getopt */
77*600f14f4SXin Li /* Describe the long-named options requested by the application.
78*600f14f4SXin Li    The LONG_OPTIONS argument to share__getopt_long or share__getopt_long_only is a vector
79*600f14f4SXin Li    of `struct share__option' terminated by an element containing a name which is
80*600f14f4SXin Li    zero.
81*600f14f4SXin Li 
82*600f14f4SXin Li    The field `has_arg' is:
83*600f14f4SXin Li    share__no_argument		(or 0) if the option does not take an argument,
84*600f14f4SXin Li    share__required_argument	(or 1) if the option requires an argument,
85*600f14f4SXin Li    share__optional_argument 	(or 2) if the option takes an optional argument.
86*600f14f4SXin Li 
87*600f14f4SXin Li    If the field `flag' is not NULL, it points to a variable that is set
88*600f14f4SXin Li    to the value given in the field `val' when the option is found, but
89*600f14f4SXin Li    left unchanged if the option is not found.
90*600f14f4SXin Li 
91*600f14f4SXin Li    To have a long-named option do something other than set an `int' to
92*600f14f4SXin Li    a compiled-in constant, such as set a value from `share__optarg', set the
93*600f14f4SXin Li    option's `flag' field to zero and its `val' field to a nonzero
94*600f14f4SXin Li    value (the equivalent single-letter option character, if there is
95*600f14f4SXin Li    one).  For long options that have a zero `flag' field, `share__getopt'
96*600f14f4SXin Li    returns the contents of the `val' field.  */
97*600f14f4SXin Li 
98*600f14f4SXin Li struct share__option
99*600f14f4SXin Li {
100*600f14f4SXin Li # if defined __STDC__ && __STDC__
101*600f14f4SXin Li   const char *name;
102*600f14f4SXin Li # else
103*600f14f4SXin Li   char *name;
104*600f14f4SXin Li # endif
105*600f14f4SXin Li   /* has_arg can't be an enum because some compilers complain about
106*600f14f4SXin Li      type mismatches in all the code that assumes it is an int.  */
107*600f14f4SXin Li   int has_arg;
108*600f14f4SXin Li   int *flag;
109*600f14f4SXin Li   int val;
110*600f14f4SXin Li };
111*600f14f4SXin Li 
112*600f14f4SXin Li /* Names for the values of the `has_arg' field of `struct share__option'.  */
113*600f14f4SXin Li 
114*600f14f4SXin Li # define share__no_argument		0
115*600f14f4SXin Li # define share__required_argument	1
116*600f14f4SXin Li # define share__optional_argument	2
117*600f14f4SXin Li /*[JEC] was:#endif*/	/* need getopt */
118*600f14f4SXin Li 
119*600f14f4SXin Li 
120*600f14f4SXin Li /* Get definitions and prototypes for functions to process the
121*600f14f4SXin Li    arguments in ARGV (ARGC of them, minus the program name) for
122*600f14f4SXin Li    options given in OPTS.
123*600f14f4SXin Li 
124*600f14f4SXin Li    Return the option character from OPTS just read.  Return -1 when
125*600f14f4SXin Li    there are no more options.  For unrecognized options, or options
126*600f14f4SXin Li    missing arguments, `share__optopt' is set to the option letter, and '?' is
127*600f14f4SXin Li    returned.
128*600f14f4SXin Li 
129*600f14f4SXin Li    The OPTS string is a list of characters which are recognized option
130*600f14f4SXin Li    letters, optionally followed by colons, specifying that that letter
131*600f14f4SXin Li    takes an argument, to be placed in `share__optarg'.
132*600f14f4SXin Li 
133*600f14f4SXin Li    If a letter in OPTS is followed by two colons, its argument is
134*600f14f4SXin Li    optional.  This behavior is specific to the GNU `share__getopt'.
135*600f14f4SXin Li 
136*600f14f4SXin Li    The argument `--' causes premature termination of argument
137*600f14f4SXin Li    scanning, explicitly telling `share__getopt' that there are no more
138*600f14f4SXin Li    options.
139*600f14f4SXin Li 
140*600f14f4SXin Li    If OPTS begins with `--', then non-option arguments are treated as
141*600f14f4SXin Li    arguments to the option '\0'.  This behavior is specific to the GNU
142*600f14f4SXin Li    `share__getopt'.  */
143*600f14f4SXin Li 
144*600f14f4SXin Li /*[JEC] was:#if defined __STDC__ && __STDC__*/
145*600f14f4SXin Li /*[JEC] was:# ifdef __GNU_LIBRARY__*/
146*600f14f4SXin Li /* Many other libraries have conflicting prototypes for getopt, with
147*600f14f4SXin Li    differences in the consts, in stdlib.h.  To avoid compilation
148*600f14f4SXin Li    errors, only prototype getopt for the GNU C library.  */
149*600f14f4SXin Li extern int share__getopt (int argc, char *const *argv, const char *shortopts);
150*600f14f4SXin Li /*[JEC] was:# else*/ /* not __GNU_LIBRARY__ */
151*600f14f4SXin Li /*[JEC] was:extern int getopt ();*/
152*600f14f4SXin Li /*[JEC] was:# endif*/ /* __GNU_LIBRARY__ */
153*600f14f4SXin Li 
154*600f14f4SXin Li /*[JEC] was:# ifndef __need_getopt*/
155*600f14f4SXin Li extern int share__getopt_long (int argc, char *const *argv, const char *shortopts,
156*600f14f4SXin Li 		        const struct share__option *longopts, int *longind);
157*600f14f4SXin Li extern int share__getopt_long_only (int argc, char *const *argv,
158*600f14f4SXin Li 			     const char *shortopts,
159*600f14f4SXin Li 		             const struct share__option *longopts, int *longind);
160*600f14f4SXin Li 
161*600f14f4SXin Li /* Internal only.  Users should not call this directly.  */
162*600f14f4SXin Li extern int share___getopt_internal (int argc, char *const *argv,
163*600f14f4SXin Li 			     const char *shortopts,
164*600f14f4SXin Li 		             const struct share__option *longopts, int *longind,
165*600f14f4SXin Li 			     int long_only);
166*600f14f4SXin Li /*[JEC] was:# endif*/
167*600f14f4SXin Li /*[JEC] was:#else*/ /* not __STDC__ */
168*600f14f4SXin Li /*[JEC] was:extern int getopt ();*/
169*600f14f4SXin Li /*[JEC] was:# ifndef __need_getopt*/
170*600f14f4SXin Li /*[JEC] was:extern int getopt_long ();*/
171*600f14f4SXin Li /*[JEC] was:extern int getopt_long_only ();*/
172*600f14f4SXin Li 
173*600f14f4SXin Li /*[JEC] was:extern int _getopt_internal ();*/
174*600f14f4SXin Li /*[JEC] was:# endif*/
175*600f14f4SXin Li /*[JEC] was:#endif*/ /* __STDC__ */
176*600f14f4SXin Li 
177*600f14f4SXin Li #ifdef	__cplusplus
178*600f14f4SXin Li }
179*600f14f4SXin Li #endif
180*600f14f4SXin Li 
181*600f14f4SXin Li /* Make sure we later can get all the definitions and declarations.  */
182*600f14f4SXin Li /*[JEC] was:#undef __need_getopt*/
183*600f14f4SXin Li 
184*600f14f4SXin Li #endif /* getopt.h */
185