]>
git.proxmox.com Git - mirror_frr.git/blob - lib/getopt.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * NOTE: getopt is now part of the C library, so if you don't know what
4 * "Keep this file name-space clean" means, talk to drepper@gnu.org
7 * Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
8 * Free Software Foundation, Inc.
10 * NOTE: The canonical source of this file is maintained with the GNU C Library.
11 * Bugs can be reported to bug-glibc@gnu.org.
14 /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
15 Ditto for AIX 3.2 and <stdlib.h>. */
22 #if !defined __STDC__ || !__STDC__
23 /* This is a separate conditional since some stdc systems
24 reject `defined (const)'. */
32 /* Comment out all this code if we are using the GNU C Library, and are not
33 actually compiling the library itself. This code is part of the GNU C
34 Library, but also included in many other GNU distributions. Compiling
35 and linking in this code is a waste when using the GNU C library
36 (especially if it is a shared library). Rather than having every GNU
37 program understand `configure --with-gnu-libc' and omit the object files,
38 it is simpler to just do this in the source for each such file. */
40 #define GETOPT_INTERFACE_VERSION 2
41 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
42 #include <gnu-versions.h>
43 #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
51 /* This needs to come after some library #include
52 to get __GNU_LIBRARY__ defined. */
53 #ifdef __GNU_LIBRARY__
54 /* Don't include stdlib.h for non-GNU C libraries because some of them
55 contain conflicting prototypes for getopt. */
58 #endif /* GNU C library. */
68 /* This is for other GNU distributions with internationalized messages.
69 When compiling libc, the _ macro is predefined. */
72 # define _(msgid) gettext (msgid)
74 # define _(msgid) (msgid)
78 /* This version of `getopt' appears to the caller like standard Unix `getopt'
79 but it behaves differently for the user, since it allows the user
80 to intersperse the options with the other arguments.
82 As `getopt' works, it permutes the elements of ARGV so that,
83 when it is done, all the options precede everything else. Thus
84 all application programs are extended to handle flexible argument order.
86 Setting the environment variable POSIXLY_CORRECT disables permutation.
87 Then the behavior is completely standard.
89 GNU application programs can use a third alternative mode in which
90 they can distinguish the relative order of options and other arguments. */
94 /* For communication from `getopt' to the caller.
95 When `getopt' finds an option that takes an argument,
96 the argument value is returned here.
97 Also, when `ordering' is RETURN_IN_ORDER,
98 each non-option ARGV-element is returned here. */
102 /* Index in ARGV of the next element to be scanned.
103 This is used for communication to and from the caller
104 and for communication between successive calls to `getopt'.
106 On entry to `getopt', zero means this is the first call; initialize.
108 When `getopt' returns -1, this is the index of the first of the
109 non-option elements that the caller should itself scan.
111 Otherwise, `optind' communicates from one call to the next
112 how much of ARGV has been scanned so far. */
114 /* 1003.2 says this must be 1 before any call. */
117 /* Formerly, initialization of getopt depended on optind==0, which
118 causes problems with re-calling getopt as programs generally don't
121 int __getopt_initialized
= 0;
123 /* The next char to be scanned in the option-element
124 in which the last option character we returned was found.
125 This allows us to pick up the scan where we left off.
127 If this is zero, or a null string, it means resume the scan
128 by advancing to the next ARGV-element. */
130 static char *nextchar
;
132 /* Callers store zero here to inhibit the error message
133 for unrecognized options. */
137 /* Set to an option character which was unrecognized.
138 This must be initialized on some systems to avoid linking in the
139 system's own getopt implementation. */
143 /* Describe how to deal with options that follow non-option ARGV-elements.
145 If the caller did not specify anything,
146 the default is REQUIRE_ORDER if the environment variable
147 POSIXLY_CORRECT is defined, PERMUTE otherwise.
149 REQUIRE_ORDER means don't recognize them as options;
150 stop option processing when the first non-option is seen.
151 This is what Unix does.
152 This mode of operation is selected by either setting the environment
153 variable POSIXLY_CORRECT, or using `+' as the first character
154 of the list of option characters.
156 PERMUTE is the default. We permute the contents of ARGV as we scan,
157 so that eventually all the non-options are at the end. This allows options
158 to be given in any order, even with programs that were not written to
161 RETURN_IN_ORDER is an option available to programs that were written
162 to expect options and other ARGV-elements in any order and that care about
163 the ordering of the two. We describe each non-option ARGV-element
164 as if it were the argument of an option with character code 1.
165 Using `-' as the first character of the list of option characters
166 selects this mode of operation.
168 The special argument `--' forces an end of option-scanning regardless
169 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
170 `--' can cause `getopt' to return -1 with `optind' != ARGC. */
172 static enum { REQUIRE_ORDER
, PERMUTE
, RETURN_IN_ORDER
} ordering
;
174 /* Value of POSIXLY_CORRECT environment variable. */
175 static char *posixly_correct
;
177 #ifdef __GNU_LIBRARY__
178 /* We want to avoid inclusion of string.h with non-GNU libraries
179 because there are many ways it can cause trouble.
180 On some systems, it contains special magic macros that don't work
183 # define my_index strchr
192 /* Avoid depending on library functions or files
193 whose names are inconsistent. */
196 extern char *getenv(const char *);
199 static char *my_index(const char *str
, int chr
)
209 /* If using GCC, we can safely declare strlen this way.
210 If not using GCC, it is ok not to declare it. */
212 /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
213 That was relevant to code that was here before. */
214 #if (!defined __STDC__ || !__STDC__) && !defined strlen
215 /* gcc with -traditional declares the built-in strlen to return int,
216 and has done so at least since version 2.4.5. -- rms. */
217 extern int strlen(const char *);
218 #endif /* not __STDC__ */
219 #endif /* __GNUC__ */
221 #endif /* not __GNU_LIBRARY__ */
223 /* Handle permutation of arguments. */
225 /* Describe the part of ARGV that contains non-options that have
226 been skipped. `first_nonopt' is the index in ARGV of the first of them;
227 `last_nonopt' is the index after the last of them. */
229 static int first_nonopt
;
230 static int last_nonopt
;
233 /* Bash 2.0 gives us an environment variable containing flags
234 indicating ARGV elements that should not be considered arguments. */
236 /* Defined in getopt_init.c */
237 extern char *__getopt_nonoption_flags
;
239 static int nonoption_flags_max_len
;
240 static int nonoption_flags_len
;
242 static int original_argc
;
243 static char *const *original_argv
;
245 /* Make sure the environment variable bash 2.0 puts in the environment
246 is valid for the getopt call we must make sure that the ARGV passed
247 to getopt is that one passed to the process. */
248 static void __attribute__((unused
))
249 store_args_and_env(int argc
, char *const *argv
)
251 /* XXX This is no good solution. We should rather copy the args so
252 that we can compare them later. But we must not use malloc(3). */
253 original_argc
= argc
;
254 original_argv
= argv
;
256 #ifdef text_set_element
257 text_set_element(__libc_subinit
, store_args_and_env
);
258 #endif /* text_set_element */
260 #define SWAP_FLAGS(ch1, ch2) \
261 if (nonoption_flags_len > 0) { \
262 char __tmp = __getopt_nonoption_flags[ch1]; \
263 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
264 __getopt_nonoption_flags[ch2] = __tmp; \
267 # define SWAP_FLAGS(ch1, ch2)
270 /* Exchange two adjacent subsequences of ARGV.
271 One subsequence is elements [first_nonopt,last_nonopt)
272 which contains all the non-options that have been skipped so far.
273 The other is elements [last_nonopt,optind), which contains all
274 the options processed since those non-options were skipped.
276 `first_nonopt' and `last_nonopt' are relocated so that they describe
277 the new indices of the non-options in ARGV after they are moved. */
279 #if defined __STDC__ && __STDC__
280 static void exchange(char **);
283 static void exchange(argv
) char **argv
;
285 int bottom
= first_nonopt
;
286 int middle
= last_nonopt
;
290 /* Exchange the shorter segment with the far end of the longer segment.
291 That puts the shorter segment into the right place.
292 It leaves the longer segment in the right place overall,
293 but it consists of two parts that need to be swapped next. */
296 /* First make sure the handling of the `__getopt_nonoption_flags'
297 string can work normally. Our top argument must be in the range
299 if (nonoption_flags_len
> 0 && top
>= nonoption_flags_max_len
) {
300 /* We must extend the array. The user plays games with us and
301 presents new arguments. */
302 char *new_str
= malloc(top
+ 1);
304 nonoption_flags_len
= nonoption_flags_max_len
= 0;
306 memset(__mempcpy(new_str
, __getopt_nonoption_flags
,
307 nonoption_flags_max_len
),
308 '\0', top
+ 1 - nonoption_flags_max_len
);
309 nonoption_flags_max_len
= top
+ 1;
310 __getopt_nonoption_flags
= new_str
;
315 while (top
> middle
&& middle
> bottom
) {
316 if (top
- middle
> middle
- bottom
) {
317 /* Bottom segment is the short one. */
318 int len
= middle
- bottom
;
321 /* Swap it with the top part of the top segment. */
322 for (i
= 0; i
< len
; i
++) {
323 tem
= argv
[bottom
+ i
];
325 argv
[top
- (middle
- bottom
) + i
];
326 argv
[top
- (middle
- bottom
) + i
] = tem
;
327 SWAP_FLAGS(bottom
+ i
,
328 top
- (middle
- bottom
) + i
);
330 /* Exclude the moved bottom segment from further
334 /* Top segment is the short one. */
335 int len
= top
- middle
;
338 /* Swap it with the bottom part of the bottom segment.
340 for (i
= 0; i
< len
; i
++) {
341 tem
= argv
[bottom
+ i
];
342 argv
[bottom
+ i
] = argv
[middle
+ i
];
343 argv
[middle
+ i
] = tem
;
344 SWAP_FLAGS(bottom
+ i
, middle
+ i
);
346 /* Exclude the moved top segment from further swapping.
352 /* Update records for the slots the non-options now occupy. */
354 first_nonopt
+= (optind
- last_nonopt
);
355 last_nonopt
= optind
;
358 /* Initialize the internal data when the first call is made. */
360 #if defined __STDC__ && __STDC__
361 static const char *_getopt_initialize(int, char *const *, const char *);
363 static const char *_getopt_initialize(argc
, argv
, optstring
) int argc
;
365 const char *optstring
;
367 /* Start processing options with ARGV-element 1 (since ARGV-element 0
368 is the program name); the sequence of previously skipped
369 non-option ARGV-elements is empty. */
371 first_nonopt
= last_nonopt
= optind
;
375 posixly_correct
= getenv("POSIXLY_CORRECT");
377 /* Determine how to handle the ordering of options and nonoptions. */
379 if (optstring
[0] == '-') {
380 ordering
= RETURN_IN_ORDER
;
382 } else if (optstring
[0] == '+') {
383 ordering
= REQUIRE_ORDER
;
385 } else if (posixly_correct
!= NULL
)
386 ordering
= REQUIRE_ORDER
;
391 if (posixly_correct
== NULL
&& argc
== original_argc
392 && argv
== original_argv
) {
393 if (nonoption_flags_max_len
== 0) {
394 if (__getopt_nonoption_flags
== NULL
395 || __getopt_nonoption_flags
[0] == '\0')
396 nonoption_flags_max_len
= -1;
398 const char *orig_str
= __getopt_nonoption_flags
;
399 int len
= nonoption_flags_max_len
=
401 if (nonoption_flags_max_len
< argc
)
402 nonoption_flags_max_len
= argc
;
403 __getopt_nonoption_flags
=
404 (char *)malloc(nonoption_flags_max_len
);
405 if (__getopt_nonoption_flags
== NULL
)
406 nonoption_flags_max_len
= -1;
409 __getopt_nonoption_flags
,
412 nonoption_flags_max_len
- len
);
415 nonoption_flags_len
= nonoption_flags_max_len
;
417 nonoption_flags_len
= 0;
423 /* Scan elements of ARGV (whose length is ARGC) for option characters
426 If an element of ARGV starts with '-', and is not exactly "-" or "--",
427 then it is an option element. The characters of this element
428 (aside from the initial '-') are option characters. If `getopt'
429 is called repeatedly, it returns successively each of the option characters
430 from each of the option elements.
432 If `getopt' finds another option character, it returns that character,
433 updating `optind' and `nextchar' so that the next call to `getopt' can
434 resume the scan with the following option character or ARGV-element.
436 If there are no more option characters, `getopt' returns -1.
437 Then `optind' is the index in ARGV of the first ARGV-element
438 that is not an option. (The ARGV-elements have been permuted
439 so that those that are not options now come last.)
441 OPTSTRING is a string containing the legitimate option characters.
442 If an option character is seen that is not listed in OPTSTRING,
443 return '?' after printing an error message. If you set `opterr' to
444 zero, the error message is suppressed but we still return '?'.
446 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
447 so the following text in the same ARGV-element, or the text of the following
448 ARGV-element, is returned in `optarg'. Two colons mean an option that
449 wants an optional arg; if there is text in the current ARGV-element,
450 it is returned in `optarg', otherwise `optarg' is set to zero.
452 If OPTSTRING starts with `-' or `+', it requests different methods of
453 handling the non-option ARGV-elements.
454 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
456 Long-named options begin with `--' instead of `-'.
457 Their names may be abbreviated as long as the abbreviation is unique
458 or is an exact match for some defined option. If they have an
459 argument, it follows the option name in the same ARGV-element, separated
460 from the option name by a `=', or else the in next ARGV-element.
461 When `getopt' finds a long-named option, it returns 0 if that option's
462 `flag' field is nonzero, the value of the option's `val' field
463 if the `flag' field is zero.
465 The elements of ARGV aren't really const, because we permute them.
466 But we pretend they're const in the prototype to be compatible
469 LONGOPTS is a vector of `struct option' terminated by an
470 element containing a name which is zero.
472 LONGIND returns the index in LONGOPT of the long-named option found.
473 It is only valid when a long-named option has been found by the most
476 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
477 long-named options. */
479 int _getopt_internal(argc
, argv
, optstring
, longopts
, longind
,
482 const char *optstring
;
483 const struct option
*longopts
;
489 if (optind
== 0 || !__getopt_initialized
) {
491 optind
= 1; /* Don't scan ARGV[0], the program name. */
492 optstring
= _getopt_initialize(argc
, argv
, optstring
);
493 __getopt_initialized
= 1;
496 /* Test whether ARGV[optind] points to a non-option argument.
497 Either it does not have option syntax, or there is an environment flag
498 from the shell indicating it is not an option. The later information
499 is only used when the used in the GNU libc. */
501 #define NONOPTION_P \
502 (argv[optind][0] != '-' || argv[optind][1] == '\0' \
503 || (optind < nonoption_flags_len \
504 && __getopt_nonoption_flags[optind] == '1'))
506 # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
509 if (nextchar
== NULL
|| *nextchar
== '\0') {
510 /* Advance to the next ARGV-element. */
512 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has
514 moved back by the user (who may also have changed the
516 if (last_nonopt
> optind
)
517 last_nonopt
= optind
;
518 if (first_nonopt
> optind
)
519 first_nonopt
= optind
;
521 if (ordering
== PERMUTE
) {
522 /* If we have just processed some options following some
524 exchange them so that the options come first. */
526 if (first_nonopt
!= last_nonopt
527 && last_nonopt
!= optind
)
528 exchange((char **)argv
);
529 else if (last_nonopt
!= optind
)
530 first_nonopt
= optind
;
532 /* Skip any additional non-options
533 and extend the range of non-options previously
536 while (optind
< argc
&& NONOPTION_P
)
538 last_nonopt
= optind
;
541 /* The special ARGV-element `--' means premature end of options.
542 Skip it like a null option,
543 then exchange with previous non-options as if it were an
545 then skip everything else like a non-option. */
547 if (optind
!= argc
&& !strcmp(argv
[optind
], "--")) {
550 if (first_nonopt
!= last_nonopt
551 && last_nonopt
!= optind
)
552 exchange((char **)argv
);
553 else if (first_nonopt
== last_nonopt
)
554 first_nonopt
= optind
;
560 /* If we have done all the ARGV-elements, stop the scan
561 and back over any non-options that we skipped and permuted.
564 if (optind
== argc
) {
565 /* Set the next-arg-index to point at the non-options
566 that we previously skipped, so the caller will digest
568 if (first_nonopt
!= last_nonopt
)
569 optind
= first_nonopt
;
573 /* If we have come to a non-option and did not permute it,
574 either stop the scan or describe it to the caller and pass it
578 if (ordering
== REQUIRE_ORDER
)
580 optarg
= argv
[optind
++];
584 /* We have found another option-ARGV-element.
585 Skip the initial punctuation. */
587 nextchar
= (argv
[optind
] + 1
588 + (longopts
!= NULL
&& argv
[optind
][1] == '-'));
591 /* Decode the current option-ARGV-element. */
593 /* Check whether the ARGV-element is a long option.
595 If long_only and the ARGV-element has the form "-f", where f is
596 a valid short option, don't consider it an abbreviated form of
597 a long option that starts with f. Otherwise there would be no
598 way to give the -f short option.
600 On the other hand, if there's a long option "fubar" and
601 the ARGV-element is "-fu", do consider that an abbreviation of
602 the long option, just like "--fu", and not "-f" with arg "u".
604 This distinction seems to be the most useful approach. */
607 && (argv
[optind
][1] == '-'
608 || (long_only
&& (argv
[optind
][2]
609 || !my_index(optstring
, argv
[optind
][1]))))) {
611 const struct option
*p
;
612 const struct option
*pfound
= NULL
;
618 for (nameend
= nextchar
; *nameend
&& *nameend
!= '='; nameend
++)
621 /* Test all long options for either exact match
622 or abbreviated matches. */
623 for (p
= longopts
, option_index
= 0; p
->name
;
625 if (!strncmp(p
->name
, nextchar
, nameend
- nextchar
)) {
626 if ((unsigned int)(nameend
- nextchar
)
627 == (unsigned int)strlen(p
->name
)) {
628 /* Exact match found. */
630 indfound
= option_index
;
633 } else if (pfound
== NULL
) {
634 /* First nonexact match found. */
636 indfound
= option_index
;
638 /* Second or later nonexact match found.
643 if (ambig
&& !exact
) {
646 _("%s: option `%s' is ambiguous\n"),
647 argv
[0], argv
[optind
]);
648 nextchar
+= strlen(nextchar
);
654 if (pfound
!= NULL
) {
655 option_index
= indfound
;
658 /* Don't test has_arg with >, because some C
660 allow it to be used on enums. */
662 optarg
= nameend
+ 1;
665 if (argv
[optind
- 1][1] == '-')
668 _("%s: option `--%s' doesn't allow an argument\n"),
672 /* +option or -option */
674 _("%s: option `%c%s' doesn't allow an argument\n"),
681 nextchar
+= strlen(nextchar
);
683 optopt
= pfound
->val
;
686 } else if (pfound
->has_arg
== 1) {
688 optarg
= argv
[optind
++];
692 _("%s: option `%s' requires an argument\n"),
695 nextchar
+= strlen(nextchar
);
696 optopt
= pfound
->val
;
697 return optstring
[0] == ':' ? ':' : '?';
700 nextchar
+= strlen(nextchar
);
702 *longind
= option_index
;
704 *(pfound
->flag
) = pfound
->val
;
710 /* Can't find it as a long option. If this is not
712 or the option starts with '--' or is not a valid short
713 option, then it's an error.
714 Otherwise interpret it as a short option. */
715 if (!long_only
|| argv
[optind
][1] == '-'
716 || my_index(optstring
, *nextchar
) == NULL
) {
718 if (argv
[optind
][1] == '-')
721 _("%s: unrecognized option `--%s'\n"),
724 /* +option or -option */
726 _("%s: unrecognized option `%c%s'\n"),
727 argv
[0], argv
[optind
][0],
730 nextchar
= (char *)"";
737 /* Look at and handle the next short option-character. */
740 char c
= *nextchar
++;
741 char *temp
= my_index(optstring
, c
);
743 /* Increment `optind' when we start to process its last
745 if (*nextchar
== '\0')
748 if (temp
== NULL
|| c
== ':') {
751 /* 1003.2 specifies the format of this
754 _("%s: illegal option -- %c\n"),
758 _("%s: invalid option -- %c\n"),
764 /* Convenience. Treat POSIX -W foo same as long option --foo */
765 if (temp
[0] == 'W' && temp
[1] == ';') {
767 const struct option
*p
;
768 const struct option
*pfound
= NULL
;
774 /* This is an option that requires an argument. */
775 if (*nextchar
!= '\0') {
777 /* If we end this ARGV-element by taking the
779 we must advance to the next element now. */
781 } else if (optind
== argc
) {
783 /* 1003.2 specifies the format of this
786 _("%s: option requires an argument -- %c\n"),
790 if (optstring
[0] == ':')
796 /* We already incremented `optind' once;
797 increment it again when taking next ARGV-elt
799 optarg
= argv
[optind
++];
801 /* optarg is now the argument, see if it's in the
802 table of longopts. */
804 for (nextchar
= nameend
= optarg
;
805 *nameend
&& *nameend
!= '='; nameend
++)
808 /* Test all long options for either exact match
809 or abbreviated matches. */
810 for (p
= longopts
, option_index
= 0; p
->name
;
812 if (!strncmp(p
->name
, nextchar
,
813 nameend
- nextchar
)) {
814 if ((unsigned int)(nameend
- nextchar
)
815 == strlen(p
->name
)) {
816 /* Exact match found. */
818 indfound
= option_index
;
821 } else if (pfound
== NULL
) {
822 /* First nonexact match found.
825 indfound
= option_index
;
827 /* Second or later nonexact
831 if (ambig
&& !exact
) {
834 _("%s: option `-W %s' is ambiguous\n"),
835 argv
[0], argv
[optind
]);
836 nextchar
+= strlen(nextchar
);
840 if (pfound
!= NULL
) {
841 option_index
= indfound
;
843 /* Don't test has_arg with >, because
844 some C compilers don't
845 allow it to be used on enums. */
847 optarg
= nameend
+ 1;
851 %s: option `-W %s' doesn't allow an argument\n"),
855 nextchar
+= strlen(nextchar
);
858 } else if (pfound
->has_arg
== 1) {
860 optarg
= argv
[optind
++];
864 _("%s: option `%s' requires an argument\n"),
868 nextchar
+= strlen(nextchar
);
869 return optstring
[0] == ':'
874 nextchar
+= strlen(nextchar
);
876 *longind
= option_index
;
878 *(pfound
->flag
) = pfound
->val
;
884 return 'W'; /* Let the application handle it. */
886 if (temp
[1] == ':') {
887 if (temp
[2] == ':') {
888 /* This is an option that accepts an argument
890 if (*nextchar
!= '\0') {
897 /* This is an option that requires an argument.
899 if (*nextchar
!= '\0') {
901 /* If we end this ARGV-element by taking
903 we must advance to the next element
906 } else if (optind
== argc
) {
908 /* 1003.2 specifies the format
909 * of this message. */
911 _("%s: option requires an argument -- %c\n"),
915 if (optstring
[0] == ':')
920 /* We already incremented `optind' once;
921 increment it again when taking next
922 ARGV-elt as argument. */
923 optarg
= argv
[optind
++];
931 #ifdef REALLY_NEED_PLAIN_GETOPT
933 int getopt(argc
, argv
, optstring
) int argc
;
935 const char *optstring
;
937 return _getopt_internal(argc
, argv
, optstring
, (const struct option
*)0,
941 #endif /* REALLY_NEED_PLAIN_GETOPT */
943 #endif /* Not ELIDE_CODE. */
947 /* Compile with -DTEST to make an executable for use in testing
948 the above definition of `getopt'. */
950 int main(argc
, argv
) int argc
;
954 int digit_optind
= 0;
957 int this_option_optind
= optind
? optind
: 1;
959 c
= getopt(argc
, argv
, "abc:d:0123456789");
974 if (digit_optind
!= 0
975 && digit_optind
!= this_option_optind
)
976 printf("digits occur in two different argv-elements.\n");
977 digit_optind
= this_option_optind
;
978 printf("option %c\n", c
);
982 printf("option a\n");
986 printf("option b\n");
990 printf("option c with value `%s'\n", optarg
);
997 printf("?? getopt returned character code 0%o ??\n", c
);
1001 if (optind
< argc
) {
1002 printf("non-option ARGV-elements: ");
1003 while (optind
< argc
)
1004 printf("%s ", argv
[optind
++]);