aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/.gitignore5
-rw-r--r--lib-src/ChangeLog31
-rw-r--r--lib-src/Makefile.in23
-rw-r--r--lib-src/cvtmail.c3
-rw-r--r--lib-src/digest-doc.c3
-rw-r--r--lib-src/ebrowse.c4
-rw-r--r--lib-src/emacsclient.c4
-rw-r--r--lib-src/emacstool.c3
-rw-r--r--lib-src/etags.c5
-rw-r--r--lib-src/fakemail.c3
-rw-r--r--lib-src/getopt.c633
-rw-r--r--lib-src/getopt1.c81
-rw-r--r--lib-src/getopt_.h (renamed from lib-src/getopt.h)121
-rw-r--r--lib-src/getopt_int.h134
-rw-r--r--lib-src/gettext.h82
-rwxr-xr-xlib-src/grep-changelog3
-rw-r--r--lib-src/hexl.c2
-rw-r--r--lib-src/make-docfile.c4
-rw-r--r--lib-src/makefile.w32-in6
-rw-r--r--lib-src/movemail.c3
-rw-r--r--lib-src/ntlib.c2
-rw-r--r--lib-src/ntlib.h2
-rw-r--r--lib-src/pop.c38
-rw-r--r--lib-src/pop.h3
-rw-r--r--lib-src/profile.c3
-rwxr-xr-xlib-src/rcs-checkin3
-rwxr-xr-xlib-src/rcs2log4
-rw-r--r--lib-src/sorted-doc.c4
-rw-r--r--lib-src/test-distrib.c4
-rw-r--r--lib-src/update-game-score.c2
-rwxr-xr-xlib-src/vcdiff4
31 files changed, 737 insertions, 485 deletions
diff --git a/lib-src/.gitignore b/lib-src/.gitignore
index 167540307ae..66933a62c36 100644
--- a/lib-src/.gitignore
+++ b/lib-src/.gitignore
@@ -1,7 +1,7 @@
1DOC 1DOC
2Makefile.c 2Makefile.c
3b2m 3b2m
4ctags 4ctags*
5cvtmail 5cvtmail
6digest-doc 6digest-doc
7ebrowse 7ebrowse
@@ -9,8 +9,7 @@ emacsclient
9emacsserver 9emacsserver
10etags 10etags
11fakemail 11fakemail
12fns-* 12getopt.h
13fns.el
14hexl 13hexl
15make-docfile 14make-docfile
16movemail 15movemail
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index bd6949c799c..5767b49aaed 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,34 @@
12005-07-27 Juanma Barranquero <lekktu@gmail.com>
2
3 * .cvsignore: Don't ignore fns-* and fns.el, which are no longer
4 generated. Ignore also ctags.c and getopt.h.
5
6 * makefile.w32-in (clean): Delete getopt.h.
7 (getopt.h): New rule.
8
92005-07-26 Paul Eggert <eggert@cs.ucla.edu>
10
11 Merge gnulib getopt implementation into Emacs.
12
13 * Makefile.in (mostlyclean): Remove getopt.h, getopt.h-t.
14 (GETOPT_H): New macro, from gnulib.
15 (getopt.h): New rule, from gnulib.
16 (GETOPTOBJS): Now autoconfigured.
17 (GETOPTDEPS): getopt.h is now autoconfigured.
18 (getopt.o, getopt1.o): Depend on $(GETOPT_H), not ${srcdir}/getopt.h.
19 (getopt.o): Depend on ${srcdir}/gettext.h.
20 (movemail.o): Depend on $(GETOPT_H).
21 * getopt.c, getopt1.c: Sync from gnulib.
22 * getopt_.h, getopt_int.h, gettext.h: New files, from gnulib.
23 * getopt.h: Removed (now is getopt_.h).
24
252005-07-13 Ken Raeburn <raeburn@gnu.org>
26
27 * pop.c: Don't include des.h (or variants thereof); krb.h will do
28 it.
29 (sendline): Add the \r\n to the line in a temporary buffer, and
30 write it all at once.
31
12005-07-04 Lute Kamstra <lute@gnu.org> 322005-07-04 Lute Kamstra <lute@gnu.org>
2 33
3 Update FSF's address in GPL notices. 34 Update FSF's address in GPL notices.
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in
index 372983221a3..274bbabe29f 100644
--- a/lib-src/Makefile.in
+++ b/lib-src/Makefile.in
@@ -1,6 +1,6 @@
1# Makefile for lib-src subdirectory in GNU Emacs. 1# Makefile for lib-src subdirectory in GNU Emacs.
2# Copyright (C) 1985, 1987, 1988, 1993, 1994, 2002, 2003, 2004 2# Copyright (C) 1985, 1987, 1988, 1993, 1994, 2002, 2003, 2004,
3# Free Software Foundation, Inc. 3# 2005 Free Software Foundation, Inc.
4 4
5# This file is part of GNU Emacs. 5# This file is part of GNU Emacs.
6 6
@@ -344,7 +344,7 @@ uninstall:
344 rm -f ${UTILITIES} ${INSTALLABLES} ${SCRIPTS} ${INSTALLABLE_SCRIPTS}) 344 rm -f ${UTILITIES} ${INSTALLABLES} ${SCRIPTS} ${INSTALLABLE_SCRIPTS})
345 345
346mostlyclean: 346mostlyclean:
347 -rm -f core *.o 347 -rm -f core *.o getopt.h getopt.h-t
348 348
349clean: mostlyclean 349clean: mostlyclean
350 -rm -f ${INSTALLABLES} ${UTILITIES} ${DONT_INSTALL} 350 -rm -f ${INSTALLABLES} ${UTILITIES} ${DONT_INSTALL}
@@ -382,11 +382,18 @@ test-distrib${EXEEXT}: ${srcdir}/test-distrib.c
382 $(CC) ${ALL_CFLAGS} -o test-distrib ${srcdir}/test-distrib.c 382 $(CC) ${ALL_CFLAGS} -o test-distrib ${srcdir}/test-distrib.c
383 ./test-distrib ${srcdir}/testfile 383 ./test-distrib ${srcdir}/testfile
384 384
385GETOPTOBJS = getopt.o getopt1.o 385/* We need the following in order to create a <getopt.h> when the system
386GETOPTDEPS = $(GETOPTOBJS) ${srcdir}/getopt.h 386 doesn't have one that works with the given compiler. */
387getopt.o: ${srcdir}/getopt.c ${srcdir}/getopt.h 387GETOPT_H = @GETOPT_H@
388getopt.h: getopt_.h
389 cp $(srcdir)/getopt_.h $@-t
390 mv $@-t $@
391
392GETOPTOBJS = @GETOPTOBJS@
393GETOPTDEPS = $(GETOPTOBJS) $(GETOPT_H)
394getopt.o: ${srcdir}/getopt.c $(GETOPT_H) ${srcdir}/gettext.h
388 ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt.c 395 ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt.c
389getopt1.o: ${srcdir}/getopt1.c ${srcdir}/getopt.h 396getopt1.o: ${srcdir}/getopt1.c $(GETOPT_H)
390 ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt1.c 397 ${CC} -c ${CPP_CFLAGS} ${srcdir}/getopt1.c
391 398
392#ifdef REGEXP_IN_LIBC 399#ifdef REGEXP_IN_LIBC
@@ -430,7 +437,7 @@ b2m${EXEEXT}: ${srcdir}/b2m.c ../src/config.h $(GETOPTDEPS)
430movemail${EXEEXT}: movemail.o pop.o $(GETOPTDEPS) 437movemail${EXEEXT}: movemail.o pop.o $(GETOPTDEPS)
431 $(CC) ${LINK_CFLAGS} ${MOVE_FLAGS} movemail.o pop.o $(GETOPTOBJS) $(LOADLIBES) $(LIBS_MAIL) $(LIBS_MOVE) -o movemail 438 $(CC) ${LINK_CFLAGS} ${MOVE_FLAGS} movemail.o pop.o $(GETOPTOBJS) $(LOADLIBES) $(LIBS_MAIL) $(LIBS_MOVE) -o movemail
432 439
433movemail.o: ${srcdir}/movemail.c ../src/config.h 440movemail.o: ${srcdir}/movemail.c ../src/config.h $(GETOPT_H)
434 $(CC) -c ${CPP_CFLAGS} -Demacs ${MOVE_FLAGS} ${srcdir}/movemail.c 441 $(CC) -c ${CPP_CFLAGS} -Demacs ${MOVE_FLAGS} ${srcdir}/movemail.c
435 442
436pop.o: ${srcdir}/pop.c ../src/config.h 443pop.o: ${srcdir}/pop.c ../src/config.h
diff --git a/lib-src/cvtmail.c b/lib-src/cvtmail.c
index 4dd6bb20a68..562c5522ed9 100644
--- a/lib-src/cvtmail.c
+++ b/lib-src/cvtmail.c
@@ -1,4 +1,5 @@
1/* Copyright (C) 1985, 1994 Free Software Foundation 1/* Copyright (C) 1985, 1994, 2002, 2003, 2004,
2 2005 Free Software Foundation, Inc.
2 3
3This file is part of GNU Emacs. 4This file is part of GNU Emacs.
4 5
diff --git a/lib-src/digest-doc.c b/lib-src/digest-doc.c
index 9db4a190803..d3df334841e 100644
--- a/lib-src/digest-doc.c
+++ b/lib-src/digest-doc.c
@@ -1,7 +1,8 @@
1/* Give this program DOC-mm.nn.oo as standard input and it outputs to 1/* Give this program DOC-mm.nn.oo as standard input and it outputs to
2 standard output a file of nroff output containing the doc strings. 2 standard output a file of nroff output containing the doc strings.
3 3
4 Copyright (C) 1987, 1994, 2001 Free Software Foundation Inc. 4 Copyright (C) 1987, 1994, 2001, 2002, 2003, 2004,
5 2005 Free Software Foundation, Inc.
5 6
6 This file is part of GNU Emacs. 7 This file is part of GNU Emacs.
7 8
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index bc323fbbbd8..49e353cf536 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -1,7 +1,7 @@
1/* ebrowse.c --- parsing files for the ebrowse C++ browser 1/* ebrowse.c --- parsing files for the ebrowse C++ browser
2 2
3 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 2000, 2001, 2002 Free Software Foundation Inc. 4 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 5
6 This file is part of GNU Emacs. 6 This file is part of GNU Emacs.
7 7
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 7cb40bb1968..4908d49441b 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1,6 +1,6 @@
1/* Client process that communicates with GNU Emacs acting as server. 1/* Client process that communicates with GNU Emacs acting as server.
2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2003, 2004 2 Copyright (C) 1986, 1987, 1994, 1999, 2000, 2001, 2002, 2003, 2004,
3 Free Software Foundation, Inc. 3 2005 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
diff --git a/lib-src/emacstool.c b/lib-src/emacstool.c
index f0e9ad8c1f6..b883b442bd9 100644
--- a/lib-src/emacstool.c
+++ b/lib-src/emacstool.c
@@ -1,5 +1,6 @@
1/* 1/*
2 Copyright (C) 1986, 1988, 1990, 1991 Free Software Foundation, Inc. 2 Copyright (C) 1986, 1988, 1990, 1991, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 2f273771a96..fe4fa84f4c5 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -1,6 +1,7 @@
1/* Tags file maker to go with GNU Emacs -*- coding: latin-1 -*- 1/* Tags file maker to go with GNU Emacs -*- coding: latin-1 -*-
2 Copyright (C) 1984, 1987-1989, 1993-1995, 1998-2001, 2002, 2004 2 Copyright (C) 1984, 1987, 1988, 1989, 1993, 1994, 1995,
3 Free Software Foundation, Inc. and Ken Arnold 3 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005 Free Software Foundation, Inc. and Ken Arnold
4 5
5 This file is not considered part of GNU Emacs. 6 This file is not considered part of GNU Emacs.
6 7
diff --git a/lib-src/fakemail.c b/lib-src/fakemail.c
index cf6c1ff334d..de1e2cbf858 100644
--- a/lib-src/fakemail.c
+++ b/lib-src/fakemail.c
@@ -1,5 +1,6 @@
1/* sendmail-like interface to /bin/mail for system V, 1/* sendmail-like interface to /bin/mail for system V,
2 Copyright (C) 1985, 1994, 1999 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1994, 1999, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
diff --git a/lib-src/getopt.c b/lib-src/getopt.c
index 6799045bde8..70fd4186261 100644
--- a/lib-src/getopt.c
+++ b/lib-src/getopt.c
@@ -2,8 +2,9 @@
2 NOTE: getopt is now part of the C library, so if you don't know what 2 NOTE: getopt is now part of the C library, so if you don't know what
3 "Keep this file name-space clean" means, talk to drepper@gnu.org 3 "Keep this file name-space clean" means, talk to drepper@gnu.org
4 before changing it! 4 before changing it!
5 Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002 5 Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
6 Free Software Foundation, Inc. 6 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
7 2004, 2005 Free Software Foundation, Inc.
7 This file is part of the GNU C Library. 8 This file is part of the GNU C Library.
8 9
9 This program is free software; you can redistribute it and/or modify 10 This program is free software; you can redistribute it and/or modify
@@ -30,35 +31,8 @@
30# include <config.h> 31# include <config.h>
31#endif 32#endif
32 33
33#if !defined __STDC__ || !__STDC__
34/* This is a separate conditional since some stdc systems
35 reject `defined (const)'. */
36# ifndef const
37# define const
38# endif
39#endif
40
41#include <stdio.h> 34#include <stdio.h>
42 35
43/* Comment out all this code if we are using the GNU C Library, and are not
44 actually compiling the library itself. This code is part of the GNU C
45 Library, but also included in many other GNU distributions. Compiling
46 and linking in this code is a waste when using the GNU C library
47 (especially if it is a shared library). Rather than having every GNU
48 program understand `configure --with-gnu-libc' and omit the object files,
49 it is simpler to just do this in the source for each such file. */
50
51#define GETOPT_INTERFACE_VERSION 2
52#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
53# include <gnu-versions.h>
54# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
55# define ELIDE_CODE
56# endif
57#endif
58
59#ifndef ELIDE_CODE
60
61
62/* This needs to come after some library #include 36/* This needs to come after some library #include
63 to get __GNU_LIBRARY__ defined. */ 37 to get __GNU_LIBRARY__ defined. */
64#ifdef __GNU_LIBRARY__ 38#ifdef __GNU_LIBRARY__
@@ -68,32 +42,18 @@
68# include <unistd.h> 42# include <unistd.h>
69#endif /* GNU C library. */ 43#endif /* GNU C library. */
70 44
45#include <string.h>
46
71#ifdef VMS 47#ifdef VMS
72# include <unixlib.h> 48# include <unixlib.h>
73# if HAVE_STRING_H - 0
74# include <string.h>
75# endif
76#endif 49#endif
77 50
78#if HAVE_LIBINTL_H 51#ifdef _LIBC
79# include <libintl.h> 52# include <libintl.h>
80#endif /* HAVE_LIBINTL_H */ 53#else
81 54# include "gettext.h"
82#if 0 55# define _(msgid) gettext (msgid)
83# ifdef _LIBC 56#endif
84# include <libintl.h>
85# else /* not #ifdef _LIBC */
86/* This is for other GNU distributions with internationalized messages. */
87# include "gettext.h"
88# endif /* end #ifdef _LIBC */
89#endif /* end #if 0 */
90
91#if HAVE_LIBINTL_H
92 /* Should I include libintl.h here as in regex.c ? */
93# define _(msgid) gettext (msgid)
94#else /* not #if HAVE_LIBINTL_H */
95# define _(msgid) (msgid)
96#endif /* end #if HAVE_LIBINTL_H */
97 57
98#if defined _LIBC && defined USE_IN_LIBIO 58#if defined _LIBC && defined USE_IN_LIBIO
99# include <wchar.h> 59# include <wchar.h>
@@ -103,21 +63,22 @@
103# define attribute_hidden 63# define attribute_hidden
104#endif 64#endif
105 65
106/* This version of `getopt' appears to the caller like standard Unix `getopt' 66/* Unlike standard Unix `getopt', functions like `getopt_long'
107 but it behaves differently for the user, since it allows the user 67 let the user intersperse the options with the other arguments.
108 to intersperse the options with the other arguments.
109 68
110 As `getopt' works, it permutes the elements of ARGV so that, 69 As `getopt_long' works, it permutes the elements of ARGV so that,
111 when it is done, all the options precede everything else. Thus 70 when it is done, all the options precede everything else. Thus
112 all application programs are extended to handle flexible argument order. 71 all application programs are extended to handle flexible argument order.
113 72
114 Setting the environment variable POSIXLY_CORRECT disables permutation. 73 Using `getopt' or setting the environment variable POSIXLY_CORRECT
115 Then the behavior is completely standard. 74 disables permutation.
75 Then the application's behavior is completely standard.
116 76
117 GNU application programs can use a third alternative mode in which 77 GNU application programs can use a third alternative mode in which
118 they can distinguish the relative order of options and other arguments. */ 78 they can distinguish the relative order of options and other arguments. */
119 79
120#include "getopt.h" 80#include "getopt.h"
81#include "getopt_int.h"
121 82
122/* For communication from `getopt' to the caller. 83/* For communication from `getopt' to the caller.
123 When `getopt' finds an option that takes an argument, 84 When `getopt' finds an option that takes an argument,
@@ -142,21 +103,6 @@ char *optarg;
142/* 1003.2 says this must be 1 before any call. */ 103/* 1003.2 says this must be 1 before any call. */
143int optind = 1; 104int optind = 1;
144 105
145/* Formerly, initialization of getopt depended on optind==0, which
146 causes problems with re-calling getopt as programs generally don't
147 know that. */
148
149int __getopt_initialized attribute_hidden;
150
151/* The next char to be scanned in the option-element
152 in which the last option character we returned was found.
153 This allows us to pick up the scan where we left off.
154
155 If this is zero, or a null string, it means resume the scan
156 by advancing to the next ARGV-element. */
157
158static char *nextchar;
159
160/* Callers store zero here to inhibit the error message 106/* Callers store zero here to inhibit the error message
161 for unrecognized options. */ 107 for unrecognized options. */
162 108
@@ -168,57 +114,12 @@ int opterr = 1;
168 114
169int optopt = '?'; 115int optopt = '?';
170 116
171/* Describe how to deal with options that follow non-option ARGV-elements. 117/* Keep a global copy of all internal members of getopt_data. */
172
173 If the caller did not specify anything,
174 the default is REQUIRE_ORDER if the environment variable
175 POSIXLY_CORRECT is defined, PERMUTE otherwise.
176
177 REQUIRE_ORDER means don't recognize them as options;
178 stop option processing when the first non-option is seen.
179 This is what Unix does.
180 This mode of operation is selected by either setting the environment
181 variable POSIXLY_CORRECT, or using `+' as the first character
182 of the list of option characters.
183
184 PERMUTE is the default. We permute the contents of ARGV as we scan,
185 so that eventually all the non-options are at the end. This allows options
186 to be given in any order, even with programs that were not written to
187 expect this.
188 118
189 RETURN_IN_ORDER is an option available to programs that were written 119static struct _getopt_data getopt_data;
190 to expect options and other ARGV-elements in any order and that care about
191 the ordering of the two. We describe each non-option ARGV-element
192 as if it were the argument of an option with character code 1.
193 Using `-' as the first character of the list of option characters
194 selects this mode of operation.
195 120
196 The special argument `--' forces an end of option-scanning regardless
197 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
198 `--' can cause `getopt' to return -1 with `optind' != ARGC. */
199
200static enum
201{
202 REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
203} ordering;
204
205/* Value of POSIXLY_CORRECT environment variable. */
206static char *posixly_correct;
207 121
208#ifdef __GNU_LIBRARY__ 122#ifndef __GNU_LIBRARY__
209/* We want to avoid inclusion of string.h with non-GNU libraries
210 because there are many ways it can cause trouble.
211 On some systems, it contains special magic macros that don't work
212 in GCC. */
213# include <string.h>
214# define my_index strchr
215#else
216
217# if HAVE_STRING_H
218# include <string.h>
219# else
220# include <strings.h>
221# endif
222 123
223/* Avoid depending on library functions or files 124/* Avoid depending on library functions or files
224 whose names are inconsistent. */ 125 whose names are inconsistent. */
@@ -227,43 +128,8 @@ static char *posixly_correct;
227extern char *getenv (); 128extern char *getenv ();
228#endif 129#endif
229 130
230static char *
231my_index (str, chr)
232 const char *str;
233 int chr;
234{
235 while (*str)
236 {
237 if (*str == chr)
238 return (char *) str;
239 str++;
240 }
241 return 0;
242}
243
244/* If using GCC, we can safely declare strlen this way.
245 If not using GCC, it is ok not to declare it. */
246#ifdef __GNUC__
247/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
248 That was relevant to code that was here before. */
249# if (!defined __STDC__ || !__STDC__) && !defined strlen
250/* gcc with -traditional declares the built-in strlen to return int,
251 and has done so at least since version 2.4.5. -- rms. */
252extern int strlen (const char *);
253# endif /* not __STDC__ */
254#endif /* __GNUC__ */
255
256#endif /* not __GNU_LIBRARY__ */ 131#endif /* not __GNU_LIBRARY__ */
257 132
258/* Handle permutation of arguments. */
259
260/* Describe the part of ARGV that contains non-options that have
261 been skipped. `first_nonopt' is the index in ARGV of the first of them;
262 `last_nonopt' is the index after the last of them. */
263
264static int first_nonopt;
265static int last_nonopt;
266
267#ifdef _LIBC 133#ifdef _LIBC
268/* Stored original parameters. 134/* Stored original parameters.
269 XXX This is no good solution. We should rather copy the args so 135 XXX This is no good solution. We should rather copy the args so
@@ -277,14 +143,11 @@ extern char **__libc_argv;
277# ifdef USE_NONOPTION_FLAGS 143# ifdef USE_NONOPTION_FLAGS
278/* Defined in getopt_init.c */ 144/* Defined in getopt_init.c */
279extern char *__getopt_nonoption_flags; 145extern char *__getopt_nonoption_flags;
280
281static int nonoption_flags_max_len;
282static int nonoption_flags_len;
283# endif 146# endif
284 147
285# ifdef USE_NONOPTION_FLAGS 148# ifdef USE_NONOPTION_FLAGS
286# define SWAP_FLAGS(ch1, ch2) \ 149# define SWAP_FLAGS(ch1, ch2) \
287 if (nonoption_flags_len > 0) \ 150 if (d->__nonoption_flags_len > 0) \
288 { \ 151 { \
289 char __tmp = __getopt_nonoption_flags[ch1]; \ 152 char __tmp = __getopt_nonoption_flags[ch1]; \
290 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ 153 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
@@ -306,17 +169,12 @@ static int nonoption_flags_len;
306 `first_nonopt' and `last_nonopt' are relocated so that they describe 169 `first_nonopt' and `last_nonopt' are relocated so that they describe
307 the new indices of the non-options in ARGV after they are moved. */ 170 the new indices of the non-options in ARGV after they are moved. */
308 171
309#if defined __STDC__ && __STDC__
310static void exchange (char **);
311#endif
312
313static void 172static void
314exchange (argv) 173exchange (char **argv, struct _getopt_data *d)
315 char **argv;
316{ 174{
317 int bottom = first_nonopt; 175 int bottom = d->__first_nonopt;
318 int middle = last_nonopt; 176 int middle = d->__last_nonopt;
319 int top = optind; 177 int top = d->optind;
320 char *tem; 178 char *tem;
321 179
322 /* Exchange the shorter segment with the far end of the longer segment. 180 /* Exchange the shorter segment with the far end of the longer segment.
@@ -328,19 +186,19 @@ exchange (argv)
328 /* First make sure the handling of the `__getopt_nonoption_flags' 186 /* First make sure the handling of the `__getopt_nonoption_flags'
329 string can work normally. Our top argument must be in the range 187 string can work normally. Our top argument must be in the range
330 of the string. */ 188 of the string. */
331 if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) 189 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
332 { 190 {
333 /* We must extend the array. The user plays games with us and 191 /* We must extend the array. The user plays games with us and
334 presents new arguments. */ 192 presents new arguments. */
335 char *new_str = malloc (top + 1); 193 char *new_str = malloc (top + 1);
336 if (new_str == NULL) 194 if (new_str == NULL)
337 nonoption_flags_len = nonoption_flags_max_len = 0; 195 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
338 else 196 else
339 { 197 {
340 memset (__mempcpy (new_str, __getopt_nonoption_flags, 198 memset (__mempcpy (new_str, __getopt_nonoption_flags,
341 nonoption_flags_max_len), 199 d->__nonoption_flags_max_len),
342 '\0', top + 1 - nonoption_flags_max_len); 200 '\0', top + 1 - d->__nonoption_flags_max_len);
343 nonoption_flags_max_len = top + 1; 201 d->__nonoption_flags_max_len = top + 1;
344 __getopt_nonoption_flags = new_str; 202 __getopt_nonoption_flags = new_str;
345 } 203 }
346 } 204 }
@@ -386,76 +244,71 @@ exchange (argv)
386 244
387 /* Update records for the slots the non-options now occupy. */ 245 /* Update records for the slots the non-options now occupy. */
388 246
389 first_nonopt += (optind - last_nonopt); 247 d->__first_nonopt += (d->optind - d->__last_nonopt);
390 last_nonopt = optind; 248 d->__last_nonopt = d->optind;
391} 249}
392 250
393/* Initialize the internal data when the first call is made. */ 251/* Initialize the internal data when the first call is made. */
394 252
395#if defined __STDC__ && __STDC__
396static const char *_getopt_initialize (int, char *const *, const char *);
397#endif
398static const char * 253static const char *
399_getopt_initialize (argc, argv, optstring) 254_getopt_initialize (int argc, char **argv, const char *optstring,
400 int argc; 255 int posixly_correct, struct _getopt_data *d)
401 char *const *argv;
402 const char *optstring;
403{ 256{
404 /* Start processing options with ARGV-element 1 (since ARGV-element 0 257 /* Start processing options with ARGV-element 1 (since ARGV-element 0
405 is the program name); the sequence of previously skipped 258 is the program name); the sequence of previously skipped
406 non-option ARGV-elements is empty. */ 259 non-option ARGV-elements is empty. */
407 260
408 first_nonopt = last_nonopt = optind; 261 d->__first_nonopt = d->__last_nonopt = d->optind;
409 262
410 nextchar = NULL; 263 d->__nextchar = NULL;
411 264
412 posixly_correct = getenv ("POSIXLY_CORRECT"); 265 d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
413 266
414 /* Determine how to handle the ordering of options and nonoptions. */ 267 /* Determine how to handle the ordering of options and nonoptions. */
415 268
416 if (optstring[0] == '-') 269 if (optstring[0] == '-')
417 { 270 {
418 ordering = RETURN_IN_ORDER; 271 d->__ordering = RETURN_IN_ORDER;
419 ++optstring; 272 ++optstring;
420 } 273 }
421 else if (optstring[0] == '+') 274 else if (optstring[0] == '+')
422 { 275 {
423 ordering = REQUIRE_ORDER; 276 d->__ordering = REQUIRE_ORDER;
424 ++optstring; 277 ++optstring;
425 } 278 }
426 else if (posixly_correct != NULL) 279 else if (d->__posixly_correct)
427 ordering = REQUIRE_ORDER; 280 d->__ordering = REQUIRE_ORDER;
428 else 281 else
429 ordering = PERMUTE; 282 d->__ordering = PERMUTE;
430 283
431#if defined _LIBC && defined USE_NONOPTION_FLAGS 284#if defined _LIBC && defined USE_NONOPTION_FLAGS
432 if (posixly_correct == NULL 285 if (!d->__posixly_correct
433 && argc == __libc_argc && argv == __libc_argv) 286 && argc == __libc_argc && argv == __libc_argv)
434 { 287 {
435 if (nonoption_flags_max_len == 0) 288 if (d->__nonoption_flags_max_len == 0)
436 { 289 {
437 if (__getopt_nonoption_flags == NULL 290 if (__getopt_nonoption_flags == NULL
438 || __getopt_nonoption_flags[0] == '\0') 291 || __getopt_nonoption_flags[0] == '\0')
439 nonoption_flags_max_len = -1; 292 d->__nonoption_flags_max_len = -1;
440 else 293 else
441 { 294 {
442 const char *orig_str = __getopt_nonoption_flags; 295 const char *orig_str = __getopt_nonoption_flags;
443 int len = nonoption_flags_max_len = strlen (orig_str); 296 int len = d->__nonoption_flags_max_len = strlen (orig_str);
444 if (nonoption_flags_max_len < argc) 297 if (d->__nonoption_flags_max_len < argc)
445 nonoption_flags_max_len = argc; 298 d->__nonoption_flags_max_len = argc;
446 __getopt_nonoption_flags = 299 __getopt_nonoption_flags =
447 (char *) malloc (nonoption_flags_max_len); 300 (char *) malloc (d->__nonoption_flags_max_len);
448 if (__getopt_nonoption_flags == NULL) 301 if (__getopt_nonoption_flags == NULL)
449 nonoption_flags_max_len = -1; 302 d->__nonoption_flags_max_len = -1;
450 else 303 else
451 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), 304 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
452 '\0', nonoption_flags_max_len - len); 305 '\0', d->__nonoption_flags_max_len - len);
453 } 306 }
454 } 307 }
455 nonoption_flags_len = nonoption_flags_max_len; 308 d->__nonoption_flags_len = d->__nonoption_flags_max_len;
456 } 309 }
457 else 310 else
458 nonoption_flags_len = 0; 311 d->__nonoption_flags_len = 0;
459#endif 312#endif
460 313
461 return optstring; 314 return optstring;
@@ -503,10 +356,6 @@ _getopt_initialize (argc, argv, optstring)
503 `flag' field is nonzero, the value of the option's `val' field 356 `flag' field is nonzero, the value of the option's `val' field
504 if the `flag' field is zero. 357 if the `flag' field is zero.
505 358
506 The elements of ARGV aren't really const, because we permute them.
507 But we pretend they're const in the prototype to be compatible
508 with other systems.
509
510 LONGOPTS is a vector of `struct option' terminated by an 359 LONGOPTS is a vector of `struct option' terminated by an
511 element containing a name which is zero. 360 element containing a name which is zero.
512 361
@@ -515,32 +364,32 @@ _getopt_initialize (argc, argv, optstring)
515 recent call. 364 recent call.
516 365
517 If LONG_ONLY is nonzero, '-' as well as '--' can introduce 366 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
518 long-named options. */ 367 long-named options.
368
369 If POSIXLY_CORRECT is nonzero, behave as if the POSIXLY_CORRECT
370 environment variable were set. */
519 371
520int 372int
521_getopt_internal (argc, argv, optstring, longopts, longind, long_only) 373_getopt_internal_r (int argc, char **argv, const char *optstring,
522 int argc; 374 const struct option *longopts, int *longind,
523 char *const *argv; 375 int long_only, int posixly_correct, struct _getopt_data *d)
524 const char *optstring;
525 const struct option *longopts;
526 int *longind;
527 int long_only;
528{ 376{
529 int print_errors = opterr; 377 int print_errors = d->opterr;
530 if (optstring[0] == ':') 378 if (optstring[0] == ':')
531 print_errors = 0; 379 print_errors = 0;
532 380
533 if (argc < 1) 381 if (argc < 1)
534 return -1; 382 return -1;
535 383
536 optarg = NULL; 384 d->optarg = NULL;
537 385
538 if (optind == 0 || !__getopt_initialized) 386 if (d->optind == 0 || !d->__initialized)
539 { 387 {
540 if (optind == 0) 388 if (d->optind == 0)
541 optind = 1; /* Don't scan ARGV[0], the program name. */ 389 d->optind = 1; /* Don't scan ARGV[0], the program name. */
542 optstring = _getopt_initialize (argc, argv, optstring); 390 optstring = _getopt_initialize (argc, argv, optstring,
543 __getopt_initialized = 1; 391 posixly_correct, d);
392 d->__initialized = 1;
544 } 393 }
545 394
546 /* Test whether ARGV[optind] points to a non-option argument. 395 /* Test whether ARGV[optind] points to a non-option argument.
@@ -548,40 +397,41 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
548 from the shell indicating it is not an option. The later information 397 from the shell indicating it is not an option. The later information
549 is only used when the used in the GNU libc. */ 398 is only used when the used in the GNU libc. */
550#if defined _LIBC && defined USE_NONOPTION_FLAGS 399#if defined _LIBC && defined USE_NONOPTION_FLAGS
551# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ 400# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
552 || (optind < nonoption_flags_len \ 401 || (d->optind < d->__nonoption_flags_len \
553 && __getopt_nonoption_flags[optind] == '1')) 402 && __getopt_nonoption_flags[d->optind] == '1'))
554#else 403#else
555# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') 404# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
556#endif 405#endif
557 406
558 if (nextchar == NULL || *nextchar == '\0') 407 if (d->__nextchar == NULL || *d->__nextchar == '\0')
559 { 408 {
560 /* Advance to the next ARGV-element. */ 409 /* Advance to the next ARGV-element. */
561 410
562 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been 411 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
563 moved back by the user (who may also have changed the arguments). */ 412 moved back by the user (who may also have changed the arguments). */
564 if (last_nonopt > optind) 413 if (d->__last_nonopt > d->optind)
565 last_nonopt = optind; 414 d->__last_nonopt = d->optind;
566 if (first_nonopt > optind) 415 if (d->__first_nonopt > d->optind)
567 first_nonopt = optind; 416 d->__first_nonopt = d->optind;
568 417
569 if (ordering == PERMUTE) 418 if (d->__ordering == PERMUTE)
570 { 419 {
571 /* If we have just processed some options following some non-options, 420 /* If we have just processed some options following some non-options,
572 exchange them so that the options come first. */ 421 exchange them so that the options come first. */
573 422
574 if (first_nonopt != last_nonopt && last_nonopt != optind) 423 if (d->__first_nonopt != d->__last_nonopt
575 exchange ((char **) argv); 424 && d->__last_nonopt != d->optind)
576 else if (last_nonopt != optind) 425 exchange ((char **) argv, d);
577 first_nonopt = optind; 426 else if (d->__last_nonopt != d->optind)
427 d->__first_nonopt = d->optind;
578 428
579 /* Skip any additional non-options 429 /* Skip any additional non-options
580 and extend the range of non-options previously skipped. */ 430 and extend the range of non-options previously skipped. */
581 431
582 while (optind < argc && NONOPTION_P) 432 while (d->optind < argc && NONOPTION_P)
583 optind++; 433 d->optind++;
584 last_nonopt = optind; 434 d->__last_nonopt = d->optind;
585 } 435 }
586 436
587 /* The special ARGV-element `--' means premature end of options. 437 /* The special ARGV-element `--' means premature end of options.
@@ -589,28 +439,29 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
589 then exchange with previous non-options as if it were an option, 439 then exchange with previous non-options as if it were an option,
590 then skip everything else like a non-option. */ 440 then skip everything else like a non-option. */
591 441
592 if (optind != argc && !strcmp (argv[optind], "--")) 442 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
593 { 443 {
594 optind++; 444 d->optind++;
595 445
596 if (first_nonopt != last_nonopt && last_nonopt != optind) 446 if (d->__first_nonopt != d->__last_nonopt
597 exchange ((char **) argv); 447 && d->__last_nonopt != d->optind)
598 else if (first_nonopt == last_nonopt) 448 exchange ((char **) argv, d);
599 first_nonopt = optind; 449 else if (d->__first_nonopt == d->__last_nonopt)
600 last_nonopt = argc; 450 d->__first_nonopt = d->optind;
451 d->__last_nonopt = argc;
601 452
602 optind = argc; 453 d->optind = argc;
603 } 454 }
604 455
605 /* If we have done all the ARGV-elements, stop the scan 456 /* If we have done all the ARGV-elements, stop the scan
606 and back over any non-options that we skipped and permuted. */ 457 and back over any non-options that we skipped and permuted. */
607 458
608 if (optind == argc) 459 if (d->optind == argc)
609 { 460 {
610 /* Set the next-arg-index to point at the non-options 461 /* Set the next-arg-index to point at the non-options
611 that we previously skipped, so the caller will digest them. */ 462 that we previously skipped, so the caller will digest them. */
612 if (first_nonopt != last_nonopt) 463 if (d->__first_nonopt != d->__last_nonopt)
613 optind = first_nonopt; 464 d->optind = d->__first_nonopt;
614 return -1; 465 return -1;
615 } 466 }
616 467
@@ -619,17 +470,17 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
619 470
620 if (NONOPTION_P) 471 if (NONOPTION_P)
621 { 472 {
622 if (ordering == REQUIRE_ORDER) 473 if (d->__ordering == REQUIRE_ORDER)
623 return -1; 474 return -1;
624 optarg = argv[optind++]; 475 d->optarg = argv[d->optind++];
625 return 1; 476 return 1;
626 } 477 }
627 478
628 /* We have found another option-ARGV-element. 479 /* We have found another option-ARGV-element.
629 Skip the initial punctuation. */ 480 Skip the initial punctuation. */
630 481
631 nextchar = (argv[optind] + 1 482 d->__nextchar = (argv[d->optind] + 1
632 + (longopts != NULL && argv[optind][1] == '-')); 483 + (longopts != NULL && argv[d->optind][1] == '-'));
633 } 484 }
634 485
635 /* Decode the current option-ARGV-element. */ 486 /* Decode the current option-ARGV-element. */
@@ -648,8 +499,9 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
648 This distinction seems to be the most useful approach. */ 499 This distinction seems to be the most useful approach. */
649 500
650 if (longopts != NULL 501 if (longopts != NULL
651 && (argv[optind][1] == '-' 502 && (argv[d->optind][1] == '-'
652 || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) 503 || (long_only && (argv[d->optind][2]
504 || !strchr (optstring, argv[d->optind][1])))))
653 { 505 {
654 char *nameend; 506 char *nameend;
655 const struct option *p; 507 const struct option *p;
@@ -659,15 +511,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
659 int indfound = -1; 511 int indfound = -1;
660 int option_index; 512 int option_index;
661 513
662 for (nameend = nextchar; *nameend && *nameend != '='; nameend++) 514 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
663 /* Do nothing. */ ; 515 /* Do nothing. */ ;
664 516
665 /* Test all long options for either exact match 517 /* Test all long options for either exact match
666 or abbreviated matches. */ 518 or abbreviated matches. */
667 for (p = longopts, option_index = 0; p->name; p++, option_index++) 519 for (p = longopts, option_index = 0; p->name; p++, option_index++)
668 if (!strncmp (p->name, nextchar, nameend - nextchar)) 520 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
669 { 521 {
670 if ((unsigned int) (nameend - nextchar) 522 if ((unsigned int) (nameend - d->__nextchar)
671 == (unsigned int) strlen (p->name)) 523 == (unsigned int) strlen (p->name))
672 { 524 {
673 /* Exact match found. */ 525 /* Exact match found. */
@@ -698,37 +550,44 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
698 char *buf; 550 char *buf;
699 551
700 if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"), 552 if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
701 argv[0], argv[optind]) >= 0) 553 argv[0], argv[d->optind]) >= 0)
702 { 554 {
555 _IO_flockfile (stderr);
556
557 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
558 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
703 559
704 if (_IO_fwide (stderr, 0) > 0) 560 if (_IO_fwide (stderr, 0) > 0)
705 __fwprintf (stderr, L"%s", buf); 561 __fwprintf (stderr, L"%s", buf);
706 else 562 else
707 fputs (buf, stderr); 563 fputs (buf, stderr);
708 564
565 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
566 _IO_funlockfile (stderr);
567
709 free (buf); 568 free (buf);
710 } 569 }
711#else 570#else
712 fprintf (stderr, _("%s: option `%s' is ambiguous\n"), 571 fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
713 argv[0], argv[optind]); 572 argv[0], argv[d->optind]);
714#endif 573#endif
715 } 574 }
716 nextchar += strlen (nextchar); 575 d->__nextchar += strlen (d->__nextchar);
717 optind++; 576 d->optind++;
718 optopt = 0; 577 d->optopt = 0;
719 return '?'; 578 return '?';
720 } 579 }
721 580
722 if (pfound != NULL) 581 if (pfound != NULL)
723 { 582 {
724 option_index = indfound; 583 option_index = indfound;
725 optind++; 584 d->optind++;
726 if (*nameend) 585 if (*nameend)
727 { 586 {
728 /* Don't test has_arg with >, because some C compilers don't 587 /* Don't test has_arg with >, because some C compilers don't
729 allow it to be used on enums. */ 588 allow it to be used on enums. */
730 if (pfound->has_arg) 589 if (pfound->has_arg)
731 optarg = nameend + 1; 590 d->optarg = nameend + 1;
732 else 591 else
733 { 592 {
734 if (print_errors) 593 if (print_errors)
@@ -738,7 +597,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
738 int n; 597 int n;
739#endif 598#endif
740 599
741 if (argv[optind - 1][1] == '-') 600 if (argv[d->optind - 1][1] == '-')
742 { 601 {
743 /* --option */ 602 /* --option */
744#if defined _LIBC && defined USE_IN_LIBIO 603#if defined _LIBC && defined USE_IN_LIBIO
@@ -757,38 +616,48 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
757#if defined _LIBC && defined USE_IN_LIBIO 616#if defined _LIBC && defined USE_IN_LIBIO
758 n = __asprintf (&buf, _("\ 617 n = __asprintf (&buf, _("\
759%s: option `%c%s' doesn't allow an argument\n"), 618%s: option `%c%s' doesn't allow an argument\n"),
760 argv[0], argv[optind - 1][0], 619 argv[0], argv[d->optind - 1][0],
761 pfound->name); 620 pfound->name);
762#else 621#else
763 fprintf (stderr, _("\ 622 fprintf (stderr, _("\
764%s: option `%c%s' doesn't allow an argument\n"), 623%s: option `%c%s' doesn't allow an argument\n"),
765 argv[0], argv[optind - 1][0], pfound->name); 624 argv[0], argv[d->optind - 1][0],
625 pfound->name);
766#endif 626#endif
767 } 627 }
768 628
769#if defined _LIBC && defined USE_IN_LIBIO 629#if defined _LIBC && defined USE_IN_LIBIO
770 if (n >= 0) 630 if (n >= 0)
771 { 631 {
632 _IO_flockfile (stderr);
633
634 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
635 ((_IO_FILE *) stderr)->_flags2
636 |= _IO_FLAGS2_NOTCANCEL;
637
772 if (_IO_fwide (stderr, 0) > 0) 638 if (_IO_fwide (stderr, 0) > 0)
773 __fwprintf (stderr, L"%s", buf); 639 __fwprintf (stderr, L"%s", buf);
774 else 640 else
775 fputs (buf, stderr); 641 fputs (buf, stderr);
776 642
643 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
644 _IO_funlockfile (stderr);
645
777 free (buf); 646 free (buf);
778 } 647 }
779#endif 648#endif
780 } 649 }
781 650
782 nextchar += strlen (nextchar); 651 d->__nextchar += strlen (d->__nextchar);
783 652
784 optopt = pfound->val; 653 d->optopt = pfound->val;
785 return '?'; 654 return '?';
786 } 655 }
787 } 656 }
788 else if (pfound->has_arg == 1) 657 else if (pfound->has_arg == 1)
789 { 658 {
790 if (optind < argc) 659 if (d->optind < argc)
791 optarg = argv[optind++]; 660 d->optarg = argv[d->optind++];
792 else 661 else
793 { 662 {
794 if (print_errors) 663 if (print_errors)
@@ -798,27 +667,36 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
798 667
799 if (__asprintf (&buf, _("\ 668 if (__asprintf (&buf, _("\
800%s: option `%s' requires an argument\n"), 669%s: option `%s' requires an argument\n"),
801 argv[0], argv[optind - 1]) >= 0) 670 argv[0], argv[d->optind - 1]) >= 0)
802 { 671 {
672 _IO_flockfile (stderr);
673
674 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
675 ((_IO_FILE *) stderr)->_flags2
676 |= _IO_FLAGS2_NOTCANCEL;
677
803 if (_IO_fwide (stderr, 0) > 0) 678 if (_IO_fwide (stderr, 0) > 0)
804 __fwprintf (stderr, L"%s", buf); 679 __fwprintf (stderr, L"%s", buf);
805 else 680 else
806 fputs (buf, stderr); 681 fputs (buf, stderr);
807 682
683 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
684 _IO_funlockfile (stderr);
685
808 free (buf); 686 free (buf);
809 } 687 }
810#else 688#else
811 fprintf (stderr, 689 fprintf (stderr,
812 _("%s: option `%s' requires an argument\n"), 690 _("%s: option `%s' requires an argument\n"),
813 argv[0], argv[optind - 1]); 691 argv[0], argv[d->optind - 1]);
814#endif 692#endif
815 } 693 }
816 nextchar += strlen (nextchar); 694 d->__nextchar += strlen (d->__nextchar);
817 optopt = pfound->val; 695 d->optopt = pfound->val;
818 return optstring[0] == ':' ? ':' : '?'; 696 return optstring[0] == ':' ? ':' : '?';
819 } 697 }
820 } 698 }
821 nextchar += strlen (nextchar); 699 d->__nextchar += strlen (d->__nextchar);
822 if (longind != NULL) 700 if (longind != NULL)
823 *longind = option_index; 701 *longind = option_index;
824 if (pfound->flag) 702 if (pfound->flag)
@@ -833,8 +711,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
833 or the option starts with '--' or is not a valid short 711 or the option starts with '--' or is not a valid short
834 option, then it's an error. 712 option, then it's an error.
835 Otherwise interpret it as a short option. */ 713 Otherwise interpret it as a short option. */
836 if (!long_only || argv[optind][1] == '-' 714 if (!long_only || argv[d->optind][1] == '-'
837 || my_index (optstring, *nextchar) == NULL) 715 || strchr (optstring, *d->__nextchar) == NULL)
838 { 716 {
839 if (print_errors) 717 if (print_errors)
840 { 718 {
@@ -843,15 +721,15 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
843 int n; 721 int n;
844#endif 722#endif
845 723
846 if (argv[optind][1] == '-') 724 if (argv[d->optind][1] == '-')
847 { 725 {
848 /* --option */ 726 /* --option */
849#if defined _LIBC && defined USE_IN_LIBIO 727#if defined _LIBC && defined USE_IN_LIBIO
850 n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), 728 n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
851 argv[0], nextchar); 729 argv[0], d->__nextchar);
852#else 730#else
853 fprintf (stderr, _("%s: unrecognized option `--%s'\n"), 731 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
854 argv[0], nextchar); 732 argv[0], d->__nextchar);
855#endif 733#endif
856 } 734 }
857 else 735 else
@@ -859,28 +737,36 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
859 /* +option or -option */ 737 /* +option or -option */
860#if defined _LIBC && defined USE_IN_LIBIO 738#if defined _LIBC && defined USE_IN_LIBIO
861 n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), 739 n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
862 argv[0], argv[optind][0], nextchar); 740 argv[0], argv[d->optind][0], d->__nextchar);
863#else 741#else
864 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), 742 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
865 argv[0], argv[optind][0], nextchar); 743 argv[0], argv[d->optind][0], d->__nextchar);
866#endif 744#endif
867 } 745 }
868 746
869#if defined _LIBC && defined USE_IN_LIBIO 747#if defined _LIBC && defined USE_IN_LIBIO
870 if (n >= 0) 748 if (n >= 0)
871 { 749 {
750 _IO_flockfile (stderr);
751
752 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
753 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
754
872 if (_IO_fwide (stderr, 0) > 0) 755 if (_IO_fwide (stderr, 0) > 0)
873 __fwprintf (stderr, L"%s", buf); 756 __fwprintf (stderr, L"%s", buf);
874 else 757 else
875 fputs (buf, stderr); 758 fputs (buf, stderr);
876 759
760 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
761 _IO_funlockfile (stderr);
762
877 free (buf); 763 free (buf);
878 } 764 }
879#endif 765#endif
880 } 766 }
881 nextchar = (char *) ""; 767 d->__nextchar = (char *) "";
882 optind++; 768 d->optind++;
883 optopt = 0; 769 d->optopt = 0;
884 return '?'; 770 return '?';
885 } 771 }
886 } 772 }
@@ -888,12 +774,12 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
888 /* Look at and handle the next short option-character. */ 774 /* Look at and handle the next short option-character. */
889 775
890 { 776 {
891 char c = *nextchar++; 777 char c = *d->__nextchar++;
892 char *temp = my_index (optstring, c); 778 char *temp = strchr (optstring, c);
893 779
894 /* Increment `optind' when we start to process its last character. */ 780 /* Increment `optind' when we start to process its last character. */
895 if (*nextchar == '\0') 781 if (*d->__nextchar == '\0')
896 ++optind; 782 ++d->optind;
897 783
898 if (temp == NULL || c == ':') 784 if (temp == NULL || c == ':')
899 { 785 {
@@ -904,7 +790,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
904 int n; 790 int n;
905#endif 791#endif
906 792
907 if (posixly_correct) 793 if (d->__posixly_correct)
908 { 794 {
909 /* 1003.2 specifies the format of this message. */ 795 /* 1003.2 specifies the format of this message. */
910#if defined _LIBC && defined USE_IN_LIBIO 796#if defined _LIBC && defined USE_IN_LIBIO
@@ -927,16 +813,24 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
927#if defined _LIBC && defined USE_IN_LIBIO 813#if defined _LIBC && defined USE_IN_LIBIO
928 if (n >= 0) 814 if (n >= 0)
929 { 815 {
816 _IO_flockfile (stderr);
817
818 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
819 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
820
930 if (_IO_fwide (stderr, 0) > 0) 821 if (_IO_fwide (stderr, 0) > 0)
931 __fwprintf (stderr, L"%s", buf); 822 __fwprintf (stderr, L"%s", buf);
932 else 823 else
933 fputs (buf, stderr); 824 fputs (buf, stderr);
934 825
826 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
827 _IO_funlockfile (stderr);
828
935 free (buf); 829 free (buf);
936 } 830 }
937#endif 831#endif
938 } 832 }
939 optopt = c; 833 d->optopt = c;
940 return '?'; 834 return '?';
941 } 835 }
942 /* Convenience. Treat POSIX -W foo same as long option --foo */ 836 /* Convenience. Treat POSIX -W foo same as long option --foo */
@@ -951,14 +845,14 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
951 int option_index; 845 int option_index;
952 846
953 /* This is an option that requires an argument. */ 847 /* This is an option that requires an argument. */
954 if (*nextchar != '\0') 848 if (*d->__nextchar != '\0')
955 { 849 {
956 optarg = nextchar; 850 d->optarg = d->__nextchar;
957 /* If we end this ARGV-element by taking the rest as an arg, 851 /* If we end this ARGV-element by taking the rest as an arg,
958 we must advance to the next element now. */ 852 we must advance to the next element now. */
959 optind++; 853 d->optind++;
960 } 854 }
961 else if (optind == argc) 855 else if (d->optind == argc)
962 { 856 {
963 if (print_errors) 857 if (print_errors)
964 { 858 {
@@ -970,11 +864,19 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
970 _("%s: option requires an argument -- %c\n"), 864 _("%s: option requires an argument -- %c\n"),
971 argv[0], c) >= 0) 865 argv[0], c) >= 0)
972 { 866 {
867 _IO_flockfile (stderr);
868
869 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
870 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
871
973 if (_IO_fwide (stderr, 0) > 0) 872 if (_IO_fwide (stderr, 0) > 0)
974 __fwprintf (stderr, L"%s", buf); 873 __fwprintf (stderr, L"%s", buf);
975 else 874 else
976 fputs (buf, stderr); 875 fputs (buf, stderr);
977 876
877 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
878 _IO_funlockfile (stderr);
879
978 free (buf); 880 free (buf);
979 } 881 }
980#else 882#else
@@ -982,7 +884,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
982 argv[0], c); 884 argv[0], c);
983#endif 885#endif
984 } 886 }
985 optopt = c; 887 d->optopt = c;
986 if (optstring[0] == ':') 888 if (optstring[0] == ':')
987 c = ':'; 889 c = ':';
988 else 890 else
@@ -990,22 +892,23 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
990 return c; 892 return c;
991 } 893 }
992 else 894 else
993 /* We already incremented `optind' once; 895 /* We already incremented `d->optind' once;
994 increment it again when taking next ARGV-elt as argument. */ 896 increment it again when taking next ARGV-elt as argument. */
995 optarg = argv[optind++]; 897 d->optarg = argv[d->optind++];
996 898
997 /* optarg is now the argument, see if it's in the 899 /* optarg is now the argument, see if it's in the
998 table of longopts. */ 900 table of longopts. */
999 901
1000 for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) 902 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
903 nameend++)
1001 /* Do nothing. */ ; 904 /* Do nothing. */ ;
1002 905
1003 /* Test all long options for either exact match 906 /* Test all long options for either exact match
1004 or abbreviated matches. */ 907 or abbreviated matches. */
1005 for (p = longopts, option_index = 0; p->name; p++, option_index++) 908 for (p = longopts, option_index = 0; p->name; p++, option_index++)
1006 if (!strncmp (p->name, nextchar, nameend - nextchar)) 909 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
1007 { 910 {
1008 if ((unsigned int) (nameend - nextchar) == strlen (p->name)) 911 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
1009 { 912 {
1010 /* Exact match found. */ 913 /* Exact match found. */
1011 pfound = p; 914 pfound = p;
@@ -1031,22 +934,30 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1031 char *buf; 934 char *buf;
1032 935
1033 if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), 936 if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
1034 argv[0], argv[optind]) >= 0) 937 argv[0], argv[d->optind]) >= 0)
1035 { 938 {
939 _IO_flockfile (stderr);
940
941 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
942 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
943
1036 if (_IO_fwide (stderr, 0) > 0) 944 if (_IO_fwide (stderr, 0) > 0)
1037 __fwprintf (stderr, L"%s", buf); 945 __fwprintf (stderr, L"%s", buf);
1038 else 946 else
1039 fputs (buf, stderr); 947 fputs (buf, stderr);
1040 948
949 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
950 _IO_funlockfile (stderr);
951
1041 free (buf); 952 free (buf);
1042 } 953 }
1043#else 954#else
1044 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), 955 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
1045 argv[0], argv[optind]); 956 argv[0], argv[d->optind]);
1046#endif 957#endif
1047 } 958 }
1048 nextchar += strlen (nextchar); 959 d->__nextchar += strlen (d->__nextchar);
1049 optind++; 960 d->optind++;
1050 return '?'; 961 return '?';
1051 } 962 }
1052 if (pfound != NULL) 963 if (pfound != NULL)
@@ -1057,7 +968,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1057 /* Don't test has_arg with >, because some C compilers don't 968 /* Don't test has_arg with >, because some C compilers don't
1058 allow it to be used on enums. */ 969 allow it to be used on enums. */
1059 if (pfound->has_arg) 970 if (pfound->has_arg)
1060 optarg = nameend + 1; 971 d->optarg = nameend + 1;
1061 else 972 else
1062 { 973 {
1063 if (print_errors) 974 if (print_errors)
@@ -1069,11 +980,20 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1069%s: option `-W %s' doesn't allow an argument\n"), 980%s: option `-W %s' doesn't allow an argument\n"),
1070 argv[0], pfound->name) >= 0) 981 argv[0], pfound->name) >= 0)
1071 { 982 {
983 _IO_flockfile (stderr);
984
985 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
986 ((_IO_FILE *) stderr)->_flags2
987 |= _IO_FLAGS2_NOTCANCEL;
988
1072 if (_IO_fwide (stderr, 0) > 0) 989 if (_IO_fwide (stderr, 0) > 0)
1073 __fwprintf (stderr, L"%s", buf); 990 __fwprintf (stderr, L"%s", buf);
1074 else 991 else
1075 fputs (buf, stderr); 992 fputs (buf, stderr);
1076 993
994 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
995 _IO_funlockfile (stderr);
996
1077 free (buf); 997 free (buf);
1078 } 998 }
1079#else 999#else
@@ -1083,14 +1003,14 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1083#endif 1003#endif
1084 } 1004 }
1085 1005
1086 nextchar += strlen (nextchar); 1006 d->__nextchar += strlen (d->__nextchar);
1087 return '?'; 1007 return '?';
1088 } 1008 }
1089 } 1009 }
1090 else if (pfound->has_arg == 1) 1010 else if (pfound->has_arg == 1)
1091 { 1011 {
1092 if (optind < argc) 1012 if (d->optind < argc)
1093 optarg = argv[optind++]; 1013 d->optarg = argv[d->optind++];
1094 else 1014 else
1095 { 1015 {
1096 if (print_errors) 1016 if (print_errors)
@@ -1100,26 +1020,35 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1100 1020
1101 if (__asprintf (&buf, _("\ 1021 if (__asprintf (&buf, _("\
1102%s: option `%s' requires an argument\n"), 1022%s: option `%s' requires an argument\n"),
1103 argv[0], argv[optind - 1]) >= 0) 1023 argv[0], argv[d->optind - 1]) >= 0)
1104 { 1024 {
1025 _IO_flockfile (stderr);
1026
1027 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1028 ((_IO_FILE *) stderr)->_flags2
1029 |= _IO_FLAGS2_NOTCANCEL;
1030
1105 if (_IO_fwide (stderr, 0) > 0) 1031 if (_IO_fwide (stderr, 0) > 0)
1106 __fwprintf (stderr, L"%s", buf); 1032 __fwprintf (stderr, L"%s", buf);
1107 else 1033 else
1108 fputs (buf, stderr); 1034 fputs (buf, stderr);
1109 1035
1036 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1037 _IO_funlockfile (stderr);
1038
1110 free (buf); 1039 free (buf);
1111 } 1040 }
1112#else 1041#else
1113 fprintf (stderr, 1042 fprintf (stderr,
1114 _("%s: option `%s' requires an argument\n"), 1043 _("%s: option `%s' requires an argument\n"),
1115 argv[0], argv[optind - 1]); 1044 argv[0], argv[d->optind - 1]);
1116#endif 1045#endif
1117 } 1046 }
1118 nextchar += strlen (nextchar); 1047 d->__nextchar += strlen (d->__nextchar);
1119 return optstring[0] == ':' ? ':' : '?'; 1048 return optstring[0] == ':' ? ':' : '?';
1120 } 1049 }
1121 } 1050 }
1122 nextchar += strlen (nextchar); 1051 d->__nextchar += strlen (d->__nextchar);
1123 if (longind != NULL) 1052 if (longind != NULL)
1124 *longind = option_index; 1053 *longind = option_index;
1125 if (pfound->flag) 1054 if (pfound->flag)
@@ -1129,7 +1058,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1129 } 1058 }
1130 return pfound->val; 1059 return pfound->val;
1131 } 1060 }
1132 nextchar = NULL; 1061 d->__nextchar = NULL;
1133 return 'W'; /* Let the application handle it. */ 1062 return 'W'; /* Let the application handle it. */
1134 } 1063 }
1135 if (temp[1] == ':') 1064 if (temp[1] == ':')
@@ -1137,26 +1066,26 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1137 if (temp[2] == ':') 1066 if (temp[2] == ':')
1138 { 1067 {
1139 /* This is an option that accepts an argument optionally. */ 1068 /* This is an option that accepts an argument optionally. */
1140 if (*nextchar != '\0') 1069 if (*d->__nextchar != '\0')
1141 { 1070 {
1142 optarg = nextchar; 1071 d->optarg = d->__nextchar;
1143 optind++; 1072 d->optind++;
1144 } 1073 }
1145 else 1074 else
1146 optarg = NULL; 1075 d->optarg = NULL;
1147 nextchar = NULL; 1076 d->__nextchar = NULL;
1148 } 1077 }
1149 else 1078 else
1150 { 1079 {
1151 /* This is an option that requires an argument. */ 1080 /* This is an option that requires an argument. */
1152 if (*nextchar != '\0') 1081 if (*d->__nextchar != '\0')
1153 { 1082 {
1154 optarg = nextchar; 1083 d->optarg = d->__nextchar;
1155 /* If we end this ARGV-element by taking the rest as an arg, 1084 /* If we end this ARGV-element by taking the rest as an arg,
1156 we must advance to the next element now. */ 1085 we must advance to the next element now. */
1157 optind++; 1086 d->optind++;
1158 } 1087 }
1159 else if (optind == argc) 1088 else if (d->optind == argc)
1160 { 1089 {
1161 if (print_errors) 1090 if (print_errors)
1162 { 1091 {
@@ -1168,11 +1097,19 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1168%s: option requires an argument -- %c\n"), 1097%s: option requires an argument -- %c\n"),
1169 argv[0], c) >= 0) 1098 argv[0], c) >= 0)
1170 { 1099 {
1100 _IO_flockfile (stderr);
1101
1102 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1103 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1104
1171 if (_IO_fwide (stderr, 0) > 0) 1105 if (_IO_fwide (stderr, 0) > 0)
1172 __fwprintf (stderr, L"%s", buf); 1106 __fwprintf (stderr, L"%s", buf);
1173 else 1107 else
1174 fputs (buf, stderr); 1108 fputs (buf, stderr);
1175 1109
1110 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1111 _IO_funlockfile (stderr);
1112
1176 free (buf); 1113 free (buf);
1177 } 1114 }
1178#else 1115#else
@@ -1181,7 +1118,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1181 argv[0], c); 1118 argv[0], c);
1182#endif 1119#endif
1183 } 1120 }
1184 optopt = c; 1121 d->optopt = c;
1185 if (optstring[0] == ':') 1122 if (optstring[0] == ':')
1186 c = ':'; 1123 c = ':';
1187 else 1124 else
@@ -1190,8 +1127,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1190 else 1127 else
1191 /* We already incremented `optind' once; 1128 /* We already incremented `optind' once;
1192 increment it again when taking next ARGV-elt as argument. */ 1129 increment it again when taking next ARGV-elt as argument. */
1193 optarg = argv[optind++]; 1130 d->optarg = argv[d->optind++];
1194 nextchar = NULL; 1131 d->__nextchar = NULL;
1195 } 1132 }
1196 } 1133 }
1197 return c; 1134 return c;
@@ -1199,18 +1136,40 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
1199} 1136}
1200 1137
1201int 1138int
1202getopt (argc, argv, optstring) 1139_getopt_internal (int argc, char **argv, const char *optstring,
1203 int argc; 1140 const struct option *longopts, int *longind,
1204 char *const *argv; 1141 int long_only, int posixly_correct)
1205 const char *optstring; 1142{
1143 int result;
1144
1145 getopt_data.optind = optind;
1146 getopt_data.opterr = opterr;
1147
1148 result = _getopt_internal_r (argc, argv, optstring, longopts, longind,
1149 long_only, posixly_correct, &getopt_data);
1150
1151 optind = getopt_data.optind;
1152 optarg = getopt_data.optarg;
1153 optopt = getopt_data.optopt;
1154
1155 return result;
1156}
1157
1158/* glibc gets a LSB-compliant getopt.
1159 Standalone applications get a POSIX-compliant getopt. */
1160#if _LIBC
1161enum { POSIXLY_CORRECT = 0 };
1162#else
1163enum { POSIXLY_CORRECT = 1 };
1164#endif
1165
1166int
1167getopt (int argc, char *const *argv, const char *optstring)
1206{ 1168{
1207 return _getopt_internal (argc, argv, optstring, 1169 return _getopt_internal (argc, (char **) argv, optstring, NULL, NULL, 0,
1208 (const struct option *) 0, 1170 POSIXLY_CORRECT);
1209 (int *) 0,
1210 0);
1211} 1171}
1212 1172
1213#endif /* Not ELIDE_CODE. */
1214 1173
1215#ifdef TEST 1174#ifdef TEST
1216 1175
@@ -1218,9 +1177,7 @@ getopt (argc, argv, optstring)
1218 the above definition of `getopt'. */ 1177 the above definition of `getopt'. */
1219 1178
1220int 1179int
1221main (argc, argv) 1180main (int argc, char **argv)
1222 int argc;
1223 char **argv;
1224{ 1181{
1225 int c; 1182 int c;
1226 int digit_optind = 0; 1183 int digit_optind = 0;
diff --git a/lib-src/getopt1.c b/lib-src/getopt1.c
index 4ec1e50b830..8aa9b183578 100644
--- a/lib-src/getopt1.c
+++ b/lib-src/getopt1.c
@@ -1,6 +1,6 @@
1/* getopt_long and getopt_long_only entry points for GNU getopt. 1/* getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 2 Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
3 Free Software Foundation, Inc. 3 1998, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -26,36 +26,10 @@
26#else 26#else
27# include "getopt.h" 27# include "getopt.h"
28#endif 28#endif
29 29#include "getopt_int.h"
30#if !defined __STDC__ || !__STDC__
31/* This is a separate conditional since some stdc systems
32 reject `defined (const)'. */
33#ifndef const
34#define const
35#endif
36#endif
37 30
38#include <stdio.h> 31#include <stdio.h>
39 32
40/* Comment out all this code if we are using the GNU C Library, and are not
41 actually compiling the library itself. This code is part of the GNU C
42 Library, but also included in many other GNU distributions. Compiling
43 and linking in this code is a waste when using the GNU C library
44 (especially if it is a shared library). Rather than having every GNU
45 program understand `configure --with-gnu-libc' and omit the object files,
46 it is simpler to just do this in the source for each such file. */
47
48#define GETOPT_INTERFACE_VERSION 2
49#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
50#include <gnu-versions.h>
51#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
52#define ELIDE_CODE
53#endif
54#endif
55
56#ifndef ELIDE_CODE
57
58
59/* This needs to come after some library #include 33/* This needs to come after some library #include
60 to get __GNU_LIBRARY__ defined. */ 34 to get __GNU_LIBRARY__ defined. */
61#ifdef __GNU_LIBRARY__ 35#ifdef __GNU_LIBRARY__
@@ -67,14 +41,20 @@
67#endif 41#endif
68 42
69int 43int
70getopt_long (argc, argv, options, long_options, opt_index) 44getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
71 int argc; 45 const struct option *long_options, int *opt_index)
72 char *const *argv;
73 const char *options;
74 const struct option *long_options;
75 int *opt_index;
76{ 46{
77 return _getopt_internal (argc, argv, options, long_options, opt_index, 0); 47 return _getopt_internal (argc, (char **) argv, options, long_options,
48 opt_index, 0, 0);
49}
50
51int
52_getopt_long_r (int argc, char **argv, const char *options,
53 const struct option *long_options, int *opt_index,
54 struct _getopt_data *d)
55{
56 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
57 0, 0, d);
78} 58}
79 59
80/* Like getopt_long, but '-' as well as '--' can indicate a long option. 60/* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -83,31 +63,30 @@ getopt_long (argc, argv, options, long_options, opt_index)
83 instead. */ 63 instead. */
84 64
85int 65int
86getopt_long_only (argc, argv, options, long_options, opt_index) 66getopt_long_only (int argc, char *__getopt_argv_const *argv,
87 int argc; 67 const char *options,
88 char *const *argv; 68 const struct option *long_options, int *opt_index)
89 const char *options;
90 const struct option *long_options;
91 int *opt_index;
92{ 69{
93 return _getopt_internal (argc, argv, options, long_options, opt_index, 1); 70 return _getopt_internal (argc, (char **) argv, options, long_options,
71 opt_index, 1, 0);
94} 72}
95 73
96# ifdef _LIBC 74int
97libc_hidden_def (getopt_long) 75_getopt_long_only_r (int argc, char **argv, const char *options,
98libc_hidden_def (getopt_long_only) 76 const struct option *long_options, int *opt_index,
99# endif 77 struct _getopt_data *d)
78{
79 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
80 1, 0, d);
81}
100 82
101#endif /* Not ELIDE_CODE. */
102 83
103#ifdef TEST 84#ifdef TEST
104 85
105#include <stdio.h> 86#include <stdio.h>
106 87
107int 88int
108main (argc, argv) 89main (int argc, char **argv)
109 int argc;
110 char **argv;
111{ 90{
112 int c; 91 int c;
113 int digit_optind = 0; 92 int digit_optind = 0;
diff --git a/lib-src/getopt.h b/lib-src/getopt_.h
index 953a7d15252..fbd45d42aab 100644
--- a/lib-src/getopt.h
+++ b/lib-src/getopt_.h
@@ -1,5 +1,6 @@
1/* Declarations for getopt. 1/* Declarations for getopt.
2 Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
3 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 4 This file is part of the GNU C Library.
4 5
5 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
@@ -22,6 +23,64 @@
22# define _GETOPT_H 1 23# define _GETOPT_H 1
23#endif 24#endif
24 25
26/* Standalone applications should #define __GETOPT_PREFIX to an
27 identifier that prefixes the external functions and variables
28 defined in this header. When this happens, include the
29 headers that might declare getopt so that they will not cause
30 confusion if included after this file. Then systematically rename
31 identifiers so that they do not collide with the system functions
32 and variables. Renaming avoids problems with some compilers and
33 linkers. */
34#if defined __GETOPT_PREFIX && !defined __need_getopt
35# include <stdlib.h>
36# include <stdio.h>
37# if HAVE_UNISTD_H
38# include <unistd.h>
39# endif
40# undef __need_getopt
41# undef getopt
42# undef getopt_long
43# undef getopt_long_only
44# undef optarg
45# undef opterr
46# undef optind
47# undef optopt
48# define __GETOPT_CONCAT(x, y) x ## y
49# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
50# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
51# define getopt __GETOPT_ID (getopt)
52# define getopt_long __GETOPT_ID (getopt_long)
53# define getopt_long_only __GETOPT_ID (getopt_long_only)
54# define optarg __GETOPT_ID (optarg)
55# define opterr __GETOPT_ID (opterr)
56# define optind __GETOPT_ID (optind)
57# define optopt __GETOPT_ID (optopt)
58#endif
59
60/* Standalone applications get correct prototypes for getopt_long and
61 getopt_long_only; they declare "char **argv". libc uses prototypes
62 with "char *const *argv" that are incorrect because getopt_long and
63 getopt_long_only can permute argv; this is required for backward
64 compatibility (e.g., for LSB 2.0.1).
65
66 This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
67 but it caused redefinition warnings if both unistd.h and getopt.h were
68 included, since unistd.h includes getopt.h having previously defined
69 __need_getopt.
70
71 The only place where __getopt_argv_const is used is in definitions
72 of getopt_long and getopt_long_only below, but these are visible
73 only if __need_getopt is not defined, so it is quite safe to rewrite
74 the conditional as follows:
75*/
76#if !defined __need_getopt
77# if defined __GETOPT_PREFIX
78# define __getopt_argv_const /* empty */
79# else
80# define __getopt_argv_const const
81# endif
82#endif
83
25/* If __GNU_LIBRARY__ is not already defined, either we are being used 84/* If __GNU_LIBRARY__ is not already defined, either we are being used
26 standalone, or this is the first header included in the source file. 85 standalone, or this is the first header included in the source file.
27 If we are being used with glibc, we need to include <features.h>, but 86 If we are being used with glibc, we need to include <features.h>, but
@@ -33,6 +92,17 @@
33# include <ctype.h> 92# include <ctype.h>
34#endif 93#endif
35 94
95#ifndef __THROW
96# ifndef __GNUC_PREREQ
97# define __GNUC_PREREQ(maj, min) (0)
98# endif
99# if defined __cplusplus && __GNUC_PREREQ (2,8)
100# define __THROW throw ()
101# else
102# define __THROW
103# endif
104#endif
105
36#ifdef __cplusplus 106#ifdef __cplusplus
37extern "C" { 107extern "C" {
38#endif 108#endif
@@ -77,7 +147,7 @@ extern int optopt;
77 The field `has_arg' is: 147 The field `has_arg' is:
78 no_argument (or 0) if the option does not take an argument, 148 no_argument (or 0) if the option does not take an argument,
79 required_argument (or 1) if the option requires an argument, 149 required_argument (or 1) if the option requires an argument,
80 optional_argument (or 2) if the option takes an optional argument. 150 optional_argument (or 2) if the option takes an optional argument.
81 151
82 If the field `flag' is not NULL, it points to a variable that is set 152 If the field `flag' is not NULL, it points to a variable that is set
83 to the value given in the field `val' when the option is found, but 153 to the value given in the field `val' when the option is found, but
@@ -92,11 +162,7 @@ extern int optopt;
92 162
93struct option 163struct option
94{ 164{
95# if (defined __STDC__ && __STDC__) || defined __cplusplus
96 const char *name; 165 const char *name;
97# else
98 char *name;
99# endif
100 /* has_arg can't be an enum because some compilers complain about 166 /* has_arg can't be an enum because some compilers complain about
101 type mismatches in all the code that assumes it is an int. */ 167 type mismatches in all the code that assumes it is an int. */
102 int has_arg; 168 int has_arg;
@@ -136,39 +202,20 @@ struct option
136 arguments to the option '\0'. This behavior is specific to the GNU 202 arguments to the option '\0'. This behavior is specific to the GNU
137 `getopt'. */ 203 `getopt'. */
138 204
139#if (defined __STDC__ && __STDC__) || defined __cplusplus 205extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
140# ifdef __GNU_LIBRARY__ 206 __THROW;
141/* Many other libraries have conflicting prototypes for getopt, with
142 differences in the consts, in stdlib.h. To avoid compilation
143 errors, only prototype getopt for the GNU C library. */
144extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
145# else /* not __GNU_LIBRARY__ */
146extern int getopt ();
147# endif /* __GNU_LIBRARY__ */
148
149# ifndef __need_getopt
150extern int getopt_long (int ___argc, char *const *___argv,
151 const char *__shortopts,
152 const struct option *__longopts, int *__longind);
153extern int getopt_long_only (int ___argc, char *const *___argv,
154 const char *__shortopts,
155 const struct option *__longopts, int *__longind);
156 207
157/* Internal only. Users should not call this directly. */ 208#ifndef __need_getopt
158extern int _getopt_internal (int ___argc, char *const *___argv, 209extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
210 const char *__shortopts,
211 const struct option *__longopts, int *__longind)
212 __THROW;
213extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
159 const char *__shortopts, 214 const char *__shortopts,
160 const struct option *__longopts, int *__longind, 215 const struct option *__longopts, int *__longind)
161 int __long_only); 216 __THROW;
162# endif
163#else /* not __STDC__ */
164extern int getopt ();
165# ifndef __need_getopt
166extern int getopt_long ();
167extern int getopt_long_only ();
168 217
169extern int _getopt_internal (); 218#endif
170# endif
171#endif /* __STDC__ */
172 219
173#ifdef __cplusplus 220#ifdef __cplusplus
174} 221}
@@ -179,5 +226,5 @@ extern int _getopt_internal ();
179 226
180#endif /* getopt.h */ 227#endif /* getopt.h */
181 228
182/* arch-tag: 9adb7828-e6a6-40cd-8512-0cdf1f20ddd4 229/* arch-tag: e36f5607-3ac6-4cdc-9aa7-c26c6525fe9b
183 (do not change this comment) */ 230 (do not change this comment) */
diff --git a/lib-src/getopt_int.h b/lib-src/getopt_int.h
new file mode 100644
index 00000000000..f59ab32ce28
--- /dev/null
+++ b/lib-src/getopt_int.h
@@ -0,0 +1,134 @@
1/* Internal declarations for getopt.
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
3 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20#ifndef _GETOPT_INT_H
21#define _GETOPT_INT_H 1
22
23extern int _getopt_internal (int ___argc, char **___argv,
24 const char *__shortopts,
25 const struct option *__longopts, int *__longind,
26 int __long_only, int __posixly_correct);
27
28
29/* Reentrant versions which can handle parsing multiple argument
30 vectors at the same time. */
31
32/* Data type for reentrant functions. */
33struct _getopt_data
34{
35 /* These have exactly the same meaning as the corresponding global
36 variables, except that they are used for the reentrant
37 versions of getopt. */
38 int optind;
39 int opterr;
40 int optopt;
41 char *optarg;
42
43 /* Internal members. */
44
45 /* True if the internal members have been initialized. */
46 int __initialized;
47
48 /* The next char to be scanned in the option-element
49 in which the last option character we returned was found.
50 This allows us to pick up the scan where we left off.
51
52 If this is zero, or a null string, it means resume the scan
53 by advancing to the next ARGV-element. */
54 char *__nextchar;
55
56 /* Describe how to deal with options that follow non-option ARGV-elements.
57
58 If the caller did not specify anything,
59 the default is REQUIRE_ORDER if the environment variable
60 POSIXLY_CORRECT is defined, PERMUTE otherwise.
61
62 REQUIRE_ORDER means don't recognize them as options;
63 stop option processing when the first non-option is seen.
64 This is what Unix does.
65 This mode of operation is selected by either setting the environment
66 variable POSIXLY_CORRECT, or using `+' as the first character
67 of the list of option characters, or by calling getopt.
68
69 PERMUTE is the default. We permute the contents of ARGV as we
70 scan, so that eventually all the non-options are at the end.
71 This allows options to be given in any order, even with programs
72 that were not written to expect this.
73
74 RETURN_IN_ORDER is an option available to programs that were
75 written to expect options and other ARGV-elements in any order
76 and that care about the ordering of the two. We describe each
77 non-option ARGV-element as if it were the argument of an option
78 with character code 1. Using `-' as the first character of the
79 list of option characters selects this mode of operation.
80
81 The special argument `--' forces an end of option-scanning regardless
82 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
83 `--' can cause `getopt' to return -1 with `optind' != ARGC. */
84
85 enum
86 {
87 REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
88 } __ordering;
89
90 /* If the POSIXLY_CORRECT environment variable is set
91 or getopt was called. */
92 int __posixly_correct;
93
94
95 /* Handle permutation of arguments. */
96
97 /* Describe the part of ARGV that contains non-options that have
98 been skipped. `first_nonopt' is the index in ARGV of the first
99 of them; `last_nonopt' is the index after the last of them. */
100
101 int __first_nonopt;
102 int __last_nonopt;
103
104#if defined _LIBC && defined USE_NONOPTION_FLAGS
105 int __nonoption_flags_max_len;
106 int __nonoption_flags_len;
107# endif
108};
109
110/* The initializer is necessary to set OPTIND and OPTERR to their
111 default values and to clear the initialization flag. */
112#define _GETOPT_DATA_INITIALIZER { 1, 1 }
113
114extern int _getopt_internal_r (int ___argc, char **___argv,
115 const char *__shortopts,
116 const struct option *__longopts, int *__longind,
117 int __long_only, int __posixly_correct,
118 struct _getopt_data *__data);
119
120extern int _getopt_long_r (int ___argc, char **___argv,
121 const char *__shortopts,
122 const struct option *__longopts, int *__longind,
123 struct _getopt_data *__data);
124
125extern int _getopt_long_only_r (int ___argc, char **___argv,
126 const char *__shortopts,
127 const struct option *__longopts,
128 int *__longind,
129 struct _getopt_data *__data);
130
131#endif /* getopt_int.h */
132
133/* arch-tag: 8bfc548f-23d6-46aa-b5b5-2739b0edaf79
134 (do not change this comment) */
diff --git a/lib-src/gettext.h b/lib-src/gettext.h
new file mode 100644
index 00000000000..658fa17fcb8
--- /dev/null
+++ b/lib-src/gettext.h
@@ -0,0 +1,82 @@
1/* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004,
3 2005 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19#ifndef _LIBGETTEXT_H
20#define _LIBGETTEXT_H 1
21
22/* NLS can be disabled through the configure --disable-nls option. */
23#if ENABLE_NLS
24
25/* Get declarations of GNU message catalog functions. */
26# include <libintl.h>
27
28#else
29
30/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
31 chokes if dcgettext is defined as a macro. So include it now, to make
32 later inclusions of <locale.h> a NOP. We don't include <libintl.h>
33 as well because people using "gettext.h" will not include <libintl.h>,
34 and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
35 is OK. */
36#if defined(__sun)
37# include <locale.h>
38#endif
39
40/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
41 <libintl.h>, which chokes if dcgettext is defined as a macro. So include
42 it now, to make later inclusions of <libintl.h> a NOP. */
43#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
44# include <cstdlib>
45# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
46# include <libintl.h>
47# endif
48#endif
49
50/* Disabled NLS.
51 The casts to 'const char *' serve the purpose of producing warnings
52 for invalid uses of the value returned from these functions.
53 On pre-ANSI systems without 'const', the config.h file is supposed to
54 contain "#define const". */
55# define gettext(Msgid) ((const char *) (Msgid))
56# define dgettext(Domainname, Msgid) ((const char *) (Msgid))
57# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid))
58# define ngettext(Msgid1, Msgid2, N) \
59 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
60# define dngettext(Domainname, Msgid1, Msgid2, N) \
61 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
62# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
63 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
64# define textdomain(Domainname) ((const char *) (Domainname))
65# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname))
66# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset))
67
68#endif
69
70/* A pseudo function call that serves as a marker for the automated
71 extraction of messages, but does not call gettext(). The run-time
72 translation is done at a different place in the code.
73 The argument, String, should be a literal string. Concatenated strings
74 and other string expressions won't work.
75 The macro's expansion is not parenthesized, so that it is suitable as
76 initializer for static 'char[]' or 'const char[]' variables. */
77#define gettext_noop(String) String
78
79#endif /* _LIBGETTEXT_H */
80
81/* arch-tag: 3d01bb8e-82e3-4674-9812-de4c4224f7d1
82 (do not change this comment) */
diff --git a/lib-src/grep-changelog b/lib-src/grep-changelog
index 04468535e02..45bf841ae59 100755
--- a/lib-src/grep-changelog
+++ b/lib-src/grep-changelog
@@ -1,6 +1,7 @@
1#! /usr/bin/perl 1#! /usr/bin/perl
2 2
3# Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc. 3# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4# 2005 Free Software Foundation, Inc.
4# 5#
5# This file is part of GNU Emacs. 6# This file is part of GNU Emacs.
6# 7#
diff --git a/lib-src/hexl.c b/lib-src/hexl.c
index 05e0658e566..0dfdddf468f 100644
--- a/lib-src/hexl.c
+++ b/lib-src/hexl.c
@@ -1,5 +1,5 @@
1/* Convert files for Emacs Hexl mode. 1/* Convert files for Emacs Hexl mode.
2 Copyright (C) 1989 Free Software Foundation, Inc 2 Copyright (C) 1989, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 3
4This file is not considered part of GNU Emacs. 4This file is not considered part of GNU Emacs.
5 5
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index 6c0816ed98a..537eafec7f5 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -1,6 +1,6 @@
1/* Generate doc-string file for GNU Emacs from source files. 1/* Generate doc-string file for GNU Emacs from source files.
2 Copyright (C) 1985, 86, 92, 93, 94, 97, 1999, 2000, 01, 2004 2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1997, 1999, 2000, 2001,
3 Free Software Foundation, Inc. 3 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
diff --git a/lib-src/makefile.w32-in b/lib-src/makefile.w32-in
index d8e8c205b3b..bfda0f25d5f 100644
--- a/lib-src/makefile.w32-in
+++ b/lib-src/makefile.w32-in
@@ -1,5 +1,6 @@
1# -*- Makefile -*- for GNU Emacs on the Microsoft W32 API. 1# -*- Makefile -*- for GNU Emacs on the Microsoft W32 API.
2# Copyright (c) 2000-2001, 2004 Free Software Foundation, Inc. 2# Copyright (C) 2000, 2001, 2002, 2003, 2004,
3# 2005 Free Software Foundation, Inc.
3# 4#
4# This file is part of GNU Emacs. 5# This file is part of GNU Emacs.
5# 6#
@@ -286,6 +287,7 @@ install: $(INSTALL_FILES)
286clean: 287clean:
287 - $(DEL) *~ DOC* $(COMPILER_TEMP_FILES) 288 - $(DEL) *~ DOC* $(COMPILER_TEMP_FILES)
288 - $(DEL) ctags.c 289 - $(DEL) ctags.c
290 - $(DEL) getopt.h
289 - $(DEL_TREE) $(OBJDIR) 291 - $(DEL_TREE) $(OBJDIR)
290 292
291cleanall: clean 293cleanall: clean
@@ -301,6 +303,8 @@ cleanall: clean
301 $(CP) $(ALL_DEPS) $@ 303 $(CP) $(ALL_DEPS) $@
302../src/paths.h: ../nt/paths.h 304../src/paths.h: ../nt/paths.h
303 $(CP) $(ALL_DEPS) $@ 305 $(CP) $(ALL_DEPS) $@
306getopt.h: getopt_.h
307 $(CP) $(ALL_DEPS) $@
304 308
305### DEPENDENCIES ### 309### DEPENDENCIES ###
306 310
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index f82bebd4f2b..e8f1122e943 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -1,6 +1,7 @@
1/* movemail foo bar -- move file foo to file bar, 1/* movemail foo bar -- move file foo to file bar,
2 locking file foo the way /bin/mail respects. 2 locking file foo the way /bin/mail respects.
3 Copyright (C) 1986, 92, 93, 94, 96, 1999 Free Software Foundation, Inc. 3 Copyright (C) 1986, 1992, 1993, 1994, 1996, 1999, 2002, 2003, 2004,
4 2005 Free Software Foundation, Inc.
4 5
5This file is part of GNU Emacs. 6This file is part of GNU Emacs.
6 7
diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c
index c346ccd908b..caaf521206b 100644
--- a/lib-src/ntlib.c
+++ b/lib-src/ntlib.c
@@ -1,5 +1,5 @@
1/* Utility and Unix shadow routines for GNU Emacs support programs on NT. 1/* Utility and Unix shadow routines for GNU Emacs support programs on NT.
2 Copyright (C) 1994 Free Software Foundation, Inc. 2 Copyright (C) 1994, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h
index b1cb97dabda..07e730567f7 100644
--- a/lib-src/ntlib.h
+++ b/lib-src/ntlib.h
@@ -1,5 +1,5 @@
1/* Utility and Unix shadow routines for GNU Emacs support programs on NT. 1/* Utility and Unix shadow routines for GNU Emacs support programs on NT.
2 Copyright (C) 1994 Free Software Foundation, Inc. 2 Copyright (C) 1994, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 3
4 This file is part of GNU Emacs. 4 This file is part of GNU Emacs.
5 5
diff --git a/lib-src/pop.c b/lib-src/pop.c
index 9a85ba3746c..9bc73e90a54 100644
--- a/lib-src/pop.c
+++ b/lib-src/pop.c
@@ -1,5 +1,6 @@
1/* pop.c: client routines for talking to a POP3-protocol post-office server 1/* pop.c: client routines for talking to a POP3-protocol post-office server
2 Copyright (c) 1991, 1993, 1996, 1997, 1999 Free Software Foundation, Inc. 2 Copyright (C) 1991, 1993, 1996, 1997, 1999, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 Written by Jonathan Kamens, jik@security.ov.com. 4 Written by Jonathan Kamens, jik@security.ov.com.
4 5
5This file is part of GNU Emacs. 6This file is part of GNU Emacs.
@@ -76,17 +77,6 @@ extern struct servent *hes_getservbyname (/* char *, char * */);
76# ifdef HAVE_KRB5_H 77# ifdef HAVE_KRB5_H
77# include <krb5.h> 78# include <krb5.h>
78# endif 79# endif
79# ifdef HAVE_DES_H
80# include <des.h>
81# else
82# ifdef HAVE_KERBEROSIV_DES_H
83# include <kerberosIV/des.h>
84# else
85# ifdef HAVE_KERBEROS_DES_H
86# include <kerberos/des.h>
87# endif
88# endif
89# endif
90# ifdef HAVE_KRB_H 80# ifdef HAVE_KRB_H
91# include <krb.h> 81# include <krb.h>
92# else 82# else
@@ -1403,12 +1393,24 @@ sendline (server, line)
1403{ 1393{
1404#define SENDLINE_ERROR "Error writing to POP server: " 1394#define SENDLINE_ERROR "Error writing to POP server: "
1405 int ret; 1395 int ret;
1406 1396 char *buf;
1407 ret = fullwrite (server->file, line, strlen (line)); 1397
1408 if (ret >= 0) 1398 /* Combine the string and the CR-LF into one buffer. Otherwise, two
1409 { /* 0 indicates that a blank line was written */ 1399 reasonable network stack optimizations, Nagle's algorithm and
1410 ret = fullwrite (server->file, "\r\n", 2); 1400 delayed acks, combine to delay us a fraction of a second on every
1411 } 1401 message we send. (Movemail writes line without \r\n, client
1402 kernel sends packet, server kernel delays the ack to see if it
1403 can combine it with data, movemail writes \r\n, client kernel
1404 waits because it has unacked data already in its outgoing queue,
1405 client kernel eventually times out and sends.)
1406
1407 This can be something like 0.2s per command, which can add up
1408 over a few dozen messages, and is a big chunk of the time we
1409 spend fetching mail from a server close by. */
1410 buf = alloca (strlen (line) + 3);
1411 strcpy (buf, line);
1412 strcat (buf, "\r\n");
1413 ret = fullwrite (server->file, buf, strlen (buf));
1412 1414
1413 if (ret < 0) 1415 if (ret < 0)
1414 { 1416 {
diff --git a/lib-src/pop.h b/lib-src/pop.h
index 5267ec97eb4..eed24a89934 100644
--- a/lib-src/pop.h
+++ b/lib-src/pop.h
@@ -1,5 +1,6 @@
1/* pop.h: Header file for the "pop.c" client POP3 protocol. 1/* pop.h: Header file for the "pop.c" client POP3 protocol.
2 Copyright (c) 1991,1993 Free Software Foundation, Inc. 2 Copyright (C) 1991, 1993, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 Written by Jonathan Kamens, jik@security.ov.com. 4 Written by Jonathan Kamens, jik@security.ov.com.
4 5
5This file is part of GNU Emacs. 6This file is part of GNU Emacs.
diff --git a/lib-src/profile.c b/lib-src/profile.c
index 7bc7186c259..615a43d912c 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -1,5 +1,6 @@
1/* profile.c --- generate periodic events for profiling of Emacs Lisp code. 1/* profile.c --- generate periodic events for profiling of Emacs Lisp code.
2 Copyright (C) 1992, 1994, 1999 Free Software Foundation, Inc. 2 Copyright (C) 1992, 1994, 1999, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
3 4
4 Author: Boaz Ben-Zvi <boaz@lcs.mit.edu> 5 Author: Boaz Ben-Zvi <boaz@lcs.mit.edu>
5 6
diff --git a/lib-src/rcs-checkin b/lib-src/rcs-checkin
index 2a7de0f2f11..beee6ce29f7 100755
--- a/lib-src/rcs-checkin
+++ b/lib-src/rcs-checkin
@@ -2,7 +2,8 @@
2 2
3# This script accepts any number of file arguments and checks them into RCS. 3# This script accepts any number of file arguments and checks them into RCS.
4 4
5# Copyright (C) 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc. 5# Copyright (C) 1993, 1994, 1995, 2001, 2002, 2003, 2004,
6# 2005 Free Software Foundation, Inc.
6# 7#
7# This file is part of GNU Emacs. 8# This file is part of GNU Emacs.
8# 9#
diff --git a/lib-src/rcs2log b/lib-src/rcs2log
index 05864c2ad26..4e7c6c1bb1b 100755
--- a/lib-src/rcs2log
+++ b/lib-src/rcs2log
@@ -55,7 +55,7 @@ Report bugs to <bug-gnu-emacs@gnu.org>.'
55Id='$Id$' 55Id='$Id$'
56 56
57# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003, 57# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2001, 2002, 2003,
58# 2004 Free Software Foundation, Inc. 58# 2004, 2005 Free Software Foundation, Inc.
59 59
60# This program is free software; you can redistribute it and/or modify 60# This program is free software; you can redistribute it and/or modify
61# it under the terms of the GNU General Public License as published by 61# it under the terms of the GNU General Public License as published by
@@ -72,7 +72,7 @@ Id='$Id$'
72# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 72# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
73# Boston, MA 02110-1301, USA. 73# Boston, MA 02110-1301, USA.
74 74
75Copyright='Copyright (C) 2004 Free Software Foundation, Inc. 75Copyright='Copyright (C) 2005 Free Software Foundation, Inc.
76This program comes with NO WARRANTY, to the extent permitted by law. 76This program comes with NO WARRANTY, to the extent permitted by law.
77You may redistribute copies of this program 77You may redistribute copies of this program
78under the terms of the GNU General Public License. 78under the terms of the GNU General Public License.
diff --git a/lib-src/sorted-doc.c b/lib-src/sorted-doc.c
index 120a510f006..cb04be26842 100644
--- a/lib-src/sorted-doc.c
+++ b/lib-src/sorted-doc.c
@@ -1,8 +1,8 @@
1/* Give this program DOC-mm.nn.oo as standard input and it outputs to 1/* Give this program DOC-mm.nn.oo as standard input and it outputs to
2 standard output a file of texinfo input containing the doc strings. 2 standard output a file of texinfo input containing the doc strings.
3 3
4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001 4 Copyright (C) 1989, 1992, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
5 Free Software Foundation Inc. 5 2004, 2005 Free Software Foundation, Inc.
6 6
7 This file is part of GNU Emacs. 7 This file is part of GNU Emacs.
8 8
diff --git a/lib-src/test-distrib.c b/lib-src/test-distrib.c
index 0bbc6806d71..0d3587af8da 100644
--- a/lib-src/test-distrib.c
+++ b/lib-src/test-distrib.c
@@ -1,7 +1,7 @@
1/* test-distrib.c --- testing distribution of nonprinting chars 1/* test-distrib.c --- testing distribution of nonprinting chars
2 2
3 Copyright (C) 1987, 1993, 1994, 1995, 1999, 2001 3 Copyright (C) 1987, 1993, 1994, 1995, 1999, 2001, 2002, 2003,
4 Free Software Foundation Inc. 4 2004, 2005 Free Software Foundation, Inc.
5 5
6 This file is part of GNU Emacs. 6 This file is part of GNU Emacs.
7 7
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index d9d20b8525d..46d0d8b0600 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -1,5 +1,5 @@
1/* update-game-score.c --- Update a score file 1/* update-game-score.c --- Update a score file
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc. 2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
diff --git a/lib-src/vcdiff b/lib-src/vcdiff
index 8e1722d43ba..a57811a7f6d 100755
--- a/lib-src/vcdiff
+++ b/lib-src/vcdiff
@@ -3,8 +3,8 @@
3# Enhanced sccs diff utility for use with vc mode. 3# Enhanced sccs diff utility for use with vc mode.
4# This version is more compatible with rcsdiff(1). 4# This version is more compatible with rcsdiff(1).
5# 5#
6# Copyright (C) 1992, 1993, 1995, 1997, 2001, 2004 6# Copyright (C) 1992, 1993, 1995, 1997, 2001, 2002, 2003, 2004,
7# Free Software Foundation, Inc. 7# 2005 Free Software Foundation, Inc.
8# 8#
9# This file is part of GNU Emacs. 9# This file is part of GNU Emacs.
10# 10#