Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 80499:8feaa8d04c56 | 80503:d2df83d7c649 |
|---|---|
| 39 char *_PyOS_optarg = NULL; /* optional argument */ | 39 char *_PyOS_optarg = NULL; /* optional argument */ |
| 40 static char *opt_ptr = ""; | 40 static char *opt_ptr = ""; |
| 41 | 41 |
| 42 void _PyOS_ResetGetOpt(void) | 42 void _PyOS_ResetGetOpt(void) |
| 43 { | 43 { |
| 44 _PyOS_opterr = 1; | 44 _PyOS_opterr = 0; /* prevent printing the error in 2nd loop in main.c */ |
| 45 _PyOS_optind = 1; | 45 _PyOS_optind = 1; |
| 46 _PyOS_optarg = NULL; | 46 _PyOS_optarg = NULL; |
| 47 opt_ptr = ""; | 47 opt_ptr = ""; |
| 48 } | 48 } |
| 49 | 49 |
| 84 | 84 |
| 85 | 85 |
| 86 opt_ptr = &argv[_PyOS_optind++][1]; | 86 opt_ptr = &argv[_PyOS_optind++][1]; |
| 87 } | 87 } |
| 88 | 88 |
| 89 if ( (option = *opt_ptr++) == '\0') | 89 if ((option = *opt_ptr++) == '\0') |
| 90 return -1; | 90 return -1; |
| 91 | 91 |
| 92 if (option == 'J') { | 92 if (option == 'J') { |
| 93 fprintf(stderr, "-J is reserved for Jython\n"); | 93 if (_PyOS_opterr) |
| 94 fprintf(stderr, "-J is reserved for Jython\n"); | |
| 94 return '_'; | 95 return '_'; |
| 95 } | 96 } |
| 96 | 97 |
| 97 if (option == 'X') { | 98 if (option == 'X') { |
| 98 fprintf(stderr, | 99 if (_PyOS_opterr) |
| 99 "-X is reserved for implementation-specific arguments\n"); | 100 fprintf(stderr, |
| 101 "-X is reserved for implementation-specific arguments\n"); | |
| 100 return '_'; | 102 return '_'; |
| 101 } | 103 } |
| 102 | 104 |
| 103 if ((ptr = strchr(optstring, option)) == NULL) { | 105 if ((ptr = strchr(optstring, option)) == NULL) { |
| 104 if (_PyOS_opterr) | 106 if (_PyOS_opterr) |
| 115 | 117 |
| 116 else { | 118 else { |
| 117 if (_PyOS_optind >= argc) { | 119 if (_PyOS_optind >= argc) { |
| 118 if (_PyOS_opterr) | 120 if (_PyOS_opterr) |
| 119 fprintf(stderr, | 121 fprintf(stderr, |
| 120 "Argument expected for the -%c option\n", option); | 122 "Argument expected for the -%c option\n", option); |
| 121 return '_'; | 123 return '_'; |
| 122 } | 124 } |
| 123 | 125 |
| 124 _PyOS_optarg = argv[_PyOS_optind++]; | 126 _PyOS_optarg = argv[_PyOS_optind++]; |
| 125 } | 127 } |
