1169695Skan/* Declarations for getopt.
2169695Skan   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000,
3169695Skan   2002 Free Software Foundation, Inc.
4169695Skan
5169695Skan   NOTE: The canonical source of this file is maintained with the GNU C Library.
6169695Skan   Bugs can be reported to bug-glibc@gnu.org.
7169695Skan
8169695Skan   This program is free software; you can redistribute it and/or modify it
9169695Skan   under the terms of the GNU General Public License as published by the
10169695Skan   Free Software Foundation; either version 2, or (at your option) any
11169695Skan   later version.
12169695Skan
13169695Skan   This program is distributed in the hope that it will be useful,
14169695Skan   but WITHOUT ANY WARRANTY; without even the implied warranty of
15169695Skan   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16169695Skan   GNU General Public License for more details.
17169695Skan
18169695Skan   You should have received a copy of the GNU General Public License
19169695Skan   along with this program; if not, write to the Free Software
20169695Skan   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
21169695Skan   USA.  */
22169695Skan
23169695Skan#ifndef _GETOPT_H
24169695Skan#define _GETOPT_H 1
25169695Skan
26169695Skan#ifdef	__cplusplus
27169695Skanextern "C" {
28169695Skan#endif
29169695Skan
30169695Skan/* For communication from `getopt' to the caller.
31169695Skan   When `getopt' finds an option that takes an argument,
32169695Skan   the argument value is returned here.
33169695Skan   Also, when `ordering' is RETURN_IN_ORDER,
34169695Skan   each non-option ARGV-element is returned here.  */
35169695Skan
36169695Skanextern char *optarg;
37169695Skan
38169695Skan/* Index in ARGV of the next element to be scanned.
39169695Skan   This is used for communication to and from the caller
40169695Skan   and for communication between successive calls to `getopt'.
41169695Skan
42169695Skan   On entry to `getopt', zero means this is the first call; initialize.
43169695Skan
44169695Skan   When `getopt' returns -1, this is the index of the first of the
45169695Skan   non-option elements that the caller should itself scan.
46169695Skan
47169695Skan   Otherwise, `optind' communicates from one call to the next
48169695Skan   how much of ARGV has been scanned so far.  */
49169695Skan
50169695Skanextern int optind;
51169695Skan
52169695Skan/* Callers store zero here to inhibit the error message `getopt' prints
53169695Skan   for unrecognized options.  */
54169695Skan
55169695Skanextern int opterr;
56169695Skan
57169695Skan/* Set to an option character which was unrecognized.  */
58169695Skan
59169695Skanextern int optopt;
60169695Skan
61169695Skan/* Describe the long-named options requested by the application.
62169695Skan   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
63169695Skan   of `struct option' terminated by an element containing a name which is
64169695Skan   zero.
65169695Skan
66169695Skan   The field `has_arg' is:
67169695Skan   no_argument		(or 0) if the option does not take an argument,
68169695Skan   required_argument	(or 1) if the option requires an argument,
69169695Skan   optional_argument 	(or 2) if the option takes an optional argument.
70169695Skan
71169695Skan   If the field `flag' is not NULL, it points to a variable that is set
72169695Skan   to the value given in the field `val' when the option is found, but
73169695Skan   left unchanged if the option is not found.
74169695Skan
75169695Skan   To have a long-named option do something other than set an `int' to
76169695Skan   a compiled-in constant, such as set a value from `optarg', set the
77169695Skan   option's `flag' field to zero and its `val' field to a nonzero
78169695Skan   value (the equivalent single-letter option character, if there is
79169695Skan   one).  For long options that have a zero `flag' field, `getopt'
80169695Skan   returns the contents of the `val' field.  */
81169695Skan
82169695Skanstruct option
83169695Skan{
84169695Skan#if defined (__STDC__) && __STDC__
85169695Skan  const char *name;
86169695Skan#else
87169695Skan  char *name;
88169695Skan#endif
89169695Skan  /* has_arg can't be an enum because some compilers complain about
90169695Skan     type mismatches in all the code that assumes it is an int.  */
91169695Skan  int has_arg;
92169695Skan  int *flag;
93169695Skan  int val;
94169695Skan};
95169695Skan
96169695Skan/* Names for the values of the `has_arg' field of `struct option'.  */
97169695Skan
98169695Skan#define	no_argument		0
99169695Skan#define required_argument	1
100169695Skan#define optional_argument	2
101169695Skan
102169695Skan#if defined (__STDC__) && __STDC__
103169695Skan/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
104169695Skan   undefined, we haven't run the autoconf check so provide the
105169695Skan   declaration without arguments.  If it is 0, we checked and failed
106169695Skan   to find the declaration so provide a fully prototyped one.  If it
107169695Skan   is 1, we found it so don't provide any declaration at all.  */
108169695Skan#if !HAVE_DECL_GETOPT
109169695Skan#if defined (__GNU_LIBRARY__) || defined (HAVE_DECL_GETOPT)
110169695Skan/* Many other libraries have conflicting prototypes for getopt, with
111169695Skan   differences in the consts, in unistd.h.  To avoid compilation
112169695Skan   errors, only prototype getopt for the GNU C library.  */
113169695Skanextern int getopt (int argc, char *const *argv, const char *shortopts);
114169695Skan#else
115169695Skan#ifndef __cplusplus
116169695Skanextern int getopt ();
117169695Skan#endif /* __cplusplus */
118169695Skan#endif
119169695Skan#endif /* !HAVE_DECL_GETOPT */
120169695Skan
121169695Skanextern int getopt_long (int argc, char *const *argv, const char *shortopts,
122169695Skan		        const struct option *longopts, int *longind);
123169695Skanextern int getopt_long_only (int argc, char *const *argv,
124169695Skan			     const char *shortopts,
125169695Skan		             const struct option *longopts, int *longind);
126169695Skan
127169695Skan/* Internal only.  Users should not call this directly.  */
128169695Skanextern int _getopt_internal (int argc, char *const *argv,
129169695Skan			     const char *shortopts,
130169695Skan		             const struct option *longopts, int *longind,
131169695Skan			     int long_only);
132169695Skan#else /* not __STDC__ */
133169695Skanextern int getopt ();
134169695Skanextern int getopt_long ();
135169695Skanextern int getopt_long_only ();
136169695Skan
137169695Skanextern int _getopt_internal ();
138169695Skan#endif /* __STDC__ */
139169695Skan
140169695Skan#ifdef	__cplusplus
141169695Skan}
142169695Skan#endif
143169695Skan
144169695Skan#endif /* getopt.h */
145