blob: 576baacc6b91ee1e1ad2c25d8d4cab451005ca41 [file] [log] [blame]
Guido van Rossumf56e3db1993-04-01 20:59:32 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossumf56e3db1993-04-01 20:59:32 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf56e3db1993-04-01 20:59:32 +00009******************************************************************/
10
11/* Python interpreter main program for frozen scripts */
12
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000013#include "Python.h"
Guido van Rossumf56e3db1993-04-01 20:59:32 +000014
Guido van Rossum6deac7a1998-04-03 21:11:15 +000015#ifdef MS_WIN32
Thomas Woutersb4bd21c2000-07-22 23:38:01 +000016extern void PyWinFreeze_ExeInit(void);
17extern void PyWinFreeze_ExeTerm(void);
18extern int PyInitFrozenExtensions(void);
Guido van Rossum6deac7a1998-04-03 21:11:15 +000019#endif
20
Guido van Rossum73bacfc1998-01-19 22:05:22 +000021#ifdef HAVE_UNISTD_H
22#include <unistd.h> /* For isatty() */
23#endif
24
Guido van Rossum1a8791e1998-08-04 22:46:29 +000025/* For isatty()'s proto. - [cjh] */
26#ifdef HAVE_UNISTD_H
27#include <unistd.h>
28#endif
29
Guido van Rossum47ad5e71995-08-04 04:10:43 +000030/* Main program */
31
32int
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000033Py_FrozenMain(int argc, char **argv)
Guido van Rossumf56e3db1993-04-01 20:59:32 +000034{
35 char *p;
Guido van Rossum094885b1993-11-05 10:16:09 +000036 int n, sts;
37 int inspect = 0;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000038 int unbuffered = 0;
39
Guido van Rossum919b83d1998-02-06 22:30:29 +000040 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
41
Guido van Rossum9e90a671993-06-24 11:10:19 +000042 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
43 inspect = 1;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000044 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
45 unbuffered = 1;
Guido van Rossum9e90a671993-06-24 11:10:19 +000046
Guido van Rossum1d5735e1994-08-30 08:27:36 +000047 if (unbuffered) {
Guido van Rossumc425d2f1997-12-02 20:41:39 +000048 setbuf(stdin, (char *)NULL);
Guido van Rossum1d5735e1994-08-30 08:27:36 +000049 setbuf(stdout, (char *)NULL);
50 setbuf(stderr, (char *)NULL);
51 }
52
Guido van Rossum47ae0281999-01-02 21:42:48 +000053#ifdef MS_WIN32
54 PyInitFrozenExtensions();
55#endif /* MS_WIN32 */
Guido van Rossum3768fb11997-07-19 19:24:41 +000056 Py_SetProgramName(argv[0]);
57 Py_Initialize();
Guido van Rossum6deac7a1998-04-03 21:11:15 +000058#ifdef MS_WIN32
59 PyWinFreeze_ExeInit();
60#endif
Guido van Rossum3768fb11997-07-19 19:24:41 +000061
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000062 if (Py_VerboseFlag)
Guido van Rossum1d5735e1994-08-30 08:27:36 +000063 fprintf(stderr, "Python %s\n%s\n",
Guido van Rossum582646a1996-05-28 22:30:17 +000064 Py_GetVersion(), Py_GetCopyright());
Guido van Rossum3768fb11997-07-19 19:24:41 +000065
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000066 PySys_SetArgv(argc, argv);
Guido van Rossum9e90a671993-06-24 11:10:19 +000067
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000068 n = PyImport_ImportFrozenModule("__main__");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000069 if (n == 0)
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000070 Py_FatalError("__main__ not frozen");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000071 if (n < 0) {
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000072 PyErr_Print();
Guido van Rossum9e90a671993-06-24 11:10:19 +000073 sts = 1;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000074 }
75 else
Guido van Rossum9e90a671993-06-24 11:10:19 +000076 sts = 0;
77
Guido van Rossumf1dc5661993-07-05 10:31:29 +000078 if (inspect && isatty((int)fileno(stdin)))
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000079 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Guido van Rossum9e90a671993-06-24 11:10:19 +000080
Guido van Rossum6deac7a1998-04-03 21:11:15 +000081#ifdef MS_WIN32
82 PyWinFreeze_ExeTerm();
83#endif
Guido van Rossum7c141031997-08-15 02:52:08 +000084 Py_Finalize();
85 return sts;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000086}