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