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