VirtualBox

source: kBuild/trunk/src/kmk/kmkbuiltin/getopt_r.h@ 3387

Last change on this file since 3387 was 3248, checked in by bird, 5 years ago

kmkbuiltin: Darwin build fixes

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1/* Reentrant version of getopt.
2
3Based on ../getopt*.*:
4
5 Declarations for getopt.
6Copyright (C) 1989-2016 Free Software Foundation, Inc.
7
8NOTE: The canonical source of this file is maintained with the GNU C Library.
9Bugs can be reported to bug-glibc@gnu.org.
10
11GNU Make is free software; you can redistribute it and/or modify it under the
12terms of the GNU General Public License as published by the Free Software
13Foundation; either version 3 of the License, or (at your option) any later
14version.
15
16GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
17WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program. If not, see <http://www.gnu.org/licenses/>.
22
23Modifications:
24 Copyright (c) 2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
25*/
26
27/* Not quite safe to mix when converting code. */
28#ifdef _GETOPT_H
29# define _GETOPT_H "getopt.h was included already"
30# error "getopt.h was included already"
31#endif
32
33#ifndef INCLUDED_GETOPT_R_H
34#define INCLUDED_GETOPT_R_H 1
35
36#include <stddef.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42typedef struct getopt_state_r
43{
44
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. */
50
51/*extern*/ char *optarg;
52
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'.
56
57 On entry to `getopt', zero means this is the first call; initialize.
58
59 When `getopt' returns -1, this is the index of the first of the
60 non-option elements that the caller should itself scan.
61
62 Otherwise, `optind' communicates from one call to the next
63 how much of ARGV has been scanned so far. */
64
65/*extern*/ int optind;
66
67/* Callers store zero here to inhibit the error message `getopt' prints
68 for unrecognized options. */
69
70/*extern*/ int opterr;
71
72/* Set to an option character which was unrecognized. */
73
74/*extern*/ int optopt;
75
76
77/* Internal state: */
78
79/* The next char to be scanned in the option-element
80 in which the last option character we returned was found.
81 This allows us to pick up the scan where we left off.
82
83 If this is zero, or a null string, it means resume the scan
84 by advancing to the next ARGV-element. */
85
86/*static*/ char *nextchar;
87
88/* REQUIRE_ORDER, PERMUTE or RETURN_IN_ORDER, see getopt_r.c. */
89/*static*/ int ordering;
90
91/* Value of POSIXLY_CORRECT environment variable. */
92/*static*/ const char *posixly_correct; /* bird: added 'const' */
93
94/* Describe the part of ARGV that contains non-options that have
95 been skipped. `first_nonopt' is the index in ARGV of the first of them;
96 `last_nonopt' is the index after the last of them. */
97
98/*static*/ int first_nonopt;
99/*static*/ int last_nonopt;
100
101/* Mainly for asserting usage sanity. */
102/*static*/ void *__getopt_initialized;
103
104/* New internal state (to resubmitting same parameters in each call): */
105 /* new: the argument vector length. */
106 int argc;
107 /* new: the argument vector. */
108 char * const *argv;
109 /* new: the short option string (can be NULL/empty). */
110 const char *optstring;
111 /* new: the short option string length. */
112 size_t len_optstring;
113 /* new: the long options (can be NULL) */
114 const struct option *long_options;
115 /* Output context for err.h. */
116 struct KMKBUILTINCTX *pCtx;
117} getopt_state_r;
118
119
120#ifndef no_argument
121
122/* Describe the long-named options requested by the application.
123 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
124 of `struct option' terminated by an element containing a name which is
125 zero.
126
127 The field `has_arg' is:
128 no_argument (or 0) if the option does not take an argument,
129 required_argument (or 1) if the option requires an argument,
130 optional_argument (or 2) if the option takes an optional argument.
131
132 If the field `flag' is not NULL, it points to a variable that is set
133 to the value given in the field `val' when the option is found, but
134 left unchanged if the option is not found.
135
136 To have a long-named option do something other than set an `int' to
137 a compiled-in constant, such as set a value from `optarg', set the
138 option's `flag' field to zero and its `val' field to a nonzero
139 value (the equivalent single-letter option character, if there is
140 one). For long options that have a zero `flag' field, `getopt'
141 returns the contents of the `val' field. */
142
143struct option
144{
145#if defined (__STDC__) && __STDC__
146 const char *name;
147#else
148 char *name;
149#endif
150 /* has_arg can't be an enum because some compilers complain about
151 type mismatches in all the code that assumes it is an int. */
152 int has_arg;
153 int *flag;
154 int val;
155};
156
157/* Names for the values of the `has_arg' field of `struct option'. */
158
159#define no_argument 0
160#define required_argument 1
161#define optional_argument 2
162
163#endif /* Same as ../getopt.h. Fix later? */
164
165extern void getopt_initialize_r (struct getopt_state_r *gos, int argc,
166 char *const *argv, const char *shortopts,
167 const struct option *longopts,
168 char **envp, struct KMKBUILTINCTX *pCtx);
169extern int getopt_r (struct getopt_state_r *gos);
170extern int getopt_long_r (struct getopt_state_r *gos, int *longind);
171extern int getopt_long_only_r (struct getopt_state_r *gos, int *longind);
172
173/* Internal only. Users should not call this directly. */
174extern int _getopt_internal_r (struct getopt_state_r *gos,
175 const struct option *longopts,
176 int *longind, int long_only);
177
178#ifdef __cplusplus
179}
180#endif
181
182#endif /* getopt_r.h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use