blob: 397f0465ce641af03d2c03faabe8aa56df499d8f [file] [log] [blame]
Guido van Rossumf56e3db1993-04-01 20:59:32 +00001
2/* Python interpreter main program for frozen scripts */
3
Guido van Rossum4e2e0f91995-03-31 10:27:23 +00004#include "Python.h"
Guido van Rossumf56e3db1993-04-01 20:59:32 +00005
Martin v. Löwis6238d2b2002-06-30 15:26:10 +00006#ifdef MS_WINDOWS
Thomas Woutersb4bd21c2000-07-22 23:38:01 +00007extern void PyWinFreeze_ExeInit(void);
8extern void PyWinFreeze_ExeTerm(void);
9extern int PyInitFrozenExtensions(void);
Guido van Rossum6deac7a1998-04-03 21:11:15 +000010#endif
11
Guido van Rossum47ad5e71995-08-04 04:10:43 +000012/* Main program */
13
14int
Thomas Woutersf70ef4f2000-07-22 18:47:25 +000015Py_FrozenMain(int argc, char **argv)
Guido van Rossumf56e3db1993-04-01 20:59:32 +000016{
17 char *p;
Guido van Rossum094885b1993-11-05 10:16:09 +000018 int n, sts;
19 int inspect = 0;
Guido van Rossum1d5735e1994-08-30 08:27:36 +000020 int unbuffered = 0;
21
Guido van Rossum919b83d1998-02-06 22:30:29 +000022 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
23
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000024 if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
Guido van Rossum9e90a671993-06-24 11:10:19 +000025 inspect = 1;
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000026 if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
Guido van Rossum1d5735e1994-08-30 08:27:36 +000027 unbuffered = 1;
Guido van Rossum9e90a671993-06-24 11:10:19 +000028
Guido van Rossum1d5735e1994-08-30 08:27:36 +000029 if (unbuffered) {
Guido van Rossumc425d2f1997-12-02 20:41:39 +000030 setbuf(stdin, (char *)NULL);
Guido van Rossum1d5735e1994-08-30 08:27:36 +000031 setbuf(stdout, (char *)NULL);
32 setbuf(stderr, (char *)NULL);
33 }
34
Martin v. Löwis6238d2b2002-06-30 15:26:10 +000035#ifdef MS_WINDOWS
Guido van Rossum47ae0281999-01-02 21:42:48 +000036 PyInitFrozenExtensions();
Martin v. Löwis6238d2b2002-06-30 15:26:10 +000037#endif /* MS_WINDOWS */
Guido van Rossum3768fb11997-07-19 19:24:41 +000038 Py_SetProgramName(argv[0]);
39 Py_Initialize();
Martin v. Löwis6238d2b2002-06-30 15:26:10 +000040#ifdef MS_WINDOWS
Guido van Rossum6deac7a1998-04-03 21:11:15 +000041 PyWinFreeze_ExeInit();
42#endif
Guido van Rossum3768fb11997-07-19 19:24:41 +000043
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000044 if (Py_VerboseFlag)
Guido van Rossum1d5735e1994-08-30 08:27:36 +000045 fprintf(stderr, "Python %s\n%s\n",
Guido van Rossum582646a1996-05-28 22:30:17 +000046 Py_GetVersion(), Py_GetCopyright());
Guido van Rossum3768fb11997-07-19 19:24:41 +000047
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000048 PySys_SetArgv(argc, argv);
Guido van Rossum9e90a671993-06-24 11:10:19 +000049
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000050 n = PyImport_ImportFrozenModule("__main__");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000051 if (n == 0)
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000052 Py_FatalError("__main__ not frozen");
Guido van Rossumf56e3db1993-04-01 20:59:32 +000053 if (n < 0) {
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000054 PyErr_Print();
Guido van Rossum9e90a671993-06-24 11:10:19 +000055 sts = 1;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000056 }
57 else
Guido van Rossum9e90a671993-06-24 11:10:19 +000058 sts = 0;
59
Guido van Rossumf1dc5661993-07-05 10:31:29 +000060 if (inspect && isatty((int)fileno(stdin)))
Guido van Rossum4e2e0f91995-03-31 10:27:23 +000061 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Guido van Rossum9e90a671993-06-24 11:10:19 +000062
Martin v. Löwis6238d2b2002-06-30 15:26:10 +000063#ifdef MS_WINDOWS
Guido van Rossum6deac7a1998-04-03 21:11:15 +000064 PyWinFreeze_ExeTerm();
65#endif
Guido van Rossum7c141031997-08-15 02:52:08 +000066 Py_Finalize();
67 return sts;
Guido van Rossumf56e3db1993-04-01 20:59:32 +000068}