1993-04-01 16:59:32 -04:00
|
|
|
|
|
|
|
/* Python interpreter main program for frozen scripts */
|
|
|
|
|
1995-03-31 06:27:23 -04:00
|
|
|
#include "Python.h"
|
1993-04-01 16:59:32 -04:00
|
|
|
|
2002-06-30 12:26:10 -03:00
|
|
|
#ifdef MS_WINDOWS
|
2000-07-22 20:38:01 -03:00
|
|
|
extern void PyWinFreeze_ExeInit(void);
|
|
|
|
extern void PyWinFreeze_ExeTerm(void);
|
|
|
|
extern int PyInitFrozenExtensions(void);
|
1998-04-03 17:11:15 -04:00
|
|
|
#endif
|
|
|
|
|
1995-08-04 01:10:43 -03:00
|
|
|
/* Main program */
|
|
|
|
|
|
|
|
int
|
2000-07-22 15:47:25 -03:00
|
|
|
Py_FrozenMain(int argc, char **argv)
|
1993-04-01 16:59:32 -04:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
char *p;
|
|
|
|
int n, sts;
|
|
|
|
int inspect = 0;
|
|
|
|
int unbuffered = 0;
|
1994-08-30 05:27:36 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
|
1998-02-06 18:30:29 -04:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
if ((p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')
|
|
|
|
inspect = 1;
|
|
|
|
if ((p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
|
|
|
|
unbuffered = 1;
|
1994-08-30 05:27:36 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
if (unbuffered) {
|
|
|
|
setbuf(stdin, (char *)NULL);
|
|
|
|
setbuf(stdout, (char *)NULL);
|
|
|
|
setbuf(stderr, (char *)NULL);
|
|
|
|
}
|
1993-06-24 08:10:19 -03:00
|
|
|
|
2002-06-30 12:26:10 -03:00
|
|
|
#ifdef MS_WINDOWS
|
2010-05-09 11:46:46 -03:00
|
|
|
PyInitFrozenExtensions();
|
2002-06-30 12:26:10 -03:00
|
|
|
#endif /* MS_WINDOWS */
|
2010-05-09 11:46:46 -03:00
|
|
|
Py_SetProgramName(argv[0]);
|
|
|
|
Py_Initialize();
|
2002-06-30 12:26:10 -03:00
|
|
|
#ifdef MS_WINDOWS
|
2010-05-09 11:46:46 -03:00
|
|
|
PyWinFreeze_ExeInit();
|
1998-04-03 17:11:15 -04:00
|
|
|
#endif
|
1997-07-19 16:24:41 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
if (Py_VerboseFlag)
|
|
|
|
fprintf(stderr, "Python %s\n%s\n",
|
|
|
|
Py_GetVersion(), Py_GetCopyright());
|
1997-07-19 16:24:41 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
PySys_SetArgv(argc, argv);
|
1993-06-24 08:10:19 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
n = PyImport_ImportFrozenModule("__main__");
|
|
|
|
if (n == 0)
|
|
|
|
Py_FatalError("__main__ not frozen");
|
|
|
|
if (n < 0) {
|
|
|
|
PyErr_Print();
|
|
|
|
sts = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sts = 0;
|
1993-06-24 08:10:19 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
if (inspect && isatty((int)fileno(stdin)))
|
|
|
|
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
|
1993-06-24 08:10:19 -03:00
|
|
|
|
2002-06-30 12:26:10 -03:00
|
|
|
#ifdef MS_WINDOWS
|
2010-05-09 11:46:46 -03:00
|
|
|
PyWinFreeze_ExeTerm();
|
1998-04-03 17:11:15 -04:00
|
|
|
#endif
|
2010-05-09 11:46:46 -03:00
|
|
|
Py_Finalize();
|
|
|
|
return sts;
|
1993-04-01 16:59:32 -04:00
|
|
|
}
|