xref: /utopia/UTPA2-700.0.x/projects/tools/lint/mips-linux-gnu_include/getopt.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi /* Declarations for getopt.
2*53ee8cc1Swenshuai.xi    Copyright (C) 1989-1994,1996-1999,2001,2003,2004
3*53ee8cc1Swenshuai.xi    Free Software Foundation, Inc.
4*53ee8cc1Swenshuai.xi    This file is part of the GNU C Library.
5*53ee8cc1Swenshuai.xi 
6*53ee8cc1Swenshuai.xi    The GNU C Library is free software; you can redistribute it and/or
7*53ee8cc1Swenshuai.xi    modify it under the terms of the GNU Lesser General Public
8*53ee8cc1Swenshuai.xi    License as published by the Free Software Foundation; either
9*53ee8cc1Swenshuai.xi    version 2.1 of the License, or (at your option) any later version.
10*53ee8cc1Swenshuai.xi 
11*53ee8cc1Swenshuai.xi    The GNU C Library is distributed in the hope that it will be useful,
12*53ee8cc1Swenshuai.xi    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*53ee8cc1Swenshuai.xi    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*53ee8cc1Swenshuai.xi    Lesser General Public License for more details.
15*53ee8cc1Swenshuai.xi 
16*53ee8cc1Swenshuai.xi    You should have received a copy of the GNU Lesser General Public
17*53ee8cc1Swenshuai.xi    License along with the GNU C Library; if not, write to the Free
18*53ee8cc1Swenshuai.xi    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19*53ee8cc1Swenshuai.xi    02111-1307 USA.  */
20*53ee8cc1Swenshuai.xi 
21*53ee8cc1Swenshuai.xi #ifndef _GETOPT_H
22*53ee8cc1Swenshuai.xi 
23*53ee8cc1Swenshuai.xi #ifndef __need_getopt
24*53ee8cc1Swenshuai.xi # define _GETOPT_H 1
25*53ee8cc1Swenshuai.xi #endif
26*53ee8cc1Swenshuai.xi 
27*53ee8cc1Swenshuai.xi /* If __GNU_LIBRARY__ is not already defined, either we are being used
28*53ee8cc1Swenshuai.xi    standalone, or this is the first header included in the source file.
29*53ee8cc1Swenshuai.xi    If we are being used with glibc, we need to include <features.h>, but
30*53ee8cc1Swenshuai.xi    that does not exist if we are standalone.  So: if __GNU_LIBRARY__ is
31*53ee8cc1Swenshuai.xi    not defined, include <ctype.h>, which will pull in <features.h> for us
32*53ee8cc1Swenshuai.xi    if it's from glibc.  (Why ctype.h?  It's guaranteed to exist and it
33*53ee8cc1Swenshuai.xi    doesn't flood the namespace with stuff the way some other headers do.)  */
34*53ee8cc1Swenshuai.xi #if !defined __GNU_LIBRARY__
35*53ee8cc1Swenshuai.xi # include <ctype.h>
36*53ee8cc1Swenshuai.xi #endif
37*53ee8cc1Swenshuai.xi 
38*53ee8cc1Swenshuai.xi #ifndef __THROW
39*53ee8cc1Swenshuai.xi # ifndef __GNUC_PREREQ
40*53ee8cc1Swenshuai.xi #  define __GNUC_PREREQ(maj, min) (0)
41*53ee8cc1Swenshuai.xi # endif
42*53ee8cc1Swenshuai.xi # if defined __cplusplus && __GNUC_PREREQ (2,8)
43*53ee8cc1Swenshuai.xi #  define __THROW	throw ()
44*53ee8cc1Swenshuai.xi # else
45*53ee8cc1Swenshuai.xi #  define __THROW
46*53ee8cc1Swenshuai.xi # endif
47*53ee8cc1Swenshuai.xi #endif
48*53ee8cc1Swenshuai.xi 
49*53ee8cc1Swenshuai.xi #ifdef	__cplusplus
50*53ee8cc1Swenshuai.xi extern "C" {
51*53ee8cc1Swenshuai.xi #endif
52*53ee8cc1Swenshuai.xi 
53*53ee8cc1Swenshuai.xi /* For communication from `getopt' to the caller.
54*53ee8cc1Swenshuai.xi    When `getopt' finds an option that takes an argument,
55*53ee8cc1Swenshuai.xi    the argument value is returned here.
56*53ee8cc1Swenshuai.xi    Also, when `ordering' is RETURN_IN_ORDER,
57*53ee8cc1Swenshuai.xi    each non-option ARGV-element is returned here.  */
58*53ee8cc1Swenshuai.xi 
59*53ee8cc1Swenshuai.xi extern char *optarg;
60*53ee8cc1Swenshuai.xi 
61*53ee8cc1Swenshuai.xi /* Index in ARGV of the next element to be scanned.
62*53ee8cc1Swenshuai.xi    This is used for communication to and from the caller
63*53ee8cc1Swenshuai.xi    and for communication between successive calls to `getopt'.
64*53ee8cc1Swenshuai.xi 
65*53ee8cc1Swenshuai.xi    On entry to `getopt', zero means this is the first call; initialize.
66*53ee8cc1Swenshuai.xi 
67*53ee8cc1Swenshuai.xi    When `getopt' returns -1, this is the index of the first of the
68*53ee8cc1Swenshuai.xi    non-option elements that the caller should itself scan.
69*53ee8cc1Swenshuai.xi 
70*53ee8cc1Swenshuai.xi    Otherwise, `optind' communicates from one call to the next
71*53ee8cc1Swenshuai.xi    how much of ARGV has been scanned so far.  */
72*53ee8cc1Swenshuai.xi 
73*53ee8cc1Swenshuai.xi extern int optind;
74*53ee8cc1Swenshuai.xi 
75*53ee8cc1Swenshuai.xi /* Callers store zero here to inhibit the error message `getopt' prints
76*53ee8cc1Swenshuai.xi    for unrecognized options.  */
77*53ee8cc1Swenshuai.xi 
78*53ee8cc1Swenshuai.xi extern int opterr;
79*53ee8cc1Swenshuai.xi 
80*53ee8cc1Swenshuai.xi /* Set to an option character which was unrecognized.  */
81*53ee8cc1Swenshuai.xi 
82*53ee8cc1Swenshuai.xi extern int optopt;
83*53ee8cc1Swenshuai.xi 
84*53ee8cc1Swenshuai.xi #ifndef __need_getopt
85*53ee8cc1Swenshuai.xi /* Describe the long-named options requested by the application.
86*53ee8cc1Swenshuai.xi    The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
87*53ee8cc1Swenshuai.xi    of `struct option' terminated by an element containing a name which is
88*53ee8cc1Swenshuai.xi    zero.
89*53ee8cc1Swenshuai.xi 
90*53ee8cc1Swenshuai.xi    The field `has_arg' is:
91*53ee8cc1Swenshuai.xi    no_argument		(or 0) if the option does not take an argument,
92*53ee8cc1Swenshuai.xi    required_argument	(or 1) if the option requires an argument,
93*53ee8cc1Swenshuai.xi    optional_argument 	(or 2) if the option takes an optional argument.
94*53ee8cc1Swenshuai.xi 
95*53ee8cc1Swenshuai.xi    If the field `flag' is not NULL, it points to a variable that is set
96*53ee8cc1Swenshuai.xi    to the value given in the field `val' when the option is found, but
97*53ee8cc1Swenshuai.xi    left unchanged if the option is not found.
98*53ee8cc1Swenshuai.xi 
99*53ee8cc1Swenshuai.xi    To have a long-named option do something other than set an `int' to
100*53ee8cc1Swenshuai.xi    a compiled-in constant, such as set a value from `optarg', set the
101*53ee8cc1Swenshuai.xi    option's `flag' field to zero and its `val' field to a nonzero
102*53ee8cc1Swenshuai.xi    value (the equivalent single-letter option character, if there is
103*53ee8cc1Swenshuai.xi    one).  For long options that have a zero `flag' field, `getopt'
104*53ee8cc1Swenshuai.xi    returns the contents of the `val' field.  */
105*53ee8cc1Swenshuai.xi 
106*53ee8cc1Swenshuai.xi struct option
107*53ee8cc1Swenshuai.xi {
108*53ee8cc1Swenshuai.xi   const char *name;
109*53ee8cc1Swenshuai.xi   /* has_arg can't be an enum because some compilers complain about
110*53ee8cc1Swenshuai.xi      type mismatches in all the code that assumes it is an int.  */
111*53ee8cc1Swenshuai.xi   int has_arg;
112*53ee8cc1Swenshuai.xi   int *flag;
113*53ee8cc1Swenshuai.xi   int val;
114*53ee8cc1Swenshuai.xi };
115*53ee8cc1Swenshuai.xi 
116*53ee8cc1Swenshuai.xi /* Names for the values of the `has_arg' field of `struct option'.  */
117*53ee8cc1Swenshuai.xi 
118*53ee8cc1Swenshuai.xi # define no_argument		0
119*53ee8cc1Swenshuai.xi # define required_argument	1
120*53ee8cc1Swenshuai.xi # define optional_argument	2
121*53ee8cc1Swenshuai.xi #endif	/* need getopt */
122*53ee8cc1Swenshuai.xi 
123*53ee8cc1Swenshuai.xi 
124*53ee8cc1Swenshuai.xi /* Get definitions and prototypes for functions to process the
125*53ee8cc1Swenshuai.xi    arguments in ARGV (ARGC of them, minus the program name) for
126*53ee8cc1Swenshuai.xi    options given in OPTS.
127*53ee8cc1Swenshuai.xi 
128*53ee8cc1Swenshuai.xi    Return the option character from OPTS just read.  Return -1 when
129*53ee8cc1Swenshuai.xi    there are no more options.  For unrecognized options, or options
130*53ee8cc1Swenshuai.xi    missing arguments, `optopt' is set to the option letter, and '?' is
131*53ee8cc1Swenshuai.xi    returned.
132*53ee8cc1Swenshuai.xi 
133*53ee8cc1Swenshuai.xi    The OPTS string is a list of characters which are recognized option
134*53ee8cc1Swenshuai.xi    letters, optionally followed by colons, specifying that that letter
135*53ee8cc1Swenshuai.xi    takes an argument, to be placed in `optarg'.
136*53ee8cc1Swenshuai.xi 
137*53ee8cc1Swenshuai.xi    If a letter in OPTS is followed by two colons, its argument is
138*53ee8cc1Swenshuai.xi    optional.  This behavior is specific to the GNU `getopt'.
139*53ee8cc1Swenshuai.xi 
140*53ee8cc1Swenshuai.xi    The argument `--' causes premature termination of argument
141*53ee8cc1Swenshuai.xi    scanning, explicitly telling `getopt' that there are no more
142*53ee8cc1Swenshuai.xi    options.
143*53ee8cc1Swenshuai.xi 
144*53ee8cc1Swenshuai.xi    If OPTS begins with `--', then non-option arguments are treated as
145*53ee8cc1Swenshuai.xi    arguments to the option '\0'.  This behavior is specific to the GNU
146*53ee8cc1Swenshuai.xi    `getopt'.  */
147*53ee8cc1Swenshuai.xi 
148*53ee8cc1Swenshuai.xi #ifdef __GNU_LIBRARY__
149*53ee8cc1Swenshuai.xi /* Many other libraries have conflicting prototypes for getopt, with
150*53ee8cc1Swenshuai.xi    differences in the consts, in stdlib.h.  To avoid compilation
151*53ee8cc1Swenshuai.xi    errors, only prototype getopt for the GNU C library.  */
152*53ee8cc1Swenshuai.xi extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
153*53ee8cc1Swenshuai.xi        __THROW;
154*53ee8cc1Swenshuai.xi #else /* not __GNU_LIBRARY__ */
155*53ee8cc1Swenshuai.xi extern int getopt ();
156*53ee8cc1Swenshuai.xi #endif /* __GNU_LIBRARY__ */
157*53ee8cc1Swenshuai.xi 
158*53ee8cc1Swenshuai.xi #ifndef __need_getopt
159*53ee8cc1Swenshuai.xi extern int getopt_long (int ___argc, char *const *___argv,
160*53ee8cc1Swenshuai.xi 			const char *__shortopts,
161*53ee8cc1Swenshuai.xi 		        const struct option *__longopts, int *__longind)
162*53ee8cc1Swenshuai.xi        __THROW;
163*53ee8cc1Swenshuai.xi extern int getopt_long_only (int ___argc, char *const *___argv,
164*53ee8cc1Swenshuai.xi 			     const char *__shortopts,
165*53ee8cc1Swenshuai.xi 		             const struct option *__longopts, int *__longind)
166*53ee8cc1Swenshuai.xi        __THROW;
167*53ee8cc1Swenshuai.xi 
168*53ee8cc1Swenshuai.xi #endif
169*53ee8cc1Swenshuai.xi 
170*53ee8cc1Swenshuai.xi #ifdef	__cplusplus
171*53ee8cc1Swenshuai.xi }
172*53ee8cc1Swenshuai.xi #endif
173*53ee8cc1Swenshuai.xi 
174*53ee8cc1Swenshuai.xi /* Make sure we later can get all the definitions and declarations.  */
175*53ee8cc1Swenshuai.xi #undef __need_getopt
176*53ee8cc1Swenshuai.xi 
177*53ee8cc1Swenshuai.xi #endif /* getopt.h */
178