1*6ea1f93eSDaniel Fojt /* Declarations for getopt (GNU extensions).
2*6ea1f93eSDaniel Fojt    Copyright (C) 1989-2018 Free Software Foundation, Inc.
3*6ea1f93eSDaniel Fojt    This file is part of the GNU C Library and is also part of gnulib.
4*6ea1f93eSDaniel Fojt    Patches to this file should be submitted to both projects.
5*6ea1f93eSDaniel Fojt 
6*6ea1f93eSDaniel Fojt    The GNU C Library is free software; you can redistribute it and/or
7*6ea1f93eSDaniel Fojt    modify it under the terms of the GNU General Public
8*6ea1f93eSDaniel Fojt    License as published by the Free Software Foundation; either
9*6ea1f93eSDaniel Fojt    version 3 of the License, or (at your option) any later version.
10*6ea1f93eSDaniel Fojt 
11*6ea1f93eSDaniel Fojt    The GNU C Library is distributed in the hope that it will be useful,
12*6ea1f93eSDaniel Fojt    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*6ea1f93eSDaniel Fojt    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*6ea1f93eSDaniel Fojt    General Public License for more details.
15*6ea1f93eSDaniel Fojt 
16*6ea1f93eSDaniel Fojt    You should have received a copy of the GNU General Public
17*6ea1f93eSDaniel Fojt    License along with the GNU C Library; if not, see
18*6ea1f93eSDaniel Fojt    <https://www.gnu.org/licenses/>.  */
19*6ea1f93eSDaniel Fojt 
20*6ea1f93eSDaniel Fojt #ifndef _GETOPT_EXT_H
21*6ea1f93eSDaniel Fojt #define _GETOPT_EXT_H 1
22*6ea1f93eSDaniel Fojt 
23*6ea1f93eSDaniel Fojt /* This header should not be used directly; include getopt.h instead.
24*6ea1f93eSDaniel Fojt    Unlike most bits headers, it does not have a protective #error,
25*6ea1f93eSDaniel Fojt    because the guard macro for getopt.h in gnulib is not fixed.  */
26*6ea1f93eSDaniel Fojt 
27*6ea1f93eSDaniel Fojt __BEGIN_DECLS
28*6ea1f93eSDaniel Fojt 
29*6ea1f93eSDaniel Fojt /* Describe the long-named options requested by the application.
30*6ea1f93eSDaniel Fojt    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
31*6ea1f93eSDaniel Fojt    of 'struct option' terminated by an element containing a name which is
32*6ea1f93eSDaniel Fojt    zero.
33*6ea1f93eSDaniel Fojt 
34*6ea1f93eSDaniel Fojt    The field 'has_arg' is:
35*6ea1f93eSDaniel Fojt    no_argument		(or 0) if the option does not take an argument,
36*6ea1f93eSDaniel Fojt    required_argument	(or 1) if the option requires an argument,
37*6ea1f93eSDaniel Fojt    optional_argument 	(or 2) if the option takes an optional argument.
38*6ea1f93eSDaniel Fojt 
39*6ea1f93eSDaniel Fojt    If the field 'flag' is not NULL, it points to a variable that is set
40*6ea1f93eSDaniel Fojt    to the value given in the field 'val' when the option is found, but
41*6ea1f93eSDaniel Fojt    left unchanged if the option is not found.
42*6ea1f93eSDaniel Fojt 
43*6ea1f93eSDaniel Fojt    To have a long-named option do something other than set an 'int' to
44*6ea1f93eSDaniel Fojt    a compiled-in constant, such as set a value from 'optarg', set the
45*6ea1f93eSDaniel Fojt    option's 'flag' field to zero and its 'val' field to a nonzero
46*6ea1f93eSDaniel Fojt    value (the equivalent single-letter option character, if there is
47*6ea1f93eSDaniel Fojt    one).  For long options that have a zero 'flag' field, 'getopt'
48*6ea1f93eSDaniel Fojt    returns the contents of the 'val' field.  */
49*6ea1f93eSDaniel Fojt 
50*6ea1f93eSDaniel Fojt struct option
51*6ea1f93eSDaniel Fojt {
52*6ea1f93eSDaniel Fojt   const char *name;
53*6ea1f93eSDaniel Fojt   /* has_arg can't be an enum because some compilers complain about
54*6ea1f93eSDaniel Fojt      type mismatches in all the code that assumes it is an int.  */
55*6ea1f93eSDaniel Fojt   int has_arg;
56*6ea1f93eSDaniel Fojt   int *flag;
57*6ea1f93eSDaniel Fojt   int val;
58*6ea1f93eSDaniel Fojt };
59*6ea1f93eSDaniel Fojt 
60*6ea1f93eSDaniel Fojt /* Names for the values of the 'has_arg' field of 'struct option'.  */
61*6ea1f93eSDaniel Fojt 
62*6ea1f93eSDaniel Fojt #define no_argument		0
63*6ea1f93eSDaniel Fojt #define required_argument	1
64*6ea1f93eSDaniel Fojt #define optional_argument	2
65*6ea1f93eSDaniel Fojt 
66*6ea1f93eSDaniel Fojt extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
67*6ea1f93eSDaniel Fojt 			const char *__shortopts,
68*6ea1f93eSDaniel Fojt 		        const struct option *__longopts, int *__longind)
69*6ea1f93eSDaniel Fojt        __THROW _GL_ARG_NONNULL ((2, 3));
70*6ea1f93eSDaniel Fojt extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
71*6ea1f93eSDaniel Fojt 			     const char *__shortopts,
72*6ea1f93eSDaniel Fojt 		             const struct option *__longopts, int *__longind)
73*6ea1f93eSDaniel Fojt        __THROW _GL_ARG_NONNULL ((2, 3));
74*6ea1f93eSDaniel Fojt 
75*6ea1f93eSDaniel Fojt __END_DECLS
76*6ea1f93eSDaniel Fojt 
77*6ea1f93eSDaniel Fojt #endif /* _GETOPT_EXT_H */
78