annotate lib-src/getopt.c @ 64760:4f6b04b42ad4

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