2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)getopt.h 1.3 03/03/06 eric */
14 /* Declarations for getopt.
15 Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Library General Public License
19 as published by the Free Software Foundation; either version 2, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU Library General Public License for more details.
27 You should have received a copy of the GNU Library General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
42 /* For communication from `getopt' to the caller.
43 When `getopt' finds an option that takes an argument,
44 the argument value is returned here.
45 Also, when `ordering' is RETURN_IN_ORDER,
46 each non-option ARGV-element is returned here. */
50 /* Index in ARGV of the next element to be scanned.
51 This is used for communication to and from the caller
52 and for communication between successive calls to `getopt'.
54 On entry to `getopt', zero means this is the first call; initialize.
56 When `getopt' returns EOF, this is the index of the first of the
57 non-option elements that the caller should itself scan.
59 Otherwise, `optind' communicates from one call to the next
60 how much of ARGV has been scanned so far. */
64 /* Callers store zero here to inhibit the error message `getopt' prints
65 for unrecognized options. */
69 /* Set to an option character which was unrecognized. */
73 /* Describe the long-named options requested by the application.
74 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
75 of `struct option' terminated by an element containing a name which is
78 The field `has_arg' is:
79 no_argument (or 0) if the option does not take an argument,
80 required_argument (or 1) if the option requires an argument,
81 optional_argument (or 2) if the option takes an optional argument.
83 If the field `flag' is not NULL, it points to a variable that is set
84 to the value given in the field `val' when the option is found, but
85 left unchanged if the option is not found.
87 To have a long-named option do something other than set an `int' to
88 a compiled-in constant, such as set a value from `optarg', set the
89 option's `flag' field to zero and its `val' field to a nonzero
90 value (the equivalent single-letter option character, if there is
91 one). For long options that have a zero `flag' field, `getopt'
92 returns the contents of the `val' field. */
102 /* has_arg can't be an enum because some compilers complain about
103 type mismatches in all the code that assumes it is an int. */
109 /* Names for the values of the `has_arg' field of `struct option'. */
111 #define no_argument 0
112 #define required_argument 1
113 #define optional_argument 2
117 #if defined(__GNU_LIBRARY__)
118 /* Many other libraries have conflicting prototypes for getopt, with
119 differences in the consts, in stdlib.h. To avoid compilation
120 errors, only prototype getopt for the GNU C library. */
121 extern int getopt (int argc, char *const *argv, const char *shortopts);
122 #else /* not __GNU_LIBRARY__ */
123 extern int getopt ();
124 #endif /* not __GNU_LIBRARY__ */
125 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
126 const struct option *longopts, int *longind);
127 extern int getopt_long_only (int argc, char *const *argv,
128 const char *shortopts,
129 const struct option *longopts, int *longind);
131 /* Internal only. Users should not call this directly. */
132 extern int _getopt_internal (int argc, char *const *argv,
133 const char *shortopts,
134 const struct option *longopts, int *longind,
136 #else /* not __STDC__ */
137 extern int getopt ();
138 extern int getopt_long ();
139 extern int getopt_long_only ();
141 extern int _getopt_internal ();
142 #endif /* not __STDC__ */
148 #endif /* _GETOPT_H */