blob: cb46d65944acf09f37e19f3cc1281850ee335f8a [file] [log] [blame]
Guido van Rossumf56e3db1993-04-01 20:59:32 +00001/***********************************************************
Guido van Rossum6d023c91995-01-04 19:12:13 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf56e3db1993-04-01 20:59:32 +00004
5 All Rights Reserved
6
Guido van Rossumd266eb41996-10-25 14:44:06 +00007Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
Guido van Rossumf56e3db1993-04-01 20:59:32 +00009provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000010both that copyright notice and this permission notice appear in
Guido van Rossumf56e3db1993-04-01 20:59:32 +000011supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000012Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
Guido van Rossumf56e3db1993-04-01 20:59:32 +000016
Guido van Rossumd266eb41996-10-25 14:44:06 +000017While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf56e3db1993-04-01 20:59:32 +000029
30******************************************************************/
31
32/* Python interpreter main program for frozen scripts */
33
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000034#include "Python.h"
Guido van Rossumf56e3db1993-04-01 20:59:32 +000035
Guido van Rossum6deac7a1998-04-03 21:11:15 +000036#ifdef MS_WIN32
37extern void PyWinFreeze_ExeInit();
38extern void PyWinFreeze_ExeTerm();
39#endif
40
Guido van Rossum73bacfc1998-01-19 22:05:22 +000041#ifdef HAVE_UNISTD_H
42#include <unistd.h> /* For isatty() */
43#endif
44
Guido van Rossum1a8791e1998-08-04 22:46:29 +000045/* For isatty()'s proto. - [cjh] */
46#ifdef HAVE_UNISTD_H
47#include <unistd.h>
48#endif
49
Guido van Rossum47ad5e71995-08-04 04:10:43 +000050/* Main program */
51
52int
Guido van Rossuma9414511997-07-19 21:59:47 +000053Py_FrozenMain(argc, argv)
Guido van Rossumf56e3db1993-04-01 20:59:32 +000054 int argc;
55 char **argv;
56{
57 char *p;
Guido van Rossum094885b1993-11-05 10:16:09 +000058 int n, sts;
59 int inspect = 0;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000060 int unbuffered = 0;
61
Guido van Rossum919b83d1998-02-06 22:30:29 +000062 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
63
Guido van Rossum9e90a671993-06-24 11:10:19 +000064 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
65 inspect = 1;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000066 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
67 unbuffered = 1;
Guido van Rossum9e90a671993-06-24 11:10:19 +000068
Guido van Rossum1d5735e1994-08-30 08:27:36 +000069 if (unbuffered) {
Guido van Rossumc425d2f1997-12-02 20:41:39 +000070 setbuf(stdin, (char *)NULL);
Guido van Rossum1d5735e1994-08-30 08:27:36 +000071 setbuf(stdout, (char *)NULL);
72 setbuf(stderr, (char *)NULL);
73 }
74
Guido van Rossum3768fb11997-07-19 19:24:41 +000075 Py_SetProgramName(argv[0]);
76 Py_Initialize();
Guido van Rossum6deac7a1998-04-03 21:11:15 +000077#ifdef MS_WIN32
78 PyWinFreeze_ExeInit();
79#endif
Guido van Rossum3768fb11997-07-19 19:24:41 +000080
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000081 if (Py_VerboseFlag)
Guido van Rossum1d5735e1994-08-30 08:27:36 +000082 fprintf(stderr, "Python %s\n%s\n",
Guido van Rossum582646a1996-05-28 22:30:17 +000083 Py_GetVersion(), Py_GetCopyright());
Guido van Rossum3768fb11997-07-19 19:24:41 +000084
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000085 PySys_SetArgv(argc, argv);
Guido van Rossum9e90a671993-06-24 11:10:19 +000086
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000087 n = PyImport_ImportFrozenModule("__main__");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000088 if (n == 0)
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000089 Py_FatalError("__main__ not frozen");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000090 if (n < 0) {
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000091 PyErr_Print();
Guido van Rossum9e90a671993-06-24 11:10:19 +000092 sts = 1;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000093 }
94 else
Guido van Rossum9e90a671993-06-24 11:10:19 +000095 sts = 0;
96
Guido van Rossumf1dc5661993-07-05 10:31:29 +000097 if (inspect && isatty((int)fileno(stdin)))
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000098 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Guido van Rossum9e90a671993-06-24 11:10:19 +000099
Guido van Rossum6deac7a1998-04-03 21:11:15 +0000100#ifdef MS_WIN32
101 PyWinFreeze_ExeTerm();
102#endif
Guido van Rossum7c141031997-08-15 02:52:08 +0000103 Py_Finalize();
104 return sts;
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000105}