Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 9 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 10 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 11 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 16 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* Python interpreter main program */ |
| 33 | |
| 34 | #include "Python.h" |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 35 | #include "osdefs.h" |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 36 | |
Guido van Rossum | 66a7013 | 1996-12-09 18:46:58 +0000 | [diff] [blame] | 37 | #ifdef HAVE_UNISTD_H |
| 38 | #include <unistd.h> |
| 39 | #endif |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | 3e7ae7a | 1997-01-17 22:05:38 +0000 | [diff] [blame] | 41 | #ifdef MS_WINDOWS |
| 42 | #include <fcntl.h> |
| 43 | #endif |
| 44 | |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 45 | #if defined(PYOS_OS2) || defined(MS_WINDOWS) |
| 46 | #define PYTHONHOMEHELP "<prefix>\\lib" |
| 47 | #else |
| 48 | #define PYTHONHOMEHELP "<prefix>/python1.5" |
| 49 | #endif |
| 50 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 51 | /* Interface to getopt(): */ |
| 52 | extern int optind; |
| 53 | extern char *optarg; |
| 54 | extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */ |
| 55 | |
| 56 | |
Guido van Rossum | ac56b03 | 1996-07-21 02:33:38 +0000 | [diff] [blame] | 57 | /* For Py_GetArgcArgv(); set by main() */ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 58 | static char **orig_argv; |
| 59 | static int orig_argc; |
| 60 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 61 | /* Short usage message (with %s for argv0) */ |
| 62 | static char *usage_line = |
Guido van Rossum | 6b86a42 | 1999-01-28 15:07:47 +0000 | [diff] [blame] | 63 | "usage: %s [option] ... [-c cmd | file | -] [arg] ...\n"; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 64 | |
| 65 | /* Long usage message, split into parts < 512 bytes */ |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 66 | static char *usage_top = "\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 67 | Options and arguments (and corresponding environment variables):\n\ |
| 68 | -d : debug output from parser (also PYTHONDEBUG=x)\n\ |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 69 | -i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\ |
Guido van Rossum | bba92ca | 1998-04-10 19:39:15 +0000 | [diff] [blame] | 70 | and force prompts, even if stdin does not appear to be a terminal\n\ |
Guido van Rossum | e7adf3e | 1998-10-07 14:50:06 +0000 | [diff] [blame] | 71 | -O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\ |
Guido van Rossum | 6b86a42 | 1999-01-28 15:07:47 +0000 | [diff] [blame] | 72 | -OO : remove doc-strings in addition to the -O optimizations\n\ |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 73 | -S : don't imply 'import site' on initialization\n\ |
Guido van Rossum | bba92ca | 1998-04-10 19:39:15 +0000 | [diff] [blame] | 74 | -t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 75 | "; |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 76 | static char *usage_mid = "\ |
Guido van Rossum | bba92ca | 1998-04-10 19:39:15 +0000 | [diff] [blame] | 77 | -u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\ |
Guido van Rossum | c15a9a1 | 2000-05-01 17:54:33 +0000 | [diff] [blame] | 78 | -U : Unicode literals: treats '...' literals like u'...'\n\ |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 79 | -v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\ |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 80 | -x : skip first line of source, allowing use of non-Unix forms of #!cmd\n\ |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 81 | -c cmd : program passed in as string (terminates option list)\n\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 82 | file : program read from script file\n\ |
| 83 | - : program read from stdin (default; interactive mode if a tty)\n\ |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 84 | "; |
| 85 | static char *usage_bot = "\ |
Guido van Rossum | bba92ca | 1998-04-10 19:39:15 +0000 | [diff] [blame] | 86 | arg ...: arguments passed to program in sys.argv[1:]\n\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 87 | Other environment variables:\n\ |
| 88 | PYTHONSTARTUP: file executed on interactive startup (no default)\n\ |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 89 | PYTHONPATH : '%c'-separated list of directories prefixed to the\n\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 90 | default module search path. The result is sys.path.\n\ |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 91 | PYTHONHOME : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\ |
| 92 | The default module search path uses %s.\n\ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 93 | "; |
| 94 | |
| 95 | |
| 96 | /* Main program */ |
| 97 | |
Guido van Rossum | 9c1201f | 1998-12-07 14:28:47 +0000 | [diff] [blame] | 98 | DL_EXPORT(int) |
Guido van Rossum | ed52aac | 1997-07-19 19:20:32 +0000 | [diff] [blame] | 99 | Py_Main(argc, argv) |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 100 | int argc; |
| 101 | char **argv; |
| 102 | { |
| 103 | int c; |
| 104 | int sts; |
| 105 | char *command = NULL; |
| 106 | char *filename = NULL; |
| 107 | FILE *fp = stdin; |
| 108 | char *p; |
| 109 | int inspect = 0; |
| 110 | int unbuffered = 0; |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 111 | int skipfirstline = 0; |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 112 | int stdin_is_interactive = 0; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 113 | |
Guido van Rossum | ac56b03 | 1996-07-21 02:33:38 +0000 | [diff] [blame] | 114 | orig_argc = argc; /* For Py_GetArgcArgv() */ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 115 | orig_argv = argv; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 116 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 117 | if ((p = getenv("PYTHONINSPECT")) && *p != '\0') |
| 118 | inspect = 1; |
| 119 | if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
| 120 | unbuffered = 1; |
| 121 | |
Guido van Rossum | c15a9a1 | 2000-05-01 17:54:33 +0000 | [diff] [blame] | 122 | while ((c = getopt(argc, argv, "c:diOStuUvxX")) != EOF) { |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 123 | if (c == 'c') { |
| 124 | /* -c is the last option; following arguments |
| 125 | that look like options are left for the |
| 126 | the command to interpret. */ |
| 127 | command = malloc(strlen(optarg) + 2); |
| 128 | if (command == NULL) |
| 129 | Py_FatalError( |
| 130 | "not enough memory to copy -c argument"); |
| 131 | strcpy(command, optarg); |
| 132 | strcat(command, "\n"); |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | switch (c) { |
| 137 | |
| 138 | case 'd': |
| 139 | Py_DebugFlag++; |
| 140 | break; |
| 141 | |
| 142 | case 'i': |
| 143 | inspect++; |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 144 | Py_InteractiveFlag++; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 145 | break; |
| 146 | |
Guido van Rossum | 7614da6 | 1997-03-03 19:14:45 +0000 | [diff] [blame] | 147 | case 'O': |
| 148 | Py_OptimizeFlag++; |
| 149 | break; |
| 150 | |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 151 | case 'S': |
| 152 | Py_NoSiteFlag++; |
| 153 | break; |
| 154 | |
Guido van Rossum | bba92ca | 1998-04-10 19:39:15 +0000 | [diff] [blame] | 155 | case 't': |
| 156 | Py_TabcheckFlag++; |
| 157 | break; |
| 158 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 159 | case 'u': |
| 160 | unbuffered++; |
| 161 | break; |
| 162 | |
| 163 | case 'v': |
| 164 | Py_VerboseFlag++; |
| 165 | break; |
| 166 | |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 167 | case 'x': |
| 168 | skipfirstline = 1; |
| 169 | break; |
| 170 | |
Guido van Rossum | c15a9a1 | 2000-05-01 17:54:33 +0000 | [diff] [blame] | 171 | case 'U': |
| 172 | Py_UnicodeFlag++; |
| 173 | break; |
| 174 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 175 | /* This space reserved for other options */ |
| 176 | |
| 177 | default: |
| 178 | fprintf(stderr, usage_line, argv[0]); |
| 179 | fprintf(stderr, usage_top); |
Guido van Rossum | 7922bd7 | 1997-08-29 22:34:47 +0000 | [diff] [blame] | 180 | fprintf(stderr, usage_mid); |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 181 | fprintf(stderr, usage_bot, |
| 182 | DELIM, DELIM, PYTHONHOMEHELP); |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 183 | exit(2); |
| 184 | /*NOTREACHED*/ |
| 185 | |
| 186 | } |
| 187 | } |
| 188 | |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 189 | if (command == NULL && optind < argc && |
| 190 | strcmp(argv[optind], "-") != 0) |
| 191 | { |
| 192 | filename = argv[optind]; |
| 193 | if (filename != NULL) { |
| 194 | if ((fp = fopen(filename, "r")) == NULL) { |
| 195 | fprintf(stderr, "%s: can't open file '%s'\n", |
| 196 | argv[0], filename); |
| 197 | exit(2); |
| 198 | } |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 199 | else if (skipfirstline) { |
Guido van Rossum | dc8b569 | 1999-04-19 17:54:19 +0000 | [diff] [blame] | 200 | int ch; |
| 201 | /* Push back first newline so line numbers |
| 202 | remain the same */ |
| 203 | while ((ch = getc(fp)) != EOF) { |
| 204 | if (ch == '\n') { |
| 205 | (void)ungetc(ch, fp); |
| 206 | break; |
| 207 | } |
| 208 | } |
Guido van Rossum | a075ce1 | 1997-12-05 21:56:45 +0000 | [diff] [blame] | 209 | } |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
| 213 | stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0); |
| 214 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 215 | if (unbuffered) { |
Guido van Rossum | f22d7e2 | 1997-01-11 19:28:55 +0000 | [diff] [blame] | 216 | #ifdef MS_WINDOWS |
Guido van Rossum | 3e7ae7a | 1997-01-17 22:05:38 +0000 | [diff] [blame] | 217 | _setmode(fileno(stdin), O_BINARY); |
| 218 | _setmode(fileno(stdout), O_BINARY); |
Guido van Rossum | f22d7e2 | 1997-01-11 19:28:55 +0000 | [diff] [blame] | 219 | #endif |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 220 | #ifndef MPW |
Guido van Rossum | 22ffac1 | 1998-03-06 15:30:39 +0000 | [diff] [blame] | 221 | #ifdef HAVE_SETVBUF |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 222 | setvbuf(stdin, (char *)NULL, _IONBF, BUFSIZ); |
| 223 | setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ); |
| 224 | setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ); |
Guido van Rossum | 22ffac1 | 1998-03-06 15:30:39 +0000 | [diff] [blame] | 225 | #else /* !HAVE_SETVBUF */ |
| 226 | setbuf(stdin, (char *)NULL); |
| 227 | setbuf(stdout, (char *)NULL); |
| 228 | setbuf(stderr, (char *)NULL); |
| 229 | #endif /* !HAVE_SETVBUF */ |
| 230 | #else /* MPW */ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 231 | /* On MPW (3.2) unbuffered seems to hang */ |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 232 | setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ); |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 233 | setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
| 234 | setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ); |
Guido van Rossum | 22ffac1 | 1998-03-06 15:30:39 +0000 | [diff] [blame] | 235 | #endif /* MPW */ |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 236 | } |
Guido van Rossum | 2a21219 | 1997-04-11 21:57:53 +0000 | [diff] [blame] | 237 | else if (Py_InteractiveFlag) { |
Guido van Rossum | b31c7dc | 1997-04-11 22:19:12 +0000 | [diff] [blame] | 238 | #ifdef MS_WINDOWS |
| 239 | /* Doesn't have to have line-buffered -- use unbuffered */ |
Guido van Rossum | 01b7ced | 1999-02-09 18:36:51 +0000 | [diff] [blame] | 240 | /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */ |
Guido van Rossum | b31c7dc | 1997-04-11 22:19:12 +0000 | [diff] [blame] | 241 | setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ); |
Guido van Rossum | 22ffac1 | 1998-03-06 15:30:39 +0000 | [diff] [blame] | 242 | #else /* !MS_WINDOWS */ |
| 243 | #ifdef HAVE_SETVBUF |
Guido van Rossum | b31c7dc | 1997-04-11 22:19:12 +0000 | [diff] [blame] | 244 | setvbuf(stdin, (char *)NULL, _IOLBF, BUFSIZ); |
| 245 | setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ); |
Guido van Rossum | 22ffac1 | 1998-03-06 15:30:39 +0000 | [diff] [blame] | 246 | #endif /* HAVE_SETVBUF */ |
| 247 | #endif /* !MS_WINDOWS */ |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 248 | /* Leave stderr alone - it should be unbuffered anyway. */ |
| 249 | } |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 250 | |
Guido van Rossum | ed52aac | 1997-07-19 19:20:32 +0000 | [diff] [blame] | 251 | Py_SetProgramName(argv[0]); |
| 252 | Py_Initialize(); |
| 253 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 254 | if (Py_VerboseFlag || |
Guido van Rossum | 129e91a | 1997-02-14 21:00:50 +0000 | [diff] [blame] | 255 | (command == NULL && filename == NULL && stdin_is_interactive)) |
Guido van Rossum | fe4dfc7 | 1997-05-19 18:33:01 +0000 | [diff] [blame] | 256 | fprintf(stderr, "Python %s on %s\n%s\n", |
| 257 | Py_GetVersion(), Py_GetPlatform(), Py_GetCopyright()); |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 258 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 259 | |
| 260 | if (command != NULL) { |
| 261 | /* Backup optind and force sys.argv[0] = '-c' */ |
| 262 | optind--; |
| 263 | argv[optind] = "-c"; |
| 264 | } |
| 265 | |
| 266 | PySys_SetArgv(argc-optind, argv+optind); |
| 267 | |
Guido van Rossum | 3d26cc9 | 1997-09-16 16:11:28 +0000 | [diff] [blame] | 268 | if ((inspect || (command == NULL && filename == NULL)) && |
| 269 | isatty(fileno(stdin))) { |
| 270 | PyObject *v; |
| 271 | v = PyImport_ImportModule("readline"); |
| 272 | if (v == NULL) |
| 273 | PyErr_Clear(); |
| 274 | else |
| 275 | Py_DECREF(v); |
| 276 | } |
| 277 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 278 | if (command) { |
| 279 | sts = PyRun_SimpleString(command) != 0; |
Guido van Rossum | 05f7c50 | 1997-08-02 03:00:42 +0000 | [diff] [blame] | 280 | free(command); |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 281 | } |
| 282 | else { |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 283 | if (filename == NULL && stdin_is_interactive) { |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 284 | char *startup = getenv("PYTHONSTARTUP"); |
| 285 | if (startup != NULL && startup[0] != '\0') { |
| 286 | FILE *fp = fopen(startup, "r"); |
| 287 | if (fp != NULL) { |
| 288 | (void) PyRun_SimpleFile(fp, startup); |
| 289 | PyErr_Clear(); |
| 290 | fclose(fp); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | sts = PyRun_AnyFile( |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 295 | fp, |
| 296 | filename == NULL ? "<stdin>" : filename) != 0; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 297 | if (filename != NULL) |
| 298 | fclose(fp); |
| 299 | } |
| 300 | |
Guido van Rossum | 775af91 | 1997-02-14 19:50:32 +0000 | [diff] [blame] | 301 | if (inspect && stdin_is_interactive && |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 302 | (filename != NULL || command != NULL)) |
| 303 | sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
| 304 | |
Guido van Rossum | 5d1770e | 1997-08-05 02:23:48 +0000 | [diff] [blame] | 305 | Py_Finalize(); |
Guido van Rossum | 05f7c50 | 1997-08-02 03:00:42 +0000 | [diff] [blame] | 306 | return sts; |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 310 | /* Make the *original* argc/argv available to other modules. |
| 311 | This is rare, but it is needed by the secureware extension. */ |
| 312 | |
| 313 | void |
Guido van Rossum | ac56b03 | 1996-07-21 02:33:38 +0000 | [diff] [blame] | 314 | Py_GetArgcArgv(argc, argv) |
Guido van Rossum | 667d704 | 1995-08-04 04:20:48 +0000 | [diff] [blame] | 315 | int *argc; |
| 316 | char ***argv; |
| 317 | { |
| 318 | *argc = orig_argc; |
| 319 | *argv = orig_argv; |
| 320 | } |