|
17 | 17 | #define PYTHONHOMEHELP "<prefix>/python2.0" |
18 | 18 | #endif |
19 | 19 |
|
| 20 | +#include "pygetopt.h" |
| 21 | + |
20 | 22 | #define COPYRIGHT \ |
21 | 23 | "Type \"copyright\", \"credits\" or \"license\" for more information." |
22 | 24 |
|
23 | | -/* Interface to getopt(): */ |
24 | | -extern int optind; |
25 | | -extern char *optarg; |
26 | | -extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */ |
27 | | - |
28 | | - |
29 | 25 | /* For Py_GetArgcArgv(); set by main() */ |
30 | 26 | static char **orig_argv; |
31 | 27 | static int orig_argc; |
@@ -105,16 +101,16 @@ Py_Main(int argc, char **argv) |
105 | 101 | if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
106 | 102 | unbuffered = 1; |
107 | 103 |
|
108 | | - while ((c = getopt(argc, argv, "c:diOStuUvxXhV")) != EOF) { |
| 104 | + while ((c = _PyOS_GetOpt(argc, argv, "c:diOStuUvxXhV")) != EOF) { |
109 | 105 | if (c == 'c') { |
110 | 106 | /* -c is the last option; following arguments |
111 | 107 | that look like options are left for the |
112 | 108 | the command to interpret. */ |
113 | | - command = malloc(strlen(optarg) + 2); |
| 109 | + command = malloc(strlen(_PyOS_optarg) + 2); |
114 | 110 | if (command == NULL) |
115 | 111 | Py_FatalError( |
116 | 112 | "not enough memory to copy -c argument"); |
117 | | - strcpy(command, optarg); |
| 113 | + strcpy(command, _PyOS_optarg); |
118 | 114 | strcat(command, "\n"); |
119 | 115 | break; |
120 | 116 | } |
@@ -181,10 +177,10 @@ Py_Main(int argc, char **argv) |
181 | 177 | exit(0); |
182 | 178 | } |
183 | 179 |
|
184 | | - if (command == NULL && optind < argc && |
185 | | - strcmp(argv[optind], "-") != 0) |
| 180 | + if (command == NULL && _PyOS_optind < argc && |
| 181 | + strcmp(argv[_PyOS_optind], "-") != 0) |
186 | 182 | { |
187 | | - filename = argv[optind]; |
| 183 | + filename = argv[_PyOS_optind]; |
188 | 184 | if (filename != NULL) { |
189 | 185 | if ((fp = fopen(filename, "r")) == NULL) { |
190 | 186 | fprintf(stderr, "%s: can't open file '%s'\n", |
@@ -253,12 +249,12 @@ Py_Main(int argc, char **argv) |
253 | 249 |
|
254 | 250 |
|
255 | 251 | if (command != NULL) { |
256 | | - /* Backup optind and force sys.argv[0] = '-c' */ |
257 | | - optind--; |
258 | | - argv[optind] = "-c"; |
| 252 | + /* Backup _PyOS_optind and force sys.argv[0] = '-c' */ |
| 253 | + _PyOS_optind--; |
| 254 | + argv[_PyOS_optind] = "-c"; |
259 | 255 | } |
260 | 256 |
|
261 | | - PySys_SetArgv(argc-optind, argv+optind); |
| 257 | + PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind); |
262 | 258 |
|
263 | 259 | if ((inspect || (command == NULL && filename == NULL)) && |
264 | 260 | isatty(fileno(stdin))) { |
|
0 commit comments