dvitomp fix from Akira
[mplib] / src / texk / kpathsea / getopt.h
1 /* Declarations for getopt.
2
3    Copyright 2008 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
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.
15
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.
20
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/>.  */
23
24 #ifndef _GETOPT_H
25 #define _GETOPT_H 1
26
27 #if defined(WIN32)
28 #ifndef __STDC__
29 #define __STDC__ 1
30 #endif
31 #endif
32
33 #if defined (KPSE_DLL) && (defined (WIN32) || defined (__CYGWIN__))
34 #ifdef MAKE_KPSE_DLL
35 #define KPSEDLL __declspec(dllexport)
36 #else /* ! MAKE_KPSE_DLL */
37 #define KPSEDLL __declspec(dllimport)
38 #endif
39 #else /* ! (KPSE_DLL && (WIN32 || __CYGWIN__)) */
40 #define KPSEDLL
41 #endif
42
43 #ifdef  __cplusplus
44 extern "C" {
45 #endif
46
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.  */
52
53 extern KPSEDLL char *optarg;
54
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'.
58
59    On entry to `getopt', zero means this is the first call; initialize.
60
61    When `getopt' returns -1, this is the index of the first of the
62    non-option elements that the caller should itself scan.
63
64    Otherwise, `optind' communicates from one call to the next
65    how much of ARGV has been scanned so far.  */
66
67 extern KPSEDLL int optind;
68
69 /* Callers store zero here to inhibit the error message `getopt' prints
70    for unrecognized options.  */
71
72 extern KPSEDLL int opterr;
73
74 /* Set to an option character which was unrecognized.  */
75
76 extern KPSEDLL int optopt;
77
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
81    zero.
82
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.
87
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.
91
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.  */
98
99 struct option
100 {
101 #if defined (__STDC__) && __STDC__
102   const char *name;
103 #else
104   char *name;
105 #endif
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;
111 };
112
113 /* Names for the values of the `has_arg' field of `struct option'.  */
114
115 #define no_argument             0
116 #define required_argument       1
117 #define optional_argument       2
118
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);
133
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,
138                              int long_only);
139 #else /* not __STDC__ */
140 extern KPSEDLL int getopt ();
141 extern KPSEDLL int getopt_long ();
142 extern KPSEDLL int getopt_long_only ();
143
144 extern int _getopt_internal ();
145 #endif /* __STDC__ */
146
147 #ifdef  __cplusplus
148 }
149 #endif
150
151 #endif /* _GETOPT_H */