diff Python/getopt.c @ 80503:d2df83d7c649 2.7

#16306: Fix multiple error messages when unknown command line parameters where passed to the interpreter. Patch by Hieu Nguyen.
author Ezio Melotti <ezio.melotti@gmail.com>
date Sun, 18 Nov 2012 13:46:38 +0200
parents 0abffbe7cf22
children 6a79e3beb854
line wrap: on
line diff
--- a/Python/getopt.c	Sun Nov 18 13:18:06 2012 +0200
+++ b/Python/getopt.c	Sun Nov 18 13:46:38 2012 +0200
@@ -41,7 +41,7 @@
 
 void _PyOS_ResetGetOpt(void)
 {
-    _PyOS_opterr = 1;
+    _PyOS_opterr = 0;   /* prevent printing the error in 2nd loop in main.c */
     _PyOS_optind = 1;
     _PyOS_optarg = NULL;
     opt_ptr = "";
@@ -86,17 +86,19 @@
         opt_ptr = &argv[_PyOS_optind++][1];
     }
 
-    if ( (option = *opt_ptr++) == '\0')
+    if ((option = *opt_ptr++) == '\0')
         return -1;
 
     if (option == 'J') {
-        fprintf(stderr, "-J is reserved for Jython\n");
+        if (_PyOS_opterr)
+            fprintf(stderr, "-J is reserved for Jython\n");
         return '_';
     }
 
     if (option == 'X') {
-        fprintf(stderr,
-          "-X is reserved for implementation-specific arguments\n");
+        if (_PyOS_opterr)
+            fprintf(stderr,
+                "-X is reserved for implementation-specific arguments\n");
         return '_';
     }
 
@@ -117,7 +119,7 @@
             if (_PyOS_optind >= argc) {
                 if (_PyOS_opterr)
                     fprintf(stderr,
-                "Argument expected for the -%c option\n", option);
+                        "Argument expected for the -%c option\n", option);
                 return '_';
             }