|
@@ -106,7 +106,7 @@
|
|
|
Also, when `ordering' is RETURN_IN_ORDER,
|
|
|
each non-option ARGV-element is returned here. */
|
|
|
|
|
|
-char* getopt_optarg;
|
|
|
+char* optarg;
|
|
|
|
|
|
/* Index in ARGV of the next element to be scanned.
|
|
|
This is used for communication to and from the caller
|
|
@@ -117,13 +117,13 @@ char* getopt_optarg;
|
|
|
When `getopt' returns -1, this is the index of the first of the
|
|
|
non-option elements that the caller should itself scan.
|
|
|
|
|
|
- Otherwise, `getopt_optind' communicates from one call to the next
|
|
|
+ Otherwise, `optind' communicates from one call to the next
|
|
|
how much of ARGV has been scanned so far. */
|
|
|
|
|
|
/* 1003.2 says this must be 1 before any call. */
|
|
|
-int getopt_optind = 1;
|
|
|
+int optind = 1;
|
|
|
|
|
|
-/* Formerly, initialization of getopt depended on getopt_optind==0, which
|
|
|
+/* Formerly, initialization of getopt depended on optind==0, which
|
|
|
causes problems with re-calling getopt as programs generally don't
|
|
|
know that. */
|
|
|
|
|
@@ -176,7 +176,7 @@ int optopt = '?';
|
|
|
|
|
|
The special argument `--' forces an end of option-scanning regardless
|
|
|
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
|
|
|
- `--' can cause `getopt' to return -1 with `getopt_optind' != ARGC. */
|
|
|
+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
|
|
|
|
|
|
static enum
|
|
|
{
|
|
@@ -278,7 +278,7 @@ static int nonoption_flags_len;
|
|
|
/* Exchange two adjacent subsequences of ARGV.
|
|
|
One subsequence is elements [first_nonopt,last_nonopt)
|
|
|
which contains all the non-options that have been skipped so far.
|
|
|
- The other is elements [last_nonopt,getopt_optind), which contains all
|
|
|
+ The other is elements [last_nonopt,optind), which contains all
|
|
|
the options processed since those non-options were skipped.
|
|
|
|
|
|
`first_nonopt' and `last_nonopt' are relocated so that they describe
|
|
@@ -293,7 +293,7 @@ exchange(char** argv)
|
|
|
{
|
|
|
int bottom = first_nonopt;
|
|
|
int middle = last_nonopt;
|
|
|
- int top = getopt_optind;
|
|
|
+ int top = optind;
|
|
|
char* tem;
|
|
|
|
|
|
/* Exchange the shorter segment with the far end of the longer segment.
|
|
@@ -356,8 +356,8 @@ exchange(char** argv)
|
|
|
|
|
|
/* Update records for the slots the non-options now occupy. */
|
|
|
|
|
|
- first_nonopt += (getopt_optind - last_nonopt);
|
|
|
- last_nonopt = getopt_optind;
|
|
|
+ first_nonopt += (optind - last_nonopt);
|
|
|
+ last_nonopt = optind;
|
|
|
}
|
|
|
|
|
|
/* Initialize the internal data when the first call is made. */
|
|
@@ -371,7 +371,7 @@ static const char* _getopt_initialize(int argc, char* const* argv, const char* o
|
|
|
is the program name); the sequence of previously skipped
|
|
|
non-option ARGV-elements is empty. */
|
|
|
|
|
|
- first_nonopt = last_nonopt = getopt_optind;
|
|
|
+ first_nonopt = last_nonopt = optind;
|
|
|
|
|
|
nextchar = NULL;
|
|
|
|
|
@@ -432,11 +432,11 @@ static const char* _getopt_initialize(int argc, char* const* argv, const char* o
|
|
|
from each of the option elements.
|
|
|
|
|
|
If `getopt' finds another option character, it returns that character,
|
|
|
- updating `getopt_optind' and `nextchar' so that the next call to `getopt' can
|
|
|
+ updating `optind' and `nextchar' so that the next call to `getopt' can
|
|
|
resume the scan with the following option character or ARGV-element.
|
|
|
|
|
|
If there are no more option characters, `getopt' returns -1.
|
|
|
- Then `getopt_optind' is the index in ARGV of the first ARGV-element
|
|
|
+ Then `optind' is the index in ARGV of the first ARGV-element
|
|
|
that is not an option. (The ARGV-elements have been permuted
|
|
|
so that those that are not options now come last.)
|
|
|
|
|
@@ -489,25 +489,25 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
if (argc < 1)
|
|
|
return -1;
|
|
|
|
|
|
- getopt_optarg = NULL;
|
|
|
+ optarg = NULL;
|
|
|
|
|
|
- if (getopt_optind == 0 || !__getopt_initialized) {
|
|
|
- if (getopt_optind == 0)
|
|
|
- getopt_optind = 1; /* Don't scan ARGV[0], the program name. */
|
|
|
+ if (optind == 0 || !__getopt_initialized) {
|
|
|
+ if (optind == 0)
|
|
|
+ optind = 1; /* Don't scan ARGV[0], the program name. */
|
|
|
optstring = _getopt_initialize(argc, argv, optstring);
|
|
|
__getopt_initialized = 1;
|
|
|
}
|
|
|
|
|
|
- /* Test whether ARGV[getopt_optind] points to a non-option argument.
|
|
|
+ /* Test whether ARGV[optind] points to a non-option argument.
|
|
|
Either it does not have option syntax, or there is an environment flag
|
|
|
from the shell indicating it is not an option. The later information
|
|
|
is only used when the used in the GNU libc. */
|
|
|
#if defined _LIBC && defined USE_NONOPTION_FLAGS
|
|
|
-# define NONOPTION_P (argv[getopt_optind][0] != '-' || argv[getopt_optind][1] == '\0' \
|
|
|
- || (getopt_optind < nonoption_flags_len \
|
|
|
- && __getopt_nonoption_flags[getopt_optind] == '1'))
|
|
|
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
|
|
|
+ || (optind < nonoption_flags_len \
|
|
|
+ && __getopt_nonoption_flags[optind] == '1'))
|
|
|
#else
|
|
|
-# define NONOPTION_P (argv[getopt_optind][0] != '-' || argv[getopt_optind][1] == '\0')
|
|
|
+# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
|
|
|
#endif
|
|
|
|
|
|
if (nextchar == NULL || *nextchar == '\0') {
|
|
@@ -515,26 +515,26 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
|
|
|
/* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
|
|
|
moved back by the user (who may also have changed the arguments). */
|
|
|
- if (last_nonopt > getopt_optind)
|
|
|
- last_nonopt = getopt_optind;
|
|
|
- if (first_nonopt > getopt_optind)
|
|
|
- first_nonopt = getopt_optind;
|
|
|
+ if (last_nonopt > optind)
|
|
|
+ last_nonopt = optind;
|
|
|
+ if (first_nonopt > optind)
|
|
|
+ first_nonopt = optind;
|
|
|
|
|
|
if (ordering == PERMUTE) {
|
|
|
/* If we have just processed some options following some non-options,
|
|
|
exchange them so that the options come first. */
|
|
|
|
|
|
- if (first_nonopt != last_nonopt && last_nonopt != getopt_optind)
|
|
|
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
|
|
|
exchange((char**)argv);
|
|
|
- else if (last_nonopt != getopt_optind)
|
|
|
- first_nonopt = getopt_optind;
|
|
|
+ else if (last_nonopt != optind)
|
|
|
+ first_nonopt = optind;
|
|
|
|
|
|
/* Skip any additional non-options
|
|
|
and extend the range of non-options previously skipped. */
|
|
|
|
|
|
- while (getopt_optind < argc && NONOPTION_P)
|
|
|
- getopt_optind++;
|
|
|
- last_nonopt = getopt_optind;
|
|
|
+ while (optind < argc && NONOPTION_P)
|
|
|
+ optind++;
|
|
|
+ last_nonopt = optind;
|
|
|
}
|
|
|
|
|
|
/* The special ARGV-element `--' means premature end of options.
|
|
@@ -542,26 +542,26 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
then exchange with previous non-options as if it were an option,
|
|
|
then skip everything else like a non-option. */
|
|
|
|
|
|
- if (getopt_optind != argc && !strcmp(argv[getopt_optind], "--")) {
|
|
|
- getopt_optind++;
|
|
|
+ if (optind != argc && !strcmp(argv[optind], "--")) {
|
|
|
+ optind++;
|
|
|
|
|
|
- if (first_nonopt != last_nonopt && last_nonopt != getopt_optind)
|
|
|
+ if (first_nonopt != last_nonopt && last_nonopt != optind)
|
|
|
exchange((char**)argv);
|
|
|
else if (first_nonopt == last_nonopt)
|
|
|
- first_nonopt = getopt_optind;
|
|
|
+ first_nonopt = optind;
|
|
|
last_nonopt = argc;
|
|
|
|
|
|
- getopt_optind = argc;
|
|
|
+ optind = argc;
|
|
|
}
|
|
|
|
|
|
/* If we have done all the ARGV-elements, stop the scan
|
|
|
and back over any non-options that we skipped and permuted. */
|
|
|
|
|
|
- if (getopt_optind == argc) {
|
|
|
+ if (optind == argc) {
|
|
|
/* Set the next-arg-index to point at the non-options
|
|
|
that we previously skipped, so the caller will digest them. */
|
|
|
if (first_nonopt != last_nonopt)
|
|
|
- getopt_optind = first_nonopt;
|
|
|
+ optind = first_nonopt;
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -571,15 +571,15 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
if (NONOPTION_P) {
|
|
|
if (ordering == REQUIRE_ORDER)
|
|
|
return -1;
|
|
|
- getopt_optarg = argv[getopt_optind++];
|
|
|
+ optarg = argv[optind++];
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/* We have found another option-ARGV-element.
|
|
|
Skip the initial punctuation. */
|
|
|
|
|
|
- nextchar = (argv[getopt_optind] + 1
|
|
|
- + (longopts != NULL && argv[getopt_optind][1] == '-'));
|
|
|
+ nextchar = (argv[optind] + 1
|
|
|
+ + (longopts != NULL && argv[optind][1] == '-'));
|
|
|
}
|
|
|
|
|
|
/* Decode the current option-ARGV-element. */
|
|
@@ -598,8 +598,8 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
This distinction seems to be the most useful approach. */
|
|
|
|
|
|
if (longopts != NULL
|
|
|
- && (argv[getopt_optind][1] == '-'
|
|
|
- || (long_only && (argv[getopt_optind][2] || !my_index(optstring, argv[getopt_optind][1]))))) {
|
|
|
+ && (argv[optind][1] == '-'
|
|
|
+ || (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1]))))) {
|
|
|
char* nameend;
|
|
|
const struct option* p;
|
|
|
const struct option* pfound = NULL;
|
|
@@ -639,24 +639,24 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
if (ambig && !exact) {
|
|
|
if (print_errors)
|
|
|
fprintf(stderr, _("%s: option `%s' is ambiguous\n"),
|
|
|
- argv[0], argv[getopt_optind]);
|
|
|
+ argv[0], argv[optind]);
|
|
|
nextchar += strlen(nextchar);
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
optopt = 0;
|
|
|
return '?';
|
|
|
}
|
|
|
|
|
|
if (pfound != NULL) {
|
|
|
option_index = indfound;
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
if (*nameend) {
|
|
|
/* Don't test has_arg with >, because some C compilers don't
|
|
|
allow it to be used on enums. */
|
|
|
if (pfound->has_arg)
|
|
|
- getopt_optarg = nameend + 1;
|
|
|
+ optarg = nameend + 1;
|
|
|
else {
|
|
|
if (print_errors) {
|
|
|
- if (argv[getopt_optind - 1][1] == '-')
|
|
|
+ if (argv[optind - 1][1] == '-')
|
|
|
/* --option */
|
|
|
fprintf(stderr,
|
|
|
_("%s: option `--%s' doesn't allow an argument\n"),
|
|
@@ -665,7 +665,7 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
/* +option or -option */
|
|
|
fprintf(stderr,
|
|
|
_("%s: option `%c%s' doesn't allow an argument\n"),
|
|
|
- argv[0], argv[getopt_optind - 1][0], pfound->name);
|
|
|
+ argv[0], argv[optind - 1][0], pfound->name);
|
|
|
}
|
|
|
|
|
|
nextchar += strlen(nextchar);
|
|
@@ -675,13 +675,13 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
}
|
|
|
}
|
|
|
else if (pfound->has_arg == 1) {
|
|
|
- if (getopt_optind < argc)
|
|
|
- getopt_optarg = argv[getopt_optind++];
|
|
|
+ if (optind < argc)
|
|
|
+ optarg = argv[optind++];
|
|
|
else {
|
|
|
if (print_errors)
|
|
|
fprintf(stderr,
|
|
|
_("%s: option `%s' requires an argument\n"),
|
|
|
- argv[0], argv[getopt_optind - 1]);
|
|
|
+ argv[0], argv[optind - 1]);
|
|
|
nextchar += strlen(nextchar);
|
|
|
optopt = pfound->val;
|
|
|
return optstring[0] == ':' ? ':' : '?';
|
|
@@ -701,20 +701,20 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
or the option starts with '--' or is not a valid short
|
|
|
option, then it's an error.
|
|
|
Otherwise interpret it as a short option. */
|
|
|
- if (!long_only || argv[getopt_optind][1] == '-'
|
|
|
+ if (!long_only || argv[optind][1] == '-'
|
|
|
|| my_index(optstring, *nextchar) == NULL) {
|
|
|
if (print_errors) {
|
|
|
- if (argv[getopt_optind][1] == '-')
|
|
|
+ if (argv[optind][1] == '-')
|
|
|
/* --option */
|
|
|
fprintf(stderr, _("%s: unrecognized option `--%s'\n"),
|
|
|
argv[0], nextchar);
|
|
|
else
|
|
|
/* +option or -option */
|
|
|
fprintf(stderr, _("%s: unrecognized option `%c%s'\n"),
|
|
|
- argv[0], argv[getopt_optind][0], nextchar);
|
|
|
+ argv[0], argv[optind][0], nextchar);
|
|
|
}
|
|
|
nextchar = (char*)"";
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
optopt = 0;
|
|
|
return '?';
|
|
|
}
|
|
@@ -726,9 +726,9 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
char c = *nextchar++;
|
|
|
char* temp = my_index(optstring, c);
|
|
|
|
|
|
- /* Increment `getopt_optind' when we start to process its last character. */
|
|
|
+ /* Increment `optind' when we start to process its last character. */
|
|
|
if (*nextchar == '\0')
|
|
|
- ++getopt_optind;
|
|
|
+ ++optind;
|
|
|
|
|
|
if (temp == NULL || c == ':') {
|
|
|
if (print_errors) {
|
|
@@ -755,12 +755,12 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
|
|
|
/* This is an option that requires an argument. */
|
|
|
if (*nextchar != '\0') {
|
|
|
- getopt_optarg = nextchar;
|
|
|
+ optarg = nextchar;
|
|
|
/* If we end this ARGV-element by taking the rest as an arg,
|
|
|
we must advance to the next element now. */
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
}
|
|
|
- else if (getopt_optind == argc) {
|
|
|
+ else if (optind == argc) {
|
|
|
if (print_errors) {
|
|
|
/* 1003.2 specifies the format of this message. */
|
|
|
fprintf(stderr, _("%s: option requires an argument -- %c\n"),
|
|
@@ -774,14 +774,14 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
return c;
|
|
|
}
|
|
|
else
|
|
|
- /* We already incremented `getopt_optind' once;
|
|
|
+ /* We already incremented `optind' once;
|
|
|
increment it again when taking next ARGV-elt as argument. */
|
|
|
- getopt_optarg = argv[getopt_optind++];
|
|
|
+ optarg = argv[optind++];
|
|
|
|
|
|
- /* getopt_optarg is now the argument, see if it's in the
|
|
|
+ /* optarg is now the argument, see if it's in the
|
|
|
table of longopts. */
|
|
|
|
|
|
- for (nextchar = nameend = getopt_optarg; *nameend && *nameend != '='; nameend++)
|
|
|
+ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
|
|
|
/* Do nothing. */;
|
|
|
|
|
|
/* Test all long options for either exact match
|
|
@@ -807,9 +807,9 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
if (ambig && !exact) {
|
|
|
if (print_errors)
|
|
|
fprintf(stderr, _("%s: option `-W %s' is ambiguous\n"),
|
|
|
- argv[0], argv[getopt_optind]);
|
|
|
+ argv[0], argv[optind]);
|
|
|
nextchar += strlen(nextchar);
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
return '?';
|
|
|
}
|
|
|
if (pfound != NULL) {
|
|
@@ -818,7 +818,7 @@ _getopt_internal(int argc, char* const* argv, const char* optstring,
|
|
|
/* Don't test has_arg with >, because some C compilers don't
|
|
|
allow it to be used on enums. */
|
|
|
if (pfound->has_arg)
|
|
|
- getopt_optarg = nameend + 1;
|
|
|
+ optarg = nameend + 1;
|
|
|
else {
|
|
|
if (print_errors)
|
|
|
fprintf(stderr, _("\
|
|
@@ -830,13 +830,13 @@ argv[0], pfound->name);
|
|
|
}
|
|
|
}
|
|
|
else if (pfound->has_arg == 1) {
|
|
|
- if (getopt_optind < argc)
|
|
|
- getopt_optarg = argv[getopt_optind++];
|
|
|
+ if (optind < argc)
|
|
|
+ optarg = argv[optind++];
|
|
|
else {
|
|
|
if (print_errors)
|
|
|
fprintf(stderr,
|
|
|
_("%s: option `%s' requires an argument\n"),
|
|
|
- argv[0], argv[getopt_optind - 1]);
|
|
|
+ argv[0], argv[optind - 1]);
|
|
|
nextchar += strlen(nextchar);
|
|
|
return optstring[0] == ':' ? ':' : '?';
|
|
|
}
|
|
@@ -857,22 +857,22 @@ argv[0], pfound->name);
|
|
|
if (temp[2] == ':') {
|
|
|
/* This is an option that accepts an argument optionally. */
|
|
|
if (*nextchar != '\0') {
|
|
|
- getopt_optarg = nextchar;
|
|
|
- getopt_optind++;
|
|
|
+ optarg = nextchar;
|
|
|
+ optind++;
|
|
|
}
|
|
|
else
|
|
|
- getopt_optarg = NULL;
|
|
|
+ optarg = NULL;
|
|
|
nextchar = NULL;
|
|
|
}
|
|
|
else {
|
|
|
/* This is an option that requires an argument. */
|
|
|
if (*nextchar != '\0') {
|
|
|
- getopt_optarg = nextchar;
|
|
|
+ optarg = nextchar;
|
|
|
/* If we end this ARGV-element by taking the rest as an arg,
|
|
|
we must advance to the next element now. */
|
|
|
- getopt_optind++;
|
|
|
+ optind++;
|
|
|
}
|
|
|
- else if (getopt_optind == argc) {
|
|
|
+ else if (optind == argc) {
|
|
|
if (print_errors) {
|
|
|
/* 1003.2 specifies the format of this message. */
|
|
|
fprintf(stderr,
|
|
@@ -886,9 +886,9 @@ argv[0], pfound->name);
|
|
|
c = '?';
|
|
|
}
|
|
|
else
|
|
|
- /* We already incremented `getopt_optind' once;
|
|
|
+ /* We already incremented `optind' once;
|
|
|
increment it again when taking next ARGV-elt as argument. */
|
|
|
- getopt_optarg = argv[getopt_optind++];
|
|
|
+ optarg = argv[optind++];
|
|
|
nextchar = NULL;
|
|
|
}
|
|
|
}
|
|
@@ -932,7 +932,7 @@ char** argv;
|
|
|
int digit_optind = 0;
|
|
|
|
|
|
while (1) {
|
|
|
- int this_option_optind = getopt_optind ? getopt_optind : 1;
|
|
|
+ int this_option_optind = optind ? optind : 1;
|
|
|
|
|
|
c = getopt(argc, argv, "abc:d:0123456789");
|
|
|
if (c == -1)
|
|
@@ -964,7 +964,7 @@ char** argv;
|
|
|
break;
|
|
|
|
|
|
case 'c':
|
|
|
- printf("option c with value '%s'\n", getopt_optarg);
|
|
|
+ printf("option c with value '%s'\n", optarg);
|
|
|
break;
|
|
|
|
|
|
case '?':
|
|
@@ -975,10 +975,10 @@ char** argv;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (getopt_optind < argc) {
|
|
|
+ if (optind < argc) {
|
|
|
printf("non-option ARGV-elements: ");
|
|
|
- while (getopt_optind < argc)
|
|
|
- printf("%s ", argv[getopt_optind++]);
|
|
|
+ while (optind < argc)
|
|
|
+ printf("%s ", argv[optind++]);
|
|
|
printf("\n");
|
|
|
}
|
|
|
|