]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - builtins/getopts.def
Bash-4.4 patch 11
[thirdparty/bash.git] / builtins / getopts.def
index 1d2a68a44304303b7c2b86d5640e859c3d507511..590b110357732e427c8c1dda3d1cc29bc65f19fe 100644 (file)
@@ -1,7 +1,7 @@
 This file is getopts.def, from which is created getopts.c.
 It implements the builtin "getopts" in Bash.
 
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -74,6 +74,7 @@ $END
 #endif
 
 #include "../bashansi.h"
+#include "../bashintl.h"
 
 #include "../shell.h"
 #include "common.h"
@@ -86,6 +87,7 @@ $END
 
 extern char *this_command_name;
 
+static int getopts_unbind_variable __P((char *));
 static int getopts_bind_variable __P((char *, char *));
 static int dogetopts __P((int, char **));
 
@@ -99,6 +101,17 @@ getopts_reset (newind)
   sh_badopt = 0;
 }
 
+static int
+getopts_unbind_variable (name)
+     char *name;
+{
+#if 0
+  return (unbind_variable (name));
+#else
+  return (unbind_variable_noref (name));
+#endif
+}
+
 static int
 getopts_bind_variable (name, value)
      char *name, *value;
@@ -253,7 +266,7 @@ dogetopts (argc, argv)
            
   if (ret == G_EOF)
     {
-      unbind_variable ("OPTARG");
+      getopts_unbind_variable ("OPTARG");
       getopts_bind_variable (name, "?");
       return (EXECUTION_FAILURE);
     }
@@ -270,7 +283,7 @@ dogetopts (argc, argv)
          bind_variable ("OPTARG", strval, 0);
        }
       else
-       unbind_variable ("OPTARG");
+       getopts_unbind_variable ("OPTARG");
 
       return (ret);
     }
@@ -289,7 +302,7 @@ dogetopts (argc, argv)
       else
        {
          ret = getopts_bind_variable (name, "?");
-         unbind_variable ("OPTARG");
+         getopts_unbind_variable ("OPTARG");
        }
       return (ret);
     }                  
@@ -316,9 +329,12 @@ getopts_builtin (list)
     }
 
   reset_internal_getopt ();
-  if (internal_getopt (list, "") != -1)
+  if ((ret = internal_getopt (list, "")) != -1)
     {
-      builtin_usage ();
+      if (ret == GETOPT_HELP)
+       builtin_help ();
+      else
+       builtin_usage ();
       return (EX_USAGE);
     }
   list = loptend;