annotate Modules/main.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 12079c3d4b77
children 4468666d01c4
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"
35766
34ef9f138c30 Fix a bunch of imports to use code.h instead of compile.h.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35673
diff changeset
5 #include "code.h" /* For CO_FUTURE_DIVISION */
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
6 #include "import.h"
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
8 #ifdef __VMS
28169
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
9 #include <unixlib.h>
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
10 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
11
24695
a989a2eaa2ac On Cygwin, put stdin, stderr, and stdout in binary mode when the -u
Sjoerd Mullender <sjoerd@acm.org>
parents: 24480
diff changeset
12 #if defined(MS_WINDOWS) || defined(__CYGWIN__)
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 37655
diff changeset
13 #ifdef HAVE_FCNTL_H
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
14 #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
15 #endif
38232
aa620856e8a3 Patch #1492356: Port to Windows CE (patch set 1).
Martin v. Löwis <martin@v.loewis.de>
parents: 37655
diff changeset
16 #endif
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
17
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
18 #if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS)
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
19 #define PYTHONHOMEHELP "<prefix>\\lib"
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
20 #else
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
21 #if defined(PYOS_OS2) && defined(PYCC_GCC)
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
22 #define PYTHONHOMEHELP "<prefix>/Lib"
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
23 #else
18088
86ccf93cc952 Removed the Python version from the PYTHONHOMEHELP string. It was
Marc-André Lemburg <mal@egenix.com>
parents: 17396
diff changeset
24 #define PYTHONHOMEHELP "<prefix>/pythonX.X"
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
25 #endif
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
26 #endif
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
27
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
28 #include "pygetopt.h"
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
29
14411
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
30 #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
31 "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
32 "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
33
37655
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
34 #ifdef __cplusplus
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
35 extern "C" {
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
36 #endif
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
37
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
38 /* For Py_GetArgcArgv(); set by main() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 static char **orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 static int orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
42 /* command line options */
46698
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
43 #define BASE_OPTS "3bBc:dEhiJm:OQ:sStuUvVW:xX?"
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
44
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
45 #ifndef RISCOS
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
46 #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
47 #else /*RISCOS*/
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
48 /* 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
49 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
50 #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
51 /* corresponding flag */
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
52 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
53 #endif /*RISCOS*/
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
54
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 /* Short usage message (with %s for argv0) */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 static char *usage_line =
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
57 "usage: %s [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 /* 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
60 static char *usage_1 = "\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 Options and arguments (and corresponding environment variables):\n\
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
62 -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=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
63 -c cmd : program passed in as string (terminates option list)\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
64 -d : debug output from parser; also PYTHONDEBUG=x\n\
44569
132d908471c8 patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
Georg Brandl <georg@python.org>
parents: 44566
diff changeset
65 -E : ignore PYTHON* environment variables (such as PYTHONPATH)\n\
39073
c48b3a68f696 Accept long options "--help" and "--version".
Georg Brandl <georg@python.org>
parents: 38778
diff changeset
66 -h : print this help message and exit (also --help)\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
67 -i : inspect interactively after running script; forces a prompt even\n\
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
68 ";
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
69 static char *usage_2 = "\
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
70 if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
71 -m mod : run library module as a script (terminates option list)\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
72 -O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\
9986
d4b8ddd9a4fd Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9601
diff changeset
73 -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
74 -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
46698
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
75 -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\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
76 -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
77 -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
78 ";
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
79 static char *usage_3 = "\
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
80 -u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x\n\
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
81 see man page for details on internal buffering relating to '-u'\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
82 -v : verbose (trace import statements); also PYTHONVERBOSE=x\n\
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
83 can be supplied multiple times to increase verbosity\n\
39073
c48b3a68f696 Accept long options "--help" and "--version".
Georg Brandl <georg@python.org>
parents: 38778
diff changeset
84 -V : print the Python version number and exit (also --version)\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
85 -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
86 -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
87 ";
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
88 static char *usage_4 = "\
50786
2d453b221bec Merged revisions 68292,68344,68361,68378,68424,68426,68429-68430,68450,68457,68480-68481,68493,68495,68499,68501,68512,68514-68515 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47527
diff changeset
89 -3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 file : program read from script file\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 - : program read from stdin (default; interactive mode if a tty)\n\
39841
2b05ec5df777 Rewrite help message to remove some of the parentheticals. (There were a lot of them.)
Andrew M. Kuchling <amk@amk.ca>
parents: 39840
diff changeset
92 arg ...: arguments passed to program in sys.argv[1:]\n\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 Other environment variables:\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 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
95 PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 default module search path. The result is sys.path.\n\
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
97 ";
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
98 static char *usage_5 = "\
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
99 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
100 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
101 PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
47413
1062b7dec95b New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents: 47294
diff changeset
102 PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 ";
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
106 static int
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
107 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
108 {
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
109 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
110
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
111 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
112 if (exitcode)
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
113 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
114 else {
55298
5d7d85240426 Fix GCC warning about fprintf used without a string literal and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 53083
diff changeset
115 fputs(usage_1, f);
5d7d85240426 Fix GCC warning about fprintf used without a string literal and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 53083
diff changeset
116 fputs(usage_2, f);
5d7d85240426 Fix GCC warning about fprintf used without a string literal and
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 53083
diff changeset
117 fputs(usage_3, f);
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
118 fprintf(f, usage_4, DELIM);
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
119 fprintf(f, usage_5, DELIM, PYTHONHOMEHELP);
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
120 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
121 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
122 if (exitcode == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
123 /* suppress 'error' message */
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
124 return 1;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
125 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
126 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
127 /* STS$M_INHIB_MSG + SS$_ABORT */
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
128 return 0x1000002c;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
129 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
130 #else
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
131 return exitcode;
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
132 #endif
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
133 /*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
134 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
135
30935
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
136 static void RunStartupFile(PyCompilerFlags *cf)
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
137 {
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
138 char *startup = Py_GETENV("PYTHONSTARTUP");
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
139 if (startup != NULL && startup[0] != '\0') {
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
140 FILE *fp = fopen(startup, "r");
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
141 if (fp != NULL) {
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
142 (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
143 PyErr_Clear();
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
144 fclose(fp);
46184
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
145 } else {
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
146 int save_errno;
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
147 save_errno = errno;
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
148 PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
149 errno = save_errno;
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
150 PyErr_SetFromErrnoWithFilename(PyExc_IOError,
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
151 startup);
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
152 PyErr_Print();
6b3ac89e0dd4 Backport #1442: report exception when startup file cannot be run.
Georg Brandl <georg@python.org>
parents: 46107
diff changeset
153 PyErr_Clear();
30935
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
154 }
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
155 }
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
156 }
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
157
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
158
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
159 static int RunModule(char *module, int set_argv0)
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
160 {
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
161 PyObject *runpy, *runmodule, *runargs, *result;
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
162 runpy = PyImport_ImportModule("runpy");
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
163 if (runpy == NULL) {
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
164 fprintf(stderr, "Could not import runpy module\n");
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
165 return -1;
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
166 }
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 41832
diff changeset
167 runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main");
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
168 if (runmodule == NULL) {
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 41832
diff changeset
169 fprintf(stderr, "Could not access runpy._run_module_as_main\n");
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
170 Py_DECREF(runpy);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
171 return -1;
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
172 }
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
173 runargs = Py_BuildValue("(si)", module, set_argv0);
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
174 if (runargs == NULL) {
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
175 fprintf(stderr,
42825
543f2ba97fab Fix bug 1764407 - the -i switch now does the right thing when using the -m switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 41832
diff changeset
176 "Could not create arguments for runpy._run_module_as_main\n");
36995
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
177 Py_DECREF(runpy);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
178 Py_DECREF(runmodule);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
179 return -1;
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
180 }
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
181 result = PyObject_Call(runmodule, runargs, NULL);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
182 if (result == NULL) {
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
183 PyErr_Print();
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
184 }
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
185 Py_DECREF(runpy);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
186 Py_DECREF(runmodule);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
187 Py_DECREF(runargs);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
188 if (result == NULL) {
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
189 return -1;
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
190 }
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
191 Py_DECREF(result);
f914630f419c Implement PEP 338 which has been marked as accepted by GvR
Nick Coghlan <ncoghlan@gmail.com>
parents: 36910
diff changeset
192 return 0;
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
193 }
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
194
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
195 static int RunMainFromImporter(char *filename)
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
196 {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
197 PyObject *argv0 = NULL, *importer = NULL;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
198
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47413
diff changeset
199 if ((argv0 = PyString_FromString(filename)) &&
43929
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
200 (importer = PyImport_GetImporter(argv0)) &&
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
201 (importer->ob_type != &PyNullImporter_Type))
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
202 {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
203 /* argv0 is usable as an import source, so
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
204 put it in sys.path[0] and import __main__ */
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
205 PyObject *sys_path = NULL;
43929
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
206 if ((sys_path = PySys_GetObject("path")) &&
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
207 !PyList_SetItem(sys_path, 0, argv0))
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
208 {
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
209 Py_INCREF(argv0);
43929
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
210 Py_DECREF(importer);
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
211 sys_path = NULL;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
212 return RunModule("__main__", 0) != 0;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
213 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
214 }
43929
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
215 Py_XDECREF(argv0);
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
216 Py_XDECREF(importer);
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
217 if (PyErr_Occurred()) {
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
218 PyErr_Print();
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
219 return 1;
7ab49064d430 Backport some main.c cleanup from the py3k branch
Nick Coghlan <ncoghlan@gmail.com>
parents: 43895
diff changeset
220 }
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
221 return -1;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
222 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
223
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
224
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 /* Main program */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24405
diff changeset
227 int
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
228 Py_Main(int argc, char **argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 int c;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 int sts;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 char *command = NULL;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 char *filename = NULL;
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
234 char *module = NULL;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 FILE *fp = stdin;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 char *p;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 int unbuffered = 0;
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
238 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
239 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
240 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
241 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
242 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
243 PyCompilerFlags cf;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
245 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
246
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
247 orig_argc = argc; /* For Py_GetArgcArgv() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 orig_argv = argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
250 #ifdef RISCOS
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
251 Py_RISCOSWimpFlag = 0;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
252 #endif
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
253
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
254 PySys_ResetWarnOptions();
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
255
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
256 while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 if (c == 'c') {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 /* -c is the last option; following arguments
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 that look like options are left for the
30723
6f15e73b59f2 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 29682
diff changeset
260 command to interpret. */
37607
480a5625e286 Some more changes to make code compile under a C++ compiler.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 36995
diff changeset
261 command = (char *)malloc(strlen(_PyOS_optarg) + 2);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 if (command == NULL)
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 Py_FatalError(
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 "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
265 strcpy(command, _PyOS_optarg);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 strcat(command, "\n");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 }
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
269
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
270 if (c == 'm') {
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
271 /* -m is the last option; following arguments
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
272 that look like options are left for the
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
273 module to interpret. */
37607
480a5625e286 Some more changes to make code compile under a C++ compiler.
Anthony Baxter <anthonybaxter@gmail.com>
parents: 36995
diff changeset
274 module = (char *)malloc(strlen(_PyOS_optarg) + 2);
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
275 if (module == NULL)
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
276 Py_FatalError(
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
277 "not enough memory to copy -m argument");
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
278 strcpy(module, _PyOS_optarg);
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
279 break;
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
280 }
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
281
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 switch (c) {
46107
5341b30b1812 Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45854
diff changeset
283 case 'b':
5341b30b1812 Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45854
diff changeset
284 Py_BytesWarningFlag++;
5341b30b1812 Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45854
diff changeset
285 break;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 case 'd':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 Py_DebugFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290
41832
a0ee3b2ba361 Add -3 option to the interpreter to warn about features that are
Neal Norwitz <nnorwitz@gmail.com>
parents: 41043
diff changeset
291 case '3':
a0ee3b2ba361 Add -3 option to the interpreter to warn about features that are
Neal Norwitz <nnorwitz@gmail.com>
parents: 41043
diff changeset
292 Py_Py3kWarningFlag++;
51711
ee7011863943 Py3k warnings now automatically include -Qwarn for division.
Raymond Hettinger <python@rcn.com>
parents: 50786
diff changeset
293 if (!Py_DivisionWarningFlag)
ee7011863943 Py3k warnings now automatically include -Qwarn for division.
Raymond Hettinger <python@rcn.com>
parents: 50786
diff changeset
294 Py_DivisionWarningFlag = 1;
41832
a0ee3b2ba361 Add -3 option to the interpreter to warn about features that are
Neal Norwitz <nnorwitz@gmail.com>
parents: 41043
diff changeset
295 break;
a0ee3b2ba361 Add -3 option to the interpreter to warn about features that are
Neal Norwitz <nnorwitz@gmail.com>
parents: 41043
diff changeset
296
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
297 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
298 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
299 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
300 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
301 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
302 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
303 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
304 break;
b3271297b984 PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents: 19672
diff changeset
305 }
b3271297b984 PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents: 19672
diff changeset
306 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
307 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
308 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
309 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
310 if (strcmp(_PyOS_optarg, "new") == 0) {
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
311 /* 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
312 cf.cf_flags |= CO_FUTURE_DIVISION;
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
313 /* 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
314 BINARY_DIVIDE as BINARY_TRUE_DIVIDE */
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
315 _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
316 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
317 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
318 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
319 "-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
320 "`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
321 return usage(2, argv[0]);
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
322 /* NOTREACHED */
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
323
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 case 'i':
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
325 Py_InspectFlag++;
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
326 Py_InteractiveFlag++;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328
46406
c1fa2e758e05 Applied patch #2617 from Frank Wierzbicki wit some extras from me
Christian Heimes <christian@cheimes.de>
parents: 46184
diff changeset
329 /* case 'J': reserved for Jython */
c1fa2e758e05 Applied patch #2617 from Frank Wierzbicki wit some extras from me
Christian Heimes <christian@cheimes.de>
parents: 46184
diff changeset
330
5166
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
331 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
332 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
333 break;
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
334
44566
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
335 case 'B':
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
336 Py_DontWriteBytecodeFlag++;
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
337 break;
599f22a349a2 Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents: 43929
diff changeset
338
46698
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
339 case 's':
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
340 Py_NoUserSiteDirectory++;
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
341 break;
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
342
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
343 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
344 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
345 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
346
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
347 case 'E':
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
348 Py_IgnoreEnvironmentFlag++;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
349 break;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
350
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
351 case 't':
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
352 Py_TabcheckFlag++;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
353 break;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
354
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 case 'u':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 unbuffered++;
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
357 saw_unbuffered_flag = 1;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 case 'v':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 Py_VerboseFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
363
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
364 #ifdef RISCOS
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
365 case 'w':
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
366 Py_RISCOSWimpFlag = 1;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
367 break;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
368 #endif
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
369
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
370 case 'x':
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
371 skipfirstline = 1;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
372 break;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
373
46435
7c21cc14b94f Improve -X error message.
Georg Brandl <georg@python.org>
parents: 46406
diff changeset
374 /* case 'X': reserved for implementation-specific arguments */
46406
c1fa2e758e05 Applied patch #2617 from Frank Wierzbicki wit some extras from me
Christian Heimes <christian@cheimes.de>
parents: 46184
diff changeset
375
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
376 case 'U':
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
377 Py_UnicodeFlag++;
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
378 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
379 case 'h':
39073
c48b3a68f696 Accept long options "--help" and "--version".
Georg Brandl <georg@python.org>
parents: 38778
diff changeset
380 case '?':
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
381 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
382 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
383 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
384 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
385 break;
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
386
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
387 case 'W':
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
388 PySys_AddWarnOption(_PyOS_optarg);
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
389 break;
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
390
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 /* This space reserved for other options */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 default:
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
394 return usage(2, argv[0]);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 /*NOTREACHED*/
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399
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
400 if (help)
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
401 return usage(0, argv[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
402
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
403 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
404 fprintf(stderr, "Python %s\n", PY_VERSION);
28453
df9b7cee1339 Patch #672053: Return a result from Py_Main, instead of exiting.
Martin v. Löwis <martin@v.loewis.de>
parents: 28451
diff changeset
405 return 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
406 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
407
53083
ad3f3d304963 #5704: let python -3 imply -t as well.
Georg Brandl <georg@python.org>
parents: 51711
diff changeset
408 if (Py_Py3kWarningFlag && !Py_TabcheckFlag)
ad3f3d304963 #5704: let python -3 imply -t as well.
Georg Brandl <georg@python.org>
parents: 51711
diff changeset
409 /* -3 implies -t (but not -tt) */
ad3f3d304963 #5704: let python -3 imply -t as well.
Georg Brandl <georg@python.org>
parents: 51711
diff changeset
410 Py_TabcheckFlag = 1;
ad3f3d304963 #5704: let python -3 imply -t as well.
Georg Brandl <georg@python.org>
parents: 51711
diff changeset
411
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
412 if (!Py_InspectFlag &&
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
413 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
414 Py_InspectFlag = 1;
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
415 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
416 (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
417 unbuffered = 1;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
418
46698
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
419 if (!Py_NoUserSiteDirectory &&
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
420 (p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
421 Py_NoUserSiteDirectory = 1;
1a2dbc84bdfc Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents: 46435
diff changeset
422
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
423 if (command == NULL && module == NULL && _PyOS_optind < argc &&
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
424 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
425 {
28169
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
426 #ifdef __VMS
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
427 filename = decc$translate_vms(argv[_PyOS_optind]);
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
428 if (filename == (char *)0 || filename == (char *)-1)
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
429 filename = argv[_PyOS_optind];
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
430
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
431 #else
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
432 filename = argv[_PyOS_optind];
28169
bc2d07230934 Patch #696645: Remove VMS code with uncertain authorship.
Martin v. Löwis <martin@v.loewis.de>
parents: 26764
diff changeset
433 #endif
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
434 }
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
435
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
436 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
437
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 if (unbuffered) {
24695
a989a2eaa2ac On Cygwin, put stdin, stderr, and stdout in binary mode when the -u
Sjoerd Mullender <sjoerd@acm.org>
parents: 24480
diff changeset
439 #if defined(MS_WINDOWS) || defined(__CYGWIN__)
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
440 _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
441 _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
442 #endif
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
443 #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
444 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
445 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
446 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
447 #else /* !HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
448 setbuf(stdin, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
449 setbuf(stdout, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
450 setbuf(stderr, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
451 #endif /* !HAVE_SETVBUF */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 }
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
453 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
454 #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
455 /* 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
456 /* 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
457 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
458 #else /* !MS_WINDOWS */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
459 #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
460 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
461 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
462 #endif /* HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
463 #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
464 /* 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
465 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
466 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
467 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
468 setvbuf (stdout, (char *)NULL, _IOLBF, BUFSIZ);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
469 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
470 #endif /* __VMS */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471
28175
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
472 #ifdef __APPLE__
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
473 /* On MacOS X, when the Python interpreter is embedded in an
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
474 application bundle, it gets executed by a bootstrapping script
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
475 that does os.execve() with an argv[0] that's different from the
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
476 actual Python executable. This is needed to keep the Finder happy,
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
477 or rather, to work around Apple's overly strict requirements of
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
478 the process name. However, we still need a usable sys.executable,
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
479 so the actual executable path is passed in an environment variable.
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
480 See Lib/plat-mac/bundlebuiler.py for details about the bootstrap
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
481 script. */
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
482 if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0')
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
483 Py_SetProgramName(p);
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
484 else
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
485 Py_SetProgramName(argv[0]);
395eb561ece1 removing one Mac hack and add another:
Just van Rossum <just@letterror.com>
parents: 28169
diff changeset
486 #else
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
487 Py_SetProgramName(argv[0]);
28176
48a5113dfef9 An #endif was missing in Just's patch. Added.
Jack Jansen <jack.jansen@cwi.nl>
parents: 28175
diff changeset
488 #endif
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
489 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
490
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
491 if (Py_VerboseFlag ||
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
492 (command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) {
28451
56d9bbbae6f8 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Martin v. Löwis <martin@v.loewis.de>
parents: 28176
diff changeset
493 fprintf(stderr, "Python %s on %s\n",
56d9bbbae6f8 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Martin v. Löwis <martin@v.loewis.de>
parents: 28176
diff changeset
494 Py_GetVersion(), Py_GetPlatform());
56d9bbbae6f8 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Martin v. Löwis <martin@v.loewis.de>
parents: 28176
diff changeset
495 if (!Py_NoSiteFlag)
56d9bbbae6f8 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Martin v. Löwis <martin@v.loewis.de>
parents: 28176
diff changeset
496 fprintf(stderr, "%s\n", COPYRIGHT);
56d9bbbae6f8 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Martin v. Löwis <martin@v.loewis.de>
parents: 28176
diff changeset
497 }
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
498
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 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
500 /* 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
501 _PyOS_optind--;
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
502 argv[_PyOS_optind] = "-c";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
504
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
505 if (module != NULL) {
38778
97b61d6f6b76 Make the -m switch conform to the documentation of sys.path by behaving like the -c switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 38232
diff changeset
506 /* Backup _PyOS_optind and force sys.argv[0] = '-c'
97b61d6f6b76 Make the -m switch conform to the documentation of sys.path by behaving like the -c switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 38232
diff changeset
507 so that PySys_SetArgv correctly sets sys.path[0] to ''*/
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
508 _PyOS_optind--;
38778
97b61d6f6b76 Make the -m switch conform to the documentation of sys.path by behaving like the -c switch
Nick Coghlan <ncoghlan@gmail.com>
parents: 38232
diff changeset
509 argv[_PyOS_optind] = "-c";
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
510 }
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
511
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
512 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
513
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
514 if ((Py_InspectFlag || (command == NULL && filename == NULL && module == NULL)) &&
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
515 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
516 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
517 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
518 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
519 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
520 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
521 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
522 }
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
523
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524 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
525 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
526 free(command);
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
527 } else if (module) {
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
528 sts = RunModule(module, 1);
33680
bcafb68ad985 SF patch #1035498: -m option to run a module as a script
Raymond Hettinger <python@rcn.com>
parents: 33188
diff changeset
529 free(module);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 else {
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
532
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
533 if (filename == NULL && stdin_is_interactive) {
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
534 Py_InspectFlag = 0; /* do exit on SystemExit */
30935
5d2b0e9062d5 Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
535 RunStartupFile(&cf);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 }
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
537 /* XXX */
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
538
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
539 sts = -1; /* keep track of whether we've already run __main__ */
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
540
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
541 if (filename != NULL) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
542 sts = RunMainFromImporter(filename);
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
543 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
544
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
545 if (sts==-1 && filename!=NULL) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
546 if ((fp = fopen(filename, "r")) == NULL) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
547 fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n",
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
548 argv[0], filename, errno, strerror(errno));
45854
21139ea59b6b Remove all traces of HAVE_STRERROR.
Brett Cannon <bcannon@gmail.com>
parents: 44740
diff changeset
549
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
550 return 2;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
551 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
552 else if (skipfirstline) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
553 int ch;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
554 /* Push back first newline so line numbers
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
555 remain the same */
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
556 while ((ch = getc(fp)) != EOF) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
557 if (ch == '\n') {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
558 (void)ungetc(ch, fp);
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
559 break;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
560 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
561 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
562 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
563 {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
564 /* XXX: does this work on Win/Win64? (see posix_fstat) */
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
565 struct stat sb;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
566 if (fstat(fileno(fp), &sb) == 0 &&
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
567 S_ISDIR(sb.st_mode)) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
568 fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);
44740
79babb4ccec8 Coverity CID #168
Christian Heimes <christian@cheimes.de>
parents: 44569
diff changeset
569 fclose(fp);
43895
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
570 return 1;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
571 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
572 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
573 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
574
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
575 if (sts==-1) {
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
576 sts = PyRun_AnyFileExFlags(
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
577 fp,
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
578 filename == NULL ? "<stdin>" : filename,
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
579 filename != NULL, &cf) != 0;
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
580 }
4cec0c6392c1 Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Nick Coghlan <ncoghlan@gmail.com>
parents: 43534
diff changeset
581
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
582 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
583
29682
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
584 /* Check this environment variable at the end, to give programs the
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
585 * opportunity to set it from Python.
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
586 */
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
587 if (!Py_InspectFlag &&
29682
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
588 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
589 {
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
590 Py_InspectFlag = 1;
29682
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
591 }
920777640d28 Py_Main(): Add a check for the PYTHONINSPECT environment variable
Barry Warsaw <barry@python.org>
parents: 28453
diff changeset
592
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
593 if (Py_InspectFlag && stdin_is_interactive &&
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
594 (filename != NULL || command != NULL || module != NULL)) {
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
595 Py_InspectFlag = 0;
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
596 /* XXX */
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
597 sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
41043
728c60e85efa Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents: 40559
diff changeset
598 }
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
599
5940
eef76b3cd9ae Py_Cleanup() is now Py_Finalize().
Guido van Rossum <guido@python.org>
parents: 5922
diff changeset
600 Py_Finalize();
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
601 #ifdef RISCOS
25826
c2dd41301841 Fix minor whitespace nit, for consistency with Python's C style rules.
Fred Drake <fdrake@acm.org>
parents: 24695
diff changeset
602 if (Py_RISCOSWimpFlag)
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
603 fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
604 #endif
16752
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
605
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
606 #ifdef __INSURE__
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
607 /* 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
608 * 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
609 * 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
610 * (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
611 * 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
612 * 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
613 * 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
614 * reports. -baw
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
615 */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
616 _Py_ReleaseInternedStrings();
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
617 #endif /* __INSURE__ */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
618
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
619 return sts;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
620 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
621
31606
fd2103ae6f29 Add pystack definition to Misc/gdbinit with some explanation of its behavior
Skip Montanaro <skip@pobox.com>
parents: 30968
diff changeset
622 /* this is gonna seem *real weird*, but if you put some other code between
fd2103ae6f29 Add pystack definition to Misc/gdbinit with some explanation of its behavior
Skip Montanaro <skip@pobox.com>
parents: 30968
diff changeset
623 Py_Main() and Py_GetArgcArgv() you will need to adjust the test in the
fd2103ae6f29 Add pystack definition to Misc/gdbinit with some explanation of its behavior
Skip Montanaro <skip@pobox.com>
parents: 30968
diff changeset
624 while statement in Misc/gdbinit:ppystack */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
625
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626 /* Make the *original* argc/argv available to other modules.
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 This is rare, but it is needed by the secureware extension. */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
628
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 void
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
630 Py_GetArgcArgv(int *argc, char ***argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
632 *argc = orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
633 *argv = orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
634 }
37655
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
635
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
636 #ifdef __cplusplus
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
637 }
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
638 #endif
2f3f2e32dfd9 spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37607
diff changeset
639