1130812Smarcel/* Declarations for getopt.
2130812Smarcel   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000,
3130812Smarcel   2002 Free Software Foundation, Inc.
4130812Smarcel
5130812Smarcel   NOTE: The canonical source of this file is maintained with the GNU C Library.
6130812Smarcel   Bugs can be reported to bug-glibc@gnu.org.
7130812Smarcel
8130812Smarcel   This program is free software; you can redistribute it and/or modify it
9130812Smarcel   under the terms of the GNU General Public License as published by the
10130812Smarcel   Free Software Foundation; either version 2, or (at your option) any
11130812Smarcel   later version.
12130812Smarcel
13130812Smarcel   This program is distributed in the hope that it will be useful,
14130812Smarcel   but WITHOUT ANY WARRANTY; without even the implied warranty of
15130812Smarcel   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16130812Smarcel   GNU General Public License for more details.
17130812Smarcel
18130812Smarcel   You should have received a copy of the GNU General Public License
19130812Smarcel   along with this program; if not, write to the Free Software
20130812Smarcel   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21130812Smarcel   USA.  */
22130812Smarcel
23130812Smarcel#ifndef _GETOPT_H
24130812Smarcel#define _GETOPT_H 1
25130812Smarcel
26130812Smarcel#ifdef	__cplusplus
27130812Smarcelextern "C" {
28130812Smarcel#endif
29130812Smarcel
30130812Smarcel/* For communication from `getopt' to the caller.
31130812Smarcel   When `getopt' finds an option that takes an argument,
32130812Smarcel   the argument value is returned here.
33130812Smarcel   Also, when `ordering' is RETURN_IN_ORDER,
34130812Smarcel   each non-option ARGV-element is returned here.  */
35130812Smarcel
36130812Smarcelextern char *optarg;
37130812Smarcel
38130812Smarcel/* Index in ARGV of the next element to be scanned.
39130812Smarcel   This is used for communication to and from the caller
40130812Smarcel   and for communication between successive calls to `getopt'.
41130812Smarcel
42130812Smarcel   On entry to `getopt', zero means this is the first call; initialize.
43130812Smarcel
44130812Smarcel   When `getopt' returns -1, this is the index of the first of the
45130812Smarcel   non-option elements that the caller should itself scan.
46130812Smarcel
47130812Smarcel   Otherwise, `optind' communicates from one call to the next
48130812Smarcel   how much of ARGV has been scanned so far.  */
49130812Smarcel
50130812Smarcelextern int optind;
51130812Smarcel
52130812Smarcel/* Callers store zero here to inhibit the error message `getopt' prints
53130812Smarcel   for unrecognized options.  */
54130812Smarcel
55130812Smarcelextern int opterr;
56130812Smarcel
57130812Smarcel/* Set to an option character which was unrecognized.  */
58130812Smarcel
59130812Smarcelextern int optopt;
60130812Smarcel
61130812Smarcel/* Describe the long-named options requested by the application.
62130812Smarcel   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
63130812Smarcel   of `struct option' terminated by an element containing a name which is
64130812Smarcel   zero.
65130812Smarcel
66130812Smarcel   The field `has_arg' is:
67130812Smarcel   no_argument		(or 0) if the option does not take an argument,
68130812Smarcel   required_argument	(or 1) if the option requires an argument,
69130812Smarcel   optional_argument 	(or 2) if the option takes an optional argument.
70130812Smarcel
71130812Smarcel   If the field `flag' is not NULL, it points to a variable that is set
72130812Smarcel   to the value given in the field `val' when the option is found, but
73130812Smarcel   left unchanged if the option is not found.
74130812Smarcel
75130812Smarcel   To have a long-named option do something other than set an `int' to
76130812Smarcel   a compiled-in constant, such as set a value from `optarg', set the
77130812Smarcel   option's `flag' field to zero and its `val' field to a nonzero
78130812Smarcel   value (the equivalent single-letter option character, if there is
79130812Smarcel   one).  For long options that have a zero `flag' field, `getopt'
80130812Smarcel   returns the contents of the `val' field.  */
81130812Smarcel
82130812Smarcelstruct option
83130812Smarcel{
84130812Smarcel#if defined (__STDC__) && __STDC__
85130812Smarcel  const char *name;
86130812Smarcel#else
87130812Smarcel  char *name;
88130812Smarcel#endif
89130812Smarcel  /* has_arg can't be an enum because some compilers complain about
90130812Smarcel     type mismatches in all the code that assumes it is an int.  */
91130812Smarcel  int has_arg;
92130812Smarcel  int *flag;
93130812Smarcel  int val;
94130812Smarcel};
95130812Smarcel
96130812Smarcel/* Names for the values of the `has_arg' field of `struct option'.  */
97130812Smarcel
98130812Smarcel#define	no_argument		0
99130812Smarcel#define required_argument	1
100130812Smarcel#define optional_argument	2
101130812Smarcel
102130812Smarcel#if defined (__STDC__) && __STDC__
103130812Smarcel/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1.  If it is
104130812Smarcel   undefined, we haven't run the autoconf check so provide the
105130812Smarcel   declaration without arguments.  If it is 0, we checked and failed
106130812Smarcel   to find the declaration so provide a fully prototyped one.  If it
107130812Smarcel   is 1, we found it so don't provide any declaration at all.  */
108130812Smarcel#if !HAVE_DECL_GETOPT
109130812Smarcel#if defined (__GNU_LIBRARY__) || defined (HAVE_DECL_GETOPT)
110130812Smarcel/* Many other libraries have conflicting prototypes for getopt, with
111130812Smarcel   differences in the consts, in unistd.h.  To avoid compilation
112130812Smarcel   errors, only prototype getopt for the GNU C library.  */
113130812Smarcelextern int getopt (int argc, char *const *argv, const char *shortopts);
114130812Smarcel#else
115130812Smarcel#ifndef __cplusplus
116130812Smarcelextern int getopt ();
117130812Smarcel#endif /* __cplusplus */
118130812Smarcel#endif
119130812Smarcel#endif /* !HAVE_DECL_GETOPT */
120130812Smarcel
121130812Smarcelextern int getopt_long (int argc, char *const *argv, const char *shortopts,
122130812Smarcel		        const struct option *longopts, int *longind);
123130812Smarcelextern int getopt_long_only (int argc, char *const *argv,
124130812Smarcel			     const char *shortopts,
125130812Smarcel		             const struct option *longopts, int *longind);
126130812Smarcel
127130812Smarcel/* Internal only.  Users should not call this directly.  */
128130812Smarcelextern int _getopt_internal (int argc, char *const *argv,
129130812Smarcel			     const char *shortopts,
130130812Smarcel		             const struct option *longopts, int *longind,
131130812Smarcel			     int long_only);
132130812Smarcel#else /* not __STDC__ */
133130812Smarcelextern int getopt ();
134130812Smarcelextern int getopt_long ();
135130812Smarcelextern int getopt_long_only ();
136130812Smarcel
137130812Smarcelextern int _getopt_internal ();
138130812Smarcel#endif /* __STDC__ */
139130812Smarcel
140130812Smarcel#ifdef	__cplusplus
141130812Smarcel}
142130812Smarcel#endif
143130812Smarcel
144130812Smarcel#endif /* getopt.h */
145