diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2017-10-03 22:26:42 +0200 |
---|---|---|
committer | Ross Burton <ross.burton@intel.com> | 2017-10-04 15:34:40 +0100 |
commit | c7f97f199a6dd54d3f369f0465a6bfd2cfa739b9 (patch) | |
tree | 0d6a33c4cc7b7fa15251fe77e378881b1c9f8c31 /recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch | |
parent | 08afd879388514af24e2c720066d479cfc71a433 (diff) | |
download | meta-gplv2-c7f97f199a6dd54d3f369f0465a6bfd2cfa739b9.tar.gz |
groff: Drop local getopt implementation in favor of the one from glibc
This avoids the following error with GCC 7:
In file included from /usr/include/bits/getopt_posix.h:27:0,
from /usr/include/unistd.h:872,
from src/libs/libgroff/maxfilename.cc:28:
/usr/include/bits/getopt_core.h:91:12: error: declaration of 'int
getopt(int, char* const*, const char*) throw ()' has a different
exception specifier
extern int getopt (int ___argc, char *const *___argv,
const char *__shortopts)
^~~~~~
In file included from src/include/lib.h:42:0,
from src/libs/libgroff/maxfilename.cc:23:
src/include/groff-getopt.h:50:12: note: from previous declaration
'int getopt(int, char* const*, const char*)'
extern int getopt(int, // __argc
^~~~~~
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch')
-rw-r--r-- | recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch | 1839 |
1 files changed, 1839 insertions, 0 deletions
diff --git a/recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch b/recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch new file mode 100644 index 0000000..c47e1a7 --- /dev/null +++ b/recipes-extended/groff/groff-1.18.1.4/0002-Drop-local-getopt-implementation-in-favor-of-the-one.patch | |||
@@ -0,0 +1,1839 @@ | |||
1 | From 27a79ebb75b6fe2731be6e48add7c94dc127f8a2 Mon Sep 17 00:00:00 2001 | ||
2 | From: Peter Kjellerstedt <pkj@axis.com> | ||
3 | Date: Tue, 3 Oct 2017 21:51:04 +0200 | ||
4 | Subject: [PATCH 2/2] Drop local getopt implementation in favor of the one from | ||
5 | glibc | ||
6 | |||
7 | This avoids the following error with GCC 7: | ||
8 | |||
9 | In file included from /usr/include/bits/getopt_posix.h:27:0, | ||
10 | from /usr/include/unistd.h:872, | ||
11 | from src/libs/libgroff/maxfilename.cc:28: | ||
12 | /usr/include/bits/getopt_core.h:91:12: error: declaration of 'int | ||
13 | getopt(int, char* const*, const char*) throw ()' has a different | ||
14 | exception specifier | ||
15 | extern int getopt (int ___argc, char *const *___argv, | ||
16 | const char *__shortopts) | ||
17 | ^~~~~~ | ||
18 | In file included from src/include/lib.h:42:0, | ||
19 | from src/libs/libgroff/maxfilename.cc:23: | ||
20 | src/include/groff-getopt.h:50:12: note: from previous declaration | ||
21 | 'int getopt(int, char* const*, const char*)' | ||
22 | extern int getopt(int, // __argc | ||
23 | ^~~~~~ | ||
24 | |||
25 | Upstream-Status: Inappropriate [legacy version] | ||
26 | Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> | ||
27 | --- | ||
28 | src/include/Makefile.sub | 2 - | ||
29 | src/include/getopt.h | 181 ------ | ||
30 | src/include/groff-getopt.h | 68 --- | ||
31 | src/include/lib.h | 11 - | ||
32 | src/libs/libgroff/Makefile.sub | 4 - | ||
33 | src/libs/libgroff/getopt.c | 1277 ---------------------------------------- | ||
34 | src/libs/libgroff/getopt1.c | 188 ------ | ||
35 | 7 files changed, 1731 deletions(-) | ||
36 | delete mode 100644 src/include/getopt.h | ||
37 | delete mode 100644 src/include/groff-getopt.h | ||
38 | delete mode 100644 src/libs/libgroff/getopt.c | ||
39 | delete mode 100644 src/libs/libgroff/getopt1.c | ||
40 | |||
41 | diff --git a/src/include/Makefile.sub b/src/include/Makefile.sub | ||
42 | index 620d345..205fe8b 100644 | ||
43 | --- a/src/include/Makefile.sub | ||
44 | +++ b/src/include/Makefile.sub | ||
45 | @@ -9,8 +9,6 @@ HDRS=\ | ||
46 | error.h \ | ||
47 | font.h \ | ||
48 | geometry.h \ | ||
49 | - getopt.h \ | ||
50 | - groff-getopt.h \ | ||
51 | htmlhint.h \ | ||
52 | index.h \ | ||
53 | lib.h \ | ||
54 | diff --git a/src/include/getopt.h b/src/include/getopt.h | ||
55 | deleted file mode 100644 | ||
56 | index 4283c35..0000000 | ||
57 | --- a/src/include/getopt.h | ||
58 | +++ /dev/null | ||
59 | @@ -1,181 +0,0 @@ | ||
60 | -/* Declarations for getopt. | ||
61 | - Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. | ||
62 | - This file is part of the GNU C Library. | ||
63 | - | ||
64 | - The GNU C Library is free software; you can redistribute it and/or | ||
65 | - modify it under the terms of the GNU Lesser General Public | ||
66 | - License as published by the Free Software Foundation; either | ||
67 | - version 2.1 of the License, or (at your option) any later version. | ||
68 | - | ||
69 | - The GNU C Library is distributed in the hope that it will be useful, | ||
70 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
71 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
72 | - Lesser General Public License for more details. | ||
73 | - | ||
74 | - You should have received a copy of the GNU Lesser General Public | ||
75 | - License along with the GNU C Library; if not, write to the Free | ||
76 | - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
77 | - 02111-1307 USA. */ | ||
78 | - | ||
79 | -#ifndef _GETOPT_H | ||
80 | - | ||
81 | -#ifndef __need_getopt | ||
82 | -# define _GETOPT_H 1 | ||
83 | -#endif | ||
84 | - | ||
85 | -/* If __GNU_LIBRARY__ is not already defined, either we are being used | ||
86 | - standalone, or this is the first header included in the source file. | ||
87 | - If we are being used with glibc, we need to include <features.h>, but | ||
88 | - that does not exist if we are standalone. So: if __GNU_LIBRARY__ is | ||
89 | - not defined, include <ctype.h>, which will pull in <features.h> for us | ||
90 | - if it's from glibc. (Why ctype.h? It's guaranteed to exist and it | ||
91 | - doesn't flood the namespace with stuff the way some other headers do.) */ | ||
92 | -#if !defined __GNU_LIBRARY__ | ||
93 | -# include <ctype.h> | ||
94 | -#endif | ||
95 | - | ||
96 | -#ifdef __cplusplus | ||
97 | -extern "C" { | ||
98 | -#endif | ||
99 | - | ||
100 | -/* For communication from `getopt' to the caller. | ||
101 | - When `getopt' finds an option that takes an argument, | ||
102 | - the argument value is returned here. | ||
103 | - Also, when `ordering' is RETURN_IN_ORDER, | ||
104 | - each non-option ARGV-element is returned here. */ | ||
105 | - | ||
106 | -extern char *optarg; | ||
107 | - | ||
108 | -/* Index in ARGV of the next element to be scanned. | ||
109 | - This is used for communication to and from the caller | ||
110 | - and for communication between successive calls to `getopt'. | ||
111 | - | ||
112 | - On entry to `getopt', zero means this is the first call; initialize. | ||
113 | - | ||
114 | - When `getopt' returns -1, this is the index of the first of the | ||
115 | - non-option elements that the caller should itself scan. | ||
116 | - | ||
117 | - Otherwise, `optind' communicates from one call to the next | ||
118 | - how much of ARGV has been scanned so far. */ | ||
119 | - | ||
120 | -extern int optind; | ||
121 | - | ||
122 | -/* Callers store zero here to inhibit the error message `getopt' prints | ||
123 | - for unrecognized options. */ | ||
124 | - | ||
125 | -extern int opterr; | ||
126 | - | ||
127 | -/* Set to an option character which was unrecognized. */ | ||
128 | - | ||
129 | -extern int optopt; | ||
130 | - | ||
131 | -#ifndef __need_getopt | ||
132 | -/* Describe the long-named options requested by the application. | ||
133 | - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector | ||
134 | - of `struct option' terminated by an element containing a name which is | ||
135 | - zero. | ||
136 | - | ||
137 | - The field `has_arg' is: | ||
138 | - no_argument (or 0) if the option does not take an argument, | ||
139 | - required_argument (or 1) if the option requires an argument, | ||
140 | - optional_argument (or 2) if the option takes an optional argument. | ||
141 | - | ||
142 | - If the field `flag' is not NULL, it points to a variable that is set | ||
143 | - to the value given in the field `val' when the option is found, but | ||
144 | - left unchanged if the option is not found. | ||
145 | - | ||
146 | - To have a long-named option do something other than set an `int' to | ||
147 | - a compiled-in constant, such as set a value from `optarg', set the | ||
148 | - option's `flag' field to zero and its `val' field to a nonzero | ||
149 | - value (the equivalent single-letter option character, if there is | ||
150 | - one). For long options that have a zero `flag' field, `getopt' | ||
151 | - returns the contents of the `val' field. */ | ||
152 | - | ||
153 | -struct option | ||
154 | -{ | ||
155 | -# if (defined __STDC__ && __STDC__) || defined __cplusplus | ||
156 | - const char *name; | ||
157 | -# else | ||
158 | - char *name; | ||
159 | -# endif | ||
160 | - /* has_arg can't be an enum because some compilers complain about | ||
161 | - type mismatches in all the code that assumes it is an int. */ | ||
162 | - int has_arg; | ||
163 | - int *flag; | ||
164 | - int val; | ||
165 | -}; | ||
166 | - | ||
167 | -/* Names for the values of the `has_arg' field of `struct option'. */ | ||
168 | - | ||
169 | -# define no_argument 0 | ||
170 | -# define required_argument 1 | ||
171 | -# define optional_argument 2 | ||
172 | -#endif /* need getopt */ | ||
173 | - | ||
174 | - | ||
175 | -/* Get definitions and prototypes for functions to process the | ||
176 | - arguments in ARGV (ARGC of them, minus the program name) for | ||
177 | - options given in OPTS. | ||
178 | - | ||
179 | - Return the option character from OPTS just read. Return -1 when | ||
180 | - there are no more options. For unrecognized options, or options | ||
181 | - missing arguments, `optopt' is set to the option letter, and '?' is | ||
182 | - returned. | ||
183 | - | ||
184 | - The OPTS string is a list of characters which are recognized option | ||
185 | - letters, optionally followed by colons, specifying that that letter | ||
186 | - takes an argument, to be placed in `optarg'. | ||
187 | - | ||
188 | - If a letter in OPTS is followed by two colons, its argument is | ||
189 | - optional. This behavior is specific to the GNU `getopt'. | ||
190 | - | ||
191 | - The argument `--' causes premature termination of argument | ||
192 | - scanning, explicitly telling `getopt' that there are no more | ||
193 | - options. | ||
194 | - | ||
195 | - If OPTS begins with `--', then non-option arguments are treated as | ||
196 | - arguments to the option '\0'. This behavior is specific to the GNU | ||
197 | - `getopt'. */ | ||
198 | - | ||
199 | -#if (defined __STDC__ && __STDC__) || defined __cplusplus | ||
200 | -# ifdef __GNU_LIBRARY__ | ||
201 | -/* Many other libraries have conflicting prototypes for getopt, with | ||
202 | - differences in the consts, in stdlib.h. To avoid compilation | ||
203 | - errors, only prototype getopt for the GNU C library. */ | ||
204 | -extern int getopt (int ___argc, char *const *___argv, const char *__shortopts); | ||
205 | -# else /* not __GNU_LIBRARY__ */ | ||
206 | -extern int getopt (); | ||
207 | -# endif /* __GNU_LIBRARY__ */ | ||
208 | - | ||
209 | -# ifndef __need_getopt | ||
210 | -extern int getopt_long (int ___argc, char *const *___argv, | ||
211 | - const char *__shortopts, | ||
212 | - const struct option *__longopts, int *__longind); | ||
213 | -extern int getopt_long_only (int ___argc, char *const *___argv, | ||
214 | - const char *__shortopts, | ||
215 | - const struct option *__longopts, int *__longind); | ||
216 | - | ||
217 | -/* Internal only. Users should not call this directly. */ | ||
218 | -extern int _getopt_internal (int ___argc, char *const *___argv, | ||
219 | - const char *__shortopts, | ||
220 | - const struct option *__longopts, int *__longind, | ||
221 | - int __long_only); | ||
222 | -# endif | ||
223 | -#else /* not __STDC__ */ | ||
224 | -extern int getopt (); | ||
225 | -# ifndef __need_getopt | ||
226 | -extern int getopt_long (); | ||
227 | -extern int getopt_long_only (); | ||
228 | - | ||
229 | -extern int _getopt_internal (); | ||
230 | -# endif | ||
231 | -#endif /* __STDC__ */ | ||
232 | - | ||
233 | -#ifdef __cplusplus | ||
234 | -} | ||
235 | -#endif | ||
236 | - | ||
237 | -/* Make sure we later can get all the definitions and declarations. */ | ||
238 | -#undef __need_getopt | ||
239 | - | ||
240 | -#endif /* getopt.h */ | ||
241 | diff --git a/src/include/groff-getopt.h b/src/include/groff-getopt.h | ||
242 | deleted file mode 100644 | ||
243 | index a30e197..0000000 | ||
244 | --- a/src/include/groff-getopt.h | ||
245 | +++ /dev/null | ||
246 | @@ -1,68 +0,0 @@ | ||
247 | -// -*- C++ -*- | ||
248 | -/* Copyright (C) 2000, 2001 Free Software Foundation, Inc. | ||
249 | - Written by Werner Lemberg (wl@gnu.org) | ||
250 | - | ||
251 | -This file is part of groff. | ||
252 | - | ||
253 | -groff is free software; you can redistribute it and/or modify it under | ||
254 | -the terms of the GNU General Public License as published by the Free | ||
255 | -Software Foundation; either version 2, or (at your option) any later | ||
256 | -version. | ||
257 | - | ||
258 | -groff is distributed in the hope that it will be useful, but WITHOUT ANY | ||
259 | -WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
260 | -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
261 | -for more details. | ||
262 | - | ||
263 | -You should have received a copy of the GNU General Public License along | ||
264 | -with groff; see the file COPYING. If not, write to the Free Software | ||
265 | -Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
266 | - | ||
267 | -/* | ||
268 | - This file has to be included from within lib.h instead of getopt.h | ||
269 | - to avoid problems with picky C++ compilers. | ||
270 | -*/ | ||
271 | - | ||
272 | -#ifndef _GROFF_GETOPT_H | ||
273 | -#define _GROFF_GETOPT_H | ||
274 | - | ||
275 | -#ifdef __cplusplus | ||
276 | -extern "C" { | ||
277 | -#endif | ||
278 | - | ||
279 | -extern char *optarg; | ||
280 | -extern int optind; | ||
281 | -extern int opterr; | ||
282 | -extern int optopt; | ||
283 | - | ||
284 | -struct option | ||
285 | -{ | ||
286 | - const char *name; | ||
287 | - int has_arg; | ||
288 | - int *flag; | ||
289 | - int val; | ||
290 | -}; | ||
291 | - | ||
292 | -#define no_argument 0 | ||
293 | -#define required_argument 1 | ||
294 | -#define optional_argument 2 | ||
295 | - | ||
296 | -extern int getopt(int, // __argc | ||
297 | - char *const *, // __argv | ||
298 | - const char *); // __shortopts | ||
299 | -extern int getopt_long(int, // __argc | ||
300 | - char *const *, // __argv | ||
301 | - const char *, // __shortopts | ||
302 | - const struct option *, // __longopts | ||
303 | - int *); // __longind | ||
304 | -extern int getopt_long_only(int, // __argc | ||
305 | - char *const *, // __argv | ||
306 | - const char *, // __shortopts | ||
307 | - const struct option *, // __longopts | ||
308 | - int *); // __longind | ||
309 | - | ||
310 | -#ifdef __cplusplus | ||
311 | -} | ||
312 | -#endif | ||
313 | - | ||
314 | -#endif /* _GROFF_GETOPT_H */ | ||
315 | diff --git a/src/include/lib.h b/src/include/lib.h | ||
316 | index c6468e0..8c77938 100644 | ||
317 | --- a/src/include/lib.h | ||
318 | +++ b/src/include/lib.h | ||
319 | @@ -31,18 +31,7 @@ extern "C" { | ||
320 | const char *if_to_a(int, int); | ||
321 | } | ||
322 | |||
323 | -/* stdio.h on IRIX, OSF/1, emx, and UWIN include getopt.h */ | ||
324 | -/* unistd.h on CYGWIN includes getopt.h */ | ||
325 | - | ||
326 | -#if !(defined(__sgi) \ | ||
327 | - || (defined(__osf__) && defined(__alpha)) \ | ||
328 | - || defined(_UWIN) \ | ||
329 | - || defined(__EMX__) \ | ||
330 | - || defined(__CYGWIN__)) | ||
331 | -#include <groff-getopt.h> | ||
332 | -#else | ||
333 | #include <getopt.h> | ||
334 | -#endif | ||
335 | |||
336 | char *strsave(const char *s); | ||
337 | int is_prime(unsigned); | ||
338 | diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub | ||
339 | index ff6bd00..bc0f846 100644 | ||
340 | --- a/src/libs/libgroff/Makefile.sub | ||
341 | +++ b/src/libs/libgroff/Makefile.sub | ||
342 | @@ -13,8 +13,6 @@ OBJS=\ | ||
343 | font.$(OBJEXT) \ | ||
344 | fontfile.$(OBJEXT) \ | ||
345 | geometry.$(OBJEXT) \ | ||
346 | - getopt.$(OBJEXT) \ | ||
347 | - getopt1.$(OBJEXT) \ | ||
348 | htmlhint.$(OBJEXT) \ | ||
349 | invalid.$(OBJEXT) \ | ||
350 | lf.$(OBJEXT) \ | ||
351 | @@ -75,8 +73,6 @@ CCSRCS=\ | ||
352 | CSRCS=\ | ||
353 | $(srcdir)/fmod.c \ | ||
354 | $(srcdir)/getcwd.c \ | ||
355 | - $(srcdir)/getopt.c \ | ||
356 | - $(srcdir)/getopt1.c \ | ||
357 | $(srcdir)/iftoa.c \ | ||
358 | $(srcdir)/itoa.c \ | ||
359 | $(srcdir)/matherr.c \ | ||
360 | diff --git a/src/libs/libgroff/getopt.c b/src/libs/libgroff/getopt.c | ||
361 | deleted file mode 100644 | ||
362 | index 289d137..0000000 | ||
363 | --- a/src/libs/libgroff/getopt.c | ||
364 | +++ /dev/null | ||
365 | @@ -1,1277 +0,0 @@ | ||
366 | -/* Getopt for GNU. | ||
367 | - NOTE: getopt is now part of the C library, so if you don't know what | ||
368 | - "Keep this file name-space clean" means, talk to drepper@gnu.org | ||
369 | - before changing it! | ||
370 | - Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002 | ||
371 | - Free Software Foundation, Inc. | ||
372 | - This file is part of the GNU C Library. | ||
373 | - | ||
374 | - The GNU C Library is free software; you can redistribute it and/or | ||
375 | - modify it under the terms of the GNU Lesser General Public | ||
376 | - License as published by the Free Software Foundation; either | ||
377 | - version 2.1 of the License, or (at your option) any later version. | ||
378 | - | ||
379 | - The GNU C Library is distributed in the hope that it will be useful, | ||
380 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
381 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
382 | - Lesser General Public License for more details. | ||
383 | - | ||
384 | - You should have received a copy of the GNU Lesser General Public | ||
385 | - License along with the GNU C Library; if not, write to the Free | ||
386 | - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
387 | - 02111-1307 USA. */ | ||
388 | - | ||
389 | -/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. | ||
390 | - Ditto for AIX 3.2 and <stdlib.h>. */ | ||
391 | -#ifndef _NO_PROTO | ||
392 | -# define _NO_PROTO | ||
393 | -#endif | ||
394 | - | ||
395 | -#ifdef HAVE_CONFIG_H | ||
396 | -# include <config.h> | ||
397 | -#endif | ||
398 | - | ||
399 | -#if !defined __STDC__ || !__STDC__ | ||
400 | -/* This is a separate conditional since some stdc systems | ||
401 | - reject `defined (const)'. */ | ||
402 | -# ifndef const | ||
403 | -# define const | ||
404 | -# endif | ||
405 | -#endif | ||
406 | - | ||
407 | -#include <stdio.h> | ||
408 | - | ||
409 | -/* Comment out all this code if we are using the GNU C Library, and are not | ||
410 | - actually compiling the library itself. This code is part of the GNU C | ||
411 | - Library, but also included in many other GNU distributions. Compiling | ||
412 | - and linking in this code is a waste when using the GNU C library | ||
413 | - (especially if it is a shared library). Rather than having every GNU | ||
414 | - program understand `configure --with-gnu-libc' and omit the object files, | ||
415 | - it is simpler to just do this in the source for each such file. */ | ||
416 | - | ||
417 | -#define GETOPT_INTERFACE_VERSION 2 | ||
418 | -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 | ||
419 | -# include <gnu-versions.h> | ||
420 | -# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION | ||
421 | -# define ELIDE_CODE | ||
422 | -# endif | ||
423 | -#endif | ||
424 | - | ||
425 | -#ifndef ELIDE_CODE | ||
426 | - | ||
427 | - | ||
428 | -/* This needs to come after some library #include | ||
429 | - to get __GNU_LIBRARY__ defined. */ | ||
430 | -#ifdef __GNU_LIBRARY__ | ||
431 | -/* Don't include stdlib.h for non-GNU C libraries because some of them | ||
432 | - contain conflicting prototypes for getopt. */ | ||
433 | -# include <stdlib.h> | ||
434 | -# include <unistd.h> | ||
435 | -#endif /* GNU C library. */ | ||
436 | - | ||
437 | -#ifdef VMS | ||
438 | -# include <unixlib.h> | ||
439 | -# if HAVE_STRING_H - 0 | ||
440 | -# include <string.h> | ||
441 | -# endif | ||
442 | -#endif | ||
443 | - | ||
444 | -#ifndef _ | ||
445 | -/* This is for other GNU distributions with internationalized messages. */ | ||
446 | -# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC | ||
447 | -# include <libintl.h> | ||
448 | -# ifndef _ | ||
449 | -# define _(msgid) gettext (msgid) | ||
450 | -# endif | ||
451 | -# else | ||
452 | -# define _(msgid) (msgid) | ||
453 | -# endif | ||
454 | -# if defined _LIBC && defined USE_IN_LIBIO | ||
455 | -# include <wchar.h> | ||
456 | -# endif | ||
457 | -#endif | ||
458 | - | ||
459 | -#ifndef attribute_hidden | ||
460 | -# define attribute_hidden | ||
461 | -#endif | ||
462 | - | ||
463 | -/* This version of `getopt' appears to the caller like standard Unix `getopt' | ||
464 | - but it behaves differently for the user, since it allows the user | ||
465 | - to intersperse the options with the other arguments. | ||
466 | - | ||
467 | - As `getopt' works, it permutes the elements of ARGV so that, | ||
468 | - when it is done, all the options precede everything else. Thus | ||
469 | - all application programs are extended to handle flexible argument order. | ||
470 | - | ||
471 | - Setting the environment variable POSIXLY_CORRECT disables permutation. | ||
472 | - Then the behavior is completely standard. | ||
473 | - | ||
474 | - GNU application programs can use a third alternative mode in which | ||
475 | - they can distinguish the relative order of options and other arguments. */ | ||
476 | - | ||
477 | -#include "getopt.h" | ||
478 | - | ||
479 | -/* For communication from `getopt' to the caller. | ||
480 | - When `getopt' finds an option that takes an argument, | ||
481 | - the argument value is returned here. | ||
482 | - Also, when `ordering' is RETURN_IN_ORDER, | ||
483 | - each non-option ARGV-element is returned here. */ | ||
484 | - | ||
485 | -char *optarg; | ||
486 | - | ||
487 | -/* Index in ARGV of the next element to be scanned. | ||
488 | - This is used for communication to and from the caller | ||
489 | - and for communication between successive calls to `getopt'. | ||
490 | - | ||
491 | - On entry to `getopt', zero means this is the first call; initialize. | ||
492 | - | ||
493 | - When `getopt' returns -1, this is the index of the first of the | ||
494 | - non-option elements that the caller should itself scan. | ||
495 | - | ||
496 | - Otherwise, `optind' communicates from one call to the next | ||
497 | - how much of ARGV has been scanned so far. */ | ||
498 | - | ||
499 | -/* 1003.2 says this must be 1 before any call. */ | ||
500 | -int optind = 1; | ||
501 | - | ||
502 | -/* Formerly, initialization of getopt depended on optind==0, which | ||
503 | - causes problems with re-calling getopt as programs generally don't | ||
504 | - know that. */ | ||
505 | - | ||
506 | -int __getopt_initialized attribute_hidden; | ||
507 | - | ||
508 | -/* The next char to be scanned in the option-element | ||
509 | - in which the last option character we returned was found. | ||
510 | - This allows us to pick up the scan where we left off. | ||
511 | - | ||
512 | - If this is zero, or a null string, it means resume the scan | ||
513 | - by advancing to the next ARGV-element. */ | ||
514 | - | ||
515 | -static char *nextchar; | ||
516 | - | ||
517 | -/* Callers store zero here to inhibit the error message | ||
518 | - for unrecognized options. */ | ||
519 | - | ||
520 | -int opterr = 1; | ||
521 | - | ||
522 | -/* Set to an option character which was unrecognized. | ||
523 | - This must be initialized on some systems to avoid linking in the | ||
524 | - system's own getopt implementation. */ | ||
525 | - | ||
526 | -int optopt = '?'; | ||
527 | - | ||
528 | -/* Describe how to deal with options that follow non-option ARGV-elements. | ||
529 | - | ||
530 | - If the caller did not specify anything, | ||
531 | - the default is REQUIRE_ORDER if the environment variable | ||
532 | - POSIXLY_CORRECT is defined, PERMUTE otherwise. | ||
533 | - | ||
534 | - REQUIRE_ORDER means don't recognize them as options; | ||
535 | - stop option processing when the first non-option is seen. | ||
536 | - This is what Unix does. | ||
537 | - This mode of operation is selected by either setting the environment | ||
538 | - variable POSIXLY_CORRECT, or using `+' as the first character | ||
539 | - of the list of option characters. | ||
540 | - | ||
541 | - PERMUTE is the default. We permute the contents of ARGV as we scan, | ||
542 | - so that eventually all the non-options are at the end. This allows options | ||
543 | - to be given in any order, even with programs that were not written to | ||
544 | - expect this. | ||
545 | - | ||
546 | - RETURN_IN_ORDER is an option available to programs that were written | ||
547 | - to expect options and other ARGV-elements in any order and that care about | ||
548 | - the ordering of the two. We describe each non-option ARGV-element | ||
549 | - as if it were the argument of an option with character code 1. | ||
550 | - Using `-' as the first character of the list of option characters | ||
551 | - selects this mode of operation. | ||
552 | - | ||
553 | - The special argument `--' forces an end of option-scanning regardless | ||
554 | - of the value of `ordering'. In the case of RETURN_IN_ORDER, only | ||
555 | - `--' can cause `getopt' to return -1 with `optind' != ARGC. */ | ||
556 | - | ||
557 | -static enum | ||
558 | -{ | ||
559 | - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER | ||
560 | -} ordering; | ||
561 | - | ||
562 | -/* Value of POSIXLY_CORRECT environment variable. */ | ||
563 | -static char *posixly_correct; | ||
564 | - | ||
565 | -#ifdef __GNU_LIBRARY__ | ||
566 | -/* We want to avoid inclusion of string.h with non-GNU libraries | ||
567 | - because there are many ways it can cause trouble. | ||
568 | - On some systems, it contains special magic macros that don't work | ||
569 | - in GCC. */ | ||
570 | -# include <string.h> | ||
571 | -# define my_index strchr | ||
572 | -#else | ||
573 | - | ||
574 | -# if HAVE_STRING_H | ||
575 | -# include <string.h> | ||
576 | -# else | ||
577 | -# include <strings.h> | ||
578 | -# endif | ||
579 | - | ||
580 | -/* Avoid depending on library functions or files | ||
581 | - whose names are inconsistent. */ | ||
582 | - | ||
583 | -#ifndef getenv | ||
584 | -extern char *getenv (); | ||
585 | -#endif | ||
586 | - | ||
587 | -static char * | ||
588 | -my_index (str, chr) | ||
589 | - const char *str; | ||
590 | - int chr; | ||
591 | -{ | ||
592 | - while (*str) | ||
593 | - { | ||
594 | - if (*str == chr) | ||
595 | - return (char *) str; | ||
596 | - str++; | ||
597 | - } | ||
598 | - return 0; | ||
599 | -} | ||
600 | - | ||
601 | -/* If using GCC, we can safely declare strlen this way. | ||
602 | - If not using GCC, it is ok not to declare it. */ | ||
603 | -#ifdef __GNUC__ | ||
604 | -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. | ||
605 | - That was relevant to code that was here before. */ | ||
606 | -# if (!defined __STDC__ || !__STDC__) && !defined strlen | ||
607 | -/* gcc with -traditional declares the built-in strlen to return int, | ||
608 | - and has done so at least since version 2.4.5. -- rms. */ | ||
609 | -extern int strlen (const char *); | ||
610 | -# endif /* not __STDC__ */ | ||
611 | -#endif /* __GNUC__ */ | ||
612 | - | ||
613 | -#endif /* not __GNU_LIBRARY__ */ | ||
614 | - | ||
615 | -/* Handle permutation of arguments. */ | ||
616 | - | ||
617 | -/* Describe the part of ARGV that contains non-options that have | ||
618 | - been skipped. `first_nonopt' is the index in ARGV of the first of them; | ||
619 | - `last_nonopt' is the index after the last of them. */ | ||
620 | - | ||
621 | -static int first_nonopt; | ||
622 | -static int last_nonopt; | ||
623 | - | ||
624 | -#ifdef _LIBC | ||
625 | -/* Stored original parameters. | ||
626 | - XXX This is no good solution. We should rather copy the args so | ||
627 | - that we can compare them later. But we must not use malloc(3). */ | ||
628 | -extern int __libc_argc; | ||
629 | -extern char **__libc_argv; | ||
630 | - | ||
631 | -/* Bash 2.0 gives us an environment variable containing flags | ||
632 | - indicating ARGV elements that should not be considered arguments. */ | ||
633 | - | ||
634 | -# ifdef USE_NONOPTION_FLAGS | ||
635 | -/* Defined in getopt_init.c */ | ||
636 | -extern char *__getopt_nonoption_flags; | ||
637 | - | ||
638 | -static int nonoption_flags_max_len; | ||
639 | -static int nonoption_flags_len; | ||
640 | -# endif | ||
641 | - | ||
642 | -# ifdef USE_NONOPTION_FLAGS | ||
643 | -# define SWAP_FLAGS(ch1, ch2) \ | ||
644 | - if (nonoption_flags_len > 0) \ | ||
645 | - { \ | ||
646 | - char __tmp = __getopt_nonoption_flags[ch1]; \ | ||
647 | - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ | ||
648 | - __getopt_nonoption_flags[ch2] = __tmp; \ | ||
649 | - } | ||
650 | -# else | ||
651 | -# define SWAP_FLAGS(ch1, ch2) | ||
652 | -# endif | ||
653 | -#else /* !_LIBC */ | ||
654 | -# define SWAP_FLAGS(ch1, ch2) | ||
655 | -#endif /* _LIBC */ | ||
656 | - | ||
657 | -/* Exchange two adjacent subsequences of ARGV. | ||
658 | - One subsequence is elements [first_nonopt,last_nonopt) | ||
659 | - which contains all the non-options that have been skipped so far. | ||
660 | - The other is elements [last_nonopt,optind), which contains all | ||
661 | - the options processed since those non-options were skipped. | ||
662 | - | ||
663 | - `first_nonopt' and `last_nonopt' are relocated so that they describe | ||
664 | - the new indices of the non-options in ARGV after they are moved. */ | ||
665 | - | ||
666 | -#if defined __STDC__ && __STDC__ | ||
667 | -static void exchange (char **); | ||
668 | -#endif | ||
669 | - | ||
670 | -static void | ||
671 | -exchange (argv) | ||
672 | - char **argv; | ||
673 | -{ | ||
674 | - int bottom = first_nonopt; | ||
675 | - int middle = last_nonopt; | ||
676 | - int top = optind; | ||
677 | - char *tem; | ||
678 | - | ||
679 | - /* Exchange the shorter segment with the far end of the longer segment. | ||
680 | - That puts the shorter segment into the right place. | ||
681 | - It leaves the longer segment in the right place overall, | ||
682 | - but it consists of two parts that need to be swapped next. */ | ||
683 | - | ||
684 | -#if defined _LIBC && defined USE_NONOPTION_FLAGS | ||
685 | - /* First make sure the handling of the `__getopt_nonoption_flags' | ||
686 | - string can work normally. Our top argument must be in the range | ||
687 | - of the string. */ | ||
688 | - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) | ||
689 | - { | ||
690 | - /* We must extend the array. The user plays games with us and | ||
691 | - presents new arguments. */ | ||
692 | - char *new_str = malloc (top + 1); | ||
693 | - if (new_str == NULL) | ||
694 | - nonoption_flags_len = nonoption_flags_max_len = 0; | ||
695 | - else | ||
696 | - { | ||
697 | - memset (__mempcpy (new_str, __getopt_nonoption_flags, | ||
698 | - nonoption_flags_max_len), | ||
699 | - '\0', top + 1 - nonoption_flags_max_len); | ||
700 | - nonoption_flags_max_len = top + 1; | ||
701 | - __getopt_nonoption_flags = new_str; | ||
702 | - } | ||
703 | - } | ||
704 | -#endif | ||
705 | - | ||
706 | - while (top > middle && middle > bottom) | ||
707 | - { | ||
708 | - if (top - middle > middle - bottom) | ||
709 | - { | ||
710 | - /* Bottom segment is the short one. */ | ||
711 | - int len = middle - bottom; | ||
712 | - register int i; | ||
713 | - | ||
714 | - /* Swap it with the top part of the top segment. */ | ||
715 | - for (i = 0; i < len; i++) | ||
716 | - { | ||
717 | - tem = argv[bottom + i]; | ||
718 | - argv[bottom + i] = argv[top - (middle - bottom) + i]; | ||
719 | - argv[top - (middle - bottom) + i] = tem; | ||
720 | - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); | ||
721 | - } | ||
722 | - /* Exclude the moved bottom segment from further swapping. */ | ||
723 | - top -= len; | ||
724 | - } | ||
725 | - else | ||
726 | - { | ||
727 | - /* Top segment is the short one. */ | ||
728 | - int len = top - middle; | ||
729 | - register int i; | ||
730 | - | ||
731 | - /* Swap it with the bottom part of the bottom segment. */ | ||
732 | - for (i = 0; i < len; i++) | ||
733 | - { | ||
734 | - tem = argv[bottom + i]; | ||
735 | - argv[bottom + i] = argv[middle + i]; | ||
736 | - argv[middle + i] = tem; | ||
737 | - SWAP_FLAGS (bottom + i, middle + i); | ||
738 | - } | ||
739 | - /* Exclude the moved top segment from further swapping. */ | ||
740 | - bottom += len; | ||
741 | - } | ||
742 | - } | ||
743 | - | ||
744 | - /* Update records for the slots the non-options now occupy. */ | ||
745 | - | ||
746 | - first_nonopt += (optind - last_nonopt); | ||
747 | - last_nonopt = optind; | ||
748 | -} | ||
749 | - | ||
750 | -/* Initialize the internal data when the first call is made. */ | ||
751 | - | ||
752 | -#if defined __STDC__ && __STDC__ | ||
753 | -static const char *_getopt_initialize (int, char *const *, const char *); | ||
754 | -#endif | ||
755 | -static const char * | ||
756 | -_getopt_initialize (argc, argv, optstring) | ||
757 | - int argc; | ||
758 | - char *const *argv; | ||
759 | - const char *optstring; | ||
760 | -{ | ||
761 | - /* Start processing options with ARGV-element 1 (since ARGV-element 0 | ||
762 | - is the program name); the sequence of previously skipped | ||
763 | - non-option ARGV-elements is empty. */ | ||
764 | - | ||
765 | - first_nonopt = last_nonopt = optind; | ||
766 | - | ||
767 | - nextchar = NULL; | ||
768 | - | ||
769 | - posixly_correct = getenv ("POSIXLY_CORRECT"); | ||
770 | - | ||
771 | - /* Determine how to handle the ordering of options and nonoptions. */ | ||
772 | - | ||
773 | - if (optstring[0] == '-') | ||
774 | - { | ||
775 | - ordering = RETURN_IN_ORDER; | ||
776 | - ++optstring; | ||
777 | - } | ||
778 | - else if (optstring[0] == '+') | ||
779 | - { | ||
780 | - ordering = REQUIRE_ORDER; | ||
781 | - ++optstring; | ||
782 | - } | ||
783 | - else if (posixly_correct != NULL) | ||
784 | - ordering = REQUIRE_ORDER; | ||
785 | - else | ||
786 | - ordering = PERMUTE; | ||
787 | - | ||
788 | -#if defined _LIBC && defined USE_NONOPTION_FLAGS | ||
789 | - if (posixly_correct == NULL | ||
790 | - && argc == __libc_argc && argv == __libc_argv) | ||
791 | - { | ||
792 | - if (nonoption_flags_max_len == 0) | ||
793 | - { | ||
794 | - if (__getopt_nonoption_flags == NULL | ||
795 | - || __getopt_nonoption_flags[0] == '\0') | ||
796 | - nonoption_flags_max_len = -1; | ||
797 | - else | ||
798 | - { | ||
799 | - const char *orig_str = __getopt_nonoption_flags; | ||
800 | - int len = nonoption_flags_max_len = strlen (orig_str); | ||
801 | - if (nonoption_flags_max_len < argc) | ||
802 | - nonoption_flags_max_len = argc; | ||
803 | - __getopt_nonoption_flags = | ||
804 | - (char *) malloc (nonoption_flags_max_len); | ||
805 | - if (__getopt_nonoption_flags == NULL) | ||
806 | - nonoption_flags_max_len = -1; | ||
807 | - else | ||
808 | - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), | ||
809 | - '\0', nonoption_flags_max_len - len); | ||
810 | - } | ||
811 | - } | ||
812 | - nonoption_flags_len = nonoption_flags_max_len; | ||
813 | - } | ||
814 | - else | ||
815 | - nonoption_flags_len = 0; | ||
816 | -#endif | ||
817 | - | ||
818 | - return optstring; | ||
819 | -} | ||
820 | - | ||
821 | -/* Scan elements of ARGV (whose length is ARGC) for option characters | ||
822 | - given in OPTSTRING. | ||
823 | - | ||
824 | - If an element of ARGV starts with '-', and is not exactly "-" or "--", | ||
825 | - then it is an option element. The characters of this element | ||
826 | - (aside from the initial '-') are option characters. If `getopt' | ||
827 | - is called repeatedly, it returns successively each of the option characters | ||
828 | - from each of the option elements. | ||
829 | - | ||
830 | - If `getopt' finds another option character, it returns that character, | ||
831 | - updating `optind' and `nextchar' so that the next call to `getopt' can | ||
832 | - resume the scan with the following option character or ARGV-element. | ||
833 | - | ||
834 | - If there are no more option characters, `getopt' returns -1. | ||
835 | - Then `optind' is the index in ARGV of the first ARGV-element | ||
836 | - that is not an option. (The ARGV-elements have been permuted | ||
837 | - so that those that are not options now come last.) | ||
838 | - | ||
839 | - OPTSTRING is a string containing the legitimate option characters. | ||
840 | - If an option character is seen that is not listed in OPTSTRING, | ||
841 | - return '?' after printing an error message. If you set `opterr' to | ||
842 | - zero, the error message is suppressed but we still return '?'. | ||
843 | - | ||
844 | - If a char in OPTSTRING is followed by a colon, that means it wants an arg, | ||
845 | - so the following text in the same ARGV-element, or the text of the following | ||
846 | - ARGV-element, is returned in `optarg'. Two colons mean an option that | ||
847 | - wants an optional arg; if there is text in the current ARGV-element, | ||
848 | - it is returned in `optarg', otherwise `optarg' is set to zero. | ||
849 | - | ||
850 | - If OPTSTRING starts with `-' or `+', it requests different methods of | ||
851 | - handling the non-option ARGV-elements. | ||
852 | - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. | ||
853 | - | ||
854 | - Long-named options begin with `--' instead of `-'. | ||
855 | - Their names may be abbreviated as long as the abbreviation is unique | ||
856 | - or is an exact match for some defined option. If they have an | ||
857 | - argument, it follows the option name in the same ARGV-element, separated | ||
858 | - from the option name by a `=', or else the in next ARGV-element. | ||
859 | - When `getopt' finds a long-named option, it returns 0 if that option's | ||
860 | - `flag' field is nonzero, the value of the option's `val' field | ||
861 | - if the `flag' field is zero. | ||
862 | - | ||
863 | - The elements of ARGV aren't really const, because we permute them. | ||
864 | - But we pretend they're const in the prototype to be compatible | ||
865 | - with other systems. | ||
866 | - | ||
867 | - LONGOPTS is a vector of `struct option' terminated by an | ||
868 | - element containing a name which is zero. | ||
869 | - | ||
870 | - LONGIND returns the index in LONGOPT of the long-named option found. | ||
871 | - It is only valid when a long-named option has been found by the most | ||
872 | - recent call. | ||
873 | - | ||
874 | - If LONG_ONLY is nonzero, '-' as well as '--' can introduce | ||
875 | - long-named options. */ | ||
876 | - | ||
877 | -int | ||
878 | -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) | ||
879 | - int argc; | ||
880 | - char *const *argv; | ||
881 | - const char *optstring; | ||
882 | - const struct option *longopts; | ||
883 | - int *longind; | ||
884 | - int long_only; | ||
885 | -{ | ||
886 | - int print_errors = opterr; | ||
887 | - if (optstring[0] == ':') | ||
888 | - print_errors = 0; | ||
889 | - | ||
890 | - if (argc < 1) | ||
891 | - return -1; | ||
892 | - | ||
893 | - optarg = NULL; | ||
894 | - | ||
895 | - if (optind == 0 || !__getopt_initialized) | ||
896 | - { | ||
897 | - if (optind == 0) | ||
898 | - optind = 1; /* Don't scan ARGV[0], the program name. */ | ||
899 | - optstring = _getopt_initialize (argc, argv, optstring); | ||
900 | - __getopt_initialized = 1; | ||
901 | - } | ||
902 | - | ||
903 | - /* Test whether ARGV[optind] points to a non-option argument. | ||
904 | - Either it does not have option syntax, or there is an environment flag | ||
905 | - from the shell indicating it is not an option. The later information | ||
906 | - is only used when the used in the GNU libc. */ | ||
907 | -#if defined _LIBC && defined USE_NONOPTION_FLAGS | ||
908 | -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ | ||
909 | - || (optind < nonoption_flags_len \ | ||
910 | - && __getopt_nonoption_flags[optind] == '1')) | ||
911 | -#else | ||
912 | -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') | ||
913 | -#endif | ||
914 | - | ||
915 | - if (nextchar == NULL || *nextchar == '\0') | ||
916 | - { | ||
917 | - /* Advance to the next ARGV-element. */ | ||
918 | - | ||
919 | - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been | ||
920 | - moved back by the user (who may also have changed the arguments). */ | ||
921 | - if (last_nonopt > optind) | ||
922 | - last_nonopt = optind; | ||
923 | - if (first_nonopt > optind) | ||
924 | - first_nonopt = optind; | ||
925 | - | ||
926 | - if (ordering == PERMUTE) | ||
927 | - { | ||
928 | - /* If we have just processed some options following some non-options, | ||
929 | - exchange them so that the options come first. */ | ||
930 | - | ||
931 | - if (first_nonopt != last_nonopt && last_nonopt != optind) | ||
932 | - exchange ((char **) argv); | ||
933 | - else if (last_nonopt != optind) | ||
934 | - first_nonopt = optind; | ||
935 | - | ||
936 | - /* Skip any additional non-options | ||
937 | - and extend the range of non-options previously skipped. */ | ||
938 | - | ||
939 | - while (optind < argc && NONOPTION_P) | ||
940 | - optind++; | ||
941 | - last_nonopt = optind; | ||
942 | - } | ||
943 | - | ||
944 | - /* The special ARGV-element `--' means premature end of options. | ||
945 | - Skip it like a null option, | ||
946 | - then exchange with previous non-options as if it were an option, | ||
947 | - then skip everything else like a non-option. */ | ||
948 | - | ||
949 | - if (optind != argc && !strcmp (argv[optind], "--")) | ||
950 | - { | ||
951 | - optind++; | ||
952 | - | ||
953 | - if (first_nonopt != last_nonopt && last_nonopt != optind) | ||
954 | - exchange ((char **) argv); | ||
955 | - else if (first_nonopt == last_nonopt) | ||
956 | - first_nonopt = optind; | ||
957 | - last_nonopt = argc; | ||
958 | - | ||
959 | - optind = argc; | ||
960 | - } | ||
961 | - | ||
962 | - /* If we have done all the ARGV-elements, stop the scan | ||
963 | - and back over any non-options that we skipped and permuted. */ | ||
964 | - | ||
965 | - if (optind == argc) | ||
966 | - { | ||
967 | - /* Set the next-arg-index to point at the non-options | ||
968 | - that we previously skipped, so the caller will digest them. */ | ||
969 | - if (first_nonopt != last_nonopt) | ||
970 | - optind = first_nonopt; | ||
971 | - return -1; | ||
972 | - } | ||
973 | - | ||
974 | - /* If we have come to a non-option and did not permute it, | ||
975 | - either stop the scan or describe it to the caller and pass it by. */ | ||
976 | - | ||
977 | - if (NONOPTION_P) | ||
978 | - { | ||
979 | - if (ordering == REQUIRE_ORDER) | ||
980 | - return -1; | ||
981 | - optarg = argv[optind++]; | ||
982 | - return 1; | ||
983 | - } | ||
984 | - | ||
985 | - /* We have found another option-ARGV-element. | ||
986 | - Skip the initial punctuation. */ | ||
987 | - | ||
988 | - nextchar = (argv[optind] + 1 | ||
989 | - + (longopts != NULL && argv[optind][1] == '-')); | ||
990 | - } | ||
991 | - | ||
992 | - /* Decode the current option-ARGV-element. */ | ||
993 | - | ||
994 | - /* Check whether the ARGV-element is a long option. | ||
995 | - | ||
996 | - If long_only and the ARGV-element has the form "-f", where f is | ||
997 | - a valid short option, don't consider it an abbreviated form of | ||
998 | - a long option that starts with f. Otherwise there would be no | ||
999 | - way to give the -f short option. | ||
1000 | - | ||
1001 | - On the other hand, if there's a long option "fubar" and | ||
1002 | - the ARGV-element is "-fu", do consider that an abbreviation of | ||
1003 | - the long option, just like "--fu", and not "-f" with arg "u". | ||
1004 | - | ||
1005 | - This distinction seems to be the most useful approach. */ | ||
1006 | - | ||
1007 | - if (longopts != NULL | ||
1008 | - && (argv[optind][1] == '-' | ||
1009 | - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) | ||
1010 | - { | ||
1011 | - char *nameend; | ||
1012 | - const struct option *p; | ||
1013 | - const struct option *pfound = NULL; | ||
1014 | - int exact = 0; | ||
1015 | - int ambig = 0; | ||
1016 | - int indfound = -1; | ||
1017 | - int option_index; | ||
1018 | - | ||
1019 | - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) | ||
1020 | - /* Do nothing. */ ; | ||
1021 | - | ||
1022 | - /* Test all long options for either exact match | ||
1023 | - or abbreviated matches. */ | ||
1024 | - for (p = longopts, option_index = 0; p->name; p++, option_index++) | ||
1025 | - if (!strncmp (p->name, nextchar, nameend - nextchar)) | ||
1026 | - { | ||
1027 | - if ((unsigned int) (nameend - nextchar) | ||
1028 | - == (unsigned int) strlen (p->name)) | ||
1029 | - { | ||
1030 | - /* Exact match found. */ | ||
1031 | - pfound = p; | ||
1032 | - indfound = option_index; | ||
1033 | - exact = 1; | ||
1034 | - break; | ||
1035 | - } | ||
1036 | - else if (pfound == NULL) | ||
1037 | - { | ||
1038 | - /* First nonexact match found. */ | ||
1039 | - pfound = p; | ||
1040 | - indfound = option_index; | ||
1041 | - } | ||
1042 | - else if (long_only | ||
1043 | - || pfound->has_arg != p->has_arg | ||
1044 | - || pfound->flag != p->flag | ||
1045 | - || pfound->val != p->val) | ||
1046 | - /* Second or later nonexact match found. */ | ||
1047 | - ambig = 1; | ||
1048 | - } | ||
1049 | - | ||
1050 | - if (ambig && !exact) | ||
1051 | - { | ||
1052 | - if (print_errors) | ||
1053 | - { | ||
1054 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1055 | - char *buf; | ||
1056 | - | ||
1057 | - if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), | ||
1058 | - argv[0], argv[optind]) >= 0) | ||
1059 | - { | ||
1060 | - | ||
1061 | - if (_IO_fwide (stderr, 0) > 0) | ||
1062 | - __fwprintf (stderr, L"%s", buf); | ||
1063 | - else | ||
1064 | - fputs (buf, stderr); | ||
1065 | - | ||
1066 | - free (buf); | ||
1067 | - } | ||
1068 | -#else | ||
1069 | - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), | ||
1070 | - argv[0], argv[optind]); | ||
1071 | -#endif | ||
1072 | - } | ||
1073 | - nextchar += strlen (nextchar); | ||
1074 | - optind++; | ||
1075 | - optopt = 0; | ||
1076 | - return '?'; | ||
1077 | - } | ||
1078 | - | ||
1079 | - if (pfound != NULL) | ||
1080 | - { | ||
1081 | - option_index = indfound; | ||
1082 | - optind++; | ||
1083 | - if (*nameend) | ||
1084 | - { | ||
1085 | - /* Don't test has_arg with >, because some C compilers don't | ||
1086 | - allow it to be used on enums. */ | ||
1087 | - if (pfound->has_arg) | ||
1088 | - optarg = nameend + 1; | ||
1089 | - else | ||
1090 | - { | ||
1091 | - if (print_errors) | ||
1092 | - { | ||
1093 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1094 | - char *buf; | ||
1095 | - int n; | ||
1096 | -#endif | ||
1097 | - | ||
1098 | - if (argv[optind - 1][1] == '-') | ||
1099 | - { | ||
1100 | - /* --option */ | ||
1101 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1102 | - n = __asprintf (&buf, _("\ | ||
1103 | -%s: option `--%s' doesn't allow an argument\n"), | ||
1104 | - argv[0], pfound->name); | ||
1105 | -#else | ||
1106 | - fprintf (stderr, _("\ | ||
1107 | -%s: option `--%s' doesn't allow an argument\n"), | ||
1108 | - argv[0], pfound->name); | ||
1109 | -#endif | ||
1110 | - } | ||
1111 | - else | ||
1112 | - { | ||
1113 | - /* +option or -option */ | ||
1114 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1115 | - n = __asprintf (&buf, _("\ | ||
1116 | -%s: option `%c%s' doesn't allow an argument\n"), | ||
1117 | - argv[0], argv[optind - 1][0], | ||
1118 | - pfound->name); | ||
1119 | -#else | ||
1120 | - fprintf (stderr, _("\ | ||
1121 | -%s: option `%c%s' doesn't allow an argument\n"), | ||
1122 | - argv[0], argv[optind - 1][0], pfound->name); | ||
1123 | -#endif | ||
1124 | - } | ||
1125 | - | ||
1126 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1127 | - if (n >= 0) | ||
1128 | - { | ||
1129 | - if (_IO_fwide (stderr, 0) > 0) | ||
1130 | - __fwprintf (stderr, L"%s", buf); | ||
1131 | - else | ||
1132 | - fputs (buf, stderr); | ||
1133 | - | ||
1134 | - free (buf); | ||
1135 | - } | ||
1136 | -#endif | ||
1137 | - } | ||
1138 | - | ||
1139 | - nextchar += strlen (nextchar); | ||
1140 | - | ||
1141 | - optopt = pfound->val; | ||
1142 | - return '?'; | ||
1143 | - } | ||
1144 | - } | ||
1145 | - else if (pfound->has_arg == 1) | ||
1146 | - { | ||
1147 | - if (optind < argc) | ||
1148 | - optarg = argv[optind++]; | ||
1149 | - else | ||
1150 | - { | ||
1151 | - if (print_errors) | ||
1152 | - { | ||
1153 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1154 | - char *buf; | ||
1155 | - | ||
1156 | - if (__asprintf (&buf, _("\ | ||
1157 | -%s: option `%s' requires an argument\n"), | ||
1158 | - argv[0], argv[optind - 1]) >= 0) | ||
1159 | - { | ||
1160 | - if (_IO_fwide (stderr, 0) > 0) | ||
1161 | - __fwprintf (stderr, L"%s", buf); | ||
1162 | - else | ||
1163 | - fputs (buf, stderr); | ||
1164 | - | ||
1165 | - free (buf); | ||
1166 | - } | ||
1167 | -#else | ||
1168 | - fprintf (stderr, | ||
1169 | - _("%s: option `%s' requires an argument\n"), | ||
1170 | - argv[0], argv[optind - 1]); | ||
1171 | -#endif | ||
1172 | - } | ||
1173 | - nextchar += strlen (nextchar); | ||
1174 | - optopt = pfound->val; | ||
1175 | - return optstring[0] == ':' ? ':' : '?'; | ||
1176 | - } | ||
1177 | - } | ||
1178 | - nextchar += strlen (nextchar); | ||
1179 | - if (longind != NULL) | ||
1180 | - *longind = option_index; | ||
1181 | - if (pfound->flag) | ||
1182 | - { | ||
1183 | - *(pfound->flag) = pfound->val; | ||
1184 | - return 0; | ||
1185 | - } | ||
1186 | - return pfound->val; | ||
1187 | - } | ||
1188 | - | ||
1189 | - /* Can't find it as a long option. If this is not getopt_long_only, | ||
1190 | - or the option starts with '--' or is not a valid short | ||
1191 | - option, then it's an error. | ||
1192 | - Otherwise interpret it as a short option. */ | ||
1193 | - if (!long_only || argv[optind][1] == '-' | ||
1194 | - || my_index (optstring, *nextchar) == NULL) | ||
1195 | - { | ||
1196 | - if (print_errors) | ||
1197 | - { | ||
1198 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1199 | - char *buf; | ||
1200 | - int n; | ||
1201 | -#endif | ||
1202 | - | ||
1203 | - if (argv[optind][1] == '-') | ||
1204 | - { | ||
1205 | - /* --option */ | ||
1206 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1207 | - n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), | ||
1208 | - argv[0], nextchar); | ||
1209 | -#else | ||
1210 | - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), | ||
1211 | - argv[0], nextchar); | ||
1212 | -#endif | ||
1213 | - } | ||
1214 | - else | ||
1215 | - { | ||
1216 | - /* +option or -option */ | ||
1217 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1218 | - n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), | ||
1219 | - argv[0], argv[optind][0], nextchar); | ||
1220 | -#else | ||
1221 | - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), | ||
1222 | - argv[0], argv[optind][0], nextchar); | ||
1223 | -#endif | ||
1224 | - } | ||
1225 | - | ||
1226 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1227 | - if (n >= 0) | ||
1228 | - { | ||
1229 | - if (_IO_fwide (stderr, 0) > 0) | ||
1230 | - __fwprintf (stderr, L"%s", buf); | ||
1231 | - else | ||
1232 | - fputs (buf, stderr); | ||
1233 | - | ||
1234 | - free (buf); | ||
1235 | - } | ||
1236 | -#endif | ||
1237 | - } | ||
1238 | - nextchar = (char *) ""; | ||
1239 | - optind++; | ||
1240 | - optopt = 0; | ||
1241 | - return '?'; | ||
1242 | - } | ||
1243 | - } | ||
1244 | - | ||
1245 | - /* Look at and handle the next short option-character. */ | ||
1246 | - | ||
1247 | - { | ||
1248 | - char c = *nextchar++; | ||
1249 | - char *temp = my_index (optstring, c); | ||
1250 | - | ||
1251 | - /* Increment `optind' when we start to process its last character. */ | ||
1252 | - if (*nextchar == '\0') | ||
1253 | - ++optind; | ||
1254 | - | ||
1255 | - if (temp == NULL || c == ':') | ||
1256 | - { | ||
1257 | - if (print_errors) | ||
1258 | - { | ||
1259 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1260 | - char *buf; | ||
1261 | - int n; | ||
1262 | -#endif | ||
1263 | - | ||
1264 | - if (posixly_correct) | ||
1265 | - { | ||
1266 | - /* 1003.2 specifies the format of this message. */ | ||
1267 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1268 | - n = __asprintf (&buf, _("%s: illegal option -- %c\n"), | ||
1269 | - argv[0], c); | ||
1270 | -#else | ||
1271 | - fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); | ||
1272 | -#endif | ||
1273 | - } | ||
1274 | - else | ||
1275 | - { | ||
1276 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1277 | - n = __asprintf (&buf, _("%s: invalid option -- %c\n"), | ||
1278 | - argv[0], c); | ||
1279 | -#else | ||
1280 | - fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); | ||
1281 | -#endif | ||
1282 | - } | ||
1283 | - | ||
1284 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1285 | - if (n >= 0) | ||
1286 | - { | ||
1287 | - if (_IO_fwide (stderr, 0) > 0) | ||
1288 | - __fwprintf (stderr, L"%s", buf); | ||
1289 | - else | ||
1290 | - fputs (buf, stderr); | ||
1291 | - | ||
1292 | - free (buf); | ||
1293 | - } | ||
1294 | -#endif | ||
1295 | - } | ||
1296 | - optopt = c; | ||
1297 | - return '?'; | ||
1298 | - } | ||
1299 | - /* Convenience. Treat POSIX -W foo same as long option --foo */ | ||
1300 | - if (temp[0] == 'W' && temp[1] == ';') | ||
1301 | - { | ||
1302 | - char *nameend; | ||
1303 | - const struct option *p; | ||
1304 | - const struct option *pfound = NULL; | ||
1305 | - int exact = 0; | ||
1306 | - int ambig = 0; | ||
1307 | - int indfound = 0; | ||
1308 | - int option_index; | ||
1309 | - | ||
1310 | - /* This is an option that requires an argument. */ | ||
1311 | - if (*nextchar != '\0') | ||
1312 | - { | ||
1313 | - optarg = nextchar; | ||
1314 | - /* If we end this ARGV-element by taking the rest as an arg, | ||
1315 | - we must advance to the next element now. */ | ||
1316 | - optind++; | ||
1317 | - } | ||
1318 | - else if (optind == argc) | ||
1319 | - { | ||
1320 | - if (print_errors) | ||
1321 | - { | ||
1322 | - /* 1003.2 specifies the format of this message. */ | ||
1323 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1324 | - char *buf; | ||
1325 | - | ||
1326 | - if (__asprintf (&buf, | ||
1327 | - _("%s: option requires an argument -- %c\n"), | ||
1328 | - argv[0], c) >= 0) | ||
1329 | - { | ||
1330 | - if (_IO_fwide (stderr, 0) > 0) | ||
1331 | - __fwprintf (stderr, L"%s", buf); | ||
1332 | - else | ||
1333 | - fputs (buf, stderr); | ||
1334 | - | ||
1335 | - free (buf); | ||
1336 | - } | ||
1337 | -#else | ||
1338 | - fprintf (stderr, _("%s: option requires an argument -- %c\n"), | ||
1339 | - argv[0], c); | ||
1340 | -#endif | ||
1341 | - } | ||
1342 | - optopt = c; | ||
1343 | - if (optstring[0] == ':') | ||
1344 | - c = ':'; | ||
1345 | - else | ||
1346 | - c = '?'; | ||
1347 | - return c; | ||
1348 | - } | ||
1349 | - else | ||
1350 | - /* We already incremented `optind' once; | ||
1351 | - increment it again when taking next ARGV-elt as argument. */ | ||
1352 | - optarg = argv[optind++]; | ||
1353 | - | ||
1354 | - /* optarg is now the argument, see if it's in the | ||
1355 | - table of longopts. */ | ||
1356 | - | ||
1357 | - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) | ||
1358 | - /* Do nothing. */ ; | ||
1359 | - | ||
1360 | - /* Test all long options for either exact match | ||
1361 | - or abbreviated matches. */ | ||
1362 | - for (p = longopts, option_index = 0; p->name; p++, option_index++) | ||
1363 | - if (!strncmp (p->name, nextchar, nameend - nextchar)) | ||
1364 | - { | ||
1365 | - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) | ||
1366 | - { | ||
1367 | - /* Exact match found. */ | ||
1368 | - pfound = p; | ||
1369 | - indfound = option_index; | ||
1370 | - exact = 1; | ||
1371 | - break; | ||
1372 | - } | ||
1373 | - else if (pfound == NULL) | ||
1374 | - { | ||
1375 | - /* First nonexact match found. */ | ||
1376 | - pfound = p; | ||
1377 | - indfound = option_index; | ||
1378 | - } | ||
1379 | - else | ||
1380 | - /* Second or later nonexact match found. */ | ||
1381 | - ambig = 1; | ||
1382 | - } | ||
1383 | - if (ambig && !exact) | ||
1384 | - { | ||
1385 | - if (print_errors) | ||
1386 | - { | ||
1387 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1388 | - char *buf; | ||
1389 | - | ||
1390 | - if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), | ||
1391 | - argv[0], argv[optind]) >= 0) | ||
1392 | - { | ||
1393 | - if (_IO_fwide (stderr, 0) > 0) | ||
1394 | - __fwprintf (stderr, L"%s", buf); | ||
1395 | - else | ||
1396 | - fputs (buf, stderr); | ||
1397 | - | ||
1398 | - free (buf); | ||
1399 | - } | ||
1400 | -#else | ||
1401 | - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), | ||
1402 | - argv[0], argv[optind]); | ||
1403 | -#endif | ||
1404 | - } | ||
1405 | - nextchar += strlen (nextchar); | ||
1406 | - optind++; | ||
1407 | - return '?'; | ||
1408 | - } | ||
1409 | - if (pfound != NULL) | ||
1410 | - { | ||
1411 | - option_index = indfound; | ||
1412 | - if (*nameend) | ||
1413 | - { | ||
1414 | - /* Don't test has_arg with >, because some C compilers don't | ||
1415 | - allow it to be used on enums. */ | ||
1416 | - if (pfound->has_arg) | ||
1417 | - optarg = nameend + 1; | ||
1418 | - else | ||
1419 | - { | ||
1420 | - if (print_errors) | ||
1421 | - { | ||
1422 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1423 | - char *buf; | ||
1424 | - | ||
1425 | - if (__asprintf (&buf, _("\ | ||
1426 | -%s: option `-W %s' doesn't allow an argument\n"), | ||
1427 | - argv[0], pfound->name) >= 0) | ||
1428 | - { | ||
1429 | - if (_IO_fwide (stderr, 0) > 0) | ||
1430 | - __fwprintf (stderr, L"%s", buf); | ||
1431 | - else | ||
1432 | - fputs (buf, stderr); | ||
1433 | - | ||
1434 | - free (buf); | ||
1435 | - } | ||
1436 | -#else | ||
1437 | - fprintf (stderr, _("\ | ||
1438 | -%s: option `-W %s' doesn't allow an argument\n"), | ||
1439 | - argv[0], pfound->name); | ||
1440 | -#endif | ||
1441 | - } | ||
1442 | - | ||
1443 | - nextchar += strlen (nextchar); | ||
1444 | - return '?'; | ||
1445 | - } | ||
1446 | - } | ||
1447 | - else if (pfound->has_arg == 1) | ||
1448 | - { | ||
1449 | - if (optind < argc) | ||
1450 | - optarg = argv[optind++]; | ||
1451 | - else | ||
1452 | - { | ||
1453 | - if (print_errors) | ||
1454 | - { | ||
1455 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1456 | - char *buf; | ||
1457 | - | ||
1458 | - if (__asprintf (&buf, _("\ | ||
1459 | -%s: option `%s' requires an argument\n"), | ||
1460 | - argv[0], argv[optind - 1]) >= 0) | ||
1461 | - { | ||
1462 | - if (_IO_fwide (stderr, 0) > 0) | ||
1463 | - __fwprintf (stderr, L"%s", buf); | ||
1464 | - else | ||
1465 | - fputs (buf, stderr); | ||
1466 | - | ||
1467 | - free (buf); | ||
1468 | - } | ||
1469 | -#else | ||
1470 | - fprintf (stderr, | ||
1471 | - _("%s: option `%s' requires an argument\n"), | ||
1472 | - argv[0], argv[optind - 1]); | ||
1473 | -#endif | ||
1474 | - } | ||
1475 | - nextchar += strlen (nextchar); | ||
1476 | - return optstring[0] == ':' ? ':' : '?'; | ||
1477 | - } | ||
1478 | - } | ||
1479 | - nextchar += strlen (nextchar); | ||
1480 | - if (longind != NULL) | ||
1481 | - *longind = option_index; | ||
1482 | - if (pfound->flag) | ||
1483 | - { | ||
1484 | - *(pfound->flag) = pfound->val; | ||
1485 | - return 0; | ||
1486 | - } | ||
1487 | - return pfound->val; | ||
1488 | - } | ||
1489 | - nextchar = NULL; | ||
1490 | - return 'W'; /* Let the application handle it. */ | ||
1491 | - } | ||
1492 | - if (temp[1] == ':') | ||
1493 | - { | ||
1494 | - if (temp[2] == ':') | ||
1495 | - { | ||
1496 | - /* This is an option that accepts an argument optionally. */ | ||
1497 | - if (*nextchar != '\0') | ||
1498 | - { | ||
1499 | - optarg = nextchar; | ||
1500 | - optind++; | ||
1501 | - } | ||
1502 | - else | ||
1503 | - optarg = NULL; | ||
1504 | - nextchar = NULL; | ||
1505 | - } | ||
1506 | - else | ||
1507 | - { | ||
1508 | - /* This is an option that requires an argument. */ | ||
1509 | - if (*nextchar != '\0') | ||
1510 | - { | ||
1511 | - optarg = nextchar; | ||
1512 | - /* If we end this ARGV-element by taking the rest as an arg, | ||
1513 | - we must advance to the next element now. */ | ||
1514 | - optind++; | ||
1515 | - } | ||
1516 | - else if (optind == argc) | ||
1517 | - { | ||
1518 | - if (print_errors) | ||
1519 | - { | ||
1520 | - /* 1003.2 specifies the format of this message. */ | ||
1521 | -#if defined _LIBC && defined USE_IN_LIBIO | ||
1522 | - char *buf; | ||
1523 | - | ||
1524 | - if (__asprintf (&buf, _("\ | ||
1525 | -%s: option requires an argument -- %c\n"), | ||
1526 | - argv[0], c) >= 0) | ||
1527 | - { | ||
1528 | - if (_IO_fwide (stderr, 0) > 0) | ||
1529 | - __fwprintf (stderr, L"%s", buf); | ||
1530 | - else | ||
1531 | - fputs (buf, stderr); | ||
1532 | - | ||
1533 | - free (buf); | ||
1534 | - } | ||
1535 | -#else | ||
1536 | - fprintf (stderr, | ||
1537 | - _("%s: option requires an argument -- %c\n"), | ||
1538 | - argv[0], c); | ||
1539 | -#endif | ||
1540 | - } | ||
1541 | - optopt = c; | ||
1542 | - if (optstring[0] == ':') | ||
1543 | - c = ':'; | ||
1544 | - else | ||
1545 | - c = '?'; | ||
1546 | - } | ||
1547 | - else | ||
1548 | - /* We already incremented `optind' once; | ||
1549 | - increment it again when taking next ARGV-elt as argument. */ | ||
1550 | - optarg = argv[optind++]; | ||
1551 | - nextchar = NULL; | ||
1552 | - } | ||
1553 | - } | ||
1554 | - return c; | ||
1555 | - } | ||
1556 | -} | ||
1557 | - | ||
1558 | -int | ||
1559 | -getopt (argc, argv, optstring) | ||
1560 | - int argc; | ||
1561 | - char *const *argv; | ||
1562 | - const char *optstring; | ||
1563 | -{ | ||
1564 | - return _getopt_internal (argc, argv, optstring, | ||
1565 | - (const struct option *) 0, | ||
1566 | - (int *) 0, | ||
1567 | - 0); | ||
1568 | -} | ||
1569 | - | ||
1570 | -#endif /* Not ELIDE_CODE. */ | ||
1571 | - | ||
1572 | -#ifdef TEST | ||
1573 | - | ||
1574 | -/* Compile with -DTEST to make an executable for use in testing | ||
1575 | - the above definition of `getopt'. */ | ||
1576 | - | ||
1577 | -int | ||
1578 | -main (argc, argv) | ||
1579 | - int argc; | ||
1580 | - char **argv; | ||
1581 | -{ | ||
1582 | - int c; | ||
1583 | - int digit_optind = 0; | ||
1584 | - | ||
1585 | - while (1) | ||
1586 | - { | ||
1587 | - int this_option_optind = optind ? optind : 1; | ||
1588 | - | ||
1589 | - c = getopt (argc, argv, "abc:d:0123456789"); | ||
1590 | - if (c == -1) | ||
1591 | - break; | ||
1592 | - | ||
1593 | - switch (c) | ||
1594 | - { | ||
1595 | - case '0': | ||
1596 | - case '1': | ||
1597 | - case '2': | ||
1598 | - case '3': | ||
1599 | - case '4': | ||
1600 | - case '5': | ||
1601 | - case '6': | ||
1602 | - case '7': | ||
1603 | - case '8': | ||
1604 | - case '9': | ||
1605 | - if (digit_optind != 0 && digit_optind != this_option_optind) | ||
1606 | - printf ("digits occur in two different argv-elements.\n"); | ||
1607 | - digit_optind = this_option_optind; | ||
1608 | - printf ("option %c\n", c); | ||
1609 | - break; | ||
1610 | - | ||
1611 | - case 'a': | ||
1612 | - printf ("option a\n"); | ||
1613 | - break; | ||
1614 | - | ||
1615 | - case 'b': | ||
1616 | - printf ("option b\n"); | ||
1617 | - break; | ||
1618 | - | ||
1619 | - case 'c': | ||
1620 | - printf ("option c with value `%s'\n", optarg); | ||
1621 | - break; | ||
1622 | - | ||
1623 | - case '?': | ||
1624 | - break; | ||
1625 | - | ||
1626 | - default: | ||
1627 | - printf ("?? getopt returned character code 0%o ??\n", c); | ||
1628 | - } | ||
1629 | - } | ||
1630 | - | ||
1631 | - if (optind < argc) | ||
1632 | - { | ||
1633 | - printf ("non-option ARGV-elements: "); | ||
1634 | - while (optind < argc) | ||
1635 | - printf ("%s ", argv[optind++]); | ||
1636 | - printf ("\n"); | ||
1637 | - } | ||
1638 | - | ||
1639 | - exit (0); | ||
1640 | -} | ||
1641 | - | ||
1642 | -#endif /* TEST */ | ||
1643 | diff --git a/src/libs/libgroff/getopt1.c b/src/libs/libgroff/getopt1.c | ||
1644 | deleted file mode 100644 | ||
1645 | index 22a7efb..0000000 | ||
1646 | --- a/src/libs/libgroff/getopt1.c | ||
1647 | +++ /dev/null | ||
1648 | @@ -1,188 +0,0 @@ | ||
1649 | -/* getopt_long and getopt_long_only entry points for GNU getopt. | ||
1650 | - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 | ||
1651 | - Free Software Foundation, Inc. | ||
1652 | - This file is part of the GNU C Library. | ||
1653 | - | ||
1654 | - The GNU C Library is free software; you can redistribute it and/or | ||
1655 | - modify it under the terms of the GNU Lesser General Public | ||
1656 | - License as published by the Free Software Foundation; either | ||
1657 | - version 2.1 of the License, or (at your option) any later version. | ||
1658 | - | ||
1659 | - The GNU C Library is distributed in the hope that it will be useful, | ||
1660 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1661 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1662 | - Lesser General Public License for more details. | ||
1663 | - | ||
1664 | - You should have received a copy of the GNU Lesser General Public | ||
1665 | - License along with the GNU C Library; if not, write to the Free | ||
1666 | - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
1667 | - 02111-1307 USA. */ | ||
1668 | - | ||
1669 | -#ifdef HAVE_CONFIG_H | ||
1670 | -#include <config.h> | ||
1671 | -#endif | ||
1672 | - | ||
1673 | -#include "getopt.h" | ||
1674 | - | ||
1675 | -#if !defined __STDC__ || !__STDC__ | ||
1676 | -/* This is a separate conditional since some stdc systems | ||
1677 | - reject `defined (const)'. */ | ||
1678 | -#ifndef const | ||
1679 | -#define const | ||
1680 | -#endif | ||
1681 | -#endif | ||
1682 | - | ||
1683 | -#include <stdio.h> | ||
1684 | - | ||
1685 | -/* Comment out all this code if we are using the GNU C Library, and are not | ||
1686 | - actually compiling the library itself. This code is part of the GNU C | ||
1687 | - Library, but also included in many other GNU distributions. Compiling | ||
1688 | - and linking in this code is a waste when using the GNU C library | ||
1689 | - (especially if it is a shared library). Rather than having every GNU | ||
1690 | - program understand `configure --with-gnu-libc' and omit the object files, | ||
1691 | - it is simpler to just do this in the source for each such file. */ | ||
1692 | - | ||
1693 | -#define GETOPT_INTERFACE_VERSION 2 | ||
1694 | -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 | ||
1695 | -#include <gnu-versions.h> | ||
1696 | -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION | ||
1697 | -#define ELIDE_CODE | ||
1698 | -#endif | ||
1699 | -#endif | ||
1700 | - | ||
1701 | -#ifndef ELIDE_CODE | ||
1702 | - | ||
1703 | - | ||
1704 | -/* This needs to come after some library #include | ||
1705 | - to get __GNU_LIBRARY__ defined. */ | ||
1706 | -#ifdef __GNU_LIBRARY__ | ||
1707 | -#include <stdlib.h> | ||
1708 | -#endif | ||
1709 | - | ||
1710 | -#ifndef NULL | ||
1711 | -#define NULL 0 | ||
1712 | -#endif | ||
1713 | - | ||
1714 | -int | ||
1715 | -getopt_long (argc, argv, options, long_options, opt_index) | ||
1716 | - int argc; | ||
1717 | - char *const *argv; | ||
1718 | - const char *options; | ||
1719 | - const struct option *long_options; | ||
1720 | - int *opt_index; | ||
1721 | -{ | ||
1722 | - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); | ||
1723 | -} | ||
1724 | - | ||
1725 | -/* Like getopt_long, but '-' as well as '--' can indicate a long option. | ||
1726 | - If an option that starts with '-' (not '--') doesn't match a long option, | ||
1727 | - but does match a short option, it is parsed as a short option | ||
1728 | - instead. */ | ||
1729 | - | ||
1730 | -int | ||
1731 | -getopt_long_only (argc, argv, options, long_options, opt_index) | ||
1732 | - int argc; | ||
1733 | - char *const *argv; | ||
1734 | - const char *options; | ||
1735 | - const struct option *long_options; | ||
1736 | - int *opt_index; | ||
1737 | -{ | ||
1738 | - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); | ||
1739 | -} | ||
1740 | - | ||
1741 | - | ||
1742 | -#endif /* Not ELIDE_CODE. */ | ||
1743 | - | ||
1744 | -#ifdef TEST | ||
1745 | - | ||
1746 | -#include <stdio.h> | ||
1747 | - | ||
1748 | -int | ||
1749 | -main (argc, argv) | ||
1750 | - int argc; | ||
1751 | - char **argv; | ||
1752 | -{ | ||
1753 | - int c; | ||
1754 | - int digit_optind = 0; | ||
1755 | - | ||
1756 | - while (1) | ||
1757 | - { | ||
1758 | - int this_option_optind = optind ? optind : 1; | ||
1759 | - int option_index = 0; | ||
1760 | - static struct option long_options[] = | ||
1761 | - { | ||
1762 | - {"add", 1, 0, 0}, | ||
1763 | - {"append", 0, 0, 0}, | ||
1764 | - {"delete", 1, 0, 0}, | ||
1765 | - {"verbose", 0, 0, 0}, | ||
1766 | - {"create", 0, 0, 0}, | ||
1767 | - {"file", 1, 0, 0}, | ||
1768 | - {0, 0, 0, 0} | ||
1769 | - }; | ||
1770 | - | ||
1771 | - c = getopt_long (argc, argv, "abc:d:0123456789", | ||
1772 | - long_options, &option_index); | ||
1773 | - if (c == -1) | ||
1774 | - break; | ||
1775 | - | ||
1776 | - switch (c) | ||
1777 | - { | ||
1778 | - case 0: | ||
1779 | - printf ("option %s", long_options[option_index].name); | ||
1780 | - if (optarg) | ||
1781 | - printf (" with arg %s", optarg); | ||
1782 | - printf ("\n"); | ||
1783 | - break; | ||
1784 | - | ||
1785 | - case '0': | ||
1786 | - case '1': | ||
1787 | - case '2': | ||
1788 | - case '3': | ||
1789 | - case '4': | ||
1790 | - case '5': | ||
1791 | - case '6': | ||
1792 | - case '7': | ||
1793 | - case '8': | ||
1794 | - case '9': | ||
1795 | - if (digit_optind != 0 && digit_optind != this_option_optind) | ||
1796 | - printf ("digits occur in two different argv-elements.\n"); | ||
1797 | - digit_optind = this_option_optind; | ||
1798 | - printf ("option %c\n", c); | ||
1799 | - break; | ||
1800 | - | ||
1801 | - case 'a': | ||
1802 | - printf ("option a\n"); | ||
1803 | - break; | ||
1804 | - | ||
1805 | - case 'b': | ||
1806 | - printf ("option b\n"); | ||
1807 | - break; | ||
1808 | - | ||
1809 | - case 'c': | ||
1810 | - printf ("option c with value `%s'\n", optarg); | ||
1811 | - break; | ||
1812 | - | ||
1813 | - case 'd': | ||
1814 | - printf ("option d with value `%s'\n", optarg); | ||
1815 | - break; | ||
1816 | - | ||
1817 | - case '?': | ||
1818 | - break; | ||
1819 | - | ||
1820 | - default: | ||
1821 | - printf ("?? getopt returned character code 0%o ??\n", c); | ||
1822 | - } | ||
1823 | - } | ||
1824 | - | ||
1825 | - if (optind < argc) | ||
1826 | - { | ||
1827 | - printf ("non-option ARGV-elements: "); | ||
1828 | - while (optind < argc) | ||
1829 | - printf ("%s ", argv[optind++]); | ||
1830 | - printf ("\n"); | ||
1831 | - } | ||
1832 | - | ||
1833 | - exit (0); | ||
1834 | -} | ||
1835 | - | ||
1836 | -#endif /* TEST */ | ||
1837 | -- | ||
1838 | 2.12.0 | ||
1839 | |||