Mercurial > cpython-lru_cache-weakref
annotate Modules/main.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 98d4e97daac0 |
| children | edaf1cb63dc0 |
| rev | line source |
|---|---|
| 2896 | 1 /*********************************************************** |
| 2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, | |
| 3 The Netherlands. | |
| 4 | |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 2896 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 2896 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
15 permission. |
| 2896 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
3773
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 2896 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 32 /* Python interpreter main program */ | |
| 33 | |
| 34 #include "Python.h" | |
| 35 | |
|
4620
98c08f0c4a2e
Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
36 #ifdef HAVE_UNISTD_H |
|
98c08f0c4a2e
Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
37 #include <unistd.h> |
|
98c08f0c4a2e
Include unistd.h to keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
38 #endif |
| 2896 | 39 |
|
5000
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
40 #ifdef MS_WINDOWS |
|
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
41 #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
|
42 #endif |
|
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
43 |
| 2896 | 44 /* Interface to getopt(): */ |
| 45 extern int optind; | |
| 46 extern char *optarg; | |
| 47 extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */ | |
| 48 | |
| 49 | |
| 50 /* Subroutines that live in their own file */ | |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
51 extern char *Py_GetVersion(); |
|
5547
98d4e97daac0
Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents:
5394
diff
changeset
|
52 extern char *Py_GetPlatform(); |
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
2896
diff
changeset
|
53 extern char *Py_GetCopyright(); |
| 2896 | 54 |
| 55 | |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
56 /* For Py_GetProgramName(); set by main() */ |
| 2896 | 57 static char *argv0; |
| 58 | |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
59 /* For Py_GetArgcArgv(); set by main() */ |
| 2896 | 60 static char **orig_argv; |
| 61 static int orig_argc; | |
| 62 | |
| 63 /* Short usage message (with %s for argv0) */ | |
| 64 static char *usage_line = | |
|
5166
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
65 "usage: %s [-d] [-i] [-O] [-s] [-u] [-v] [-c cmd | file | -] [arg] ...\n"; |
| 2896 | 66 |
| 67 /* Long usage message, split into parts < 512 bytes */ | |
| 68 static char *usage_top = "\n\ | |
| 69 Options and arguments (and corresponding environment variables):\n\ | |
| 70 -d : debug output from parser (also PYTHONDEBUG=x)\n\ | |
|
5109
0bbf97861cd9
My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents:
5000
diff
changeset
|
71 -i : inspect interactively after running script, (also PYTHONINSPECT=x)\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
|
72 and force prompts, even if stdin does not appear to be a terminal.\n\ |
|
5166
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
73 -O : optimize generated bytecode (a tad).\n\ |
| 2896 | 74 -s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\ |
| 75 -u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\ | |
| 76 -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\ | |
| 77 "; | |
| 78 static char *usage_bot = "\ | |
|
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
|
79 -c cmd : program passed in as string (terminates option list)\n\ |
| 2896 | 80 file : program read from script file\n\ |
| 81 - : program read from stdin (default; interactive mode if a tty)\n\ | |
| 82 arg ...: arguments passed to program in sys.argv[1:]\n\ | |
| 83 \n\ | |
| 84 Other environment variables:\n\ | |
| 85 PYTHONSTARTUP: file executed on interactive startup (no default)\n\ | |
| 86 PYTHONPATH : colon-separated list of directories prefixed to the\n\ | |
| 87 default module search path. The result is sys.path.\n\ | |
|
5394
c2fb976beceb
Add PYTHONHOME to the usage message.
Guido van Rossum <guido@python.org>
parents:
5320
diff
changeset
|
88 PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).\n\ |
|
c2fb976beceb
Add PYTHONHOME to the usage message.
Guido van Rossum <guido@python.org>
parents:
5320
diff
changeset
|
89 The default module search path uses <prefix>/lib/python1.5.\n\ |
| 2896 | 90 "; |
| 91 | |
| 92 | |
| 93 /* Main program */ | |
| 94 | |
| 95 int | |
| 96 main(argc, argv) | |
| 97 int argc; | |
| 98 char **argv; | |
| 99 { | |
| 100 int c; | |
| 101 int sts; | |
| 102 char *command = NULL; | |
| 103 char *filename = NULL; | |
| 104 FILE *fp = stdin; | |
| 105 char *p; | |
| 106 int inspect = 0; | |
| 107 int unbuffered = 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
|
108 int stdin_is_interactive = 0; |
| 2896 | 109 |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
110 orig_argc = argc; /* For Py_GetArgcArgv() */ |
| 2896 | 111 orig_argv = argv; |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
112 argv0 = argv[0]; /* For Py_GetProgramName() */ |
| 2896 | 113 |
| 114 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') | |
| 115 Py_DebugFlag = 1; | |
| 116 if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0') | |
| 117 Py_SuppressPrintingFlag = 1; | |
| 118 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') | |
| 119 Py_VerboseFlag = 1; | |
| 120 if ((p = getenv("PYTHONINSPECT")) && *p != '\0') | |
| 121 inspect = 1; | |
| 122 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') | |
| 123 unbuffered = 1; | |
| 124 | |
|
5166
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
125 while ((c = getopt(argc, argv, "c:diOsuv")) != EOF) { |
| 2896 | 126 if (c == 'c') { |
| 127 /* -c is the last option; following arguments | |
| 128 that look like options are left for the | |
| 129 the command to interpret. */ | |
| 130 command = malloc(strlen(optarg) + 2); | |
| 131 if (command == NULL) | |
| 132 Py_FatalError( | |
| 133 "not enough memory to copy -c argument"); | |
| 134 strcpy(command, optarg); | |
| 135 strcat(command, "\n"); | |
| 136 break; | |
| 137 } | |
| 138 | |
| 139 switch (c) { | |
| 140 | |
| 141 case 'd': | |
| 142 Py_DebugFlag++; | |
| 143 break; | |
| 144 | |
| 145 case 'i': | |
| 146 inspect++; | |
|
5109
0bbf97861cd9
My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents:
5000
diff
changeset
|
147 Py_InteractiveFlag++; |
| 2896 | 148 break; |
| 149 | |
|
5166
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
150 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
|
151 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
|
152 break; |
|
7151bb727776
Add -O option which sets Py_OptimizeFlag to avoid emitting SET_LINENO.
Guido van Rossum <guido@python.org>
parents:
5113
diff
changeset
|
153 |
| 2896 | 154 case 's': |
| 155 Py_SuppressPrintingFlag++; | |
| 156 break; | |
| 157 | |
| 158 case 'u': | |
| 159 unbuffered++; | |
| 160 break; | |
| 161 | |
| 162 case 'v': | |
| 163 Py_VerboseFlag++; | |
| 164 break; | |
| 165 | |
| 166 /* This space reserved for other options */ | |
| 167 | |
| 168 default: | |
| 169 fprintf(stderr, usage_line, argv[0]); | |
| 170 fprintf(stderr, usage_top); | |
| 171 fprintf(stderr, usage_bot); | |
| 172 exit(2); | |
| 173 /*NOTREACHED*/ | |
| 174 | |
| 175 } | |
| 176 } | |
| 177 | |
|
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
|
178 if (command == NULL && optind < argc && |
|
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
|
179 strcmp(argv[optind], "-") != 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
|
180 { |
|
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
|
181 filename = argv[optind]; |
|
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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 } |
|
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
|
188 } |
|
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
|
189 } |
|
0bbf97861cd9
My version of Lee Busby's patches to make '-i' pretend stdin is a tty
Guido van Rossum <guido@python.org>
parents:
5000
diff
changeset
|
190 |
|
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
|
191 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
|
192 |
| 2896 | 193 if (unbuffered) { |
|
4934
6b61912d5f35
On Windows, -u implies binary mode for stdin/stdout
Guido van Rossum <guido@python.org>
parents:
4620
diff
changeset
|
194 #ifdef MS_WINDOWS |
|
5000
7c7a186b6d86
Fix the _setmode() patch for MS_WINDOWS: include <fcntl.h> and use
Guido van Rossum <guido@python.org>
parents:
4934
diff
changeset
|
195 _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
|
196 _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
|
197 #endif |
| 2896 | 198 #ifndef MPW |
|
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
|
199 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
|
200 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
|
201 setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ); |
| 2896 | 202 #else |
| 203 /* 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
|
204 setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ); |
| 2896 | 205 setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
| 206 setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); | |
| 207 #endif | |
| 208 } | |
|
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
|
209 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
|
210 #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
|
211 /* Doesn't have to have line-buffered -- use unbuffered */ |
|
c3ddb84a7761
OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents:
5319
diff
changeset
|
212 setvbuf(stdin, (char *)NULL, _IONBF, 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
|
213 setvbuf(stdout, (char *)NULL, _IONBF, 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
|
214 #else |
|
c3ddb84a7761
OK, I lied. On Windows, _IOLBF seems to be the same as full
Guido van Rossum <guido@python.org>
parents:
5319
diff
changeset
|
215 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
|
216 setvbuf(stdout, (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
|
217 #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
|
218 /* 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
|
219 } |
| 2896 | 220 |
| 221 if (Py_VerboseFlag || | |
|
5113
fb8cefcefd81
Add parentheses around && within || as gcc -Wall advises.
Guido van Rossum <guido@python.org>
parents:
5109
diff
changeset
|
222 (command == NULL && filename == NULL && stdin_is_interactive)) |
|
5547
98d4e97daac0
Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents:
5394
diff
changeset
|
223 fprintf(stderr, "Python %s on %s\n%s\n", |
|
98d4e97daac0
Add platform to welcome message.
Guido van Rossum <guido@python.org>
parents:
5394
diff
changeset
|
224 Py_GetVersion(), Py_GetPlatform(), Py_GetCopyright()); |
| 2896 | 225 |
| 226 Py_Initialize(); | |
| 227 | |
| 228 if (command != NULL) { | |
| 229 /* Backup optind and force sys.argv[0] = '-c' */ | |
| 230 optind--; | |
| 231 argv[optind] = "-c"; | |
| 232 } | |
| 233 | |
| 234 PySys_SetArgv(argc-optind, argv+optind); | |
| 235 | |
| 236 if (command) { | |
| 237 sts = PyRun_SimpleString(command) != 0; | |
| 238 } | |
| 239 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
|
240 if (filename == NULL && stdin_is_interactive) { |
| 2896 | 241 char *startup = getenv("PYTHONSTARTUP"); |
| 242 if (startup != NULL && startup[0] != '\0') { | |
| 243 FILE *fp = fopen(startup, "r"); | |
| 244 if (fp != NULL) { | |
| 245 (void) PyRun_SimpleFile(fp, startup); | |
| 246 PyErr_Clear(); | |
| 247 fclose(fp); | |
| 248 } | |
| 249 } | |
| 250 } | |
| 251 sts = PyRun_AnyFile( | |
|
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
|
252 fp, |
|
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
|
253 filename == NULL ? "<stdin>" : filename) != 0; |
| 2896 | 254 if (filename != NULL) |
| 255 fclose(fp); | |
| 256 } | |
| 257 | |
|
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
|
258 if (inspect && stdin_is_interactive && |
| 2896 | 259 (filename != NULL || command != NULL)) |
| 260 sts = PyRun_AnyFile(stdin, "<stdin>") != 0; | |
| 261 | |
| 262 Py_Exit(sts); | |
| 4600 | 263 return 0; /* Make gcc -Wall happy */ |
| 2896 | 264 } |
| 265 | |
| 266 | |
|
3701
f04beb80f816
Made comment for getprogramname() more helpful.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
267 /* Return the program name -- some code out there needs this |
|
f04beb80f816
Made comment for getprogramname() more helpful.
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
268 (currently _tkinter.c and importdl.c). */ |
| 2896 | 269 |
| 270 char * | |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
271 Py_GetProgramName() |
| 2896 | 272 { |
| 273 return argv0; | |
| 274 } | |
| 275 | |
| 276 | |
| 277 /* Make the *original* argc/argv available to other modules. | |
| 278 This is rare, but it is needed by the secureware extension. */ | |
| 279 | |
| 280 void | |
|
3773
6e40a2a3e6ef
New style names for getprogramname and getargcargv
Guido van Rossum <guido@python.org>
parents:
3701
diff
changeset
|
281 Py_GetArgcArgv(argc, argv) |
| 2896 | 282 int *argc; |
| 283 char ***argv; | |
| 284 { | |
| 285 *argc = orig_argc; | |
| 286 *argv = orig_argv; | |
| 287 } |
