aboutsummaryrefslogtreecommitdiffstats
path: root/lib/getopt.c
diff options
context:
space:
mode:
authorPaul Eggert2012-05-26 16:14:36 -0700
committerPaul Eggert2012-05-26 16:14:36 -0700
commitcaf8a9b2b301aba06735d403317b75b41df59bfe (patch)
treebfafb3cc0cf8a2f2394b4ed721e7c3d4891b78ab /lib/getopt.c
parentfe453991eafc32a890297a2003ac532b9f579f92 (diff)
downloademacs-caf8a9b2b301aba06735d403317b75b41df59bfe.tar.gz
emacs-caf8a9b2b301aba06735d403317b75b41df59bfe.zip
Merge from gnulib.
Fixes: debbugs:11527
Diffstat (limited to 'lib/getopt.c')
-rw-r--r--lib/getopt.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/getopt.c b/lib/getopt.c
index 7c9f7040612..4342a34104c 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -2,7 +2,7 @@
2 NOTE: getopt is part of the C library, so if you don't know what 2 NOTE: getopt is 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-1996, 1998-2004, 2006, 2008-2011 Free Software 5 Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2012 Free Software
6 Foundation, Inc. 6 Foundation, Inc.
7 This file is part of the GNU C Library. 7 This file is part of the GNU C Library.
8 8
@@ -41,15 +41,15 @@
41# include <wchar.h> 41# include <wchar.h>
42#endif 42#endif
43 43
44/* This version of `getopt' appears to the caller like standard Unix `getopt' 44/* This version of 'getopt' appears to the caller like standard Unix 'getopt'
45 but it behaves differently for the user, since it allows the user 45 but it behaves differently for the user, since it allows the user
46 to intersperse the options with the other arguments. 46 to intersperse the options with the other arguments.
47 47
48 As `getopt_long' works, it permutes the elements of ARGV so that, 48 As 'getopt_long' works, it permutes the elements of ARGV so that,
49 when it is done, all the options precede everything else. Thus 49 when it is done, all the options precede everything else. Thus
50 all application programs are extended to handle flexible argument order. 50 all application programs are extended to handle flexible argument order.
51 51
52 Using `getopt' or setting the environment variable POSIXLY_CORRECT 52 Using 'getopt' or setting the environment variable POSIXLY_CORRECT
53 disables permutation. 53 disables permutation.
54 Then the behavior is completely standard. 54 Then the behavior is completely standard.
55 55
@@ -58,24 +58,24 @@
58 58
59#include "getopt_int.h" 59#include "getopt_int.h"
60 60
61/* For communication from `getopt' to the caller. 61/* For communication from 'getopt' to the caller.
62 When `getopt' finds an option that takes an argument, 62 When 'getopt' finds an option that takes an argument,
63 the argument value is returned here. 63 the argument value is returned here.
64 Also, when `ordering' is RETURN_IN_ORDER, 64 Also, when 'ordering' is RETURN_IN_ORDER,
65 each non-option ARGV-element is returned here. */ 65 each non-option ARGV-element is returned here. */
66 66
67char *optarg; 67char *optarg;
68 68
69/* Index in ARGV of the next element to be scanned. 69/* Index in ARGV of the next element to be scanned.
70 This is used for communication to and from the caller 70 This is used for communication to and from the caller
71 and for communication between successive calls to `getopt'. 71 and for communication between successive calls to 'getopt'.
72 72
73 On entry to `getopt', zero means this is the first call; initialize. 73 On entry to 'getopt', zero means this is the first call; initialize.
74 74
75 When `getopt' returns -1, this is the index of the first of the 75 When 'getopt' returns -1, this is the index of the first of the
76 non-option elements that the caller should itself scan. 76 non-option elements that the caller should itself scan.
77 77
78 Otherwise, `optind' communicates from one call to the next 78 Otherwise, 'optind' communicates from one call to the next
79 how much of ARGV has been scanned so far. */ 79 how much of ARGV has been scanned so far. */
80 80
81/* 1003.2 says this must be 1 before any call. */ 81/* 1003.2 says this must be 1 before any call. */
@@ -137,7 +137,7 @@ extern char *__getopt_nonoption_flags;
137 The other is elements [last_nonopt,optind), which contains all 137 The other is elements [last_nonopt,optind), which contains all
138 the options processed since those non-options were skipped. 138 the options processed since those non-options were skipped.
139 139
140 `first_nonopt' and `last_nonopt' are relocated so that they describe 140 'first_nonopt' and 'last_nonopt' are relocated so that they describe
141 the new indices of the non-options in ARGV after they are moved. */ 141 the new indices of the non-options in ARGV after they are moved. */
142 142
143static void 143static void
@@ -154,7 +154,7 @@ exchange (char **argv, struct _getopt_data *d)
154 but it consists of two parts that need to be swapped next. */ 154 but it consists of two parts that need to be swapped next. */
155 155
156#if defined _LIBC && defined USE_NONOPTION_FLAGS 156#if defined _LIBC && defined USE_NONOPTION_FLAGS
157 /* First make sure the handling of the `__getopt_nonoption_flags' 157 /* First make sure the handling of the '__getopt_nonoption_flags'
158 string can work normally. Our top argument must be in the range 158 string can work normally. Our top argument must be in the range
159 of the string. */ 159 of the string. */
160 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len) 160 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
@@ -291,48 +291,48 @@ _getopt_initialize (int argc _GL_UNUSED,
291 291
292 If an element of ARGV starts with '-', and is not exactly "-" or "--", 292 If an element of ARGV starts with '-', and is not exactly "-" or "--",
293 then it is an option element. The characters of this element 293 then it is an option element. The characters of this element
294 (aside from the initial '-') are option characters. If `getopt' 294 (aside from the initial '-') are option characters. If 'getopt'
295 is called repeatedly, it returns successively each of the option characters 295 is called repeatedly, it returns successively each of the option characters
296 from each of the option elements. 296 from each of the option elements.
297 297
298 If `getopt' finds another option character, it returns that character, 298 If 'getopt' finds another option character, it returns that character,
299 updating `optind' and `nextchar' so that the next call to `getopt' can 299 updating 'optind' and 'nextchar' so that the next call to 'getopt' can
300 resume the scan with the following option character or ARGV-element. 300 resume the scan with the following option character or ARGV-element.
301 301
302 If there are no more option characters, `getopt' returns -1. 302 If there are no more option characters, 'getopt' returns -1.
303 Then `optind' is the index in ARGV of the first ARGV-element 303 Then 'optind' is the index in ARGV of the first ARGV-element
304 that is not an option. (The ARGV-elements have been permuted 304 that is not an option. (The ARGV-elements have been permuted
305 so that those that are not options now come last.) 305 so that those that are not options now come last.)
306 306
307 OPTSTRING is a string containing the legitimate option characters. 307 OPTSTRING is a string containing the legitimate option characters.
308 If an option character is seen that is not listed in OPTSTRING, 308 If an option character is seen that is not listed in OPTSTRING,
309 return '?' after printing an error message. If you set `opterr' to 309 return '?' after printing an error message. If you set 'opterr' to
310 zero, the error message is suppressed but we still return '?'. 310 zero, the error message is suppressed but we still return '?'.
311 311
312 If a char in OPTSTRING is followed by a colon, that means it wants an arg, 312 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
313 so the following text in the same ARGV-element, or the text of the following 313 so the following text in the same ARGV-element, or the text of the following
314 ARGV-element, is returned in `optarg'. Two colons mean an option that 314 ARGV-element, is returned in 'optarg'. Two colons mean an option that
315 wants an optional arg; if there is text in the current ARGV-element, 315 wants an optional arg; if there is text in the current ARGV-element,
316 it is returned in `optarg', otherwise `optarg' is set to zero. 316 it is returned in 'optarg', otherwise 'optarg' is set to zero.
317 317
318 If OPTSTRING starts with `-' or `+', it requests different methods of 318 If OPTSTRING starts with '-' or '+', it requests different methods of
319 handling the non-option ARGV-elements. 319 handling the non-option ARGV-elements.
320 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. 320 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
321 321
322 Long-named options begin with `--' instead of `-'. 322 Long-named options begin with '--' instead of '-'.
323 Their names may be abbreviated as long as the abbreviation is unique 323 Their names may be abbreviated as long as the abbreviation is unique
324 or is an exact match for some defined option. If they have an 324 or is an exact match for some defined option. If they have an
325 argument, it follows the option name in the same ARGV-element, separated 325 argument, it follows the option name in the same ARGV-element, separated
326 from the option name by a `=', or else the in next ARGV-element. 326 from the option name by a '=', or else the in next ARGV-element.
327 When `getopt' finds a long-named option, it returns 0 if that option's 327 When 'getopt' finds a long-named option, it returns 0 if that option's
328 `flag' field is nonzero, the value of the option's `val' field 328 'flag' field is nonzero, the value of the option's 'val' field
329 if the `flag' field is zero. 329 if the 'flag' field is zero.
330 330
331 The elements of ARGV aren't really const, because we permute them. 331 The elements of ARGV aren't really const, because we permute them.
332 But we pretend they're const in the prototype to be compatible 332 But we pretend they're const in the prototype to be compatible
333 with other systems. 333 with other systems.
334 334
335 LONGOPTS is a vector of `struct option' terminated by an 335 LONGOPTS is a vector of 'struct option' terminated by an
336 element containing a name which is zero. 336 element containing a name which is zero.
337 337
338 LONGIND returns the index in LONGOPT of the long-named option found. 338 LONGIND returns the index in LONGOPT of the long-named option found.
@@ -409,7 +409,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
409 d->__last_nonopt = d->optind; 409 d->__last_nonopt = d->optind;
410 } 410 }
411 411
412 /* The special ARGV-element `--' means premature end of options. 412 /* The special ARGV-element '--' means premature end of options.
413 Skip it like a null option, 413 Skip it like a null option,
414 then exchange with previous non-options as if it were an option, 414 then exchange with previous non-options as if it were an option,
415 then skip everything else like a non-option. */ 415 then skip everything else like a non-option. */
@@ -788,7 +788,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
788 char c = *d->__nextchar++; 788 char c = *d->__nextchar++;
789 const char *temp = strchr (optstring, c); 789 const char *temp = strchr (optstring, c);
790 790
791 /* Increment `optind' when we start to process its last character. */ 791 /* Increment 'optind' when we start to process its last character. */
792 if (*d->__nextchar == '\0') 792 if (*d->__nextchar == '\0')
793 ++d->optind; 793 ++d->optind;
794 794
@@ -887,7 +887,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
887 return c; 887 return c;
888 } 888 }
889 else 889 else
890 /* We already incremented `d->optind' once; 890 /* We already incremented 'd->optind' once;
891 increment it again when taking next ARGV-elt as argument. */ 891 increment it again when taking next ARGV-elt as argument. */
892 d->optarg = argv[d->optind++]; 892 d->optarg = argv[d->optind++];
893 893
@@ -1114,7 +1114,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
1114 c = '?'; 1114 c = '?';
1115 } 1115 }
1116 else 1116 else
1117 /* We already incremented `optind' once; 1117 /* We already incremented 'optind' once;
1118 increment it again when taking next ARGV-elt as argument. */ 1118 increment it again when taking next ARGV-elt as argument. */
1119 d->optarg = argv[d->optind++]; 1119 d->optarg = argv[d->optind++];
1120 d->__nextchar = NULL; 1120 d->__nextchar = NULL;
@@ -1177,7 +1177,7 @@ __posix_getopt (int argc, char *const *argv, const char *optstring)
1177#ifdef TEST 1177#ifdef TEST
1178 1178
1179/* Compile with -DTEST to make an executable for use in testing 1179/* Compile with -DTEST to make an executable for use in testing
1180 the above definition of `getopt'. */ 1180 the above definition of 'getopt'. */
1181 1181
1182int 1182int
1183main (int argc, char **argv) 1183main (int argc, char **argv)