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