1 /* Declarations for getopt.
3 Copyright 2008 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/>. */
33 #if defined (KPSE_DLL) && (defined (WIN32) || defined (__CYGWIN__))
35 #define KPSEDLL __declspec(dllexport)
36 #else /* ! MAKE_KPSE_DLL */
37 #define KPSEDLL __declspec(dllimport)
39 #else /* ! (KPSE_DLL && (WIN32 || __CYGWIN__)) */
47 /* For communication from `getopt' to the caller.
48 When `getopt' finds an option that takes an argument,
49 the argument value is returned here.
50 Also, when `ordering' is RETURN_IN_ORDER,
51 each non-option ARGV-element is returned here. */
53 extern KPSEDLL char *optarg;
55 /* Index in ARGV of the next element to be scanned.
56 This is used for communication to and from the caller
57 and for communication between successive calls to `getopt'.
59 On entry to `getopt', zero means this is the first call; initialize.
61 When `getopt' returns -1, this is the index of the first of the
62 non-option elements that the caller should itself scan.
64 Otherwise, `optind' communicates from one call to the next
65 how much of ARGV has been scanned so far. */
67 extern KPSEDLL int optind;
69 /* Callers store zero here to inhibit the error message `getopt' prints
70 for unrecognized options. */
72 extern KPSEDLL int opterr;
74 /* Set to an option character which was unrecognized. */
76 extern KPSEDLL int optopt;
78 /* Describe the long-named options requested by the application.
79 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
80 of `struct option' terminated by an element containing a name which is
83 The field `has_arg' is:
84 no_argument (or 0) if the option does not take an argument,
85 required_argument (or 1) if the option requires an argument,
86 optional_argument (or 2) if the option takes an optional argument.
88 If the field `flag' is not NULL, it points to a variable that is set
89 to the value given in the field `val' when the option is found, but
90 left unchanged if the option is not found.
92 To have a long-named option do something other than set an `int' to
93 a compiled-in constant, such as set a value from `optarg', set the
94 option's `flag' field to zero and its `val' field to a nonzero
95 value (the equivalent single-letter option character, if there is
96 one). For long options that have a zero `flag' field, `getopt'
97 returns the contents of the `val' field. */
101 #if defined (__STDC__) && __STDC__
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. */
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
119 #if defined (__STDC__) && __STDC__
120 #ifdef __GNU_LIBRARY__
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. */
124 extern KPSEDLL int getopt (int argc, char *const *argv, const char *shortopts);
125 #else /* not __GNU_LIBRARY__ */
126 extern KPSEDLL int getopt ();
127 #endif /* __GNU_LIBRARY__ */
128 extern KPSEDLL int getopt_long (int argc, char *const *argv, const char *shortopts,
129 const struct option *longopts, int *longind);
130 extern KPSEDLL int getopt_long_only (int argc, char *const *argv,
131 const char *shortopts,
132 const struct option *longopts, int *longind);
134 /* Internal only. Users should not call this directly. */
135 extern int _getopt_internal (int argc, char *const *argv,
136 const char *shortopts,
137 const struct option *longopts, int *longind,
139 #else /* not __STDC__ */
140 extern KPSEDLL int getopt ();
141 extern KPSEDLL int getopt_long ();
142 extern KPSEDLL int getopt_long_only ();
144 extern int _getopt_internal ();
145 #endif /* __STDC__ */
151 #endif /* _GETOPT_H */