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