annotate Modules/main.c @ 27998:e27f58a50737 legacy-trunk

SF bug #690377: Dud footnote reference in distutils docs
author Raymond Hettinger <python@rcn.com>
date Fri, 21 Feb 2003 02:47:09 +0000
parents 6b31b26e418d
children bc2d07230934
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"
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
5 #include "compile.h" /* For CO_FUTURE_DIVISION */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
7 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
8 extern int PyVMS_init(int* pvi_argc, char*** pvi_argv);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
9 extern PyObject* pyvms_gr_empty_string;
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__)
5000
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
13 #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
14 #endif
7c7a186b6d86 Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents: 4934
diff changeset
15
26764
6b31b26e418d Squashed compiler warnings by adding casts, making sure prototypes are in
Jack Jansen <jack.jansen@cwi.nl>
parents: 26550
diff changeset
16 #if defined(WITH_NEXT_FRAMEWORK)
6b31b26e418d Squashed compiler warnings by adding casts, making sure prototypes are in
Jack Jansen <jack.jansen@cwi.nl>
parents: 26550
diff changeset
17 #include "pymactoolbox.h"
6b31b26e418d Squashed compiler warnings by adding casts, making sure prototypes are in
Jack Jansen <jack.jansen@cwi.nl>
parents: 26550
diff changeset
18 #endif
6b31b26e418d Squashed compiler warnings by adding casts, making sure prototypes are in
Jack Jansen <jack.jansen@cwi.nl>
parents: 26550
diff changeset
19
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
20 #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
21 #define PYTHONHOMEHELP "<prefix>\\lib"
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
22 #else
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
23 #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
24 #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
25 #else
18088
86ccf93cc952 Removed the Python version from the PYTHONHOMEHELP string. It was
Marc-André Lemburg <mal@egenix.com>
parents: 17396
diff changeset
26 #define PYTHONHOMEHELP "<prefix>/pythonX.X"
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
27 #endif
22114
c454b76d51e7 OS/2 EMX port changes (Modules part of patch #450267):
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 21928
diff changeset
28 #endif
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
29
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
30 #include "pygetopt.h"
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
31
14411
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
32 #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
33 "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
34 "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
35
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
36 /* For Py_GetArgcArgv(); set by main() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 static char **orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 static int orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
40 /* command line options */
19672
3584550a622a Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents: 19635
diff changeset
41 #define BASE_OPTS "c:dEhiOQ:StuUvVW:xX"
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
42
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
43 #ifndef RISCOS
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
44 #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
45 #else /*RISCOS*/
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
46 /* 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
47 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
48 #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
49 /* corresponding flag */
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
50 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
51 #endif /*RISCOS*/
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
52
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 /* Short usage message (with %s for argv0) */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 static char *usage_line =
9986
d4b8ddd9a4fd Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9601
diff changeset
55 "usage: %s [option] ... [-c cmd | file | -] [arg] ...\n";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 /* 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
58 static char *usage_1 = "\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 Options and arguments (and corresponding environment variables):\n\
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
60 -c cmd : program passed in as string (terminates option list)\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 -d : debug output from parser (also PYTHONDEBUG=x)\n\
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
62 -E : ignore environment variables (such as PYTHONPATH)\n\
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
63 -h : print this help message and exit\n\
19672
3584550a622a Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents: 19635
diff changeset
64 -i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
3584550a622a Rename the -D option to -Q, to avoid a Jython option name conflict.
Guido van Rossum <guido@python.org>
parents: 19635
diff changeset
65 and force prompts, even if stdin does not appear to be a terminal\n\
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
66 ";
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
67 static char *usage_2 = "\
9284
faa31b1c0b54 Documented PYTHONOPTIMIZE; by Marc Lemburg.
Guido van Rossum <guido@python.org>
parents: 8044
diff changeset
68 -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
9986
d4b8ddd9a4fd Document -OO; "unsafe" optimization that removes docstrings.
Guido van Rossum <guido@python.org>
parents: 9601
diff changeset
69 -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
70 -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
71 -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
72 -t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
73 -u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
24405
80129d4a8cec Fix last checkin, can't use " inside a string
Neal Norwitz <nnorwitz@gmail.com>
parents: 24401
diff changeset
74 see man page for details on internal buffering relating to '-u'\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
75 ";
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
76 static char *usage_3 = "\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
78 -V : print the Python version number and exit\n\
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
79 -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
80 -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 file : program read from script file\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 - : program read from stdin (default; interactive mode if a tty)\n\
6203
f57ae68aa3ae Added -X option to suppress default import of site.py. Also split the
Guido van Rossum <guido@python.org>
parents: 6199
diff changeset
83 ";
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
84 static char *usage_4 = "\
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
85 arg ...: arguments passed to program in sys.argv[1:]\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 Other environment variables:\n\
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 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
88 PYTHONPATH : '%c'-separated list of directories prefixed to the\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 default module search path. The result is sys.path.\n\
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
90 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
91 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
92 PYTHONCASEOK : ignore case in 'import' statements (Windows).\n\
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 ";
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
96 static void
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
97 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
98 {
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
99 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
100
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
101 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
102 if (exitcode)
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
103 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
104 else {
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
105 fprintf(f, usage_1);
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
106 fprintf(f, usage_2);
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
107 fprintf(f, usage_3);
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
108 fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP);
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
109 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
110 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
111 if (exitcode == 0) {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
112 /* suppress 'error' message */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
113 exit(1);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
114 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
115 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
116 /* STS$M_INHIB_MSG + SS$_ABORT */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
117 exit(0x1000002c);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
118 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
119 #else
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
120 exit(exitcode);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
121 #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
122 /*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
123 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
124
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
125
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 /* Main program */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24405
diff changeset
128 int
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
129 Py_Main(int argc, char **argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 int c;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 int sts;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 char *command = NULL;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 char *filename = NULL;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 FILE *fp = stdin;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 char *p;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 int inspect = 0;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 int unbuffered = 0;
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
139 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
140 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
141 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
142 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
143 int saw_inspect_flag = 0;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
144 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
145 PyCompilerFlags cf;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
147 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
148
3773
6e40a2a3e6ef New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents: 3701
diff changeset
149 orig_argc = argc; /* For Py_GetArgcArgv() */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 orig_argv = argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
152 #ifdef RISCOS
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
153 Py_RISCOSWimpFlag = 0;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
154 #endif
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
155
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
156 PySys_ResetWarnOptions();
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
157
24480
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
158 #if defined(WITH_NEXT_FRAMEWORK)
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
159 /* If we are running from a framework it could be that we are actually
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
160 ** the main program for an applet. If so, the next call will return the
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
161 ** filename that we are supposed to run.
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
162 */
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
163 filename = PyMac_GetAppletScriptFile();
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
164 if (filename != NULL) {
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
165 if ((fp = fopen(filename, "r")) == NULL) {
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
166 fprintf(stderr, "%s: can't open file '%s'\n",
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
167 argv[0], filename);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
168 #if defined(__VMS)
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
169 /* STS$M_INHIB_MSG + SS$_ABORT */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
170 exit(0x1000002c);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
171 #else
24480
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
172 exit(2);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
173 #endif
24480
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
174 }
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
175 }
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
176 /* Skip option-processing if we are an applet */
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
177 if (filename == NULL)
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
178 #endif
17396
beb9d2b02846 Updated version of RISCOS support. SF patch 411213 by Dietmar Schwertberger
Guido van Rossum <guido@python.org>
parents: 17125
diff changeset
179 while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 if (c == 'c') {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 /* -c is the last option; following arguments
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 that look like options are left for the
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 the command to interpret. */
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
184 command = malloc(strlen(_PyOS_optarg) + 2);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 if (command == NULL)
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 Py_FatalError(
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 "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
188 strcpy(command, _PyOS_optarg);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 strcat(command, "\n");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 }
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
192
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 switch (c) {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 case 'd':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 Py_DebugFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
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
199 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
200 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
201 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
202 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
203 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
204 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
205 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
206 break;
b3271297b984 PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents: 19672
diff changeset
207 }
b3271297b984 PEP 238 documented -Qwarn as warning only for classic int or long
Guido van Rossum <guido@python.org>
parents: 19672
diff changeset
208 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
209 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
210 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
211 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
212 if (strcmp(_PyOS_optarg, "new") == 0) {
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
213 /* 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
214 cf.cf_flags |= CO_FUTURE_DIVISION;
21251
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
215 /* 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
216 BINARY_DIVIDE as BINARY_TRUE_DIVIDE */
45e1177424e1 SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents: 19673
diff changeset
217 _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
218 break;
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
219 }
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
220 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
221 "-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
222 "`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
223 usage(2, argv[0]);
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
224 /* NOTREACHED */
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
225
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 case 'i':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 inspect++;
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
228 saw_inspect_flag = 1;
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
229 Py_InteractiveFlag++;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
5166
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
232 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
233 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
234 break;
7151bb727776 Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents: 5113
diff changeset
235
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
236 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
237 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
238 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
239
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
240 case 'E':
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
241 Py_IgnoreEnvironmentFlag++;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
242 break;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
243
7966
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
244 case 't':
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
245 Py_TabcheckFlag++;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
246 break;
8c268d0e8822 Add -t option to set the Py_TabcheckFlag flag.
Guido van Rossum <guido@python.org>
parents: 7571
diff changeset
247
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 case 'u':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 unbuffered++;
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
250 saw_unbuffered_flag = 1;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 case 'v':
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 Py_VerboseFlag++;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 break;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
256
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
257 #ifdef RISCOS
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
258 case 'w':
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
259 Py_RISCOSWimpFlag = 1;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
260 break;
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
261 #endif
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
262
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
263 case 'x':
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
264 skipfirstline = 1;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
265 break;
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
266
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
267 case 'U':
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
268 Py_UnicodeFlag++;
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
269 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
270 case 'h':
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
271 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
272 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
273 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
274 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
275 break;
12537
7cc3dd7cd31a Marc-Andre Lemburg:
Guido van Rossum <guido@python.org>
parents: 10621
diff changeset
276
15593
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
277 case 'W':
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
278 PySys_AddWarnOption(_PyOS_optarg);
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
279 break;
9694909dbb0a Add the -W option.
Guido van Rossum <guido@python.org>
parents: 15374
diff changeset
280
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 /* This space reserved for other options */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 default:
14603
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
284 usage(2, argv[0]);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 /*NOTREACHED*/
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 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
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
290 if (help)
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
291 usage(0, argv[0]);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
292
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
293 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
294 fprintf(stderr, "Python %s\n", PY_VERSION);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
295 exit(0);
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
296 }
80a782086a57 Py_Main(), usage(), usage_mid: Add -h and -V flags to print the usage
Barry Warsaw <barry@python.org>
parents: 14411
diff changeset
297
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
298 if (!saw_inspect_flag &&
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
299 (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
300 inspect = 1;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
301 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
302 (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
303 unbuffered = 1;
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
304
24480
03d85d197052 Added one call to Py_Main(), for OSX framework builds only, that will get the
Jack Jansen <jack.jansen@cwi.nl>
parents: 24471
diff changeset
305 if (command == NULL && filename == 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
306 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
307 {
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
308 filename = argv[_PyOS_optind];
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
309 if (filename != NULL) {
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
310 if ((fp = fopen(filename, "r")) == NULL) {
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
311 fprintf(stderr, "%s: can't open file '%s'\n",
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
312 argv[0], filename);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
313 exit(2);
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
314 }
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
315 else if (skipfirstline) {
10621
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
316 int ch;
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
317 /* Push back first newline so line numbers
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
318 remain the same */
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
319 while ((ch = getc(fp)) != EOF) {
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
320 if (ch == '\n') {
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
321 (void)ungetc(ch, fp);
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
322 break;
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
323 }
5b170f0da9fe Patch from Tim Peters to repare a the problem that tracebacks are off
Guido van Rossum <guido@python.org>
parents: 10130
diff changeset
324 }
6763
12824fe04a08 Two changes by Jeff Rush (slightly tweaked):
Guido van Rossum <guido@python.org>
parents: 6538
diff changeset
325 }
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 }
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
327 }
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
328
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
329 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
330
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 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
332 #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
333 _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
334 _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
335 #endif
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 #ifndef MPW
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
337 #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
338 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
339 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
340 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
341 #else /* !HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
342 setbuf(stdin, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
343 setbuf(stdout, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
344 setbuf(stderr, (char *)NULL);
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
345 #endif /* !HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
346 #else /* MPW */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 /* On MPW (3.2) unbuffered seems to hang */
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
348 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
7571
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
351 #endif /* MPW */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 }
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
353 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
354 #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
355 /* 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
356 /* 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
357 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
358 #else /* !MS_WINDOWS */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
359 #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
360 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
361 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
362 #endif /* HAVE_SETVBUF */
968aaba281c5 Don't use setvbuf unless HAVE_SETVBUF is defined.
Guido van Rossum <guido@python.org>
parents: 6763
diff changeset
363 #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
364 /* 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
365 }
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
366 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
367 else {
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
368 setvbuf (stdout, (char *)NULL, _IOLBF, BUFSIZ);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
369 }
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
370 #endif /* __VMS */
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371
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
372 Py_SetProgramName(argv[0]);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
373 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
374 PyVMS_init(&argc, &argv);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
375 #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
376 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
377
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
378 #ifdef __VMS
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
379 /* create an empty string object */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
380 pyvms_gr_empty_string = Py_BuildValue("s#", Py_None, (unsigned int)0);
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
381 #endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
382
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 if (Py_VerboseFlag ||
5113
fb8cefcefd81 Add parentheses around && within || as gcc -Wall advises.
Guido van Rossum <guido@python.org>
parents: 5109
diff changeset
384 (command == NULL && filename == NULL && stdin_is_interactive))
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
385 #ifndef __VMS
5547
98d4e97daac0 Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents: 5394
diff changeset
386 fprintf(stderr, "Python %s on %s\n%s\n",
14411
a707a5f17139 Instead of printing all 9 lines of copyright info, print
Guido van Rossum <guido@python.org>
parents: 14375
diff changeset
387 Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
26550
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
388 #else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
389 fprintf(stderr, "Python %s on %s %s (%s_float)\n%s\n",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
390 Py_GetVersion(), Py_GetPlatform(),
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
391 # ifdef __ALPHA
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
392 "Alpha",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
393 # else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
394 "VAX",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
395 # endif
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
396 # if __IEEE_FLOAT
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
397 "T",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
398 # else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
399 # if __D_FLOAT
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
400 "D",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
401 # else
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
402 # if __G_FLOAT
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
403 "G",
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
404 # endif /* __G_FLOAT */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
405 # endif /* __D_FLOAT */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
406 # endif /* __IEEE_FLOAT */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
407 COPYRIGHT); /* << @@ defined above in this file */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
408 /* Py_GetCopyright()); */
b9c912e2c3c0 Patch #614055: Support OpenVMS.
Martin v. Löwis <martin@v.loewis.de>
parents: 25826
diff changeset
409 #endif /* __VMS */
19633
c0a44829bcd5 Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents: 18808
diff changeset
410
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 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
412 /* 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
413 _PyOS_optind--;
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
414 argv[_PyOS_optind] = "-c";
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
416
15374
a826a46bae54 Move our own getopt() implementation to _PyOS_GetOpt(), and use it
Thomas Wouters <thomas@python.org>
parents: 14603
diff changeset
417 PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418
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
419 if ((inspect || (command == NULL && filename == NULL)) &&
c2359665be80 Move the "import readline" to an earlier place so it is also done when
Guido van Rossum <guido@python.org>
parents: 6203
diff changeset
420 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
421 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
422 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
423 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
424 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
425 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
426 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
427 }
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
428
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 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
430 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
431 free(command);
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 else {
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
434 if (filename == NULL && stdin_is_interactive) {
18808
a8b1acc7a21f Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 18692
diff changeset
435 char *startup = Py_GETENV("PYTHONSTARTUP");
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 if (startup != NULL && startup[0] != '\0') {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 FILE *fp = fopen(startup, "r");
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 if (fp != NULL) {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 (void) PyRun_SimpleFile(fp, startup);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
440 PyErr_Clear();
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 fclose(fp);
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 }
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
445 /* XXX */
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
446 sts = PyRun_AnyFileExFlags(
5109
0bbf97861cd9 My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents: 5000
diff changeset
447 fp,
14228
20377f15b96a Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents: 13482
diff changeset
448 filename == NULL ? "<stdin>" : filename,
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
449 filename != NULL, &cf) != 0;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
451
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
452 if (inspect && stdin_is_interactive &&
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 (filename != NULL || command != NULL))
17125
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
454 /* XXX */
2054cea38754 Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16944
diff changeset
455 sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
456
5940
eef76b3cd9ae Py_Cleanup() is now Py_Finalize().
Guido van Rossum <guido@python.org>
parents: 5922
diff changeset
457 Py_Finalize();
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
458 #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
459 if (Py_RISCOSWimpFlag)
16944
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
460 fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */
4baa5a955532 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16752
diff changeset
461 #endif
16752
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
462
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
463 #ifdef __INSURE__
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
464 /* 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
465 * 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
466 * 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
467 * (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
468 * 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
469 * 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
470 * 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
471 * reports. -baw
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
472 */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
473 _Py_ReleaseInternedStrings();
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
474 #endif /* __INSURE__ */
5c3aedc969da Py_Main(): When compiled by Insure (i.e. __INSURE__ is defined), call
Barry Warsaw <barry@python.org>
parents: 16731
diff changeset
475
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
476 return sts;
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 }
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
478
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
479
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480 /* Make the *original* argc/argv available to other modules.
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
481 This is rare, but it is needed by the secureware extension. */
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
482
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
483 void
13482
000a1c7eb09f - changed 1.5 to 2.0 in the help text
Fredrik Lundh <fredrik@pythonware.com>
parents: 13256
diff changeset
484 Py_GetArgcArgv(int *argc, char ***argv)
2896
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
485 {
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 *argc = orig_argc;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
487 *argv = orig_argv;
f0d9f800a4aa Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
488 }