Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI...
[simgrid.git] / tools / tesh2 / w32 / src / getopt.c
index 4525144..0a1c4a5 100644 (file)
 #include <string.h>\r
 \r
 #include <getopt.h>\r
-\r
-char* \r
-optarg = NULL;\r
-\r
-int \r
-optind = 0;\r
-\r
-int \r
-optopt = '?';\r
-\r
-int \r
-opterr = 1;\r
-\r
-static char*\r
-nextchar;\r
-\r
-static \r
-int first_nonopt;\r
-\r
-static int \r
-last_nonopt;\r
-\r
-\r
-static enum\r
-{\r
-       REQUIRE_ORDER, \r
-       PERMUTE, \r
-       RETURN_IN_ORDER\r
-}ordering;\r
-\r
-\r
-static const char *\r
-__getopt_initialize (const char *optstring);\r
-\r
-static int\r
-__getopt_internal (int argc, char *const *argv, const char* optstring, const struct option *longopts, int* longind, int long_only);\r
-\r
-static void\r
-__exchange (char **argv);\r
-\r
-int \r
-getopt (int argc, char * const argv[], const char *optstring)\r
-{\r
-       return __getopt_internal(argc, argv, optstring,(const struct option *) 0,(int *) 0,0);\r
-}\r
-\r
-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
-       else if (optstring[0] == '+')\r
-       {\r
-               ordering = REQUIRE_ORDER;\r
-               ++optstring;\r
-       }\r
-       else\r
-       {\r
-               ordering = PERMUTE;\r
-       }\r
-       \r
-       return optstring;\r
-}\r
-\r
-int\r
-__getopt_internal (int argc, char *const *argv, const char* optstring, const struct option *longopts, int* longind, int long_only)\r
-{\r
-       optarg = NULL;\r
-       \r
-       if (optind == 0)\r
-               optstring = __getopt_initialize (optstring);\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
-                       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
-               if (optind != argc && !strcmp (argv[optind], "--"))\r
-               {\r
-                       optind++;\r
-       \r
-                       if (first_nonopt != last_nonopt && last_nonopt != optind)\r
-                               __exchange ((char **) argv);\r
-                       else if (first_nonopt == last_nonopt)\r
-                               first_nonopt = optind;\r
-                       \r
-                       last_nonopt = argc;\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 EOF;\r
-                       optarg = argv[optind++];\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
-               const struct option *p;\r
-               const struct option *pfound = NULL;\r
-               int exact = 0;\r
-               int ambig = 0;\r
-               int indfound = 0;\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
-               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
-                               {\r
-                                       /* Exact match found.  */\r
-                                       pfound = p;\r
-                                       indfound = option_index;\r
-                                       exact = 1;\r
-                                       break;\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
-               if (ambig && !exact)\r
-               {\r
-                       if (opterr)\r
-                               fprintf (stderr, "error   : %s: option `%s' is ambiguous\n",argv[0], argv[optind]);\r
-                       \r
-                       nextchar += strlen (nextchar);\r
-                       optind++;\r
-                       return '?';\r
-               }\r
-       \r
-               if (pfound != NULL)\r
-               {\r
-                       option_index = indfound;\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
-                               {\r
-                                       if (opterr)\r
-                                       {\r
-                                               if (argv[optind - 1][1] == '-')\r
-                                                       /* --option */\r
-                                                       fprintf (stderr,"error   : %s: option `--%s' doesn't allow an argument\n",argv[0], pfound->name);\r
-                                               else\r
-                                                       /* +option or -option */\r
-                                                       fprintf (stderr,"error   : %s: option `%c%s' doesn't allow an argument\n",argv[0], argv[optind - 1][0], pfound->name);\r
-                                       }\r
-                                       \r
-                                       nextchar += strlen (nextchar);\r
-                                       return '?';\r
-                               }\r
-                       }\r
-                       else if (pfound->has_arg == 1)\r
-                       {\r
-                               if (optind < argc)\r
-                                       optarg = argv[optind++];\r
-                               else\r
-                               {\r
-                                       if (opterr)\r
-                                               fprintf (stderr, "error   : %s: option `%s' requires an argument\n",argv[0], argv[optind - 1]);\r
-                                       \r
-                                       nextchar += strlen (nextchar);\r
-                                       return optstring[0] == ':' ? ':' : '?';\r
-                               }\r
-                       }\r
-                       \r
-                       nextchar += strlen (nextchar);\r
-                       \r
-                       if (longind != NULL)\r
-                               *longind = option_index;\r
-                       \r
-                       if (pfound->flag)\r
-                       {\r
-                               *(pfound->flag) = pfound->val;\r
-                               return 0;\r
-                       }\r
-                       \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
-                               if (argv[optind][1] == '-')\r
-                                       /* --option */\r
-                                       fprintf (stderr, "error   : %s: unrecognized option `--%s'\n",argv[0], nextchar);\r
-                               else\r
-                                       /* +option or -option */\r
-                                       fprintf (stderr, "error   : %s: unrecognized option `%c%s'\n",argv[0], argv[optind][0], nextchar);\r
-                       }\r
-                       \r
-                       nextchar = (char *) "";\r
-                       optind++;\r
-                       return '?';\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
-               /* Increment `optind' when we start to process its last character.  */\r
-               if (*nextchar == '\0')\r
-                       ++optind;\r
-       \r
-               if (temp == NULL || c == ':')\r
-               {\r
-                       if (opterr)\r
-                                       fprintf (stderr, "error   : %s: invalid option -- %c\n", argv[0], c);\r
-                       \r
-                       optopt = c;\r
-                       return '?';\r
-               }\r
-               \r
-               if (temp[1] == ':')\r
-               {\r
-                       if (temp[2] == ':')\r
-                       {\r
-                               /* This is an option that accepts an argument optionally.  */\r
-                               if (*nextchar != '\0')\r
-                               {\r
-                                       optarg = nextchar;\r
-                                       optind++;\r
-                               }\r
-                               else\r
-                                       optarg = NULL;\r
-                               \r
-                               nextchar = NULL;\r
-                       }\r
-                       else\r
-                       {\r
-                               /* This is 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
-                               {\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
-                                       }\r
-                                       optopt = c;\r
-                                       \r
-                                       if (optstring[0] == ':')\r
-                                               c = ':';\r
-                                       else\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
-                       }\r
-               }\r
-       return c;\r
-       \r
-       }\r
-}\r
-\r
-\r
-static void\r
-__exchange (char **argv)\r
-{\r
-       int bottom = first_nonopt;\r
-       int middle = last_nonopt;\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
-                       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
-}\r
-\r
-int\r
-getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index)\r
-{\r
-       return __getopt_internal (argc, argv, options, long_options, opt_index, 0);\r
-}\r
-\r
-\r
-int\r
-getopt_long_only(int argc, char *const *argv, const char *options, const struct option *long_options,int *opt_index)\r
-{\r
-       return __getopt_internal (argc, argv, options, long_options, opt_index, 1);\r
-}\r
-\r
-\r
+\rchar *\r optarg = NULL;
+\r\rint \r optind = 0;
+\r\rint \r optopt = '?';
+\r\rint \r opterr = 1;
+\r\rstatic char *\r nextchar;
+\r\rstatic \r int first_nonopt;
+\r\rstatic int \r last_nonopt;
+\r\r\rstatic enum \r { \rREQUIRE_ORDER, \rPERMUTE, \rRETURN_IN_ORDER \r
+} ordering;
+\r\r\rstatic const char *\r __getopt_initialize(const char *optstring);
+\r\rstatic int \r
+__getopt_internal(int argc, char *const *argv, const char *optstring,
+                  const struct option *longopts, int *longind,
+                  int long_only);
+\r\rstatic void \r __exchange(char **argv);
+\r\rint \r getopt(int argc, char *const argv[], const char *optstring) \r
+{
+  \rreturn __getopt_internal(argc, argv, optstring,
+                            (const struct option *) 0, (int *) 0, 0);
+\r\r\rstatic 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
+      \rfirst_nonopt = last_nonopt = optind = 1;
+  \rnextchar = NULL;
+  \r\r
+      /* Determine how to handle the ordering of options and nonoptions.  */ \r
+      \rif (optstring[0] == '-')
+    \r {
+    \rordering = 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
+      else if (optstring[0] == '+')
+    \r {
+    \rordering = REQUIRE_ORDER;
+    \r++optstring;
+    \r}
+  \r
+  else
+    \r {
+    \rordering = PERMUTE;
+    \r}
+  \r\rreturn optstring;
+\r}
+
+\r\rint \r
+__getopt_internal(int argc, char *const *argv, const char *optstring,
+                  const struct option *longopts, int *longind,
+                  int long_only) \r
+{
+  \roptarg = NULL;
+  \r\rif (optind == 0)
+    \roptstring = __getopt_initialize(optstring);
+  \r\rif (nextchar == NULL || *nextchar == '\0')
+    \r {
+    \r
+        /* Advance to the next ARGV-element.  */ \r
+        \rif (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
+          \rif (first_nonopt != last_nonopt && last_nonopt != optind)
+        \r__exchange((char **) argv);
+      \r
+      else if (last_nonopt != optind)
+        \rfirst_nonopt = optind;
+      \r\r
+          /* Skip any additional non-options\r
+             and extend the range of non-options previously skipped.  */ \r
+          \rwhile (optind < argc
+                  && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
+        \roptind++;
+      \r\rlast_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
+        \rif (optind != argc && !strcmp(argv[optind], "--"))
+      \r {
+      \roptind++;
+      \r\rif (first_nonopt != last_nonopt && last_nonopt != optind)
+        \r__exchange((char **) argv);
+      \r
+      else if (first_nonopt == last_nonopt)
+        \rfirst_nonopt = optind;
+      \r\rlast_nonopt = argc;
+      \r\roptind = 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
+        \rif (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)
+        \roptind = first_nonopt;
+      \r\rreturn 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
+        \rif ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
+      \r {
+      \rif (ordering == REQUIRE_ORDER)
+        \rreturn EOF;
+      \roptarg = argv[optind++];
+      \rreturn 1;
+      \r}
+    \r\r
+        /* We have found another option-ARGV-element.\r
+           Skip the initial punctuation.  */ \r
+        \rnextchar =
+        (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
+      \rif (longopts != NULL
+           && (argv[optind][1] == '-'
+               || (long_only
+                   && (argv[optind][2]
+                       || !strchr(optstring, argv[optind][1])))))
+    \r {
+    \rchar *nameend;
+    \rconst struct option *p;
+    \rconst struct option *pfound = NULL;
+    \rint exact = 0;
+    \rint ambig = 0;
+    \rint indfound = 0;
+    \rint option_index;
+    \r\rfor (nameend = nextchar; *nameend != '\0' && *nameend != '=';
+           nameend++)
+      \r
+          /* Do nothing.  */ ;
+    \r\r
+        /* Test all long options for either exact match\r
+           or abbreviated matches.  */ \r
+        for (p = longopts, option_index = 0; p->name; p++, option_index++)
+      \r {
+      \rif (!strncmp(p->name, nextchar, nameend - nextchar))
+        \r {
+        \r\rif (nameend - nextchar == strlen(p->name))
+          \r {
+          \r
+              /* Exact match found.  */ \r
+              pfound = p;
+          \rindfound = option_index;
+          \rexact = 1;
+          \rbreak;
+          \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\rif (ambig && !exact)
+      \r {
+      \rif (opterr)
+        \rfprintf(stderr, "error   : %s: option `%s' is ambiguous\n",
+                 argv[0], argv[optind]);
+      \r\rnextchar += strlen(nextchar);
+      \roptind++;
+      \rreturn '?';
+      \r}
+    \r\rif (pfound != NULL)
+      \r {
+      \roption_index = indfound;
+      \roptind++;
+      \r\rif (*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)
+          \roptarg = nameend + 1;
+        \r
+        else
+          \r {
+          \rif (opterr)
+            \r {
+            \rif (argv[optind - 1][1] == '-')
+              \r
+                  /* --option */ \r
+                  fprintf(stderr,
+                          "error   : %s: option `--%s' doesn't allow an argument\n",
+                          argv[0], pfound->name);
+            \r
+            else
+              \r
+                  /* +option or -option */ \r
+                  fprintf(stderr,
+                          "error   : %s: option `%c%s' doesn't allow an argument\n",
+                          argv[0], argv[optind - 1][0], pfound->name);
+            \r}
+          \r\rnextchar += strlen(nextchar);
+          \rreturn '?';
+          \r}
+        \r}
+      \r
+      else if (pfound->has_arg == 1)
+        \r {
+        \rif (optind < argc)
+          \roptarg = argv[optind++];
+        \r
+        else
+          \r {
+          \rif (opterr)
+            \rfprintf(stderr,
+                     "error   : %s: option `%s' requires an argument\n",
+                     argv[0], argv[optind - 1]);
+          \r\rnextchar += strlen(nextchar);
+          \rreturn optstring[0] == ':' ? ':' : '?';
+          \r}
+        \r}
+      \r\rnextchar += strlen(nextchar);
+      \r\rif (longind != NULL)
+        \r*longind = option_index;
+      \r\rif (pfound->flag)
+        \r {
+        \r*(pfound->flag) = pfound->val;
+        \rreturn 0;
+        \r}
+      \r\rreturn 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 {
+      \rif (opterr)
+        \r {
+        \rif (argv[optind][1] == '-')
+          \r
+              /* --option */ \r
+              fprintf(stderr, "error   : %s: unrecognized option `--%s'\n",
+                      argv[0], nextchar);
+        \r
+        else
+          \r
+              /* +option or -option */ \r
+              fprintf(stderr, "error   : %s: unrecognized option `%c%s'\n",
+                      argv[0], argv[optind][0], nextchar);
+        \r}
+      \r\rnextchar = (char *) "";
+      \roptind++;
+      \rreturn '?';
+      \r}
+    \r}
+  \r\r
+      /* Look at and handle the next short option-character.  */ \r
+      \r {
+    \rchar c = *nextchar++;
+    \rchar *temp = strchr(optstring, c);
+    \r\r
+        /* Increment `optind' when we start to process its last character.  */ \r
+        if (*nextchar == '\0')
+      \r++optind;
+    \r\rif (temp == NULL || c == ':')
+      \r {
+      \rif (opterr)
+        \rfprintf(stderr, "error   : %s: invalid option -- %c\n", argv[0],
+                 c);
+      \r\roptopt = c;
+      \rreturn '?';
+      \r}
+    \r\rif (temp[1] == ':')
+      \r {
+      \rif (temp[2] == ':')
+        \r {
+        \r
+            /* This is an option that accepts an argument optionally.  */ \r
+            if (*nextchar != '\0')
+          \r {
+          \roptarg = nextchar;
+          \roptind++;
+          \r}
+        \r
+        else
+          \roptarg = NULL;
+        \r\rnextchar = NULL;
+        \r}
+      \r
+      else
+        \r {
+        \r
+            /* This is an option that requires an argument.  */ \r
+            if (*nextchar != '\0')
+          \r {
+          \roptarg = 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 {
+          \rif (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}
+          \roptopt = c;
+          \r\rif (optstring[0] == ':')
+            \rc = ':';
+          \r
+          else
+            \rc = '?';
+          \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\rnextchar = NULL;
+        \r}
+      \r}
+    \rreturn c;
+  \r\r}
+\r}
+
+\r\r\rstatic void \r __exchange(char **argv) \r
+{
+  \rint bottom = first_nonopt;
+  \rint middle = last_nonopt;
+  \rint top = optind;
+  \rchar *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
+      \rwhile (top > middle && middle > bottom)
+    \r {
+    \rif (top - middle > middle - bottom)
+      \r {
+      \r
+          /* Bottom segment is the short one.  */ \r
+      int len = middle - bottom;
+      \rregister int i;
+      \r\r
+          /* Swap it with the top part of the top segment.  */ \r
+          for (i = 0; i < len; i++)
+        \r {
+        \rtem = argv[bottom + i];
+        \rargv[bottom + i] = argv[top - (middle - bottom) + i];
+        \rargv[top - (middle - bottom) + i] = tem;
+        \r}
+      \r
+          /* Exclude the moved bottom segment from further swapping.  */ \r
+          \rtop -= len;
+      \r}
+    \r
+    else
+      \r {
+      \r
+          /* Top segment is the short one.  */ \r
+      int len = top - middle;
+      \rregister int i;
+      \r\r
+          /* Swap it with the bottom part of the bottom segment.  */ \r
+          for (i = 0; i < len; i++)
+        \r {
+        \rtem = argv[bottom + i];
+        \rargv[bottom + i] = argv[middle + i];
+        \rargv[middle + i] = tem;
+        \r}
+      \r
+          /* Exclude the moved top segment from further swapping.  */ \r
+          bottom += len;
+      \r}
+    \r}
+  \r\r
+      /* Update records for the slots the non-options now occupy.  */ \r
+      \rfirst_nonopt += (optind - last_nonopt);
+  \rlast_nonopt = optind;
+\r}
+
+\r\rint \r
+getopt_long(int argc, char *const *argv, const char *options,
+            const struct option *long_options, int *opt_index) \r
+{
+  \rreturn __getopt_internal(argc, argv, options, long_options, opt_index,
+                            0);
+\r}
+
+\r\r\rint \r
+getopt_long_only(int argc, char *const *argv, const char *options,
+                 const struct option *long_options, int *opt_index) \r
+{
+  \rreturn __getopt_internal(argc, argv, options, long_options, opt_index,
+                            1);
+\r}
+
+\r\r\r