Debian Codegraph @

texk/kpathsea/getopt.h

raw
1 /* Declarations for getopt (for kpathsea).
2
3 Copyright 2008, 2010-2026 Karl Berry.
4 Copyright 1989,90,91,92,93,94,96,97,2000,05 Free Software Foundation, Inc.
5
6 The original version of this file was part of the GNU C Library.
7 Its master source is NOT part of the C library, however.
8 The master source lives in libc.
9 This version has been modified for use with libkpathsea
10 and is maintained independently.
11
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Lesser General Public
14 License as published by the Free Software Foundation; either
15 version 2.1 of the License, or (at your option) any later version.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with this library; if not, see <http://www.gnu.org/licenses/>. */
24
25 #ifndef _GETOPT_H
26
27 #ifndef __need_getopt
28 #define _GETOPT_H 1
29 #endif
30
31 #if defined (WIN32) && !defined (__MINGW32__) && !defined (NO_KPSE_DLL)
32 #define KPSE_DLL 1
33 #endif /* WIN32 && !__MINGW32__ && !NO_KPSE_DLL */
34
35 #if !defined (KPSEDLL)
36 #if defined (KPSE_DLL) && (defined (WIN32) || defined (__CYGWIN__))
37 #ifdef MAKE_KPSE_DLL
38 #define KPSEDLL __declspec(dllexport)
39 #else /* ! MAKE_KPSE_DLL */
40 #define KPSEDLL __declspec(dllimport)
41 #endif
42 #else /* ! (KPSE_DLL && (WIN32 || __CYGWIN__)) */
43 #define KPSEDLL
44 #endif /* ! (KPSE_DLL && (WIN32 || __CYGWIN__)) */
45 #endif /* ! KPSEDLL */
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /* For communication from `getopt' to the caller.
52 When `getopt' finds an option that takes an argument,
53 the argument value is returned here.
54 Also, when `ordering' is RETURN_IN_ORDER,
55 each non-option ARGV-element is returned here. */
56
57 extern KPSEDLL char *optarg;
58
59 /* Index in ARGV of the next element to be scanned.
60 This is used for communication to and from the caller
61 and for communication between successive calls to `getopt'.
62
63 On entry to `getopt', zero means this is the first call; initialize.
64
65 When `getopt' returns -1, this is the index of the first of the
66 non-option elements that the caller should itself scan.
67
68 Otherwise, `optind' communicates from one call to the next
69 how much of ARGV has been scanned so far. */
70
71 extern KPSEDLL int optind;
72
73 /* Callers store zero here to inhibit the error message `getopt' prints
74 for unrecognized options. */
75
76 extern KPSEDLL int opterr;
77
78 /* Set to an option character which was unrecognized. */
79
80 extern KPSEDLL int optopt;
81
82 #ifndef __need_getopt
83 /* Describe the long-named options requested by the application.
84 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
85 of `struct option' terminated by an element containing a name which is
86 zero.
87
88 The field `has_arg' is:
89 no_argument (or 0) if the option does not take an argument,
90 required_argument (or 1) if the option requires an argument,
91 optional_argument (or 2) if the option takes an optional argument.
92
93 If the field `flag' is not NULL, it points to a variable that is set
94 to the value given in the field `val' when the option is found, but
95 left unchanged if the option is not found.
96
97 To have a long-named option do something other than set an `int' to
98 a compiled-in constant, such as set a value from `optarg', set the
99 option's `flag' field to zero and its `val' field to a nonzero
100 value (the equivalent single-letter option character, if there is
101 one). For long options that have a zero `flag' field, `getopt'
102 returns the contents of the `val' field. */
103
104 struct option
105 {
106 const char *name;
107 /* has_arg can't be an enum because some compilers complain about
108 type mismatches in all the code that assumes it is an int. */
109 int has_arg;
110 int *flag;
111 int val;
112 };
113
114 /* Names for the values of the `has_arg' field of `struct option'. */
115
116 #define no_argument 0
117 #define required_argument 1
118 #define optional_argument 2
119 #endif /* need getopt */
120
121 #if defined(__GNU_LIBRARY__) || defined (WIN32) || defined (__CYGWIN__)
122 /* Many other libraries have conflicting prototypes for getopt, with
123 differences in the consts, in stdlib.h. To avoid compilation
124 errors, only prototype getopt for the GNU C library. And not when
125 compiling with C++; g++ 4.7.0 chokes on conflicting exception
126 specifications. */
127 #if !defined (__cplusplus)
128 extern KPSEDLL int getopt (int argc, char *const *argv, const char *shortopts);
129 #endif
130 #if defined (__MINGW32__) || defined (__CYGWIN__)
131 #define __GETOPT_H__ /* Avoid that <unistd.h> redeclares the getopt API. */
132 #endif
133 #elif !defined (__cplusplus)
134 /* Also, C23 made empty parentheses in declarations an error, breaking
135 compatibility with C since day one. So avoid declaring in C23 too. */
136 #if ! (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
137 extern KPSEDLL int getopt ();
138 #endif /* not C23 */
139 #endif /* not C++ */
140
141 #ifndef __need_getopt
142 extern KPSEDLL int getopt_long (int argc, char *const *argv, const char *shortopts,
143 const struct option *longopts, int *longind);
144 extern KPSEDLL int getopt_long_only (int argc, char *const *argv,
145 const char *shortopts,
146 const struct option *longopts, int *longind);
147
148 #if defined (MAKE_KPSE_DLL) || defined (NO_KPSE_DLL) /* libkpathsea internal only */
149
150 /* Internal only. Users should not call this directly. */
151 extern int _getopt_internal (int argc, char *const *argv,
152 const char *shortopts,
153 const struct option *longopts, int *longind,
154 int long_only);
155
156 #endif /* MAKE_KPSE_DLL || NO_KPSE_DLL */
157 #endif /* need getopt */
158
159 #ifdef __cplusplus
160 }
161 #endif
162
163 /* Make sure we later can get all the definitions and declarations. */
164 #undef __need_getopt
165
166 #endif /* _GETOPT_H */