168
164
if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
170
166
/* We must extend the array. The user plays games with us and
171
presents new arguments. */
167
presents new arguments. */
172
168
char *new_str = malloc (top + 1);
173
169
if (new_str == NULL)
174
d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
170
d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
177
memset (__mempcpy (new_str, __getopt_nonoption_flags,
178
d->__nonoption_flags_max_len),
179
'\0', top + 1 - d->__nonoption_flags_max_len);
180
d->__nonoption_flags_max_len = top + 1;
181
__getopt_nonoption_flags = new_str;
173
memset (__mempcpy (new_str, __getopt_nonoption_flags,
174
d->__nonoption_flags_max_len),
175
'\0', top + 1 - d->__nonoption_flags_max_len);
176
d->__nonoption_flags_max_len = top + 1;
177
__getopt_nonoption_flags = new_str;
186
182
while (top > middle && middle > bottom)
188
184
if (top - middle > middle - bottom)
190
/* Bottom segment is the short one. */
191
int len = middle - bottom;
186
/* Bottom segment is the short one. */
187
int len = middle - bottom;
194
/* Swap it with the top part of the top segment. */
195
for (i = 0; i < len; i++)
197
tem = argv[bottom + i];
198
argv[bottom + i] = argv[top - (middle - bottom) + i];
199
argv[top - (middle - bottom) + i] = tem;
200
SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
202
/* Exclude the moved bottom segment from further swapping. */
190
/* Swap it with the top part of the top segment. */
191
for (i = 0; i < len; i++)
193
tem = argv[bottom + i];
194
argv[bottom + i] = argv[top - (middle - bottom) + i];
195
argv[top - (middle - bottom) + i] = tem;
196
SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
198
/* Exclude the moved bottom segment from further swapping. */
207
/* Top segment is the short one. */
208
int len = top - middle;
203
/* Top segment is the short one. */
204
int len = top - middle;
211
/* Swap it with the bottom part of the bottom segment. */
212
for (i = 0; i < len; i++)
214
tem = argv[bottom + i];
215
argv[bottom + i] = argv[middle + i];
216
argv[middle + i] = tem;
217
SWAP_FLAGS (bottom + i, middle + i);
219
/* Exclude the moved top segment from further swapping. */
207
/* Swap it with the bottom part of the bottom segment. */
208
for (i = 0; i < len; i++)
210
tem = argv[bottom + i];
211
argv[bottom + i] = argv[middle + i];
212
argv[middle + i] = tem;
213
SWAP_FLAGS (bottom + i, middle + i);
215
/* Exclude the moved top segment from further swapping. */
224
220
/* Update records for the slots the non-options now occupy. */
388
386
/* Advance to the next ARGV-element. */
390
388
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
391
moved back by the user (who may also have changed the arguments). */
389
moved back by the user (who may also have changed the arguments). */
392
390
if (d->__last_nonopt > d->optind)
393
d->__last_nonopt = d->optind;
391
d->__last_nonopt = d->optind;
394
392
if (d->__first_nonopt > d->optind)
395
d->__first_nonopt = d->optind;
393
d->__first_nonopt = d->optind;
397
395
if (d->__ordering == PERMUTE)
399
/* If we have just processed some options following some non-options,
400
exchange them so that the options come first. */
402
if (d->__first_nonopt != d->__last_nonopt
403
&& d->__last_nonopt != d->optind)
404
exchange ((char **) argv, d);
405
else if (d->__last_nonopt != d->optind)
406
d->__first_nonopt = d->optind;
408
/* Skip any additional non-options
409
and extend the range of non-options previously skipped. */
411
while (d->optind < argc && NONOPTION_P)
413
d->__last_nonopt = d->optind;
397
/* If we have just processed some options following some non-options,
398
exchange them so that the options come first. */
400
if (d->__first_nonopt != d->__last_nonopt
401
&& d->__last_nonopt != d->optind)
402
exchange ((char **) argv, d);
403
else if (d->__last_nonopt != d->optind)
404
d->__first_nonopt = d->optind;
406
/* Skip any additional non-options
407
and extend the range of non-options previously skipped. */
409
while (d->optind < argc && NONOPTION_P)
411
d->__last_nonopt = d->optind;
416
414
/* The special ARGV-element `--' means premature end of options.
417
Skip it like a null option,
418
then exchange with previous non-options as if it were an option,
419
then skip everything else like a non-option. */
415
Skip it like a null option,
416
then exchange with previous non-options as if it were an option,
417
then skip everything else like a non-option. */
421
419
if (d->optind != argc && !strcmp (argv[d->optind], "--"))
425
if (d->__first_nonopt != d->__last_nonopt
426
&& d->__last_nonopt != d->optind)
427
exchange ((char **) argv, d);
428
else if (d->__first_nonopt == d->__last_nonopt)
429
d->__first_nonopt = d->optind;
430
d->__last_nonopt = argc;
423
if (d->__first_nonopt != d->__last_nonopt
424
&& d->__last_nonopt != d->optind)
425
exchange ((char **) argv, d);
426
else if (d->__first_nonopt == d->__last_nonopt)
427
d->__first_nonopt = d->optind;
428
d->__last_nonopt = argc;
435
433
/* If we have done all the ARGV-elements, stop the scan
436
and back over any non-options that we skipped and permuted. */
434
and back over any non-options that we skipped and permuted. */
438
436
if (d->optind == argc)
440
/* Set the next-arg-index to point at the non-options
441
that we previously skipped, so the caller will digest them. */
442
if (d->__first_nonopt != d->__last_nonopt)
443
d->optind = d->__first_nonopt;
438
/* Set the next-arg-index to point at the non-options
439
that we previously skipped, so the caller will digest them. */
440
if (d->__first_nonopt != d->__last_nonopt)
441
d->optind = d->__first_nonopt;
447
445
/* If we have come to a non-option and did not permute it,
448
either stop the scan or describe it to the caller and pass it by. */
446
either stop the scan or describe it to the caller and pass it by. */
452
if (d->__ordering == REQUIRE_ORDER)
454
d->optarg = argv[d->optind++];
450
if (d->__ordering == REQUIRE_ORDER)
452
d->optarg = argv[d->optind++];
458
456
/* We have found another option-ARGV-element.
459
Skip the initial punctuation. */
457
Skip the initial punctuation. */
461
459
d->__nextchar = (argv[d->optind] + 1
462
+ (longopts != NULL && argv[d->optind][1] == '-'));
460
+ (longopts != NULL && argv[d->optind][1] == '-'));
465
463
/* Decode the current option-ARGV-element. */
491
489
int option_index;
493
491
for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
496
494
/* Test all long options for either exact match
497
or abbreviated matches. */
495
or abbreviated matches. */
498
496
for (p = longopts, option_index = 0; p->name; p++, option_index++)
499
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
501
if ((unsigned int) (nameend - d->__nextchar)
502
== (unsigned int) strlen (p->name))
504
/* Exact match found. */
506
indfound = option_index;
510
else if (pfound == NULL)
512
/* First nonexact match found. */
514
indfound = option_index;
517
|| pfound->has_arg != p->has_arg
518
|| pfound->flag != p->flag
519
|| pfound->val != p->val)
520
/* Second or later nonexact match found. */
497
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
499
if ((unsigned int) (nameend - d->__nextchar)
500
== (unsigned int) strlen (p->name))
502
/* Exact match found. */
504
indfound = option_index;
508
else if (pfound == NULL)
510
/* First nonexact match found. */
512
indfound = option_index;
515
|| pfound->has_arg != p->has_arg
516
|| pfound->flag != p->flag
517
|| pfound->val != p->val)
518
/* Second or later nonexact match found. */
524
522
if (ambig && !exact)
528
526
#if defined _LIBC && defined USE_IN_LIBIO
531
if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
532
argv[0], argv[d->optind]) >= 0)
534
_IO_flockfile (stderr);
536
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
537
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
539
__fxprintf (NULL, "%s", buf);
541
((_IO_FILE *) stderr)->_flags2 = old_flags2;
542
_IO_funlockfile (stderr);
529
if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"),
530
argv[0], argv[d->optind]) >= 0)
532
_IO_flockfile (stderr);
534
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
535
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
537
__fxprintf (NULL, "%s", buf);
539
((_IO_FILE *) stderr)->_flags2 = old_flags2;
540
_IO_funlockfile (stderr);
547
fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
548
argv[0], argv[d->optind]);
545
fprintf (stderr, _("%s: option '%s' is ambiguous\n"),
546
argv[0], argv[d->optind]);
551
d->__nextchar += strlen (d->__nextchar);
549
d->__nextchar += strlen (d->__nextchar);
557
555
if (pfound != NULL)
559
option_index = indfound;
563
/* Don't test has_arg with >, because some C compilers don't
564
allow it to be used on enums. */
566
d->optarg = nameend + 1;
571
#if defined _LIBC && defined USE_IN_LIBIO
576
if (argv[d->optind - 1][1] == '-')
579
#if defined _LIBC && defined USE_IN_LIBIO
580
n = __asprintf (&buf, _("\
581
%s: option `--%s' doesn't allow an argument\n"),
582
argv[0], pfound->name);
584
fprintf (stderr, _("\
585
%s: option `--%s' doesn't allow an argument\n"),
586
argv[0], pfound->name);
591
/* +option or -option */
592
#if defined _LIBC && defined USE_IN_LIBIO
593
n = __asprintf (&buf, _("\
594
%s: option `%c%s' doesn't allow an argument\n"),
595
argv[0], argv[d->optind - 1][0],
598
fprintf (stderr, _("\
599
%s: option `%c%s' doesn't allow an argument\n"),
600
argv[0], argv[d->optind - 1][0],
605
#if defined _LIBC && defined USE_IN_LIBIO
608
_IO_flockfile (stderr);
610
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
611
((_IO_FILE *) stderr)->_flags2
612
|= _IO_FLAGS2_NOTCANCEL;
614
__fxprintf (NULL, "%s", buf);
616
((_IO_FILE *) stderr)->_flags2 = old_flags2;
617
_IO_funlockfile (stderr);
624
d->__nextchar += strlen (d->__nextchar);
626
d->optopt = pfound->val;
630
else if (pfound->has_arg == 1)
632
if (d->optind < argc)
633
d->optarg = argv[d->optind++];
638
#if defined _LIBC && defined USE_IN_LIBIO
641
if (__asprintf (&buf, _("\
642
%s: option `%s' requires an argument\n"),
643
argv[0], argv[d->optind - 1]) >= 0)
645
_IO_flockfile (stderr);
647
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
648
((_IO_FILE *) stderr)->_flags2
649
|= _IO_FLAGS2_NOTCANCEL;
651
__fxprintf (NULL, "%s", buf);
653
((_IO_FILE *) stderr)->_flags2 = old_flags2;
654
_IO_funlockfile (stderr);
660
_("%s: option `%s' requires an argument\n"),
661
argv[0], argv[d->optind - 1]);
664
d->__nextchar += strlen (d->__nextchar);
665
d->optopt = pfound->val;
666
return optstring[0] == ':' ? ':' : '?';
669
d->__nextchar += strlen (d->__nextchar);
671
*longind = option_index;
674
*(pfound->flag) = pfound->val;
557
option_index = indfound;
561
/* Don't test has_arg with >, because some C compilers don't
562
allow it to be used on enums. */
564
d->optarg = nameend + 1;
569
#if defined _LIBC && defined USE_IN_LIBIO
574
if (argv[d->optind - 1][1] == '-')
577
#if defined _LIBC && defined USE_IN_LIBIO
578
n = __asprintf (&buf, _("\
579
%s: option '--%s' doesn't allow an argument\n"),
580
argv[0], pfound->name);
582
fprintf (stderr, _("\
583
%s: option '--%s' doesn't allow an argument\n"),
584
argv[0], pfound->name);
589
/* +option or -option */
590
#if defined _LIBC && defined USE_IN_LIBIO
591
n = __asprintf (&buf, _("\
592
%s: option '%c%s' doesn't allow an argument\n"),
593
argv[0], argv[d->optind - 1][0],
596
fprintf (stderr, _("\
597
%s: option '%c%s' doesn't allow an argument\n"),
598
argv[0], argv[d->optind - 1][0],
603
#if defined _LIBC && defined USE_IN_LIBIO
606
_IO_flockfile (stderr);
608
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
609
((_IO_FILE *) stderr)->_flags2
610
|= _IO_FLAGS2_NOTCANCEL;
612
__fxprintf (NULL, "%s", buf);
614
((_IO_FILE *) stderr)->_flags2 = old_flags2;
615
_IO_funlockfile (stderr);
622
d->__nextchar += strlen (d->__nextchar);
624
d->optopt = pfound->val;
628
else if (pfound->has_arg == 1)
630
if (d->optind < argc)
631
d->optarg = argv[d->optind++];
636
#if defined _LIBC && defined USE_IN_LIBIO
639
if (__asprintf (&buf, _("\
640
%s: option '%s' requires an argument\n"),
641
argv[0], argv[d->optind - 1]) >= 0)
643
_IO_flockfile (stderr);
645
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
646
((_IO_FILE *) stderr)->_flags2
647
|= _IO_FLAGS2_NOTCANCEL;
649
__fxprintf (NULL, "%s", buf);
651
((_IO_FILE *) stderr)->_flags2 = old_flags2;
652
_IO_funlockfile (stderr);
658
_("%s: option '%s' requires an argument\n"),
659
argv[0], argv[d->optind - 1]);
662
d->__nextchar += strlen (d->__nextchar);
663
d->optopt = pfound->val;
664
return optstring[0] == ':' ? ':' : '?';
667
d->__nextchar += strlen (d->__nextchar);
669
*longind = option_index;
672
*(pfound->flag) = pfound->val;
680
678
/* Can't find it as a long option. If this is not getopt_long_only,
681
or the option starts with '--' or is not a valid short
682
option, then it's an error.
683
Otherwise interpret it as a short option. */
679
or the option starts with '--' or is not a valid short
680
option, then it's an error.
681
Otherwise interpret it as a short option. */
684
682
if (!long_only || argv[d->optind][1] == '-'
685
|| strchr (optstring, *d->__nextchar) == NULL)
689
#if defined _LIBC && defined USE_IN_LIBIO
694
if (argv[d->optind][1] == '-')
697
#if defined _LIBC && defined USE_IN_LIBIO
698
n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
699
argv[0], d->__nextchar);
701
fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
702
argv[0], d->__nextchar);
707
/* +option or -option */
708
#if defined _LIBC && defined USE_IN_LIBIO
709
n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
710
argv[0], argv[d->optind][0], d->__nextchar);
712
fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
713
argv[0], argv[d->optind][0], d->__nextchar);
717
#if defined _LIBC && defined USE_IN_LIBIO
720
_IO_flockfile (stderr);
722
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
723
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
725
__fxprintf (NULL, "%s", buf);
727
((_IO_FILE *) stderr)->_flags2 = old_flags2;
728
_IO_funlockfile (stderr);
734
d->__nextchar = (char *) "";
683
|| strchr (optstring, *d->__nextchar) == NULL)
687
#if defined _LIBC && defined USE_IN_LIBIO
692
if (argv[d->optind][1] == '-')
695
#if defined _LIBC && defined USE_IN_LIBIO
696
n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
697
argv[0], d->__nextchar);
699
fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
700
argv[0], d->__nextchar);
705
/* +option or -option */
706
#if defined _LIBC && defined USE_IN_LIBIO
707
n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
708
argv[0], argv[d->optind][0], d->__nextchar);
710
fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
711
argv[0], argv[d->optind][0], d->__nextchar);
715
#if defined _LIBC && defined USE_IN_LIBIO
718
_IO_flockfile (stderr);
720
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
721
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
723
__fxprintf (NULL, "%s", buf);
725
((_IO_FILE *) stderr)->_flags2 = old_flags2;
726
_IO_funlockfile (stderr);
732
d->__nextchar = (char *) "";
741
739
/* Look at and handle the next short option-character. */
751
749
if (temp == NULL || c == ':')
755
#if defined _LIBC && defined USE_IN_LIBIO
760
if (d->__posixly_correct)
762
/* 1003.2 specifies the format of this message. */
763
#if defined _LIBC && defined USE_IN_LIBIO
764
n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
767
fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
772
#if defined _LIBC && defined USE_IN_LIBIO
773
n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
776
fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
780
#if defined _LIBC && defined USE_IN_LIBIO
783
_IO_flockfile (stderr);
785
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
786
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
788
__fxprintf (NULL, "%s", buf);
790
((_IO_FILE *) stderr)->_flags2 = old_flags2;
791
_IO_funlockfile (stderr);
753
#if defined _LIBC && defined USE_IN_LIBIO
758
#if defined _LIBC && defined USE_IN_LIBIO
759
n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
762
fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
765
#if defined _LIBC && defined USE_IN_LIBIO
768
_IO_flockfile (stderr);
770
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
771
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
773
__fxprintf (NULL, "%s", buf);
775
((_IO_FILE *) stderr)->_flags2 = old_flags2;
776
_IO_funlockfile (stderr);
800
785
/* Convenience. Treat POSIX -W foo same as long option --foo */
801
786
if (temp[0] == 'W' && temp[1] == ';')
804
const struct option *p;
805
const struct option *pfound = NULL;
811
/* This is an option that requires an argument. */
812
if (*d->__nextchar != '\0')
814
d->optarg = d->__nextchar;
815
/* If we end this ARGV-element by taking the rest as an arg,
816
we must advance to the next element now. */
819
else if (d->optind == argc)
823
/* 1003.2 specifies the format of this message. */
824
#if defined _LIBC && defined USE_IN_LIBIO
827
if (__asprintf (&buf,
828
_("%s: option requires an argument -- %c\n"),
831
_IO_flockfile (stderr);
833
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
834
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
836
__fxprintf (NULL, "%s", buf);
838
((_IO_FILE *) stderr)->_flags2 = old_flags2;
839
_IO_funlockfile (stderr);
844
fprintf (stderr, _("%s: option requires an argument -- %c\n"),
849
if (optstring[0] == ':')
856
/* We already incremented `d->optind' once;
857
increment it again when taking next ARGV-elt as argument. */
858
d->optarg = argv[d->optind++];
860
/* optarg is now the argument, see if it's in the
861
table of longopts. */
863
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
867
/* Test all long options for either exact match
868
or abbreviated matches. */
869
for (p = longopts, option_index = 0; p->name; p++, option_index++)
870
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
872
if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
874
/* Exact match found. */
876
indfound = option_index;
880
else if (pfound == NULL)
882
/* First nonexact match found. */
884
indfound = option_index;
887
/* Second or later nonexact match found. */
894
#if defined _LIBC && defined USE_IN_LIBIO
897
if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
898
argv[0], argv[d->optind]) >= 0)
900
_IO_flockfile (stderr);
902
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
903
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
905
__fxprintf (NULL, "%s", buf);
907
((_IO_FILE *) stderr)->_flags2 = old_flags2;
908
_IO_funlockfile (stderr);
913
fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
914
argv[0], argv[d->optind]);
917
d->__nextchar += strlen (d->__nextchar);
923
option_index = indfound;
926
/* Don't test has_arg with >, because some C compilers don't
927
allow it to be used on enums. */
929
d->optarg = nameend + 1;
934
#if defined _LIBC && defined USE_IN_LIBIO
937
if (__asprintf (&buf, _("\
938
%s: option `-W %s' doesn't allow an argument\n"),
939
argv[0], pfound->name) >= 0)
941
_IO_flockfile (stderr);
943
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
944
((_IO_FILE *) stderr)->_flags2
945
|= _IO_FLAGS2_NOTCANCEL;
947
__fxprintf (NULL, "%s", buf);
949
((_IO_FILE *) stderr)->_flags2 = old_flags2;
950
_IO_funlockfile (stderr);
955
fprintf (stderr, _("\
956
%s: option `-W %s' doesn't allow an argument\n"),
957
argv[0], pfound->name);
961
d->__nextchar += strlen (d->__nextchar);
965
else if (pfound->has_arg == 1)
967
if (d->optind < argc)
968
d->optarg = argv[d->optind++];
973
#if defined _LIBC && defined USE_IN_LIBIO
976
if (__asprintf (&buf, _("\
977
%s: option `%s' requires an argument\n"),
978
argv[0], argv[d->optind - 1]) >= 0)
980
_IO_flockfile (stderr);
982
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
983
((_IO_FILE *) stderr)->_flags2
984
|= _IO_FLAGS2_NOTCANCEL;
986
__fxprintf (NULL, "%s", buf);
988
((_IO_FILE *) stderr)->_flags2 = old_flags2;
989
_IO_funlockfile (stderr);
995
_("%s: option `%s' requires an argument\n"),
996
argv[0], argv[d->optind - 1]);
999
d->__nextchar += strlen (d->__nextchar);
1000
return optstring[0] == ':' ? ':' : '?';
1003
d->__nextchar += strlen (d->__nextchar);
1004
if (longind != NULL)
1005
*longind = option_index;
1008
*(pfound->flag) = pfound->val;
1013
d->__nextchar = NULL;
1014
return 'W'; /* Let the application handle it. */
789
const struct option *p;
790
const struct option *pfound = NULL;
796
/* This is an option that requires an argument. */
797
if (*d->__nextchar != '\0')
799
d->optarg = d->__nextchar;
800
/* If we end this ARGV-element by taking the rest as an arg,
801
we must advance to the next element now. */
804
else if (d->optind == argc)
808
#if defined _LIBC && defined USE_IN_LIBIO
811
if (__asprintf (&buf,
812
_("%s: option requires an argument -- '%c'\n"),
815
_IO_flockfile (stderr);
817
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
818
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
820
__fxprintf (NULL, "%s", buf);
822
((_IO_FILE *) stderr)->_flags2 = old_flags2;
823
_IO_funlockfile (stderr);
829
_("%s: option requires an argument -- '%c'\n"),
834
if (optstring[0] == ':')
841
/* We already incremented `d->optind' once;
842
increment it again when taking next ARGV-elt as argument. */
843
d->optarg = argv[d->optind++];
845
/* optarg is now the argument, see if it's in the
846
table of longopts. */
848
for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
852
/* Test all long options for either exact match
853
or abbreviated matches. */
854
for (p = longopts, option_index = 0; p->name; p++, option_index++)
855
if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
857
if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
859
/* Exact match found. */
861
indfound = option_index;
865
else if (pfound == NULL)
867
/* First nonexact match found. */
869
indfound = option_index;
872
/* Second or later nonexact match found. */
879
#if defined _LIBC && defined USE_IN_LIBIO
882
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
883
argv[0], argv[d->optind]) >= 0)
885
_IO_flockfile (stderr);
887
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
888
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
890
__fxprintf (NULL, "%s", buf);
892
((_IO_FILE *) stderr)->_flags2 = old_flags2;
893
_IO_funlockfile (stderr);
898
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
899
argv[0], argv[d->optind]);
902
d->__nextchar += strlen (d->__nextchar);
908
option_index = indfound;
911
/* Don't test has_arg with >, because some C compilers don't
912
allow it to be used on enums. */
914
d->optarg = nameend + 1;
919
#if defined _LIBC && defined USE_IN_LIBIO
922
if (__asprintf (&buf, _("\
923
%s: option '-W %s' doesn't allow an argument\n"),
924
argv[0], pfound->name) >= 0)
926
_IO_flockfile (stderr);
928
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
929
((_IO_FILE *) stderr)->_flags2
930
|= _IO_FLAGS2_NOTCANCEL;
932
__fxprintf (NULL, "%s", buf);
934
((_IO_FILE *) stderr)->_flags2 = old_flags2;
935
_IO_funlockfile (stderr);
940
fprintf (stderr, _("\
941
%s: option '-W %s' doesn't allow an argument\n"),
942
argv[0], pfound->name);
946
d->__nextchar += strlen (d->__nextchar);
950
else if (pfound->has_arg == 1)
952
if (d->optind < argc)
953
d->optarg = argv[d->optind++];
958
#if defined _LIBC && defined USE_IN_LIBIO
961
if (__asprintf (&buf, _("\
962
%s: option '%s' requires an argument\n"),
963
argv[0], argv[d->optind - 1]) >= 0)
965
_IO_flockfile (stderr);
967
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
968
((_IO_FILE *) stderr)->_flags2
969
|= _IO_FLAGS2_NOTCANCEL;
971
__fxprintf (NULL, "%s", buf);
973
((_IO_FILE *) stderr)->_flags2 = old_flags2;
974
_IO_funlockfile (stderr);
980
_("%s: option '%s' requires an argument\n"),
981
argv[0], argv[d->optind - 1]);
984
d->__nextchar += strlen (d->__nextchar);
985
return optstring[0] == ':' ? ':' : '?';
988
d->__nextchar += strlen (d->__nextchar);
990
*longind = option_index;
993
*(pfound->flag) = pfound->val;
998
d->__nextchar = NULL;
999
return 'W'; /* Let the application handle it. */
1016
1001
if (temp[1] == ':')
1020
/* This is an option that accepts an argument optionally. */
1021
if (*d->__nextchar != '\0')
1023
d->optarg = d->__nextchar;
1028
d->__nextchar = NULL;
1032
/* This is an option that requires an argument. */
1033
if (*d->__nextchar != '\0')
1035
d->optarg = d->__nextchar;
1036
/* If we end this ARGV-element by taking the rest as an arg,
1037
we must advance to the next element now. */
1040
else if (d->optind == argc)
1044
/* 1003.2 specifies the format of this message. */
1005
/* This is an option that accepts an argument optionally. */
1006
if (*d->__nextchar != '\0')
1008
d->optarg = d->__nextchar;
1013
d->__nextchar = NULL;
1017
/* This is an option that requires an argument. */
1018
if (*d->__nextchar != '\0')
1020
d->optarg = d->__nextchar;
1021
/* If we end this ARGV-element by taking the rest as an arg,
1022
we must advance to the next element now. */
1025
else if (d->optind == argc)
1045
1029
#if defined _LIBC && defined USE_IN_LIBIO
1048
if (__asprintf (&buf, _("\
1049
%s: option requires an argument -- %c\n"),
1052
_IO_flockfile (stderr);
1054
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1055
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1057
__fxprintf (NULL, "%s", buf);
1059
((_IO_FILE *) stderr)->_flags2 = old_flags2;
1060
_IO_funlockfile (stderr);
1032
if (__asprintf (&buf, _("\
1033
%s: option requires an argument -- '%c'\n"),
1036
_IO_flockfile (stderr);
1038
int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1039
((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1041
__fxprintf (NULL, "%s", buf);
1043
((_IO_FILE *) stderr)->_flags2 = old_flags2;
1044
_IO_funlockfile (stderr);
1066
_("%s: option requires an argument -- %c\n"),
1050
_("%s: option requires an argument -- '%c'\n"),
1071
if (optstring[0] == ':')
1077
/* We already incremented `optind' once;
1078
increment it again when taking next ARGV-elt as argument. */
1079
d->optarg = argv[d->optind++];
1080
d->__nextchar = NULL;
1055
if (optstring[0] == ':')
1061
/* We already incremented `optind' once;
1062
increment it again when taking next ARGV-elt as argument. */
1063
d->optarg = argv[d->optind++];
1064
d->__nextchar = NULL;