Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 6d023c9 | 1995-01-04 19:12:13 +0000 | [diff] [blame] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 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 | f56e3db | 1993-04-01 20:59:32 +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 | f56e3db | 1993-04-01 20:59:32 +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 | f56e3db | 1993-04-01 20:59:32 +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 | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | /* Python interpreter main program for frozen scripts */ |
| 33 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 34 | #include "Python.h" |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 35 | |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 36 | #ifdef MS_WIN32 |
| 37 | extern void PyWinFreeze_ExeInit(); |
| 38 | extern void PyWinFreeze_ExeTerm(); |
Guido van Rossum | 47ae028 | 1999-01-02 21:42:48 +0000 | [diff] [blame] | 39 | extern int PyInitFrozenExtensions(); |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
Guido van Rossum | 73bacfc | 1998-01-19 22:05:22 +0000 | [diff] [blame] | 42 | #ifdef HAVE_UNISTD_H |
| 43 | #include <unistd.h> /* For isatty() */ |
| 44 | #endif |
| 45 | |
Guido van Rossum | 1a8791e | 1998-08-04 22:46:29 +0000 | [diff] [blame] | 46 | /* For isatty()'s proto. - [cjh] */ |
| 47 | #ifdef HAVE_UNISTD_H |
| 48 | #include <unistd.h> |
| 49 | #endif |
| 50 | |
Guido van Rossum | 47ad5e7 | 1995-08-04 04:10:43 +0000 | [diff] [blame] | 51 | /* Main program */ |
| 52 | |
| 53 | int |
Guido van Rossum | a941451 | 1997-07-19 21:59:47 +0000 | [diff] [blame] | 54 | Py_FrozenMain(argc, argv) |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 55 | int argc; |
| 56 | char **argv; |
| 57 | { |
| 58 | char *p; |
Guido van Rossum | 094885b | 1993-11-05 10:16:09 +0000 | [diff] [blame] | 59 | int n, sts; |
| 60 | int inspect = 0; |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 61 | int unbuffered = 0; |
| 62 | |
Guido van Rossum | 919b83d | 1998-02-06 22:30:29 +0000 | [diff] [blame] | 63 | Py_FrozenFlag = 1; /* Suppress errors from getpath.c */ |
| 64 | |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 65 | if ((p = getenv("PYTHONINSPECT")) && *p != '\0') |
| 66 | inspect = 1; |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 67 | if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0') |
| 68 | unbuffered = 1; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 69 | |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 70 | if (unbuffered) { |
Guido van Rossum | c425d2f | 1997-12-02 20:41:39 +0000 | [diff] [blame] | 71 | setbuf(stdin, (char *)NULL); |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 72 | setbuf(stdout, (char *)NULL); |
| 73 | setbuf(stderr, (char *)NULL); |
| 74 | } |
| 75 | |
Guido van Rossum | 47ae028 | 1999-01-02 21:42:48 +0000 | [diff] [blame] | 76 | #ifdef MS_WIN32 |
| 77 | PyInitFrozenExtensions(); |
| 78 | #endif /* MS_WIN32 */ |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 79 | Py_SetProgramName(argv[0]); |
| 80 | Py_Initialize(); |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 81 | #ifdef MS_WIN32 |
| 82 | PyWinFreeze_ExeInit(); |
| 83 | #endif |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 84 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 85 | if (Py_VerboseFlag) |
Guido van Rossum | 1d5735e | 1994-08-30 08:27:36 +0000 | [diff] [blame] | 86 | fprintf(stderr, "Python %s\n%s\n", |
Guido van Rossum | 582646a | 1996-05-28 22:30:17 +0000 | [diff] [blame] | 87 | Py_GetVersion(), Py_GetCopyright()); |
Guido van Rossum | 3768fb1 | 1997-07-19 19:24:41 +0000 | [diff] [blame] | 88 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 89 | PySys_SetArgv(argc, argv); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 90 | |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 91 | n = PyImport_ImportFrozenModule("__main__"); |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 92 | if (n == 0) |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 93 | Py_FatalError("__main__ not frozen"); |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 94 | if (n < 0) { |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 95 | PyErr_Print(); |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 96 | sts = 1; |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 97 | } |
| 98 | else |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 99 | sts = 0; |
| 100 | |
Guido van Rossum | f1dc566 | 1993-07-05 10:31:29 +0000 | [diff] [blame] | 101 | if (inspect && isatty((int)fileno(stdin))) |
Guido van Rossum | 4e2e0f9 | 1995-03-31 10:27:23 +0000 | [diff] [blame] | 102 | sts = PyRun_AnyFile(stdin, "<stdin>") != 0; |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame] | 103 | |
Guido van Rossum | 6deac7a | 1998-04-03 21:11:15 +0000 | [diff] [blame] | 104 | #ifdef MS_WIN32 |
| 105 | PyWinFreeze_ExeTerm(); |
| 106 | #endif |
Guido van Rossum | 7c14103 | 1997-08-15 02:52:08 +0000 | [diff] [blame] | 107 | Py_Finalize(); |
| 108 | return sts; |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 109 | } |