1
/* Declarations for getopt.
2
Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000, 2001,
4
Free Software Foundation, Inc.
6
NOTE: The canonical source of this file is maintained with the GNU C Library.
7
Bugs can be reported to bug-glibc@gnu.org.
9
This program is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by the
11
Free Software Foundation; either version 2, or (at your option) any
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25
#define _GNU_GETOPT_H 1
27
/* We only use getopt_long(), not getopt(), so we don't need a fully
28
prototyped declaration of getopt(). This forces the prototype for getopt()
29
to be compatible with all systems. Solaris in particular seems to have a
30
prototype for getopt() in unistd.h which conflicts with the one in this
31
file if we don't do this. */
33
#undef HAVE_DECL_GETOPT
34
#define HAVE_DECL_GETOPT 1
40
/* For communication from `getopt' to the caller.
41
When `getopt' finds an option that takes an argument,
42
the argument value is returned here.
43
Also, when `ordering' is RETURN_IN_ORDER,
44
each non-option ARGV-element is returned here. */
48
/* Index in ARGV of the next element to be scanned.
49
This is used for communication to and from the caller
50
and for communication between successive calls to `getopt'.
52
On entry to `getopt', zero means this is the first call; initialize.
54
When `getopt' returns -1, this is the index of the first of the
55
non-option elements that the caller should itself scan.
57
Otherwise, `optind' communicates from one call to the next
58
how much of ARGV has been scanned so far. */
62
/* Callers store zero here to inhibit the error message `getopt' prints
63
for unrecognized options. */
67
/* Set to an option character which was unrecognized. */
71
/* Describe the long-named options requested by the application.
72
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
73
of `struct option' terminated by an element containing a name which is
76
The field `has_arg' is:
77
no_argument (or 0) if the option does not take an argument,
78
required_argument (or 1) if the option requires an argument,
79
optional_argument (or 2) if the option takes an optional argument.
81
If the field `flag' is not NULL, it points to a variable that is set
82
to the value given in the field `val' when the option is found, but
83
left unchanged if the option is not found.
85
To have a long-named option do something other than set an `int' to
86
a compiled-in constant, such as set a value from `optarg', set the
87
option's `flag' field to zero and its `val' field to a nonzero
88
value (the equivalent single-letter option character, if there is
89
one). For long options that have a zero `flag' field, `getopt'
90
returns the contents of the `val' field. */
94
#if defined (__STDC__) && __STDC__
99
/* has_arg can't be an enum because some compilers complain about
100
type mismatches in all the code that assumes it is an int. */
106
/* Names for the values of the `has_arg' field of `struct option'. */
108
#define no_argument 0
109
#define required_argument 1
110
#define optional_argument 2
112
#if defined (__STDC__) && __STDC__
113
/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
114
undefined, we haven't run the autoconf check so provide the
115
declaration without arguments. If it is 0, we checked and failed
116
to find the declaration so provide a fully prototyped one. If it
117
is 1, we found it so don't provide any declaration at all. */
118
#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
119
/* Many other libraries have conflicting prototypes for getopt, with
120
differences in the consts, in stdlib.h. To avoid compilation
121
errors, only prototype getopt for the GNU C library. */
122
extern int getopt (int argc, char *const *argv, const char *shortopts);
123
#else /* not __GNU_LIBRARY__ */
124
# if !defined (HAVE_DECL_GETOPT)
125
extern int getopt ();
127
#endif /* __GNU_LIBRARY__ */
128
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
129
const struct option *longopts, int *longind);
130
extern 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 int getopt ();
141
extern int getopt_long ();
142
extern int getopt_long_only ();
144
extern int _getopt_internal ();
145
#endif /* __STDC__ */
151
#endif /* gnu_getopt.h */