annotate lib/getopt.c @ 425:67815606c5d9 3.0-beta2

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