static const char *\r
__getopt_initialize (const char *optstring)\r
{\r
- /* Start processing options with ARGV-element 1 (since ARGV-element 0\r
- is the program name); the sequence of previously skipped\r
- non-option ARGV-elements is empty. */\r
- \r
first_nonopt = last_nonopt = optind = 1;\r
nextchar = NULL;\r
\r
- /* Determine how to handle the ordering of options and nonoptions. */\r
- \r
if (optstring[0] == '-')\r
{\r
ordering = RETURN_IN_ORDER;\r
++optstring;\r
}\r
- /* si la chaîne d'options commence par un + alors la fonction getopt() s'arrête\r
- * dès qu'un argument de la ligne de commande n'est pas une option\r
+ \r
+ /* if the optstring begining with the character +, the getopt() function\r
+ * stop when an argument of the command line is not an option.\r
*/\r
else if (optstring[0] == '+')\r
{\r
\r
if (nextchar == NULL || *nextchar == '\0')\r
{\r
- /* Advance to the next ARGV-element. */\r
- \r
if (ordering == PERMUTE)\r
{\r
- /* If we have just processed some options following some non-options,\r
- __exchange them so that the options come first. */\r
- \r
if (first_nonopt != last_nonopt && last_nonopt != optind)\r
__exchange ((char **) argv);\r
else if (last_nonopt != optind)\r
first_nonopt = optind;\r
\r
- /* Skip any additional non-options\r
- and extend the range of non-options previously skipped. */\r
+ \r
\r
while (optind < argc && (argv[optind][0] != '-' || argv[optind][1] == '\0'))\r
optind++;\r
\r
last_nonopt = optind;\r
}\r
- \r
- /* The special ARGV-element `--' means premature end of options.\r
- Skip it like a null option,\r
- then __exchange with previous non-options as if it were an option,\r
- then skip everything else like a non-option. */\r
+\r
\r
if (optind != argc && !strcmp (argv[optind], "--"))\r
{\r
optind = argc;\r
}\r
\r
- /* If we have done all the ARGV-elements, stop the scan\r
- and back over any non-options that we skipped and permuted. */\r
- \r
if (optind == argc)\r
{\r
- /* Set the next-arg-index to point at the non-options\r
- that we previously skipped, so the caller will digest them. */\r
if (first_nonopt != last_nonopt)\r
optind = first_nonopt;\r
\r
return EOF;\r
}\r
\r
- /* If we have come to a non-option and did not permute it,\r
- either stop the scan or describe it to the caller and pass it by. */\r
- \r
if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))\r
{\r
if (ordering == REQUIRE_ORDER)\r
return 1;\r
}\r
\r
- /* We have found another option-ARGV-element.\r
- Skip the initial punctuation. */\r
- \r
nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));\r
}\r
\r
- /* Decode the current option-ARGV-element. */\r
- \r
- /* Check whether the ARGV-element is a long option.\r
- \r
- If long_only and the ARGV-element has the form "-f", where f is\r
- a valid short option, don't consider it an abbreviated form of\r
- a long option that starts with f. Otherwise there would be no\r
- way to give the -f short option.\r
- \r
- On the other hand, if there's a long option "fubar" and\r
- the ARGV-element is "-fu", do consider that an abbreviation of\r
- the long option, just like "--fu", and not "-f" with arg "u".\r
- \r
- This distinction seems to be the most useful approach. */\r
- \r
if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !strchr (optstring, argv[optind][1])))))\r
{\r
char *nameend;\r
int option_index;\r
\r
for (nameend = nextchar; *nameend !='\0' && *nameend != '='; nameend++)\r
- /* Do nothing. */ ;\r
- \r
- /* Test all long options for either exact match\r
- or abbreviated matches. */\r
+ \r
for (p = longopts, option_index = 0; p->name; p++, option_index++)\r
{\r
if(!strncmp (p->name, nextchar, nameend - nextchar))\r
{\r
\r
- if (nameend - nextchar == strlen (p->name))\r
+ if ((nameend - nextchar) == strlen (p->name))\r
{\r
- /* Exact match found. */\r
pfound = p;\r
indfound = option_index;\r
exact = 1;\r
}\r
else if (pfound == NULL)\r
{\r
- /* First nonexact match found. */\r
exact = 0;\r
- /* begin change\r
- pfound = p;\r
- indfound = option_index;\r
- end change */\r
break;\r
}\r
else\r
- {\r
-\r
- /* Second or later nonexact match found. */\r
ambig = 1;\r
- }\r
+ \r
}\r
}\r
\r
if (ambig && !exact)\r
{\r
if (opterr)\r
- fprintf (stderr, "error : %s: option `%s' is ambiguous\n",argv[0], argv[optind]);\r
+ fprintf (stderr, "ERROR : %s: option `%s' is ambiguous\n",argv[0], argv[optind]);\r
\r
nextchar += strlen (nextchar);\r
optind++;\r
\r
if (*nameend)\r
{\r
- /* Don't test has_arg with >, because some C compilers don't\r
- allow it to be used on enums. */\r
if (pfound->has_arg)\r
optarg = nameend + 1;\r
else\r
return pfound->val;\r
}\r
\r
- /* Can't find it as a long option. If this is not getopt_long_only,\r
- or the option starts with '--' or is not a valid short\r
- option, then it's an error.\r
- Otherwise interpret it as a short option. */\r
if (!long_only || argv[optind][1] == '-'|| strchr (optstring, *nextchar) == NULL)\r
{\r
if (opterr)\r
}\r
}\r
\r
- /* Look at and handle the next short option-character. */\r
- \r
{\r
char c = *nextchar++;\r
char *temp = strchr (optstring, c);\r
{\r
if (temp[2] == ':')\r
{\r
- /* This is an option that accepts an argument optionally. */\r
+ /* it's an option that accepts an argument optionally. */\r
if (*nextchar != '\0')\r
{\r
optarg = nextchar;\r
}\r
else\r
{\r
- /* This is an option that requires an argument. */\r
+ /* it's an option that requires an argument. */\r
if (*nextchar != '\0')\r
{\r
optarg = nextchar;\r
- /* If we end this ARGV-element by taking the rest as an arg,\r
- we must advance to the next element now. */\r
optind++;\r
}\r
else if (optind == argc)\r
if (opterr)\r
{\r
/* 1003.2 specifies the format of this message. */\r
- fprintf (stderr, "error : %s: option requires an argument -- %c\n",argv[0], c);\r
+ fprintf (stderr, "ERROR : %s: option requires an argument -- %c\n",argv[0], c);\r
}\r
optopt = c;\r
\r
c = '?';\r
}\r
else\r
- /* We already incremented `optind' once;\r
- increment it again when taking next ARGV-elt as argument. */\r
optarg = argv[optind++];\r
\r
nextchar = NULL;\r
int top = optind;\r
char *tem;\r
\r
- /* Exchange the shorter segment with the far end of the longer segment.\r
- That puts the shorter segment into the right place.\r
- It leaves the longer segment in the right place overall,\r
- but it consists of two parts that need to be swapped next. */\r
- \r
while (top > middle && middle > bottom)\r
{\r
if (top - middle > middle - bottom)\r
{\r
- /* Bottom segment is the short one. */\r
int len = middle - bottom;\r
register int i;\r
\r
- /* Swap it with the top part of the top segment. */\r
for (i = 0; i < len; i++)\r
{\r
tem = argv[bottom + i];\r
argv[bottom + i] = argv[top - (middle - bottom) + i];\r
argv[top - (middle - bottom) + i] = tem;\r
}\r
- /* Exclude the moved bottom segment from further swapping. */\r
\r
top -= len;\r
}\r
else\r
{\r
- /* Top segment is the short one. */\r
int len = top - middle;\r
register int i;\r
\r
- /* Swap it with the bottom part of the bottom segment. */\r
for (i = 0; i < len; i++)\r
{\r
tem = argv[bottom + i];\r
argv[bottom + i] = argv[middle + i];\r
argv[middle + i] = tem;\r
}\r
- /* Exclude the moved top segment from further swapping. */\r
+\r
bottom += len;\r
}\r
}\r
\r
- /* Update records for the slots the non-options now occupy. */\r
\r
first_nonopt += (optind - last_nonopt);\r
last_nonopt = optind;\r