Mercurial > cpython-lru_cache-weakref
annotate Modules/main.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 3513a9d090a9 |
| children | 05443430d7ed c454b76d51e7 |
| rev | line source |
|---|---|
| 2896 | 1 /* Python interpreter main program */ |
| 2 | |
| 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" |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
5 #include "compile.h" /* For CO_FUTURE_DIVISION */ |
| 2896 | 6 |
|
5000
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
7 #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
|
8 #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
|
9 #endif |
|
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
10 |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
11 #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
|
12 #define PYTHONHOMEHELP "<prefix>\\lib" |
|
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
13 #else |
|
18088
86ccf93cc952
Removed the Python version from the PYTHONHOMEHELP string. It was
Marc-André Lemburg <mal@egenix.com>
parents:
17396
diff
changeset
|
14 #define PYTHONHOMEHELP "<prefix>/pythonX.X" |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
15 #endif |
|
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
16 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
17 #include "pygetopt.h" |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
18 |
|
14411
a707a5f17139
Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
19 #define COPYRIGHT \ |
|
18692
00695551d721
Add "help" to the things one is encouraged to type for more
Guido van Rossum <guido@python.org>
parents:
18611
diff
changeset
|
20 "Type \"help\", \"copyright\", \"credits\" or \"license\" " \ |
|
00695551d721
Add "help" to the things one is encouraged to type for more
Guido van Rossum <guido@python.org>
parents:
18611
diff
changeset
|
21 "for more information." |
|
14411
a707a5f17139
Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
22 |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
23 /* For Py_GetArgcArgv(); set by main() */ |
| 2896 | 24 static char **orig_argv; |
| 25 static int orig_argc; | |
| 26 | |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
27 /* command line options */ |
|
19672
3584550a622a
Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents:
19635
diff
changeset
|
28 #define BASE_OPTS "c:dEhiOQ:StuUvVW:xX" |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
29 |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
30 #ifndef RISCOS |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
31 #define PROGRAM_OPTS BASE_OPTS |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
32 #else /*RISCOS*/ |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
33 /* extra option saying that we are running under a special task window |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
34 frontend; especially my_readline will behave different */ |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
35 #define PROGRAM_OPTS BASE_OPTS "w" |
|
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
36 /* corresponding flag */ |
|
16944
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
37 extern int Py_RISCOSWimpFlag; |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
38 #endif /*RISCOS*/ |
|
16944
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
39 |
| 2896 | 40 /* Short usage message (with %s for argv0) */ |
| 41 static char *usage_line = | |
|
9986
d4b8ddd9a4fd
Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents:
9601
diff
changeset
|
42 "usage: %s [option] ... [-c cmd | file | -] [arg] ...\n"; |
| 2896 | 43 |
| 44 /* Long usage message, split into parts < 512 bytes */ | |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
45 static char *usage_1 = "\ |
| 2896 | 46 Options and arguments (and corresponding environment variables):\n\ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
47 -c cmd : program passed in as string (terminates option list)\n\ |
| 2896 | 48 -d : debug output from parser (also PYTHONDEBUG=x)\n\ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
49 -E : ignore environment variables (such as PYTHONPATH)\n\ |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
50 -h : print this help message and exit\n\ |
|
19672
3584550a622a
Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents:
19635
diff
changeset
|
51 -i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\ |
|
3584550a622a
Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents:
19635
diff
changeset
|
52 and force prompts, even if stdin does not appear to be a terminal\n\ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
53 "; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
54 static char *usage_2 = "\ |
|
9284
faa31b1c0b54
Documented PYTHONOPTIMIZE; by Marc Lemburg.
Guido van Rossum <guido@python.org>
parents:
8044
diff
changeset
|
55 -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
|
56 -OO : remove doc-strings in addition to the -O optimizations\n\ |
|
19673
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
57 -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\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
|
58 -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
|
59 -t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
60 -u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\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
|
61 "; |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
62 static char *usage_3 = "\ |
| 2896 | 63 -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\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
|
64 -V : print the Python version number and exit\n\ |
| 15593 | 65 -W arg : warning control (arg is action:message:category:module:lineno)\n\ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
66 -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\ |
| 2896 | 67 file : program read from script file\n\ |
| 68 - : 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
|
69 "; |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
70 static char *usage_4 = "\ |
|
7966
8c268d0e8822
Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents:
7571
diff
changeset
|
71 arg ...: arguments passed to program in sys.argv[1:]\n\ |
| 2896 | 72 Other environment variables:\n\ |
| 73 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
|
74 PYTHONPATH : '%c'-separated list of directories prefixed to the\n\ |
| 2896 | 75 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
|
76 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
|
77 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
|
78 PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\ |
| 2896 | 79 "; |
| 80 | |
| 81 | |
|
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
|
82 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
|
83 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
|
84 { |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
85 FILE *f = exitcode ? stderr : stdout; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
86 |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
87 fprintf(f, usage_line, program); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
88 if (exitcode) |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
89 fprintf(f, "Try `python -h' for more information.\n"); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
90 else { |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
91 fprintf(f, usage_1); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
92 fprintf(f, usage_2); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
93 fprintf(f, usage_3); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
94 fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
95 } |
|
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
|
96 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
|
97 /*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
|
98 } |
|
80a782086a57
Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents:
14411
diff
changeset
|
99 |
|
80a782086a57
Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents:
14411
diff
changeset
|
100 |
| 2896 | 101 /* Main program */ |
| 102 | |
|
9601
0f3f9e366356
Py_Main() must be DL_EXPORT too.
Guido van Rossum <guido@python.org>
parents:
9284
diff
changeset
|
103 DL_EXPORT(int) |
|
13482
000a1c7eb09f
- changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents:
13256
diff
changeset
|
104 Py_Main(int argc, char **argv) |
| 2896 | 105 { |
| 106 int c; | |
| 107 int sts; | |
| 108 char *command = NULL; | |
| 109 char *filename = NULL; | |
| 110 FILE *fp = stdin; | |
| 111 char *p; | |
| 112 int inspect = 0; | |
| 113 int unbuffered = 0; | |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 int version = 0; |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
118 int saw_inspect_flag = 0; |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
119 int saw_unbuffered_flag = 0; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
120 PyCompilerFlags cf; |
| 2896 | 121 |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
122 cf.cf_flags = 0; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
123 |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
124 orig_argc = argc; /* For Py_GetArgcArgv() */ |
| 2896 | 125 orig_argv = argv; |
| 126 | |
|
16944
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
127 #ifdef RISCOS |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
128 Py_RISCOSWimpFlag = 0; |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
129 #endif |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
130 |
| 15593 | 131 PySys_ResetWarnOptions(); |
| 132 | |
|
17396
beb9d2b02846
Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents:
17125
diff
changeset
|
133 while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { |
| 2896 | 134 if (c == 'c') { |
| 135 /* -c is the last option; following arguments | |
| 136 that look like options are left for the | |
| 137 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
|
138 command = malloc(strlen(_PyOS_optarg) + 2); |
| 2896 | 139 if (command == NULL) |
| 140 Py_FatalError( | |
| 141 "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
|
142 strcpy(command, _PyOS_optarg); |
| 2896 | 143 strcat(command, "\n"); |
| 144 break; | |
| 145 } | |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
146 |
| 2896 | 147 switch (c) { |
| 148 | |
| 149 case 'd': | |
| 150 Py_DebugFlag++; | |
| 151 break; | |
| 152 | |
|
19672
3584550a622a
Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents:
19635
diff
changeset
|
153 case 'Q': |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
154 if (strcmp(_PyOS_optarg, "old") == 0) { |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
155 Py_DivisionWarningFlag = 0; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
156 break; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
157 } |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
158 if (strcmp(_PyOS_optarg, "warn") == 0) { |
|
19673
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
159 Py_DivisionWarningFlag = 1; |
|
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
160 break; |
|
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
161 } |
|
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
162 if (strcmp(_PyOS_optarg, "warnall") == 0) { |
|
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
163 Py_DivisionWarningFlag = 2; |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
164 break; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
165 } |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
166 if (strcmp(_PyOS_optarg, "new") == 0) { |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
167 /* This only affects __main__ */ |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
168 cf.cf_flags |= CO_FUTURE_DIVISION; |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
169 /* And this tells the eval loop to treat |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
170 BINARY_DIVIDE as BINARY_TRUE_DIVIDE */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
19673
diff
changeset
|
171 _Py_QnewFlag = 1; |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
172 break; |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
173 } |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
174 fprintf(stderr, |
|
19673
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
175 "-Q option should be `-Qold', " |
|
b3271297b984
PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents:
19672
diff
changeset
|
176 "`-Qwarn', `-Qwarnall', or `-Qnew' only\n"); |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
177 usage(2, argv[0]); |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
178 /* NOTREACHED */ |
|
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
179 |
| 2896 | 180 case 'i': |
| 181 inspect++; | |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
182 saw_inspect_flag = 1; |
|
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
|
183 Py_InteractiveFlag++; |
| 2896 | 184 break; |
| 185 | |
|
5166
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
186 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
|
187 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
|
188 break; |
|
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
189 |
|
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
|
190 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
|
191 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
|
192 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
|
193 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
194 case 'E': |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
195 Py_IgnoreEnvironmentFlag++; |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
196 break; |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
197 |
|
7966
8c268d0e8822
Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents:
7571
diff
changeset
|
198 case 't': |
|
8c268d0e8822
Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents:
7571
diff
changeset
|
199 Py_TabcheckFlag++; |
|
8c268d0e8822
Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents:
7571
diff
changeset
|
200 break; |
|
8c268d0e8822
Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents:
7571
diff
changeset
|
201 |
| 2896 | 202 case 'u': |
| 203 unbuffered++; | |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
204 saw_unbuffered_flag = 1; |
| 2896 | 205 break; |
| 206 | |
| 207 case 'v': | |
| 208 Py_VerboseFlag++; | |
| 209 break; | |
| 210 | |
|
16944
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
211 #ifdef RISCOS |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
212 case 'w': |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
213 Py_RISCOSWimpFlag = 1; |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
214 break; |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
215 #endif |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
216 |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
217 case 'x': |
|
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
218 skipfirstline = 1; |
|
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
219 break; |
|
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
220 |
| 12537 | 221 case 'U': |
| 222 Py_UnicodeFlag++; | |
| 223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 break; |
| 12537 | 230 |
| 15593 | 231 case 'W': |
| 232 PySys_AddWarnOption(_PyOS_optarg); | |
| 233 break; | |
| 234 | |
| 2896 | 235 /* This space reserved for other options */ |
| 236 | |
| 237 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
|
238 usage(2, argv[0]); |
| 2896 | 239 /*NOTREACHED*/ |
| 240 | |
| 241 } | |
| 242 } | |
| 243 | |
|
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
|
244 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
|
245 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
|
246 |
|
80a782086a57
Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents:
14411
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 } |
|
80a782086a57
Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents:
14411
diff
changeset
|
251 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
252 if (!saw_inspect_flag && |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
253 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0') |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
254 inspect = 1; |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
255 if (!saw_unbuffered_flag && |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
256 (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
257 unbuffered = 1; |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
258 |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
259 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
|
260 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
|
261 { |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 } |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
269 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
|
270 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
|
271 /* 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
|
272 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
|
273 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
|
274 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
|
275 (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
|
276 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
|
277 } |
|
5b170f0da9fe
Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents:
10130
diff
changeset
|
278 } |
|
6763
12824fe04a08
Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents:
6538
diff
changeset
|
279 } |
|
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
|
280 } |
|
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
|
281 } |
|
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 |
|
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
|
283 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
|
284 |
| 2896 | 285 if (unbuffered) { |
|
4934
6b61912d5f35
On Windows, -u implies binary mode for stdin/stdout
Guido van Rossum <guido@python.org>
parents:
4620
diff
changeset
|
286 #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
|
287 _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
|
288 _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
|
289 #endif |
| 2896 | 290 #ifndef MPW |
|
7571
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
291 #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
|
292 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
|
293 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
|
294 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
|
295 #else /* !HAVE_SETVBUF */ |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
296 setbuf(stdin, (char *)NULL); |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
297 setbuf(stdout, (char *)NULL); |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
298 setbuf(stderr, (char *)NULL); |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
299 #endif /* !HAVE_SETVBUF */ |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
300 #else /* MPW */ |
| 2896 | 301 /* 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
|
302 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ); |
| 2896 | 303 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
| 304 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
|
305 #endif /* MPW */ |
| 2896 | 306 } |
|
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
|
307 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
|
308 #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
|
309 /* 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
|
310 /* 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
|
311 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
|
312 #else /* !MS_WINDOWS */ |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
313 #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
|
314 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
|
315 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
|
316 #endif /* HAVE_SETVBUF */ |
|
968aaba281c5
Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents:
6763
diff
changeset
|
317 #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
|
318 /* 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
|
319 } |
| 2896 | 320 |
|
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
|
321 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
|
322 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
|
323 |
| 2896 | 324 if (Py_VerboseFlag || |
|
5113
fb8cefcefd81
Add parentheses around && within || as gcc -Wall advises.
Guido van Rossum <guido@python.org>
parents:
5109
diff
changeset
|
325 (command == NULL && filename == NULL && stdin_is_interactive)) |
|
5547
98d4e97daac0
Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents:
5394
diff
changeset
|
326 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
|
327 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT); |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
328 |
| 2896 | 329 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
|
330 /* 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
|
331 _PyOS_optind--; |
|
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
332 argv[_PyOS_optind] = "-c"; |
| 2896 | 333 } |
| 334 | |
|
15374
a826a46bae54
Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents:
14603
diff
changeset
|
335 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind); |
| 2896 | 336 |
|
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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 } |
|
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
|
346 |
| 2896 | 347 if (command) { |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
18808
diff
changeset
|
348 sts = PyRun_SimpleStringFlags(command, &cf) != 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
|
349 free(command); |
| 2896 | 350 } |
| 351 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
|
352 if (filename == NULL && stdin_is_interactive) { |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18692
diff
changeset
|
353 char *startup = Py_GETENV("PYTHONSTARTUP"); |
| 2896 | 354 if (startup != NULL && startup[0] != '\0') { |
| 355 FILE *fp = fopen(startup, "r"); | |
| 356 if (fp != NULL) { | |
| 357 (void) PyRun_SimpleFile(fp, startup); | |
| 358 PyErr_Clear(); | |
| 359 fclose(fp); | |
| 360 } | |
| 361 } | |
| 362 } | |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
363 /* XXX */ |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
364 sts = PyRun_AnyFileExFlags( |
|
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
|
365 fp, |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
13482
diff
changeset
|
366 filename == NULL ? "<stdin>" : filename, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
367 filename != NULL, &cf) != 0; |
| 2896 | 368 } |
| 369 | |
|
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
|
370 if (inspect && stdin_is_interactive && |
| 2896 | 371 (filename != NULL || command != NULL)) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
372 /* XXX */ |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16944
diff
changeset
|
373 sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0; |
| 2896 | 374 |
|
5940
eef76b3cd9ae
Py_Cleanup() is now Py_Finalize().
Guido van Rossum <guido@python.org>
parents:
5922
diff
changeset
|
375 Py_Finalize(); |
|
16944
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
376 #ifdef RISCOS |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
377 if(Py_RISCOSWimpFlag) |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
378 fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */ |
|
4baa5a955532
RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents:
16752
diff
changeset
|
379 #endif |
|
16752
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
380 |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
381 #ifdef __INSURE__ |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
382 /* 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
|
383 * 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
|
384 * 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
|
385 * (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
|
386 * 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
|
387 * 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
|
388 * 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
|
389 * reports. -baw |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
390 */ |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
391 _Py_ReleaseInternedStrings(); |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
392 #endif /* __INSURE__ */ |
|
5c3aedc969da
Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents:
16731
diff
changeset
|
393 |
|
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
|
394 return sts; |
| 2896 | 395 } |
| 396 | |
| 397 | |
| 398 /* Make the *original* argc/argv available to other modules. | |
| 399 This is rare, but it is needed by the secureware extension. */ | |
| 400 | |
| 401 void | |
|
13482
000a1c7eb09f
- changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents:
13256
diff
changeset
|
402 Py_GetArgcArgv(int *argc, char ***argv) |
| 2896 | 403 { |
| 404 *argc = orig_argc; | |
| 405 *argv = orig_argv; | |
| 406 } |
