1 /* Declarations for getopt.
2 Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. */
19 * If the OS defines this, just redefine the names to avoid namespace
20 * clashes. In theory, we should be testing the built in functions to
21 * see if they do what we want and use them if possible, but this is
24 * Namely, this was occurring under Mac OS X. This is a Mac OS X (or
27 * Oops. We avoid compiling this with ifdefs because pretty much all of
28 * getopt.c is switched on the same macros... this isn't right, but I think
29 * this isn't our file. Probably best not to mess with it too much.
31 #if defined (_LIBC) || !defined (__GNU_LIBRARY__)
33 # define getopt cvs_getopt
34 # define optarg cvs_optarg
35 # define opterr cvs_opterr
36 # define optind cvs_optind
37 # define optopt cvs_optopt
38 # endif /* HAVE_GETOPT */
39 #endif /* _LIBC or not __GNU_LIBRARY__. */
45 /* For communication from `getopt' to the caller.
46 When `getopt' finds an option that takes an argument,
47 the argument value is returned here.
48 Also, when `ordering' is RETURN_IN_ORDER,
49 each non-option ARGV-element is returned here. */
53 /* Index in ARGV of the next element to be scanned.
54 This is used for communication to and from the caller
55 and for communication between successive calls to `getopt'.
57 On entry to `getopt', zero means this is the first call; initialize.
59 When `getopt' returns EOF, this is the index of the first of the
60 non-option elements that the caller should itself scan.
62 Otherwise, `optind' communicates from one call to the next
63 how much of ARGV has been scanned so far. */
67 /* Callers store zero here to inhibit the error message `getopt' prints
68 for unrecognized options. */
72 /* Set to an option character which was unrecognized. */
76 /* Describe the long-named options requested by the application.
77 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
78 of `struct option' terminated by an element containing a name which is
81 The field `has_arg' is:
82 no_argument (or 0) if the option does not take an argument,
83 required_argument (or 1) if the option requires an argument,
84 optional_argument (or 2) if the option takes an optional argument.
86 If the field `flag' is not NULL, it points to a variable that is set
87 to the value given in the field `val' when the option is found, but
88 left unchanged if the option is not found.
90 To have a long-named option do something other than set an `int' to
91 a compiled-in constant, such as set a value from `optarg', set the
92 option's `flag' field to zero and its `val' field to a nonzero
93 value (the equivalent single-letter option character, if there is
94 one). For long options that have a zero `flag' field, `getopt'
95 returns the contents of the `val' field. */
104 /* has_arg can't be an enum because some compilers complain about
105 type mismatches in all the code that assumes it is an int. */
111 /* Names for the values of the `has_arg' field of `struct option'. */
113 #define no_argument 0
114 #define required_argument 1
115 #define optional_argument 2
118 /* Many other libraries have conflicting prototypes for getopt, with
119 differences in the consts, in stdlib.h. We used to try to prototype
120 it if __GNU_LIBRARY__ but that wasn't problem free either (I'm not sure
121 exactly why), and there is no particular need to prototype it.
122 We really shouldn't be trampling on the system's namespace at all by
123 declaring getopt() but that is a bigger issue. */
124 extern int getopt ();
126 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
127 const struct option *longopts, int *longind);
128 extern int getopt_long_only (int argc, char *const *argv,
129 const char *shortopts,
130 const struct option *longopts, int *longind);
132 /* Internal only. Users should not call this directly. */
133 extern int _getopt_internal (int argc, char *const *argv,
134 const char *shortopts,
135 const struct option *longopts, int *longind,
137 #else /* not __STDC__ */
138 extern int getopt ();
139 extern int getopt_long ();
140 extern int getopt_long_only ();
142 extern int _getopt_internal ();
143 #endif /* not __STDC__ */
149 #endif /* _GETOPT_H */