mirror of https://github.com/python/cpython
This is no longer the real main program; it now defines Py_Main(), so
it can be placed in the library. Other, related changes: - Moved the inspection of some environment variables to Py_Initialize(). - Got rid of -s option. - Moved Py_GetProgramName() and related logic to pythonrun.c; call Py_SetProgramName() instead. - Print the version header *after* successful initialization.
This commit is contained in:
parent
ad6dfda9af
commit
ed52aacb33
|
@ -53,9 +53,6 @@ extern char *Py_GetPlatform();
|
|||
extern char *Py_GetCopyright();
|
||||
|
||||
|
||||
/* For Py_GetProgramName(); set by main() */
|
||||
static char *argv0;
|
||||
|
||||
/* For Py_GetArgcArgv(); set by main() */
|
||||
static char **orig_argv;
|
||||
static int orig_argc;
|
||||
|
@ -71,8 +68,7 @@ Options and arguments (and corresponding environment variables):\n\
|
|||
-i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
|
||||
and force prompts, even if stdin does not appear to be a terminal.\n\
|
||||
-O : optimize generated bytecode (a tad).\n\
|
||||
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
|
||||
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
|
||||
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
|
||||
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
|
||||
";
|
||||
static char *usage_bot = "\
|
||||
|
@ -93,7 +89,7 @@ PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).\n\
|
|||
/* Main program */
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
Py_Main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
|
@ -109,20 +105,13 @@ main(argc, argv)
|
|||
|
||||
orig_argc = argc; /* For Py_GetArgcArgv() */
|
||||
orig_argv = argv;
|
||||
argv0 = argv[0]; /* For Py_GetProgramName() */
|
||||
|
||||
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
|
||||
Py_DebugFlag = 1;
|
||||
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
|
||||
Py_SuppressPrintingFlag = 1;
|
||||
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
|
||||
Py_VerboseFlag = 1;
|
||||
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
|
||||
inspect = 1;
|
||||
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
|
||||
unbuffered = 1;
|
||||
|
||||
while ((c = getopt(argc, argv, "c:diOsuv")) != EOF) {
|
||||
while ((c = getopt(argc, argv, "c:diOuv")) != EOF) {
|
||||
if (c == 'c') {
|
||||
/* -c is the last option; following arguments
|
||||
that look like options are left for the
|
||||
|
@ -151,10 +140,6 @@ main(argc, argv)
|
|||
Py_OptimizeFlag++;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
Py_SuppressPrintingFlag++;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
unbuffered++;
|
||||
break;
|
||||
|
@ -218,12 +203,14 @@ main(argc, argv)
|
|||
/* Leave stderr alone - it should be unbuffered anyway. */
|
||||
}
|
||||
|
||||
Py_SetProgramName(argv[0]);
|
||||
Py_Initialize();
|
||||
|
||||
if (Py_VerboseFlag ||
|
||||
(command == NULL && filename == NULL && stdin_is_interactive))
|
||||
fprintf(stderr, "Python %s on %s\n%s\n",
|
||||
Py_GetVersion(), Py_GetPlatform(), Py_GetCopyright());
|
||||
|
||||
Py_Initialize();
|
||||
|
||||
if (command != NULL) {
|
||||
/* Backup optind and force sys.argv[0] = '-c' */
|
||||
|
@ -264,16 +251,6 @@ main(argc, argv)
|
|||
}
|
||||
|
||||
|
||||
/* Return the program name -- some code out there needs this
|
||||
(currently _tkinter.c and importdl.c). */
|
||||
|
||||
char *
|
||||
Py_GetProgramName()
|
||||
{
|
||||
return argv0;
|
||||
}
|
||||
|
||||
|
||||
/* Make the *original* argc/argv available to other modules.
|
||||
This is rare, but it is needed by the secureware extension. */
|
||||
|
||||
|
|
Loading…
Reference in New Issue