LAL 7.7.0.1-678514e
LALgetopt.c
Go to the documentation of this file.
1/* Getopt for GNU.
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
4 before changing it!
5 Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001
6 Free Software Foundation, Inc.
7 This file is part of the GNU C Library.
8
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with the GNU C Library; if not, write to the Free
21 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301 USA. */
23
24/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
25 Ditto for AIX 3.2 and <stdlib.h>. */
26
27/* NOTE: Hacked to get rid of warning messages.
28 * Look for unions "bad" and "wtf" for these hacks.
29 */
30
31#include <config.h>
32
33#include <stdio.h>
34#include <stdlib.h>
35#ifdef HAVE_UNISTD_H
36#include <unistd.h>
37#endif
38
39#define _(msgid) ("\n" msgid)
40
41/* This version of `getopt' appears to the caller like standard Unix `getopt'
42 but it behaves differently for the user, since it allows the user
43 to intersperse the options with the other arguments.
44
45 As `getopt' works, it permutes the elements of ARGV so that,
46 when it is done, all the options precede everything else. Thus
47 all application programs are extended to handle flexible argument order.
48
49 RP 09/01/2014: the POSIXLY_CORRECT feature is undesired in lalsuite and was deactivated:
50 >> Setting the environment variable POSIXLY_CORRECT disables permutation.
51 >> Then the behavior is completely standard.
52
53 GNU application programs can use a third alternative mode in which
54 they can distinguish the relative order of options and other arguments. */
55
56#include <lal/LALgetopt.h>
57
58/* For communication from `getopt' to the caller.
59 When `getopt' finds an option that takes an argument,
60 the argument value is returned here.
61 Also, when `ordering' is RETURN_IN_ORDER,
62 each non-option ARGV-element is returned here. */
63
65
66/* Index in ARGV of the next element to be scanned.
67 This is used for communication to and from the caller
68 and for communication between successive calls to `getopt'.
69
70 On entry to `getopt', zero means this is the first call; initialize.
71
72 When `getopt' returns -1, this is the index of the first of the
73 non-option elements that the caller should itself scan.
74
75 Otherwise, `LALoptind' communicates from one call to the next
76 how much of ARGV has been scanned so far. */
77
78/* 1003.2 says this must be 1 before any call. */
79int LALoptind = 1;
80
81/* Formerly, initialization of getopt depended on LALoptind==0, which
82 causes problems with re-calling getopt as programs generally don't
83 know that. */
84
86
87/* The next char to be scanned in the option-element
88 in which the last option character we returned was found.
89 This allows us to pick up the scan where we left off.
90
91 If this is zero, or a null string, it means resume the scan
92 by advancing to the next ARGV-element. */
93
94static char *nextchar;
95
96/* Callers store zero here to inhibit the error message
97 for unrecognized options. */
98
99int LALopterr = 1;
100
101/* Set to an option character which was unrecognized.
102 This must be initialized on some systems to avoid linking in the
103 system's own getopt implementation. */
104
105int LALoptopt = '?';
106
107/* Describe how to deal with options that follow non-option ARGV-elements.
108
109 RP 09/01/2014: the POSIXLY_CORRECT feature is undesired in lalsuite and was deactivated:
110 >> If the caller did not specify anything,
111 >> the default is REQUIRE_ORDER if the environment variable
112 >> POSIXLY_CORRECT is defined, PERMUTE otherwise.
113
114 REQUIRE_ORDER means don't recognize them as options;
115 stop option processing when the first non-option is seen.
116 This is what Unix does.
117 This mode of operation is selected by either setting the environment
118 variable POSIXLY_CORRECT, or using `+' as the first character
119 of the list of option characters.
120
121 PERMUTE is the default. We permute the contents of ARGV as we scan,
122 so that eventually all the non-options are at the end. This allows options
123 to be given in any order, even with programs that were not written to
124 expect this.
125
126 RETURN_IN_ORDER is an option available to programs that were written
127 to expect options and other ARGV-elements in any order and that care about
128 the ordering of the two. We describe each non-option ARGV-element
129 as if it were the argument of an option with character code 1.
130 Using `-' as the first character of the list of option characters
131 selects this mode of operation.
132
133 The special argument `--' forces an end of option-scanning regardless
134 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
135 `--' can cause `getopt' to return -1 with `LALoptind' != ARGC.
136*/
137
138static enum
139{
142
143/* Value of POSIXLY_CORRECT environment variable. */
144static char *posixly_correct;
145
146# include <string.h>
147# define my_index strchr
148
149/* Handle permutation of arguments. */
150
151/* Describe the part of ARGV that contains non-options that have
152 been skipped. `first_nonopt' is the index in ARGV of the first of them;
153 `last_nonopt' is the index after the last of them. */
154
155static int first_nonopt;
156static int last_nonopt;
157
158/* Stored original parameters.
159 XXX This is no good solution. We should rather copy the args so
160 that we can compare them later. But we must not use malloc(3). */
161extern int __libc_argc;
162extern char **__libc_argv;
163#define SWAP_FLAGS(ch1, ch2)
164
165/* Internal only. Users should not call this directly. */
166static int _getopt_internal (int argc, char *const *argv,
167 const char *shortopts,
168 const struct LALoption *longopts, int *longind,
169 int long_only);
170
171int
172LALgetopt (int argc, char *const *argv, const char *optstring)
173{
174 return _getopt_internal (argc, argv, optstring, (const struct LALoption *) 0, (int *) 0, 0);
175}
176
177int
178LALgetopt_long (int argc, char *const *argv, const char *options,
179 const struct LALoption *long_options, int *opt_index)
180{
181 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
182}
183
184/* Like getopt_long, but '-' as well as '--' can indicate a long option.
185 If an option that starts with '-' (not '--') doesn't match a long option,
186 but does match a short option, it is parsed as a short option
187 instead. */
188
189int
190LALgetopt_long_only (int argc, char *const *argv, const char *options,
191 const struct LALoption *long_options, int *opt_index)
192{
193 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
194}
195
196/* Exchange two adjacent subsequences of ARGV.
197 One subsequence is elements [first_nonopt,last_nonopt)
198 which contains all the non-options that have been skipped so far.
199 The other is elements [last_nonopt,LALoptind), which contains all
200 the options processed since those non-options were skipped.
201
202 `first_nonopt' and `last_nonopt' are relocated so that they describe
203 the new indices of the non-options in ARGV after they are moved. */
204
205static void exchange (char **);
206
207static void
208exchange (char **argv)
209{
210 int bottom = first_nonopt;
211 int middle = last_nonopt;
212 int top = LALoptind;
213 char *tem;
214
215 /* Exchange the shorter segment with the far end of the longer segment.
216 That puts the shorter segment into the right place.
217 It leaves the longer segment in the right place overall,
218 but it consists of two parts that need to be swapped next. */
219
220 while (top > middle && middle > bottom)
221 {
222 if (top - middle > middle - bottom)
223 {
224 /* Bottom segment is the short one. */
225 int len = middle - bottom;
226 register int i;
227
228 /* Swap it with the top part of the top segment. */
229 for (i = 0; i < len; i++)
230 {
231 tem = argv[bottom + i];
232 argv[bottom + i] = argv[top - (middle - bottom) + i];
233 argv[top - (middle - bottom) + i] = tem;
234 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
235 }
236 /* Exclude the moved bottom segment from further swapping. */
237 top -= len;
238 }
239 else
240 {
241 /* Top segment is the short one. */
242 int len = top - middle;
243 register int i;
244
245 /* Swap it with the bottom part of the bottom segment. */
246 for (i = 0; i < len; i++)
247 {
248 tem = argv[bottom + i];
249 argv[bottom + i] = argv[middle + i];
250 argv[middle + i] = tem;
251 SWAP_FLAGS (bottom + i, middle + i);
252 }
253 /* Exclude the moved top segment from further swapping. */
254 bottom += len;
255 }
256 }
257
258 /* Update records for the slots the non-options now occupy. */
259
262}
263
264/* Initialize the internal data when the first call is made. */
265
266static const char *_getopt_initialize (int, char *const *, const char *);
267
268static const char *
269_getopt_initialize (int argc, char *const *argv, const char *optstring)
270{
271 /* Start processing options with ARGV-element 1 (since ARGV-element 0
272 is the program name); the sequence of previously skipped
273 non-option ARGV-elements is empty. */
274 argc = 0;
275 argv = NULL;
276
278
279 nextchar = NULL;
280
281 // RP 09/01/2014: the POSIXLY_CORRECT feature is undesired in lalsuite and was deactivated:
282 // posixly_correct = getenv ("POSIXLY_CORRECT");
283
284 /* Determine how to handle the ordering of options and nonoptions. */
285
286 if (optstring[0] == '-')
287 {
289 ++optstring;
290 }
291 else if (optstring[0] == '+')
292 {
294 ++optstring;
295 }
296 else if (posixly_correct != NULL)
298 else
300
301 return optstring;
302 (void)argc;
303 (void)argv;
304}
305
306/* Scan elements of ARGV (whose length is ARGC) for option characters
307 given in OPTSTRING.
308
309 If an element of ARGV starts with '-', and is not exactly "-" or "--",
310 then it is an option element. The characters of this element
311 (aside from the initial '-') are option characters. If `getopt'
312 is called repeatedly, it returns successively each of the option characters
313 from each of the option elements.
314
315 If `getopt' finds another option character, it returns that character,
316 updating `LALoptind' and `nextchar' so that the next call to `getopt' can
317 resume the scan with the following option character or ARGV-element.
318
319 If there are no more option characters, `getopt' returns -1.
320 Then `LALoptind' is the index in ARGV of the first ARGV-element
321 that is not an option. (The ARGV-elements have been permuted
322 so that those that are not options now come last.)
323
324 OPTSTRING is a string containing the legitimate option characters.
325 If an option character is seen that is not listed in OPTSTRING,
326 return '?' after printing an error message. If you set `LALopterr' to
327 zero, the error message is suppressed but we still return '?'.
328
329 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
330 so the following text in the same ARGV-element, or the text of the following
331 ARGV-element, is returned in `LALoptarg'. Two colons mean an option that
332 wants an optional arg; if there is text in the current ARGV-element,
333 it is returned in `LALoptarg', otherwise `LALoptarg' is set to zero.
334
335 If OPTSTRING starts with `-' or `+', it requests different methods of
336 handling the non-option ARGV-elements.
337 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
338
339 Long-named options begin with `--' instead of `-'.
340 Their names may be abbreviated as long as the abbreviation is unique
341 or is an exact match for some defined option. If they have an
342 argument, it follows the option name in the same ARGV-element, separated
343 from the option name by a `=', or else the in next ARGV-element.
344 When `getopt' finds a long-named option, it returns 0 if that option's
345 `flag' field is nonzero, the value of the option's `val' field
346 if the `flag' field is zero.
347
348 The elements of ARGV aren't really const, because we permute them.
349 But we pretend they're const in the prototype to be compatible
350 with other systems.
351
352 LONGOPTS is a vector of `struct LALoption' terminated by an
353 element containing a name which is zero.
354
355 LONGIND returns the index in LONGOPT of the long-named option found.
356 It is only valid when a long-named option has been found by the most
357 recent call.
358
359 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
360 long-named options. */
361
362static int
363_getopt_internal (int argc, char *const *argv, const char *optstring,
364 const struct LALoption *longopts, int *longind, int long_only)
365{
366 int print_errors = LALopterr;
367 if (optstring[0] == ':')
368 print_errors = 0;
369
370 if (argc < 1)
371 return -1;
372
373 LALoptarg = NULL;
374
375 if (LALoptind == 0 || !__getopt_initialized)
376 {
377 if (LALoptind == 0)
378 LALoptind = 1; /* Don't scan ARGV[0], the program name. */
379 optstring = _getopt_initialize (argc, argv, optstring);
381 }
382
383 /* Test whether ARGV[LALoptind] points to a non-option argument.
384 Either it does not have option syntax, or there is an environment flag
385 from the shell indicating it is not an option. The later information
386 is only used when the used in the GNU libc. */
387# define NONOPTION_P (argv[LALoptind][0] != '-' || argv[LALoptind][1] == '\0')
388
389 if (nextchar == NULL || *nextchar == '\0')
390 {
391 /* Advance to the next ARGV-element. */
392
393 /* Give FIRST_NONOPT & LAST_NONOPT rational values if LALOPTIND has been
394 moved back by the user (who may also have changed the arguments). */
399
400 if (ordering == PERMUTE)
401 {
402 /* If we have just processed some options following some non-options,
403 exchange them so that the options come first. */
404 union {char * const *pcs; char **ps;} bad = { argv };
405
407 exchange ((char **) bad.ps);
408 else if (last_nonopt != LALoptind)
410
411 /* Skip any additional non-options
412 and extend the range of non-options previously skipped. */
413
414 while (LALoptind < argc && NONOPTION_P)
415 LALoptind++;
417 }
418
419 /* The special ARGV-element `--' means premature end of options.
420 Skip it like a null option,
421 then exchange with previous non-options as if it were an option,
422 then skip everything else like a non-option. */
423
424 if (LALoptind != argc && !strcmp (argv[LALoptind], "--"))
425 {
426 union {char * const *pcs; char **ps;} bad = { argv };
427 LALoptind++;
428
430 exchange ((char **) bad.ps);
431 else if (first_nonopt == last_nonopt)
433 last_nonopt = argc;
434
435 LALoptind = argc;
436 }
437
438 /* If we have done all the ARGV-elements, stop the scan
439 and back over any non-options that we skipped and permuted. */
440
441 if (LALoptind == argc)
442 {
443 /* Set the next-arg-index to point at the non-options
444 that we previously skipped, so the caller will digest them. */
447 return -1;
448 }
449
450 /* If we have come to a non-option and did not permute it,
451 either stop the scan or describe it to the caller and pass it by. */
452
453 if (NONOPTION_P)
454 {
455 if (ordering == REQUIRE_ORDER)
456 return -1;
457 LALoptarg = argv[LALoptind++];
458 return 1;
459 }
460
461 /* We have found another option-ARGV-element.
462 Skip the initial punctuation. */
463
464 nextchar = (argv[LALoptind] + 1
465 + (longopts != NULL && argv[LALoptind][1] == '-'));
466 }
467
468 /* Decode the current option-ARGV-element. */
469
470 /* Check whether the ARGV-element is a long option.
471
472 If long_only and the ARGV-element has the form "-f", where f is
473 a valid short option, don't consider it an abbreviated form of
474 a long option that starts with f. Otherwise there would be no
475 way to give the -f short option.
476
477 On the other hand, if there's a long option "fubar" and
478 the ARGV-element is "-fu", do consider that an abbreviation of
479 the long option, just like "--fu", and not "-f" with arg "u".
480
481 This distinction seems to be the most useful approach. */
482
483 if (longopts != NULL
484 && (argv[LALoptind][1] == '-'
485 || (long_only && (argv[LALoptind][2] || !my_index (optstring, argv[LALoptind][1])))))
486 {
487 char *nameend;
488 const struct LALoption *p;
489 const struct LALoption *pfound = NULL;
490 int exact = 0;
491 int ambig = 0;
492 int indfound = -1;
493 int option_index;
494
495 for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
496 /* Do nothing. */ ;
497
498 /* Test all long options for either exact match
499 or abbreviated matches. */
500 for (p = longopts, option_index = 0; p->name; p++, option_index++)
501 if (!strncmp (p->name, nextchar, nameend - nextchar))
502 {
503 if ((unsigned int) (nameend - nextchar)
504 == (unsigned int) strlen (p->name))
505 {
506 /* Exact match found. */
507 pfound = p;
508 indfound = option_index;
509 exact = 1;
510 break;
511 }
512 else if (pfound == NULL)
513 {
514 /* First nonexact match found. */
515 pfound = p;
516 indfound = option_index;
517 }
518 else if (long_only
519 || pfound->has_arg != p->has_arg
520 || pfound->flag != p->flag
521 || pfound->val != p->val)
522 /* Second or later nonexact match found. */
523 ambig = 1;
524 }
525
526 if (ambig && !exact)
527 {
528 if (print_errors)
529 fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
530 argv[0], argv[LALoptind]);
531 nextchar += strlen (nextchar);
532 LALoptind++;
533 LALoptopt = 0;
534 return '?';
535 }
536
537 if (pfound != NULL)
538 {
539 option_index = indfound;
540 LALoptind++;
541 if (*nameend)
542 {
543 /* Don't test has_arg with >, because some C compilers don't
544 allow it to be used on enums. */
545 if (pfound->has_arg)
546 LALoptarg = nameend + 1;
547 else
548 {
549 if (print_errors)
550 {
551 if (argv[LALoptind - 1][1] == '-')
552 /* --option */
553 fprintf (stderr,
554 _("%s: option `--%s' doesn't allow an argument\n"),
555 argv[0], pfound->name);
556 else
557 /* +option or -option */
558 fprintf (stderr,
559 _("%s: option `%c%s' doesn't allow an argument\n"),
560 argv[0], argv[LALoptind - 1][0], pfound->name);
561 }
562
563 nextchar += strlen (nextchar);
564
565 LALoptopt = pfound->val;
566 return '?';
567 }
568 }
569 else if (pfound->has_arg == 1)
570 {
571 if (LALoptind < argc)
572 LALoptarg = argv[LALoptind++];
573 else
574 {
575 if (print_errors)
576 fprintf (stderr,
577 _("%s: option `%s' requires an argument\n"),
578 argv[0], argv[LALoptind - 1]);
579 nextchar += strlen (nextchar);
580 LALoptopt = pfound->val;
581 return optstring[0] == ':' ? ':' : '?';
582 }
583 }
584 nextchar += strlen (nextchar);
585 if (longind != NULL)
586 *longind = option_index;
587 if (pfound->flag)
588 {
589 *(pfound->flag) = pfound->val;
590 return 0;
591 }
592 return pfound->val;
593 }
594
595 /* Can't find it as a long option. If this is not getopt_long_only,
596 or the option starts with '--' or is not a valid short
597 option, then it's an error.
598 Otherwise interpret it as a short option. */
599 if (!long_only || argv[LALoptind][1] == '-'
600 || my_index (optstring, *nextchar) == NULL)
601 {
602 union { const char *cs; char *c; } wtf = { "" };
603 if (print_errors)
604 {
605 if (argv[LALoptind][1] == '-')
606 /* --option */
607 fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
608 argv[0], nextchar);
609 else
610 /* +option or -option */
611 fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
612 argv[0], argv[LALoptind][0], nextchar);
613 }
614 nextchar = wtf.c;
615 LALoptind++;
616 LALoptopt = 0;
617 return '?';
618 }
619 }
620
621 /* Look at and handle the next short option-character. */
622
623 {
624 char c = *nextchar++;
625 const char *temp = my_index (optstring, c);
626
627 /* Increment `LALoptind' when we start to process its last character. */
628 if (*nextchar == '\0')
629 ++LALoptind;
630
631 if (temp == NULL || c == ':')
632 {
633 if (print_errors)
634 {
635 if (posixly_correct)
636 /* 1003.2 specifies the format of this message. */
637 fprintf (stderr, _("%s: illegal option -- %c\n"),
638 argv[0], c);
639 else
640 fprintf (stderr, _("%s: invalid option -- %c\n"),
641 argv[0], c);
642 }
643 LALoptopt = c;
644 return '?';
645 }
646 /* Convenience. Treat POSIX -W foo same as long option --foo */
647 if (temp[0] == 'W' && temp[1] == ';')
648 {
649 char *nameend;
650 const struct LALoption *p;
651 const struct LALoption *pfound = NULL;
652 int exact = 0;
653 int ambig = 0;
654 int indfound = 0;
655 int option_index;
656
657 /* This is an option that requires an argument. */
658 if (*nextchar != '\0')
659 {
661 /* If we end this ARGV-element by taking the rest as an arg,
662 we must advance to the next element now. */
663 LALoptind++;
664 }
665 else if (LALoptind == argc)
666 {
667 if (print_errors)
668 {
669 /* 1003.2 specifies the format of this message. */
670 fprintf (stderr, _("%s: option requires an argument -- %c\n"),
671 argv[0], c);
672 }
673 LALoptopt = c;
674 if (optstring[0] == ':')
675 c = ':';
676 else
677 c = '?';
678 return c;
679 }
680 else
681 /* We already incremented `LALoptind' once;
682 increment it again when taking next ARGV-elt as argument. */
683 LALoptarg = argv[LALoptind++];
684
685 /* LALoptarg is now the argument, see if it's in the
686 table of longopts. */
687
688 for (nextchar = nameend = LALoptarg; *nameend && *nameend != '='; nameend++)
689 /* Do nothing. */ ;
690
691 /* Test all long options for either exact match
692 or abbreviated matches. */
693 for (p = longopts, option_index = 0; p->name; p++, option_index++)
694 if (!strncmp (p->name, nextchar, nameend - nextchar))
695 {
696 if ((unsigned int) (nameend - nextchar) == strlen (p->name))
697 {
698 /* Exact match found. */
699 pfound = p;
700 indfound = option_index;
701 exact = 1;
702 break;
703 }
704 else if (pfound == NULL)
705 {
706 /* First nonexact match found. */
707 pfound = p;
708 indfound = option_index;
709 }
710 else
711 /* Second or later nonexact match found. */
712 ambig = 1;
713 }
714 if (ambig && !exact)
715 {
716 if (print_errors)
717 fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
718 argv[0], argv[LALoptind]);
719 nextchar += strlen (nextchar);
720 LALoptind++;
721 return '?';
722 }
723 if (pfound != NULL)
724 {
725 option_index = indfound;
726 if (*nameend)
727 {
728 /* Don't test has_arg with >, because some C compilers don't
729 allow it to be used on enums. */
730 if (pfound->has_arg)
731 LALoptarg = nameend + 1;
732 else
733 {
734 if (print_errors)
735 fprintf (stderr, _("\
736%s: option `-W %s' doesn't allow an argument\n"),
737 argv[0], pfound->name);
738
739 nextchar += strlen (nextchar);
740 return '?';
741 }
742 }
743 else if (pfound->has_arg == 1)
744 {
745 if (LALoptind < argc)
746 LALoptarg = argv[LALoptind++];
747 else
748 {
749 if (print_errors)
750 fprintf (stderr,
751 _("%s: option `%s' requires an argument\n"),
752 argv[0], argv[LALoptind - 1]);
753 nextchar += strlen (nextchar);
754 return optstring[0] == ':' ? ':' : '?';
755 }
756 }
757 nextchar += strlen (nextchar);
758 if (longind != NULL)
759 *longind = option_index;
760 if (pfound->flag)
761 {
762 *(pfound->flag) = pfound->val;
763 return 0;
764 }
765 return pfound->val;
766 }
767 nextchar = NULL;
768 return 'W'; /* Let the application handle it. */
769 }
770 if (temp[1] == ':')
771 {
772 if (temp[2] == ':')
773 {
774 /* This is an option that accepts an argument optionally. */
775 if (*nextchar != '\0')
776 {
778 LALoptind++;
779 }
780 else
781 LALoptarg = NULL;
782 nextchar = NULL;
783 }
784 else
785 {
786 /* This is an option that requires an argument. */
787 if (*nextchar != '\0')
788 {
790 /* If we end this ARGV-element by taking the rest as an arg,
791 we must advance to the next element now. */
792 LALoptind++;
793 }
794 else if (LALoptind == argc)
795 {
796 if (print_errors)
797 {
798 /* 1003.2 specifies the format of this message. */
799 fprintf (stderr,
800 _("%s: option requires an argument -- %c\n"),
801 argv[0], c);
802 }
803 LALoptopt = c;
804 if (optstring[0] == ':')
805 c = ':';
806 else
807 c = '?';
808 }
809 else
810 /* We already incremented `LALoptind' once;
811 increment it again when taking next ARGV-elt as argument. */
812 LALoptarg = argv[LALoptind++];
813 nextchar = NULL;
814 }
815 }
816 return c;
817 }
818}
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
Definition: LALgetopt.c:190
int LALgetopt_long(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
Definition: LALgetopt.c:178
int __libc_argc
static enum @11 ordering
static int __getopt_initialized
Definition: LALgetopt.c:85
static char * nextchar
Definition: LALgetopt.c:94
static int last_nonopt
Definition: LALgetopt.c:156
int LALgetopt(int argc, char *const *argv, const char *optstring)
Definition: LALgetopt.c:172
int LALoptopt
Definition: LALgetopt.c:105
#define SWAP_FLAGS(ch1, ch2)
Definition: LALgetopt.c:163
int LALopterr
Definition: LALgetopt.c:99
#define NONOPTION_P
static int first_nonopt
Definition: LALgetopt.c:155
#define my_index
Definition: LALgetopt.c:147
int LALoptind
Definition: LALgetopt.c:79
#define _(msgid)
Definition: LALgetopt.c:39
@ REQUIRE_ORDER
Definition: LALgetopt.c:140
@ RETURN_IN_ORDER
Definition: LALgetopt.c:140
@ PERMUTE
Definition: LALgetopt.c:140
char ** __libc_argv
static char * posixly_correct
Definition: LALgetopt.c:144
static void exchange(char **)
Definition: LALgetopt.c:208
char * LALoptarg
Definition: LALgetopt.c:64
static const char * _getopt_initialize(int, char *const *, const char *)
Definition: LALgetopt.c:269
static int _getopt_internal(int argc, char *const *argv, const char *shortopts, const struct LALoption *longopts, int *longind, int long_only)
Definition: LALgetopt.c:363
#define fprintf
int has_arg
Definition: LALgetopt.h:89
int val
Definition: LALgetopt.h:91
const char * name
Definition: LALgetopt.h:86
int * flag
Definition: LALgetopt.h:90