Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
| 11 | /* Python interpreter main program for frozen scripts */ |
| 12 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 13 | #include "Python.h" |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 14 | |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 15 | #ifdef MS_WIN32 |
Thomas Wouters | b4bd21c | 2000-07-22 23:38:01 +0000 | [diff] [blame] | 16 | extern void PyWinFreeze_ExeInit(void); |
| 17 | extern void PyWinFreeze_ExeTerm(void); |
| 18 | extern int PyInitFrozenExtensions(void); |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 19 | #endif |
| 20 | |
Guido van Rossum | 73bacfc | 1998-01-19 22:05:22 +0000 | [diff] [blame] | 21 | #ifdef HAVE_UNISTD_H |
| 22 | #include <unistd.h> /* For isatty() */ |
| 23 | #endif |
| 24 | |
Guido van Rossum | 1a8791e | 1998-08-04 22:46:29 +0000 | [diff] [blame] | 25 | /* For isatty()'s proto. - [cjh] */ |
| 26 | #ifdef HAVE_UNISTD_H |
| 27 | #include <unistd.h> |
| 28 | #endif |
| 29 | |
Guido van Rossum | 47ad5e7 | 1995-08-04 04:10:43 +0000 | [diff] [blame] | 30 | /* Main program */ |
| 31 | |
| 32 | int |
Thomas Wouters | f70ef4f | 2000-07-22 18:47:25 +0000 | [diff] [blame] | 33 | Py_FrozenMain(int argc, char **argv) |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 34 | { |
| 35 | char *p; |
Guido van Rossum | 094885b | 1993-11-05 10:16:09 +0000 | [diff] [blame] | 36 | int n, sts; |
| 37 | int inspect = 0; |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 38 | int unbuffered = 0; |
| 39 | |
Guido van Rossum | 919b83d | 1998-02-06 22:30:29 +0000 | [diff] [blame] | 40 | Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ |
| 41 | |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 42 | if ((p = getenv("PYTHONINSPECT")) && *p != '\0') |
| 43 | inspect = 1; |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 44 | if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
| 45 | unbuffered = 1; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 47 | if (unbuffered) { |
Guido van Rossum | c425d2f | 1997-12-02 20:41:39 +0000 | [diff] [blame] | 48 | setbuf(stdin, (char *)NULL); |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 49 | setbuf(stdout, (char *)NULL); |
| 50 | setbuf(stderr, (char *)NULL); |
| 51 | } |
| 52 | |
Guido van Rossum | 47ae028 | 1999-01-02 21:42:48 +0000 | [diff] [blame] | 53 | #ifdef MS_WIN32 |
| 54 | PyInitFrozenExtensions(); |
| 55 | #endif /* MS_WIN32 */ |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 56 | Py_SetProgramName(argv[0]); |
| 57 | Py_Initialize(); |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 58 | #ifdef MS_WIN32 |
| 59 | PyWinFreeze_ExeInit(); |
| 60 | #endif |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 62 | if (Py_VerboseFlag) |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 63 | fprintf(stderr, "Python %s\n%s\n", |
Guido van Rossum | 582646a | 1996-05-28 22:30:17 +0000 | [diff] [blame] | 64 | Py_GetVersion(), Py_GetCopyright()); |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 65 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 66 | PySys_SetArgv(argc, argv); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 67 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 68 | n = PyImport_ImportFrozenModule("__main__"); |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 69 | if (n == 0) |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 70 | Py_FatalError("__main__ not frozen"); |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 71 | if (n < 0) { |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 72 | PyErr_Print(); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 73 | sts = 1; |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 74 | } |
| 75 | else |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 76 | sts = 0; |
| 77 | |
Guido van Rossum | f1dc566 | 1993-07-05 10:31:29 +0000 | [diff] [blame] | 78 | if (inspect && isatty((int)fileno(stdin))) |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 79 | sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 80 | |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 81 | #ifdef MS_WIN32 |
| 82 | PyWinFreeze_ExeTerm(); |
| 83 | #endif |
Guido van Rossum | 7c14103 | 1997-08-15 02:52:08 +0000 | [diff] [blame] | 84 | Py_Finalize(); |
| 85 | return sts; |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 86 | } |