141
|
1 /* Declarations for getopt. |
4288
|
2 Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. |
141
|
3 |
4288
|
4 This file is part of the GNU C Library. Its master source is NOT part of |
|
5 the C library, however. The master source lives in /gd/gnu/lib. |
141
|
6 |
4288
|
7 The GNU C Library is free software; you can redistribute it and/or |
|
8 modify it under the terms of the GNU Library General Public License as |
|
9 published by the Free Software Foundation; either version 2 of the |
|
10 License, or (at your option) any later version. |
|
11 |
|
12 The GNU C Library is distributed in the hope that it will be useful, |
141
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4288
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 Library General Public License for more details. |
141
|
16 |
4288
|
17 You should have received a copy of the GNU Library General Public |
|
18 License along with the GNU C Library; see the file COPYING.LIB. If not, |
|
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
20 Boston, MA 02111-1307, USA. */ |
141
|
21 |
|
22 #ifndef _GETOPT_H |
|
23 #define _GETOPT_H 1 |
|
24 |
4288
|
25 #if !defined(WIN32) || (defined(_DLL) && !defined(_IMPORT)) || !defined(_DLL) |
|
26 #define DllImport |
|
27 #else |
|
28 #define DllImport __declspec(dllimport) |
|
29 #endif |
|
30 |
141
|
31 #ifdef __cplusplus |
|
32 extern "C" { |
|
33 #endif |
|
34 |
|
35 /* For communication from `getopt' to the caller. |
|
36 When `getopt' finds an option that takes an argument, |
|
37 the argument value is returned here. |
|
38 Also, when `ordering' is RETURN_IN_ORDER, |
|
39 each non-option ARGV-element is returned here. */ |
|
40 |
4288
|
41 extern DllImport char *optarg; |
141
|
42 |
|
43 /* Index in ARGV of the next element to be scanned. |
|
44 This is used for communication to and from the caller |
|
45 and for communication between successive calls to `getopt'. |
|
46 |
|
47 On entry to `getopt', zero means this is the first call; initialize. |
|
48 |
4288
|
49 When `getopt' returns -1, this is the index of the first of the |
141
|
50 non-option elements that the caller should itself scan. |
|
51 |
|
52 Otherwise, `optind' communicates from one call to the next |
|
53 how much of ARGV has been scanned so far. */ |
|
54 |
4288
|
55 extern DllImport int optind; |
141
|
56 |
|
57 /* Callers store zero here to inhibit the error message `getopt' prints |
|
58 for unrecognized options. */ |
|
59 |
4288
|
60 extern DllImport int opterr; |
141
|
61 |
|
62 /* Set to an option character which was unrecognized. */ |
|
63 |
4288
|
64 extern DllImport int optopt; |
141
|
65 |
|
66 /* Describe the long-named options requested by the application. |
|
67 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector |
|
68 of `struct option' terminated by an element containing a name which is |
|
69 zero. |
|
70 |
|
71 The field `has_arg' is: |
|
72 no_argument (or 0) if the option does not take an argument, |
|
73 required_argument (or 1) if the option requires an argument, |
|
74 optional_argument (or 2) if the option takes an optional argument. |
|
75 |
|
76 If the field `flag' is not NULL, it points to a variable that is set |
|
77 to the value given in the field `val' when the option is found, but |
|
78 left unchanged if the option is not found. |
|
79 |
|
80 To have a long-named option do something other than set an `int' to |
|
81 a compiled-in constant, such as set a value from `optarg', set the |
|
82 option's `flag' field to zero and its `val' field to a nonzero |
|
83 value (the equivalent single-letter option character, if there is |
|
84 one). For long options that have a zero `flag' field, `getopt' |
|
85 returns the contents of the `val' field. */ |
|
86 |
|
87 struct option |
|
88 { |
4288
|
89 #if defined (__STDC__) && __STDC__ |
141
|
90 const char *name; |
|
91 #else |
|
92 char *name; |
|
93 #endif |
|
94 /* has_arg can't be an enum because some compilers complain about |
|
95 type mismatches in all the code that assumes it is an int. */ |
|
96 int has_arg; |
|
97 int *flag; |
|
98 int val; |
|
99 }; |
|
100 |
|
101 /* Names for the values of the `has_arg' field of `struct option'. */ |
|
102 |
|
103 #define no_argument 0 |
|
104 #define required_argument 1 |
|
105 #define optional_argument 2 |
|
106 |
4288
|
107 #if defined (__STDC__) && __STDC__ |
4378
|
108 #ifdef __GNU_LIBRARY__ |
|
109 /* Many other libraries have conflicting prototypes for getopt, with |
|
110 differences in the consts, in stdlib.h. To avoid compilation |
|
111 errors, only prototype getopt for the GNU C library. */ |
141
|
112 extern int getopt (int argc, char *const *argv, const char *shortopts); |
4378
|
113 #else /* not __GNU_LIBRARY__ */ |
|
114 extern int getopt (); |
|
115 #endif /* __GNU_LIBRARY__ */ |
141
|
116 extern int getopt_long (int argc, char *const *argv, const char *shortopts, |
|
117 const struct option *longopts, int *longind); |
|
118 extern int getopt_long_only (int argc, char *const *argv, |
|
119 const char *shortopts, |
|
120 const struct option *longopts, int *longind); |
|
121 |
|
122 /* Internal only. Users should not call this directly. */ |
|
123 extern int _getopt_internal (int argc, char *const *argv, |
|
124 const char *shortopts, |
|
125 const struct option *longopts, int *longind, |
|
126 int long_only); |
|
127 #else /* not __STDC__ */ |
|
128 extern int getopt (); |
|
129 extern int getopt_long (); |
|
130 extern int getopt_long_only (); |
|
131 |
|
132 extern int _getopt_internal (); |
4288
|
133 #endif /* __STDC__ */ |
141
|
134 |
|
135 #ifdef __cplusplus |
|
136 } |
|
137 #endif |
|
138 |
|
139 #endif /* _GETOPT_H */ |