summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-07-19 19:20:32 (GMT)
committerGuido van Rossum <guido@python.org>1997-07-19 19:20:32 (GMT)
commited52aacb33623ac2e3d768ee3fcc205c6bd9046f (patch)
tree2634b3d8a05bad7821a26a5d2a41aa1e92792f40
parentad6dfda9afa3459eb802618c07969f6a1a0a1287 (diff)
downloadcpython-ed52aacb33623ac2e3d768ee3fcc205c6bd9046f.zip
cpython-ed52aacb33623ac2e3d768ee3fcc205c6bd9046f.tar.gz
cpython-ed52aacb33623ac2e3d768ee3fcc205c6bd9046f.tar.bz2
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.
-rw-r--r--Modules/main.c37
1 files changed, 7 insertions, 30 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 5c631d0..801804b 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -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. */