Imported from ../bash-2.05b.tar.gz.
[platform/upstream/bash.git] / builtins / getopt.c
index 6ea3401..60c6188 100644 (file)
@@ -75,7 +75,7 @@ int sh_opterr = 1;
 
 int sh_optopt = '?';
 
-/* Set to 1 when we see an illegal option; public so getopts can reset it. */
+/* Set to 1 when we see an invalid option; public so getopts can reset it. */
 int sh_badopt = 0;
 
 /* Scan elements of ARGV (whose length is ARGC) for option characters
@@ -135,15 +135,6 @@ sh_getopt (argc, argv, optstring)
       nextchar = (char *)NULL;
     }
 
-  /* Do the increment of `sh_optind' we deferred because the last option
-     was illegal.  */
-  if (sh_badopt && (nextchar == 0 || *nextchar == '\0'))
-    {
-      sh_badopt = 0;
-      sh_optind++;
-      nextchar = (char *)NULL;
-    }
-
   if (nextchar == 0 || *nextchar == '\0')
     {
       /* If we have done all the ARGV-elements, stop the scan. */
@@ -179,8 +170,13 @@ sh_getopt (argc, argv, optstring)
 
   sh_optopt = c;
 
-  /* If the option is illegal, return an error, but defer updating sh_optind
-     until the next call so $OPTIND is correct. */
+  /* Increment `sh_optind' when we start to process its last character.  */
+  if (nextchar == 0 || *nextchar == '\0')
+    {
+      sh_optind++;
+      nextchar = (char *)NULL;
+    }
+
   if (sh_badopt = (temp == NULL || c == ':'))
     {
       if (sh_opterr)
@@ -189,13 +185,6 @@ sh_getopt (argc, argv, optstring)
       return '?';
     }
 
-  /* Increment `sh_optind' when we start to process its last character.  */
-  if (nextchar == 0 || *nextchar == '\0')
-    {
-      sh_optind++;
-      nextchar = (char *)NULL;
-    }
-
   if (temp[1] == ':')
     {
       if (nextchar && *nextchar)