362 int print_errors =
d->opterr;
363 if (optstring[0] ==
':')
371 if (
d->optind == 0 || !
d->__initialized)
377 d->__initialized = 1;
384 #if defined _LIBC && defined USE_NONOPTION_FLAGS
385 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
386 || (d->optind < d->__nonoption_flags_len \
387 && __getopt_nonoption_flags[d->optind] == '1'))
389 # define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
392 if (
d->__nextchar ==
NULL || *
d->__nextchar ==
'\0')
398 if (
d->__last_nonopt >
d->optind)
399 d->__last_nonopt =
d->optind;
400 if (
d->__first_nonopt >
d->optind)
401 d->__first_nonopt =
d->optind;
408 if (
d->__first_nonopt !=
d->__last_nonopt
409 &&
d->__last_nonopt !=
d->optind)
411 else if (
d->__last_nonopt !=
d->optind)
412 d->__first_nonopt =
d->optind;
419 d->__last_nonopt =
d->optind;
427 if (
d->optind != argc && !strcmp (
argv[
d->optind],
"--"))
431 if (
d->__first_nonopt !=
d->__last_nonopt
432 &&
d->__last_nonopt !=
d->optind)
434 else if (
d->__first_nonopt ==
d->__last_nonopt)
435 d->__first_nonopt =
d->optind;
436 d->__last_nonopt = argc;
444 if (
d->optind == argc)
448 if (
d->__first_nonopt !=
d->__last_nonopt)
449 d->optind =
d->__first_nonopt;
460 d->optarg =
argv[
d->optind++];
467 d->__nextchar = (
argv[
d->optind] + 1
468 + (longopts !=
NULL &&
argv[
d->optind][1] ==
'-'));
487 && (
argv[
d->optind][1] ==
'-'
488 || (long_only && (
argv[
d->optind][2]
489 || !strchr (optstring,
argv[
d->optind][1])))))
499 for (nameend =
d->__nextchar; *nameend && *nameend !=
'='; nameend++)
504 for (
p = longopts, option_index = 0;
p->name;
p++, option_index++)
505 if (!strncmp (
p->name,
d->__nextchar, nameend -
d->__nextchar))
507 if ((
unsigned int) (nameend -
d->__nextchar)
508 == (
unsigned int) strlen (
p->name))
512 indfound = option_index;
516 else if (pfound ==
NULL)
520 indfound = option_index;
524 || pfound->
flag !=
p->flag
525 || pfound->
val !=
p->val)
534 #if defined _LIBC && defined USE_IN_LIBIO
537 if (__asprintf (&
buf,
_(
"%s: option `%s' is ambiguous\n"),
540 _IO_flockfile (stderr);
542 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
543 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
547 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
548 _IO_funlockfile (stderr);
553 fprintf (stderr,
_(
"%s: option `%s' is ambiguous\n"),
557 d->__nextchar += strlen (
d->__nextchar);
565 option_index = indfound;
572 d->optarg = nameend + 1;
577 #if defined _LIBC && defined USE_IN_LIBIO
582 if (
argv[
d->optind - 1][1] ==
'-')
585 #if defined _LIBC && defined USE_IN_LIBIO
586 n = __asprintf (&
buf,
_(
"\
587 %s: option `--%s' doesn't allow an argument\n"),
590 fprintf (stderr,
_(
"\
591 %s: option `--%s' doesn't allow an argument\n"),
598 #if defined _LIBC && defined USE_IN_LIBIO
599 n = __asprintf (&
buf,
_(
"\
600 %s: option `%c%s' doesn't allow an argument\n"),
604 fprintf (stderr,
_(
"\
605 %s: option `%c%s' doesn't allow an argument\n"),
611 #if defined _LIBC && defined USE_IN_LIBIO
614 _IO_flockfile (stderr);
616 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
617 ((_IO_FILE *) stderr)->_flags2
618 |= _IO_FLAGS2_NOTCANCEL;
622 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
623 _IO_funlockfile (stderr);
630 d->__nextchar += strlen (
d->__nextchar);
632 d->optopt = pfound->
val;
638 if (
d->optind < argc)
639 d->optarg =
argv[
d->optind++];
644 #if defined _LIBC && defined USE_IN_LIBIO
647 if (__asprintf (&
buf,
_(
"\
648 %s: option `%s' requires an argument\n"),
651 _IO_flockfile (stderr);
653 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
654 ((_IO_FILE *) stderr)->_flags2
655 |= _IO_FLAGS2_NOTCANCEL;
659 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
660 _IO_funlockfile (stderr);
666 _(
"%s: option `%s' requires an argument\n"),
670 d->__nextchar += strlen (
d->__nextchar);
671 d->optopt = pfound->
val;
672 return optstring[0] ==
':' ?
':' :
'?';
675 d->__nextchar += strlen (
d->__nextchar);
677 *longind = option_index;
690 if (!long_only ||
argv[
d->optind][1] ==
'-'
691 || strchr (optstring, *
d->__nextchar) ==
NULL)
695 #if defined _LIBC && defined USE_IN_LIBIO
700 if (
argv[
d->optind][1] ==
'-')
703 #if defined _LIBC && defined USE_IN_LIBIO
704 n = __asprintf (&
buf,
_(
"%s: unrecognized option `--%s'\n"),
705 argv[0],
d->__nextchar);
707 fprintf (stderr,
_(
"%s: unrecognized option `--%s'\n"),
708 argv[0],
d->__nextchar);
714 #if defined _LIBC && defined USE_IN_LIBIO
715 n = __asprintf (&
buf,
_(
"%s: unrecognized option `%c%s'\n"),
718 fprintf (stderr,
_(
"%s: unrecognized option `%c%s'\n"),
723 #if defined _LIBC && defined USE_IN_LIBIO
726 _IO_flockfile (stderr);
728 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
729 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
733 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
734 _IO_funlockfile (stderr);
740 d->__nextchar = (
char *)
"";
750 char c = *
d->__nextchar++;
751 char *temp = strchr (optstring,
c);
754 if (*
d->__nextchar ==
'\0')
757 if (temp ==
NULL ||
c ==
':')
761 #if defined _LIBC && defined USE_IN_LIBIO
766 if (
d->__posixly_correct)
769 #if defined _LIBC && defined USE_IN_LIBIO
770 n = __asprintf (&
buf,
_(
"%s: illegal option -- %c\n"),
773 fprintf (stderr,
_(
"%s: illegal option -- %c\n"),
argv[0],
c);
778 #if defined _LIBC && defined USE_IN_LIBIO
779 n = __asprintf (&
buf,
_(
"%s: invalid option -- %c\n"),
782 fprintf (stderr,
_(
"%s: invalid option -- %c\n"),
argv[0],
c);
786 #if defined _LIBC && defined USE_IN_LIBIO
789 _IO_flockfile (stderr);
791 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
792 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
796 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
797 _IO_funlockfile (stderr);
807 if (temp[0] ==
'W' && temp[1] ==
';')
818 if (*
d->__nextchar !=
'\0')
820 d->optarg =
d->__nextchar;
825 else if (
d->optind == argc)
830 #if defined _LIBC && defined USE_IN_LIBIO
833 if (__asprintf (&
buf,
834 _(
"%s: option requires an argument -- %c\n"),
837 _IO_flockfile (stderr);
839 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
840 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
844 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
845 _IO_funlockfile (stderr);
850 fprintf (stderr,
_(
"%s: option requires an argument -- %c\n"),
855 if (optstring[0] ==
':')
864 d->optarg =
argv[
d->optind++];
869 for (
d->__nextchar = nameend =
d->optarg; *nameend && *nameend !=
'=';
875 for (
p = longopts, option_index = 0;
p->name;
p++, option_index++)
876 if (!strncmp (
p->name,
d->__nextchar, nameend -
d->__nextchar))
878 if ((
unsigned int) (nameend -
d->__nextchar) == strlen (
p->name))
882 indfound = option_index;
886 else if (pfound ==
NULL)
890 indfound = option_index;
900 #if defined _LIBC && defined USE_IN_LIBIO
903 if (__asprintf (&
buf,
_(
"%s: option `-W %s' is ambiguous\n"),
906 _IO_flockfile (stderr);
908 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
909 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
913 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
914 _IO_funlockfile (stderr);
919 fprintf (stderr,
_(
"%s: option `-W %s' is ambiguous\n"),
923 d->__nextchar += strlen (
d->__nextchar);
929 option_index = indfound;
935 d->optarg = nameend + 1;
940 #if defined _LIBC && defined USE_IN_LIBIO
943 if (__asprintf (&
buf,
_(
"\
944 %s: option `-W %s' doesn't allow an argument\n"),
947 _IO_flockfile (stderr);
949 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
950 ((_IO_FILE *) stderr)->_flags2
951 |= _IO_FLAGS2_NOTCANCEL;
955 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
956 _IO_funlockfile (stderr);
961 fprintf (stderr,
_(
"\
962 %s: option `-W %s' doesn't allow an argument\n"),
967 d->__nextchar += strlen (
d->__nextchar);
973 if (
d->optind < argc)
974 d->optarg =
argv[
d->optind++];
979 #if defined _LIBC && defined USE_IN_LIBIO
982 if (__asprintf (&
buf,
_(
"\
983 %s: option `%s' requires an argument\n"),
986 _IO_flockfile (stderr);
988 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
989 ((_IO_FILE *) stderr)->_flags2
990 |= _IO_FLAGS2_NOTCANCEL;
994 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
995 _IO_funlockfile (stderr);
1001 _(
"%s: option `%s' requires an argument\n"),
1005 d->__nextchar += strlen (
d->__nextchar);
1006 return optstring[0] ==
':' ?
':' :
'?';
1009 d->__nextchar += strlen (
d->__nextchar);
1010 if (longind !=
NULL)
1011 *longind = option_index;
1014 *(pfound->
flag) = pfound->
val;
1019 d->__nextchar =
NULL;
1027 if (*
d->__nextchar !=
'\0')
1029 d->optarg =
d->__nextchar;
1034 d->__nextchar =
NULL;
1039 if (*
d->__nextchar !=
'\0')
1041 d->optarg =
d->__nextchar;
1046 else if (
d->optind == argc)
1051 #if defined _LIBC && defined USE_IN_LIBIO
1054 if (__asprintf (&
buf,
_(
"\
1055 %s: option requires an argument -- %c\n"),
1058 _IO_flockfile (stderr);
1060 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1061 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1065 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1066 _IO_funlockfile (stderr);
1072 _(
"%s: option requires an argument -- %c\n"),
1077 if (optstring[0] ==
':')
1085 d->optarg =
argv[
d->optind++];
1086 d->__nextchar =
NULL;
RZ_API void Ht_() free(HtName_(Ht) *ht)
static const char * _getopt_initialize(int argc, char **argv, const char *optstring, int posixly_correct, struct _getopt_data *d)
static void exchange(char **argv, struct _getopt_data *d)