blob: 554f4da21736da81bc9292f3be474b97085b37e4 [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();
Guido van Rossum47ae0281999-01-02 21:42:48 +000039extern int PyInitFrozenExtensions();
Guido van Rossum6deac7a1998-04-03 21:11:15 +000040#endif
41
Guido van Rossum73bacfc1998-01-19 22:05:22 +000042#ifdef HAVE_UNISTD_H
43#include <unistd.h> /* For isatty() */
44#endif
45
Guido van Rossum1a8791e1998-08-04 22:46:29 +000046/* For isatty()'s proto. - [cjh] */
47#ifdef HAVE_UNISTD_H
48#include <unistd.h>
49#endif
50
Guido van Rossum47ad5e71995-08-04 04:10:43 +000051/* Main program */
52
53int
Guido van Rossuma9414511997-07-19 21:59:47 +000054Py_FrozenMain(argc, argv)
Guido van Rossumf56e3db1993-04-01 20:59:32 +000055 int argc;
56 char **argv;
57{
58 char *p;
Guido van Rossum094885b1993-11-05 10:16:09 +000059 int n, sts;
60 int inspect = 0;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000061 int unbuffered = 0;
62
Guido van Rossum919b83d1998-02-06 22:30:29 +000063 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
64
Guido van Rossum9e90a671993-06-24 11:10:19 +000065 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
66 inspect = 1;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000067 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
68 unbuffered = 1;
Guido van Rossum9e90a671993-06-24 11:10:19 +000069
Guido van Rossum1d5735e1994-08-30 08:27:36 +000070 if (unbuffered) {
Guido van Rossumc425d2f1997-12-02 20:41:39 +000071 setbuf(stdin, (char *)NULL);
Guido van Rossum1d5735e1994-08-30 08:27:36 +000072 setbuf(stdout, (char *)NULL);
73 setbuf(stderr, (char *)NULL);
74 }
75
Guido van Rossum47ae0281999-01-02 21:42:48 +000076#ifdef MS_WIN32
77 PyInitFrozenExtensions();
78#endif /* MS_WIN32 */
Guido van Rossum3768fb11997-07-19 19:24:41 +000079 Py_SetProgramName(argv[0]);
80 Py_Initialize();
Guido van Rossum6deac7a1998-04-03 21:11:15 +000081#ifdef MS_WIN32
82 PyWinFreeze_ExeInit();
83#endif
Guido van Rossum3768fb11997-07-19 19:24:41 +000084
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000085 if (Py_VerboseFlag)
Guido van Rossum1d5735e1994-08-30 08:27:36 +000086 fprintf(stderr, "Python %s\n%s\n",
Guido van Rossum582646a1996-05-28 22:30:17 +000087 Py_GetVersion(), Py_GetCopyright());
Guido van Rossum3768fb11997-07-19 19:24:41 +000088
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000089 PySys_SetArgv(argc, argv);
Guido van Rossum9e90a671993-06-24 11:10:19 +000090
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000091 n = PyImport_ImportFrozenModule("__main__");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000092 if (n == 0)
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000093 Py_FatalError("__main__ not frozen");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000094 if (n < 0) {
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000095 PyErr_Print();
Guido van Rossum9e90a671993-06-24 11:10:19 +000096 sts = 1;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000097 }
98 else
Guido van Rossum9e90a671993-06-24 11:10:19 +000099 sts = 0;
100
Guido van Rossumf1dc5661993-07-05 10:31:29 +0000101 if (inspect && isatty((int)fileno(stdin)))
Guido van Rossum4e2e0f91995-03-31 10:27:23 +0000102 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Guido van Rossum9e90a671993-06-24 11:10:19 +0000103
Guido van Rossum6deac7a1998-04-03 21:11:15 +0000104#ifdef MS_WIN32
105 PyWinFreeze_ExeTerm();
106#endif
Guido van Rossum7c141031997-08-15 02:52:08 +0000107 Py_Finalize();
108 return sts;
Guido van Rossumf56e3db1993-04-01 20:59:32 +0000109}