annotate lib/getopt.c @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents b8bf63962a99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
434
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1 /* Getopt for GNU.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
2 NOTE: getopt is part of the C library, so if you don't know what
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
3 "Keep this file name-space clean" means, talk to drepper@gnu.org
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
4 before changing it!
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
5 Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2010 Free Software
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
6 Foundation, Inc.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
7 This file is part of the GNU C Library.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
8
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
9 This program is free software: you can redistribute it and/or modify
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
11 the Free Software Foundation; either version 3 of the License, or
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
12 (at your option) any later version.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
13
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
17 GNU General Public License for more details.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
18
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
21
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
22 #ifndef _LIBC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
23 # include <config.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
24 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
25
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
26 #include "getopt.h"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
27
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
28 #include <stdio.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
29 #include <stdlib.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
30 #include <string.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
31 #include <unistd.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
32
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
33 #ifdef _LIBC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
34 # include <libintl.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
35 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
36 # include "gettext.h"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
37 # define _(msgid) gettext (msgid)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
38 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
39
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
40 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
41 # include <wchar.h>
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
42 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
43
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
44 #ifndef attribute_hidden
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
45 # define attribute_hidden
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
46 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
47
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
48 /* This version of `getopt' appears to the caller like standard Unix `getopt'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
49 but it behaves differently for the user, since it allows the user
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
50 to intersperse the options with the other arguments.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
51
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
52 As `getopt_long' works, it permutes the elements of ARGV so that,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
53 when it is done, all the options precede everything else. Thus
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
54 all application programs are extended to handle flexible argument order.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
55
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
56 Using `getopt' or setting the environment variable POSIXLY_CORRECT
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
57 disables permutation.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
58 Then the behavior is completely standard.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
59
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
60 GNU application programs can use a third alternative mode in which
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
61 they can distinguish the relative order of options and other arguments. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
62
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
63 #include "getopt_int.h"
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
64
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
65 /* For communication from `getopt' to the caller.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
66 When `getopt' finds an option that takes an argument,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
67 the argument value is returned here.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
68 Also, when `ordering' is RETURN_IN_ORDER,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
69 each non-option ARGV-element is returned here. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
70
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
71 char *optarg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
72
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
73 /* Index in ARGV of the next element to be scanned.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
74 This is used for communication to and from the caller
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
75 and for communication between successive calls to `getopt'.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
76
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
77 On entry to `getopt', zero means this is the first call; initialize.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
78
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
79 When `getopt' returns -1, this is the index of the first of the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
80 non-option elements that the caller should itself scan.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
81
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
82 Otherwise, `optind' communicates from one call to the next
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
83 how much of ARGV has been scanned so far. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
84
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
85 /* 1003.2 says this must be 1 before any call. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
86 int optind = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
87
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
88 /* Callers store zero here to inhibit the error message
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
89 for unrecognized options. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
90
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
91 int opterr = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
92
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
93 /* Set to an option character which was unrecognized.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
94 This must be initialized on some systems to avoid linking in the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
95 system's own getopt implementation. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
96
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
97 int optopt = '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
98
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
99 /* Keep a global copy of all internal members of getopt_data. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
100
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
101 static struct _getopt_data getopt_data;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
102
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
103
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
104 #if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
105 extern char *getenv ();
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
106 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
107
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
108 #ifdef _LIBC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
109 /* Stored original parameters.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
110 XXX This is no good solution. We should rather copy the args so
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
111 that we can compare them later. But we must not use malloc(3). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
112 extern int __libc_argc;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
113 extern char **__libc_argv;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
114
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
115 /* Bash 2.0 gives us an environment variable containing flags
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
116 indicating ARGV elements that should not be considered arguments. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
117
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
118 # ifdef USE_NONOPTION_FLAGS
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
119 /* Defined in getopt_init.c */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
120 extern char *__getopt_nonoption_flags;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
121 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
122
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
123 # ifdef USE_NONOPTION_FLAGS
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
124 # define SWAP_FLAGS(ch1, ch2) \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
125 if (d->__nonoption_flags_len > 0) \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
126 { \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
127 char __tmp = __getopt_nonoption_flags[ch1]; \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
128 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
129 __getopt_nonoption_flags[ch2] = __tmp; \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
130 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
131 # else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
132 # define SWAP_FLAGS(ch1, ch2)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
133 # endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
134 #else /* !_LIBC */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
135 # define SWAP_FLAGS(ch1, ch2)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
136 #endif /* _LIBC */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
137
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
138 /* Exchange two adjacent subsequences of ARGV.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
139 One subsequence is elements [first_nonopt,last_nonopt)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
140 which contains all the non-options that have been skipped so far.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
141 The other is elements [last_nonopt,optind), which contains all
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
142 the options processed since those non-options were skipped.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
143
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
144 `first_nonopt' and `last_nonopt' are relocated so that they describe
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
145 the new indices of the non-options in ARGV after they are moved. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
146
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
147 static void
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
148 exchange (char **argv, struct _getopt_data *d)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
149 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
150 int bottom = d->__first_nonopt;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
151 int middle = d->__last_nonopt;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
152 int top = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
153 char *tem;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
154
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
155 /* Exchange the shorter segment with the far end of the longer segment.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
156 That puts the shorter segment into the right place.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
157 It leaves the longer segment in the right place overall,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
158 but it consists of two parts that need to be swapped next. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
159
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
160 #if defined _LIBC && defined USE_NONOPTION_FLAGS
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
161 /* First make sure the handling of the `__getopt_nonoption_flags'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
162 string can work normally. Our top argument must be in the range
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
163 of the string. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
164 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
165 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
166 /* We must extend the array. The user plays games with us and
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
167 presents new arguments. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
168 char *new_str = malloc (top + 1);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
169 if (new_str == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
170 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
171 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
172 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
173 memset (__mempcpy (new_str, __getopt_nonoption_flags,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
174 d->__nonoption_flags_max_len),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
175 '\0', top + 1 - d->__nonoption_flags_max_len);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
176 d->__nonoption_flags_max_len = top + 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
177 __getopt_nonoption_flags = new_str;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
178 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
179 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
180 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
181
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
182 while (top > middle && middle > bottom)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
183 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
184 if (top - middle > middle - bottom)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
185 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
186 /* Bottom segment is the short one. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
187 int len = middle - bottom;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
188 register int i;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
189
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
190 /* Swap it with the top part of the top segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
191 for (i = 0; i < len; i++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
192 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
193 tem = argv[bottom + i];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
194 argv[bottom + i] = argv[top - (middle - bottom) + i];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
195 argv[top - (middle - bottom) + i] = tem;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
196 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
197 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
198 /* Exclude the moved bottom segment from further swapping. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
199 top -= len;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
200 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
201 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
202 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
203 /* Top segment is the short one. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
204 int len = top - middle;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
205 register int i;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
206
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
207 /* Swap it with the bottom part of the bottom segment. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
208 for (i = 0; i < len; i++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
209 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
210 tem = argv[bottom + i];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
211 argv[bottom + i] = argv[middle + i];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
212 argv[middle + i] = tem;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
213 SWAP_FLAGS (bottom + i, middle + i);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
214 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
215 /* Exclude the moved top segment from further swapping. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
216 bottom += len;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
217 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
218 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
219
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
220 /* Update records for the slots the non-options now occupy. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
221
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
222 d->__first_nonopt += (d->optind - d->__last_nonopt);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
223 d->__last_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
224 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
225
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
226 /* Initialize the internal data when the first call is made. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
227
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
228 static const char *
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
229 _getopt_initialize (int argc _GL_UNUSED,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
230 char **argv _GL_UNUSED, const char *optstring,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
231 struct _getopt_data *d, int posixly_correct)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
232 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
233 /* Start processing options with ARGV-element 1 (since ARGV-element 0
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
234 is the program name); the sequence of previously skipped
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
235 non-option ARGV-elements is empty. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
236
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
237 d->__first_nonopt = d->__last_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
238
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
239 d->__nextchar = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
240
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
241 d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
242
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
243 /* Determine how to handle the ordering of options and nonoptions. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
244
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
245 if (optstring[0] == '-')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
246 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
247 d->__ordering = RETURN_IN_ORDER;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
248 ++optstring;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
249 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
250 else if (optstring[0] == '+')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
251 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
252 d->__ordering = REQUIRE_ORDER;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
253 ++optstring;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
254 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
255 else if (d->__posixly_correct)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
256 d->__ordering = REQUIRE_ORDER;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
257 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
258 d->__ordering = PERMUTE;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
259
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
260 #if defined _LIBC && defined USE_NONOPTION_FLAGS
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
261 if (!d->__posixly_correct
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
262 && argc == __libc_argc && argv == __libc_argv)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
263 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
264 if (d->__nonoption_flags_max_len == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
265 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
266 if (__getopt_nonoption_flags == NULL
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
267 || __getopt_nonoption_flags[0] == '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
268 d->__nonoption_flags_max_len = -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
269 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
270 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
271 const char *orig_str = __getopt_nonoption_flags;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
272 int len = d->__nonoption_flags_max_len = strlen (orig_str);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
273 if (d->__nonoption_flags_max_len < argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
274 d->__nonoption_flags_max_len = argc;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
275 __getopt_nonoption_flags =
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
276 (char *) malloc (d->__nonoption_flags_max_len);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
277 if (__getopt_nonoption_flags == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
278 d->__nonoption_flags_max_len = -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
279 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
280 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
281 '\0', d->__nonoption_flags_max_len - len);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
282 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
283 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
284 d->__nonoption_flags_len = d->__nonoption_flags_max_len;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
285 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
286 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
287 d->__nonoption_flags_len = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
288 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
289
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
290 return optstring;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
291 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
292
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
293 /* Scan elements of ARGV (whose length is ARGC) for option characters
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
294 given in OPTSTRING.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
295
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
296 If an element of ARGV starts with '-', and is not exactly "-" or "--",
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
297 then it is an option element. The characters of this element
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
298 (aside from the initial '-') are option characters. If `getopt'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
299 is called repeatedly, it returns successively each of the option characters
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
300 from each of the option elements.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
301
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
302 If `getopt' finds another option character, it returns that character,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
303 updating `optind' and `nextchar' so that the next call to `getopt' can
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
304 resume the scan with the following option character or ARGV-element.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
305
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
306 If there are no more option characters, `getopt' returns -1.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
307 Then `optind' is the index in ARGV of the first ARGV-element
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
308 that is not an option. (The ARGV-elements have been permuted
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
309 so that those that are not options now come last.)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
310
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
311 OPTSTRING is a string containing the legitimate option characters.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
312 If an option character is seen that is not listed in OPTSTRING,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
313 return '?' after printing an error message. If you set `opterr' to
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
314 zero, the error message is suppressed but we still return '?'.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
315
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
316 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
317 so the following text in the same ARGV-element, or the text of the following
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
318 ARGV-element, is returned in `optarg'. Two colons mean an option that
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
319 wants an optional arg; if there is text in the current ARGV-element,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
320 it is returned in `optarg', otherwise `optarg' is set to zero.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
321
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
322 If OPTSTRING starts with `-' or `+', it requests different methods of
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
323 handling the non-option ARGV-elements.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
324 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
325
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
326 Long-named options begin with `--' instead of `-'.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
327 Their names may be abbreviated as long as the abbreviation is unique
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
328 or is an exact match for some defined option. If they have an
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
329 argument, it follows the option name in the same ARGV-element, separated
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
330 from the option name by a `=', or else the in next ARGV-element.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
331 When `getopt' finds a long-named option, it returns 0 if that option's
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
332 `flag' field is nonzero, the value of the option's `val' field
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
333 if the `flag' field is zero.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
334
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
335 The elements of ARGV aren't really const, because we permute them.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
336 But we pretend they're const in the prototype to be compatible
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
337 with other systems.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
338
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
339 LONGOPTS is a vector of `struct option' terminated by an
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
340 element containing a name which is zero.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
341
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
342 LONGIND returns the index in LONGOPT of the long-named option found.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
343 It is only valid when a long-named option has been found by the most
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
344 recent call.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
345
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
346 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
347 long-named options. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
348
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
349 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
350 _getopt_internal_r (int argc, char **argv, const char *optstring,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
351 const struct option *longopts, int *longind,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
352 int long_only, struct _getopt_data *d, int posixly_correct)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
353 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
354 int print_errors = d->opterr;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
355 if (optstring[0] == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
356 print_errors = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
357
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
358 if (argc < 1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
359 return -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
360
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
361 d->optarg = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
362
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
363 if (d->optind == 0 || !d->__initialized)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
364 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
365 if (d->optind == 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
366 d->optind = 1; /* Don't scan ARGV[0], the program name. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
367 optstring = _getopt_initialize (argc, argv, optstring, d,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
368 posixly_correct);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
369 d->__initialized = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
370 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
371
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
372 /* Test whether ARGV[optind] points to a non-option argument.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
373 Either it does not have option syntax, or there is an environment flag
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
374 from the shell indicating it is not an option. The later information
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
375 is only used when the used in the GNU libc. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
376 #if defined _LIBC && defined USE_NONOPTION_FLAGS
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
377 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
378 || (d->optind < d->__nonoption_flags_len \
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
379 && __getopt_nonoption_flags[d->optind] == '1'))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
380 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
381 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
382 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
383
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
384 if (d->__nextchar == NULL || *d->__nextchar == '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
385 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
386 /* Advance to the next ARGV-element. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
387
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
388 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
389 moved back by the user (who may also have changed the arguments). */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
390 if (d->__last_nonopt > d->optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
391 d->__last_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
392 if (d->__first_nonopt > d->optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
393 d->__first_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
394
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
395 if (d->__ordering == PERMUTE)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
396 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
397 /* If we have just processed some options following some non-options,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
398 exchange them so that the options come first. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
399
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
400 if (d->__first_nonopt != d->__last_nonopt
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
401 && d->__last_nonopt != d->optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
402 exchange ((char **) argv, d);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
403 else if (d->__last_nonopt != d->optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
404 d->__first_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
405
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
406 /* Skip any additional non-options
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
407 and extend the range of non-options previously skipped. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
408
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
409 while (d->optind < argc && NONOPTION_P)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
410 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
411 d->__last_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
412 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
413
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
414 /* The special ARGV-element `--' means premature end of options.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
415 Skip it like a null option,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
416 then exchange with previous non-options as if it were an option,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
417 then skip everything else like a non-option. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
418
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
419 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
420 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
421 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
422
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
423 if (d->__first_nonopt != d->__last_nonopt
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
424 && d->__last_nonopt != d->optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
425 exchange ((char **) argv, d);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
426 else if (d->__first_nonopt == d->__last_nonopt)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
427 d->__first_nonopt = d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
428 d->__last_nonopt = argc;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
429
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
430 d->optind = argc;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
431 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
432
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
433 /* If we have done all the ARGV-elements, stop the scan
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
434 and back over any non-options that we skipped and permuted. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
435
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
436 if (d->optind == argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
437 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
438 /* Set the next-arg-index to point at the non-options
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
439 that we previously skipped, so the caller will digest them. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
440 if (d->__first_nonopt != d->__last_nonopt)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
441 d->optind = d->__first_nonopt;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
442 return -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
443 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
444
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
445 /* If we have come to a non-option and did not permute it,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
446 either stop the scan or describe it to the caller and pass it by. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
447
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
448 if (NONOPTION_P)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
449 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
450 if (d->__ordering == REQUIRE_ORDER)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
451 return -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
452 d->optarg = argv[d->optind++];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
453 return 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
454 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
455
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
456 /* We have found another option-ARGV-element.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
457 Skip the initial punctuation. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
458
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
459 d->__nextchar = (argv[d->optind] + 1
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
460 + (longopts != NULL && argv[d->optind][1] == '-'));
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
461 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
462
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
463 /* Decode the current option-ARGV-element. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
464
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
465 /* Check whether the ARGV-element is a long option.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
466
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
467 If long_only and the ARGV-element has the form "-f", where f is
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
468 a valid short option, don't consider it an abbreviated form of
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
469 a long option that starts with f. Otherwise there would be no
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
470 way to give the -f short option.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
471
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
472 On the other hand, if there's a long option "fubar" and
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
473 the ARGV-element is "-fu", do consider that an abbreviation of
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
474 the long option, just like "--fu", and not "-f" with arg "u".
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
475
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
476 This distinction seems to be the most useful approach. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
477
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
478 if (longopts != NULL
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
479 && (argv[d->optind][1] == '-'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
480 || (long_only && (argv[d->optind][2]
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
481 || !strchr (optstring, argv[d->optind][1])))))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
482 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
483 char *nameend;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
484 const struct option *p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
485 const struct option *pfound = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
486 int exact = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
487 int ambig = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
488 int indfound = -1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
489 int option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
490
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
491 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
492 /* Do nothing. */ ;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
493
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
494 /* Test all long options for either exact match
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
495 or abbreviated matches. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
496 for (p = longopts, option_index = 0; p->name; p++, option_index++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
497 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
498 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
499 if ((unsigned int) (nameend - d->__nextchar)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
500 == (unsigned int) strlen (p->name))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
501 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
502 /* Exact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
503 pfound = p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
504 indfound = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
505 exact = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
506 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
507 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
508 else if (pfound == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
509 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
510 /* First nonexact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
511 pfound = p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
512 indfound = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
513 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
514 else if (long_only
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
515 || pfound->has_arg != p->has_arg
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
516 || pfound->flag != p->flag
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
517 || pfound->val != p->val)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
518 /* Second or later nonexact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
519 ambig = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
520 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
521
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
522 if (ambig && !exact)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
523 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
524 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
525 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
526 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
527 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
528
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
529 if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
530 argv[0], argv[d->optind]) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
531 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
532 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
533
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
534 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
535 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
536
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
537 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
538
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
539 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
540 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
541
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
542 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
543 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
544 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
545 fprintf (stderr, _("%s: option '%s' is ambiguous\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
546 argv[0], argv[d->optind]);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
547 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
548 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
549 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
550 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
551 d->optopt = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
552 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
553 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
554
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
555 if (pfound != NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
556 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
557 option_index = indfound;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
558 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
559 if (*nameend)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
560 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
561 /* Don't test has_arg with >, because some C compilers don't
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
562 allow it to be used on enums. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
563 if (pfound->has_arg)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
564 d->optarg = nameend + 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
565 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
566 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
567 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
568 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
569 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
570 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
571 int n;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
572 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
573
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
574 if (argv[d->optind - 1][1] == '-')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
575 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
576 /* --option */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
577 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
578 n = __asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
579 %s: option '--%s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
580 argv[0], pfound->name);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
581 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
582 fprintf (stderr, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
583 %s: option '--%s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
584 argv[0], pfound->name);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
585 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
586 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
587 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
588 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
589 /* +option or -option */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
590 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
591 n = __asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
592 %s: option '%c%s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
593 argv[0], argv[d->optind - 1][0],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
594 pfound->name);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
595 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
596 fprintf (stderr, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
597 %s: option '%c%s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
598 argv[0], argv[d->optind - 1][0],
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
599 pfound->name);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
600 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
601 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
602
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
603 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
604 if (n >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
605 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
606 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
607
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
608 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
609 ((_IO_FILE *) stderr)->_flags2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
610 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
611
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
612 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
613
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
614 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
615 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
616
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
617 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
618 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
619 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
620 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
621
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
622 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
623
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
624 d->optopt = pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
625 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
626 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
627 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
628 else if (pfound->has_arg == 1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
629 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
630 if (d->optind < argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
631 d->optarg = argv[d->optind++];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
632 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
633 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
634 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
635 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
636 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
637 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
638
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
639 if (__asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
640 %s: option '%s' requires an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
641 argv[0], argv[d->optind - 1]) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
642 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
643 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
644
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
645 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
646 ((_IO_FILE *) stderr)->_flags2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
647 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
648
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
649 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
650
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
651 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
652 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
653
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
654 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
655 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
656 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
657 fprintf (stderr,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
658 _("%s: option '%s' requires an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
659 argv[0], argv[d->optind - 1]);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
660 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
661 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
662 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
663 d->optopt = pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
664 return optstring[0] == ':' ? ':' : '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
665 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
666 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
667 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
668 if (longind != NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
669 *longind = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
670 if (pfound->flag)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
671 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
672 *(pfound->flag) = pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
673 return 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
674 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
675 return pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
676 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
677
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
678 /* Can't find it as a long option. If this is not getopt_long_only,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
679 or the option starts with '--' or is not a valid short
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
680 option, then it's an error.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
681 Otherwise interpret it as a short option. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
682 if (!long_only || argv[d->optind][1] == '-'
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
683 || strchr (optstring, *d->__nextchar) == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
684 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
685 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
686 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
687 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
688 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
689 int n;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
690 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
691
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
692 if (argv[d->optind][1] == '-')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
693 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
694 /* --option */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
695 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
696 n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
697 argv[0], d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
698 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
699 fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
700 argv[0], d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
701 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
702 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
703 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
704 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
705 /* +option or -option */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
706 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
707 n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
708 argv[0], argv[d->optind][0], d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
709 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
710 fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
711 argv[0], argv[d->optind][0], d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
712 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
713 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
714
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
715 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
716 if (n >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
717 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
718 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
719
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
720 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
721 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
722
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
723 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
724
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
725 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
726 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
727
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
728 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
729 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
730 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
731 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
732 d->__nextchar = (char *) "";
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
733 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
734 d->optopt = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
735 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
736 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
737 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
738
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
739 /* Look at and handle the next short option-character. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
740
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
741 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
742 char c = *d->__nextchar++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
743 char *temp = strchr (optstring, c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
744
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
745 /* Increment `optind' when we start to process its last character. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
746 if (*d->__nextchar == '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
747 ++d->optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
748
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
749 if (temp == NULL || c == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
750 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
751 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
752 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
753 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
754 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
755 int n;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
756 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
757
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
758 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
759 n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
760 argv[0], c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
761 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
762 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
763 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
764
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
765 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
766 if (n >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
767 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
768 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
769
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
770 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
771 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
772
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
773 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
774
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
775 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
776 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
777
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
778 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
779 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
780 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
781 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
782 d->optopt = c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
783 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
784 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
785 /* Convenience. Treat POSIX -W foo same as long option --foo */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
786 if (temp[0] == 'W' && temp[1] == ';')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
787 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
788 char *nameend;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
789 const struct option *p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
790 const struct option *pfound = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
791 int exact = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
792 int ambig = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
793 int indfound = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
794 int option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
795
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
796 /* This is an option that requires an argument. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
797 if (*d->__nextchar != '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
798 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
799 d->optarg = d->__nextchar;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
800 /* If we end this ARGV-element by taking the rest as an arg,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
801 we must advance to the next element now. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
802 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
803 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
804 else if (d->optind == argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
805 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
806 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
807 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
808 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
809 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
810
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
811 if (__asprintf (&buf,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
812 _("%s: option requires an argument -- '%c'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
813 argv[0], c) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
814 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
815 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
816
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
817 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
818 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
819
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
820 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
821
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
822 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
823 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
824
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
825 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
826 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
827 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
828 fprintf (stderr,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
829 _("%s: option requires an argument -- '%c'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
830 argv[0], c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
831 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
832 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
833 d->optopt = c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
834 if (optstring[0] == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
835 c = ':';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
836 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
837 c = '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
838 return c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
839 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
840 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
841 /* We already incremented `d->optind' once;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
842 increment it again when taking next ARGV-elt as argument. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
843 d->optarg = argv[d->optind++];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
844
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
845 /* optarg is now the argument, see if it's in the
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
846 table of longopts. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
847
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
848 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
849 nameend++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
850 /* Do nothing. */ ;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
851
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
852 /* Test all long options for either exact match
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
853 or abbreviated matches. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
854 for (p = longopts, option_index = 0; p->name; p++, option_index++)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
855 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
856 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
857 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
858 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
859 /* Exact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
860 pfound = p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
861 indfound = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
862 exact = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
863 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
864 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
865 else if (pfound == NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
866 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
867 /* First nonexact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
868 pfound = p;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
869 indfound = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
870 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
871 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
872 /* Second or later nonexact match found. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
873 ambig = 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
874 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
875 if (ambig && !exact)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
876 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
877 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
878 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
879 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
880 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
881
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
882 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
883 argv[0], argv[d->optind]) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
884 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
885 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
886
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
887 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
888 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
889
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
890 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
891
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
892 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
893 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
894
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
895 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
896 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
897 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
898 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
899 argv[0], argv[d->optind]);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
900 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
901 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
902 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
903 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
904 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
905 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
906 if (pfound != NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
907 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
908 option_index = indfound;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
909 if (*nameend)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
910 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
911 /* Don't test has_arg with >, because some C compilers don't
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
912 allow it to be used on enums. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
913 if (pfound->has_arg)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
914 d->optarg = nameend + 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
915 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
916 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
917 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
918 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
919 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
920 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
921
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
922 if (__asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
923 %s: option '-W %s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
924 argv[0], pfound->name) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
925 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
926 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
927
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
928 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
929 ((_IO_FILE *) stderr)->_flags2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
930 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
931
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
932 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
933
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
934 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
935 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
936
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
937 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
938 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
939 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
940 fprintf (stderr, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
941 %s: option '-W %s' doesn't allow an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
942 argv[0], pfound->name);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
943 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
944 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
945
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
946 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
947 return '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
948 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
949 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
950 else if (pfound->has_arg == 1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
951 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
952 if (d->optind < argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
953 d->optarg = argv[d->optind++];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
954 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
955 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
956 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
957 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
958 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
959 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
960
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
961 if (__asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
962 %s: option '%s' requires an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
963 argv[0], argv[d->optind - 1]) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
964 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
965 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
966
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
967 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
968 ((_IO_FILE *) stderr)->_flags2
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
969 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
970
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
971 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
972
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
973 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
974 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
975
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
976 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
977 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
978 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
979 fprintf (stderr,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
980 _("%s: option '%s' requires an argument\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
981 argv[0], argv[d->optind - 1]);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
982 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
983 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
984 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
985 return optstring[0] == ':' ? ':' : '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
986 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
987 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
988 d->__nextchar += strlen (d->__nextchar);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
989 if (longind != NULL)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
990 *longind = option_index;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
991 if (pfound->flag)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
992 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
993 *(pfound->flag) = pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
994 return 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
995 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
996 return pfound->val;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
997 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
998 d->__nextchar = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
999 return 'W'; /* Let the application handle it. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1000 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1001 if (temp[1] == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1002 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1003 if (temp[2] == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1004 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1005 /* This is an option that accepts an argument optionally. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1006 if (*d->__nextchar != '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1007 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1008 d->optarg = d->__nextchar;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1009 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1010 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1011 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1012 d->optarg = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1013 d->__nextchar = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1014 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1015 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1016 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1017 /* This is an option that requires an argument. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1018 if (*d->__nextchar != '\0')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1019 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1020 d->optarg = d->__nextchar;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1021 /* If we end this ARGV-element by taking the rest as an arg,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1022 we must advance to the next element now. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1023 d->optind++;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1024 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1025 else if (d->optind == argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1026 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1027 if (print_errors)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1028 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1029 #if defined _LIBC && defined USE_IN_LIBIO
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1030 char *buf;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1031
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1032 if (__asprintf (&buf, _("\
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1033 %s: option requires an argument -- '%c'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1034 argv[0], c) >= 0)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1035 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1036 _IO_flockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1037
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1038 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1039 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1040
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1041 __fxprintf (NULL, "%s", buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1042
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1043 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1044 _IO_funlockfile (stderr);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1045
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1046 free (buf);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1047 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1048 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1049 fprintf (stderr,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1050 _("%s: option requires an argument -- '%c'\n"),
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1051 argv[0], c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1052 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1053 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1054 d->optopt = c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1055 if (optstring[0] == ':')
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1056 c = ':';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1057 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1058 c = '?';
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1059 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1060 else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1061 /* We already incremented `optind' once;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1062 increment it again when taking next ARGV-elt as argument. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1063 d->optarg = argv[d->optind++];
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1064 d->__nextchar = NULL;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1065 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1066 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1067 return c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1068 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1069 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1070
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1071 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1072 _getopt_internal (int argc, char **argv, const char *optstring,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1073 const struct option *longopts, int *longind, int long_only,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1074 int posixly_correct)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1075 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1076 int result;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1077
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1078 getopt_data.optind = optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1079 getopt_data.opterr = opterr;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1080
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1081 result = _getopt_internal_r (argc, argv, optstring, longopts,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1082 longind, long_only, &getopt_data,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1083 posixly_correct);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1084
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1085 optind = getopt_data.optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1086 optarg = getopt_data.optarg;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1087 optopt = getopt_data.optopt;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1088
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1089 return result;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1090 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1091
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1092 /* glibc gets a LSB-compliant getopt.
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1093 Standalone applications get a POSIX-compliant getopt. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1094 #if _LIBC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1095 enum { POSIXLY_CORRECT = 0 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1096 #else
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1097 enum { POSIXLY_CORRECT = 1 };
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1098 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1099
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1100 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1101 getopt (int argc, char *const *argv, const char *optstring)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1102 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1103 return _getopt_internal (argc, (char **) argv, optstring,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1104 (const struct option *) 0,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1105 (int *) 0,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1106 0, POSIXLY_CORRECT);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1107 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1108
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1109 #ifdef _LIBC
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1110 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1111 __posix_getopt (int argc, char *const *argv, const char *optstring)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1112 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1113 return _getopt_internal (argc, argv, optstring,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1114 (const struct option *) 0,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1115 (int *) 0,
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1116 0, 1);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1117 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1118 #endif
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1119
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1120
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1121 #ifdef TEST
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1122
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1123 /* Compile with -DTEST to make an executable for use in testing
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1124 the above definition of `getopt'. */
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1125
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1126 int
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1127 main (int argc, char **argv)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1128 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1129 int c;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1130 int digit_optind = 0;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1131
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1132 while (1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1133 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1134 int this_option_optind = optind ? optind : 1;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1135
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1136 c = getopt (argc, argv, "abc:d:0123456789");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1137 if (c == -1)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1138 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1139
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1140 switch (c)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1141 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1142 case '0':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1143 case '1':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1144 case '2':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1145 case '3':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1146 case '4':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1147 case '5':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1148 case '6':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1149 case '7':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1150 case '8':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1151 case '9':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1152 if (digit_optind != 0 && digit_optind != this_option_optind)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1153 printf ("digits occur in two different argv-elements.\n");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1154 digit_optind = this_option_optind;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1155 printf ("option %c\n", c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1156 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1157
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1158 case 'a':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1159 printf ("option a\n");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1160 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1161
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1162 case 'b':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1163 printf ("option b\n");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1164 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1165
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1166 case 'c':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1167 printf ("option c with value '%s'\n", optarg);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1168 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1169
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1170 case '?':
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1171 break;
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1172
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1173 default:
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1174 printf ("?? getopt returned character code 0%o ??\n", c);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1175 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1176 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1177
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1178 if (optind < argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1179 {
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1180 printf ("non-option ARGV-elements: ");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1181 while (optind < argc)
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1182 printf ("%s ", argv[optind++]);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1183 printf ("\n");
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1184 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1185
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1186 exit (0);
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1187 }
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1188
b8bf63962a99 Added various generated files for release
lost@l-w.ca
parents:
diff changeset
1189 #endif /* TEST */