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