annotate Modules/main.c @ 16798:258dcafe2d0b legacy-trunk

Gustavo Niemeyer <niemeyer@conectiva.com>: Fixed recno support (keys are integers rather than strings). Work around DB bug that cause stdin to be closed by rnopen() when the DB file needed to exist but did not (no longer segfaults). This closes SF tracker patch #403445. Also wrapped some long lines and added whitespace around operators -- FLD.
author Fred Drake <fdrake@acm.org>
date Tue, 27 Feb 2001 18:56:46 +0000
parents 5c3aedc969da
children 4baa5a955532
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Python interpreter main program */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #include "Python.h"
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
4 #include "osdefs.h"
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
4620
98c08f0c4a2e Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
6 #ifdef HAVE_UNISTD_H
98c08f0c4a2e Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
7 #include <unistd.h>
98c08f0c4a2e Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4600
diff changeset
8 #endif
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
10 #ifdef MS_WINDOWS
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
11 #include <fcntl.h>
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
12 #endif
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
13
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
14 #if defined(PYOS_OS2) || defined(MS_WINDOWS)
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
15 #define PYTHONHOMEHELP "<prefix>\\lib"
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
16 #else
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
17 #define PYTHONHOMEHELP "<prefix>/python2.0"
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
18 #endif
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
19
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
20 #include "pygetopt.h"
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
21
14411
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
22 #define COPYRIGHT \
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
23 "Type \"copyright\", \"credits\" or \"license\" for more information."
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
24
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
25 /* For Py_GetArgcArgv(); set by main() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 static char **orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 static int orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 /* Short usage message (with %s for argv0) */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 static char *usage_line =
9986
d4b8ddd9a4fd Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9601
diff changeset
31 "usage: %s [option] ... [-c cmd | file | -] [arg] ...\n";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 /* Long usage message, split into parts < 512 bytes */
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
34 static char *usage_top = "\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 Options and arguments (and corresponding environment variables):\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 -d : debug output from parser (also PYTHONDEBUG=x)\n\
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
37 -i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
38 and force prompts, even if stdin does not appear to be a terminal\n\
9284
faa31b1c0b54 Documented PYTHONOPTIMIZE; by Marc Lemburg.
Guido van Rossum <guido@python.org>
parents: 8044
diff changeset
39 -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
9986
d4b8ddd9a4fd Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9601
diff changeset
40 -OO : remove doc-strings in addition to the -O optimizations\n\
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
41 -S : don't imply 'import site' on initialization\n\
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
42 -t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
43 ";
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
44 static char *usage_mid = "\
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
45 -u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
46 -U : Unicode literals: treats '...' literals like u'...'\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
48 -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
49 -h : print this help message and exit\n\
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
50 -V : print the Python version number and exit\n\
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
51 -W arg : warning control (arg is action:message:category:module:lineno)\n\
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
52 -c cmd : program passed in as string (terminates option list)\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 file : program read from script file\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 - : program read from stdin (default; interactive mode if a tty)\n\
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
55 ";
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
56 static char *usage_bot = "\
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
57 arg ...: arguments passed to program in sys.argv[1:]\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 Other environment variables:\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 PYTHONSTARTUP: file executed on interactive startup (no default)\n\
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
60 PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 default module search path. The result is sys.path.\n\
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
62 PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
63 The default module search path uses %s.\n\
16731
86c7683b606a Add a line to "python -h" output about PYTHONCASEOK.
Tim Peters <tim.peters@gmail.com>
parents: 15593
diff changeset
64 PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 ";
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
68 static void
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
69 usage(int exitcode, char* program)
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
70 {
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
71 fprintf(stderr, usage_line, program);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
72 fprintf(stderr, usage_top);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
73 fprintf(stderr, usage_mid);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
74 fprintf(stderr, usage_bot, DELIM, DELIM, PYTHONHOMEHELP);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
75 exit(exitcode);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
76 /*NOTREACHED*/
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
77 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
78
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
79
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 /* Main program */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
9601
0f3f9e366356 Py_Main() must be DL_EXPORT too.
Guido van Rossum <guido@python.org>
parents: 9284
diff changeset
82 DL_EXPORT(int)
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
83 Py_Main(int argc, char **argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 int c;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 int sts;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 char *command = NULL;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 char *filename = NULL;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 FILE *fp = stdin;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 char *p;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 int inspect = 0;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 int unbuffered = 0;
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
93 int skipfirstline = 0;
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
94 int stdin_is_interactive = 0;
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
95 int help = 0;
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
96 int version = 0;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
98 orig_argc = argc; /* For Py_GetArgcArgv() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 orig_argv = argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 inspect = 1;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 unbuffered = 1;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
106 PySys_ResetWarnOptions();
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
107
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
108 while ((c = _PyOS_GetOpt(argc, argv, "c:diOStuUvxXhVW:")) != EOF) {
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if (c == 'c') {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 /* -c is the last option; following arguments
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 that look like options are left for the
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 the command to interpret. */
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
113 command = malloc(strlen(_PyOS_optarg) + 2);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 if (command == NULL)
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 Py_FatalError(
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 "not enough memory to copy -c argument");
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
117 strcpy(command, _PyOS_optarg);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 strcat(command, "\n");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 switch (c) {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 case 'd':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 Py_DebugFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 case 'i':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 inspect++;
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
130 Py_InteractiveFlag++;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
5166
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
133 case 'O':
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
134 Py_OptimizeFlag++;
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
135 break;
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
136
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
137 case 'S':
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
138 Py_NoSiteFlag++;
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
139 break;
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
140
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
141 case 't':
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
142 Py_TabcheckFlag++;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
143 break;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
144
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 case 'u':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 unbuffered++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 case 'v':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 Py_VerboseFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
153 case 'x':
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
154 skipfirstline = 1;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
155 break;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
156
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
157 case 'U':
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
158 Py_UnicodeFlag++;
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
159 break;
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
160 case 'h':
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
161 help++;
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
162 break;
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
163 case 'V':
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
164 version++;
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
165 break;
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
166
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
167 case 'W':
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
168 PySys_AddWarnOption(_PyOS_optarg);
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
169 break;
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
170
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 /* This space reserved for other options */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 default:
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
174 usage(2, argv[0]);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 /*NOTREACHED*/
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
180 if (help)
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
181 usage(0, argv[0]);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
182
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
183 if (version) {
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
184 fprintf(stderr, "Python %s\n", PY_VERSION);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
185 exit(0);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
186 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
187
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
188 if (command == NULL && _PyOS_optind < argc &&
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
189 strcmp(argv[_PyOS_optind], "-") != 0)
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
190 {
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
191 filename = argv[_PyOS_optind];
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
192 if (filename != NULL) {
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
193 if ((fp = fopen(filename, "r")) == NULL) {
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
194 fprintf(stderr, "%s: can't open file '%s'\n",
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
195 argv[0], filename);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
196 exit(2);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
197 }
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
198 else if (skipfirstline) {
10621
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
199 int ch;
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
200 /* Push back first newline so line numbers
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
201 remain the same */
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
202 while ((ch = getc(fp)) != EOF) {
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
203 if (ch == '\n') {
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
204 (void)ungetc(ch, fp);
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
205 break;
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
206 }
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
207 }
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
208 }
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
209 }
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
210 }
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
211
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
212 stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
213
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 if (unbuffered) {
4934
6b61912d5f35 On Windows, -u implies binary mode for stdin/stdout
Guido van Rossum <guido@python.org>
parents: 4620
diff changeset
215 #ifdef MS_WINDOWS
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
216 _setmode(fileno(stdin), O_BINARY);
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
217 _setmode(fileno(stdout), O_BINARY);
4934
6b61912d5f35 On Windows, -u implies binary mode for stdin/stdout
Guido van Rossum <guido@python.org>
parents: 4620
diff changeset
218 #endif
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 #ifndef MPW
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
220 #ifdef HAVE_SETVBUF
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
221 setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
222 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
223 setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ);
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
224 #else /* !HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
225 setbuf(stdin, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
226 setbuf(stdout, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
227 setbuf(stderr, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
228 #endif /* !HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
229 #else /* MPW */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* On MPW (3.2) unbuffered seems to hang */
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
231 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
234 #endif /* MPW */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 }
5319
74a1bc099827 Change in when and how stdin and stdout are set to line-buffering.
Guido van Rossum <guido@python.org>
parents: 5166
diff changeset
236 else if (Py_InteractiveFlag) {
5320
c3ddb84a7761 OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents: 5319
diff changeset
237 #ifdef MS_WINDOWS
c3ddb84a7761 OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents: 5319
diff changeset
238 /* Doesn't have to have line-buffered -- use unbuffered */
10130
e569f9b0d969 On Windows, -i shouldn't call set[v]buf(stdin, ...) because it screws
Guido van Rossum <guido@python.org>
parents: 9986
diff changeset
239 /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */
5320
c3ddb84a7761 OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents: 5319
diff changeset
240 setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
241 #else /* !MS_WINDOWS */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
242 #ifdef HAVE_SETVBUF
5320
c3ddb84a7761 OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents: 5319
diff changeset
243 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
c3ddb84a7761 OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents: 5319
diff changeset
244 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
245 #endif /* HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
246 #endif /* !MS_WINDOWS */
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
247 /* Leave stderr alone - it should be unbuffered anyway. */
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
248 }
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
5851
edaf1cb63dc0 This is no longer the real main program; it now defines Py_Main(), so
Guido van Rossum <guido@python.org>
parents: 5547
diff changeset
250 Py_SetProgramName(argv[0]);
edaf1cb63dc0 This is no longer the real main program; it now defines Py_Main(), so
Guido van Rossum <guido@python.org>
parents: 5547
diff changeset
251 Py_Initialize();
edaf1cb63dc0 This is no longer the real main program; it now defines Py_Main(), so
Guido van Rossum <guido@python.org>
parents: 5547
diff changeset
252
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 if (Py_VerboseFlag ||
5113
fb8cefcefd81 Add parentheses around && within || as gcc -Wall advises.
Guido van Rossum <guido@python.org>
parents: 5109
diff changeset
254 (command == NULL && filename == NULL && stdin_is_interactive))
5547
98d4e97daac0 Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents: 5394
diff changeset
255 fprintf(stderr, "Python %s on %s\n%s\n",
14411
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
256 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 if (command != NULL) {
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
260 /* Backup _PyOS_optind and force sys.argv[0] = '-c' */
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
261 _PyOS_optind--;
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
262 argv[_PyOS_optind] = "-c";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
265 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266
6316
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
267 if ((inspect || (command == NULL && filename == NULL)) &&
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
268 isatty(fileno(stdin))) {
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
269 PyObject *v;
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
270 v = PyImport_ImportModule("readline");
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
271 if (v == NULL)
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
272 PyErr_Clear();
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
273 else
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
274 Py_DECREF(v);
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
275 }
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
276
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 if (command) {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 sts = PyRun_SimpleString(command) != 0;
5922
44ddc711ee2d Free the malloc'ed buffer that holds the command once we're done with it.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
279 free(command);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 else {
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
282 if (filename == NULL && stdin_is_interactive) {
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 char *startup = getenv("PYTHONSTARTUP");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 if (startup != NULL && startup[0] != '\0') {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 FILE *fp = fopen(startup, "r");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 if (fp != NULL) {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 (void) PyRun_SimpleFile(fp, startup);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 PyErr_Clear();
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 fclose(fp);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 }
14228
20377f15b96a Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents: 13482
diff changeset
293 sts = PyRun_AnyFileEx(
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
294 fp,
14228
20377f15b96a Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents: 13482
diff changeset
295 filename == NULL ? "<stdin>" : filename,
20377f15b96a Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents: 13482
diff changeset
296 filename != NULL) != 0;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
299 if (inspect && stdin_is_interactive &&
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 (filename != NULL || command != NULL))
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
5940
eef76b3cd9ae Py_Cleanup() is now Py_Finalize().
Guido van Rossum <guido@python.org>
parents: 5922
diff changeset
303 Py_Finalize();
16752
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
304
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
305 #ifdef __INSURE__
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
306 /* Insure++ is a memory analysis tool that aids in discovering
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
307 * memory leaks and other memory problems. On Python exit, the
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
308 * interned string dictionary is flagged as being in use at exit
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
309 * (which it is). Under normal circumstances, this is fine because
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
310 * the memory will be automatically reclaimed by the system. Under
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
311 * memory debugging, it's a huge source of useless noise, so we
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
312 * trade off slower shutdown for less distraction in the memory
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
313 * reports. -baw
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
314 */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
315 _Py_ReleaseInternedStrings();
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
316 #endif /* __INSURE__ */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
317
5922
44ddc711ee2d Free the malloc'ed buffer that holds the command once we're done with it.
Guido van Rossum <guido@python.org>
parents: 5863
diff changeset
318 return sts;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 /* Make the *original* argc/argv available to other modules.
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 This is rare, but it is needed by the secureware extension. */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 void
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
326 Py_GetArgcArgv(int *argc, char ***argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 *argc = orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 *argv = orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 }