Files for 2.1b1 distribution.
[python/dscho.git] / Python / frozenmain.c
bloba03a2f8ddb0fd6c81eb8eda2ab59401460c16797
2 /* Python interpreter main program for frozen scripts */
4 #include "Python.h"
6 #ifdef MS_WIN32
7 extern void PyWinFreeze_ExeInit(void);
8 extern void PyWinFreeze_ExeTerm(void);
9 extern int PyInitFrozenExtensions(void);
10 #endif
12 #ifdef HAVE_UNISTD_H
13 #include <unistd.h> /* For isatty() */
14 #endif
16 /* For isatty()'s proto. - [cjh] */
17 #ifdef HAVE_UNISTD_H
18 #include <unistd.h>
19 #endif
21 /* Main program */
23 int
24 Py_FrozenMain(int argc, char **argv)
26 char *p;
27 int n, sts;
28 int inspect = 0;
29 int unbuffered = 0;
31 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
33 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
34 inspect = 1;
35 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
36 unbuffered = 1;
38 if (unbuffered) {
39 setbuf(stdin, (char *)NULL);
40 setbuf(stdout, (char *)NULL);
41 setbuf(stderr, (char *)NULL);
44 #ifdef MS_WIN32
45 PyInitFrozenExtensions();
46 #endif /* MS_WIN32 */
47 Py_SetProgramName(argv[0]);
48 Py_Initialize();
49 #ifdef MS_WIN32
50 PyWinFreeze_ExeInit();
51 #endif
53 if (Py_VerboseFlag)
54 fprintf(stderr, "Python %s\n%s\n",
55 Py_GetVersion(), Py_GetCopyright());
57 PySys_SetArgv(argc, argv);
59 n = PyImport_ImportFrozenModule("__main__");
60 if (n == 0)
61 Py_FatalError("__main__ not frozen");
62 if (n < 0) {
63 PyErr_Print();
64 sts = 1;
66 else
67 sts = 0;
69 if (inspect && isatty((int)fileno(stdin)))
70 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
72 #ifdef MS_WIN32
73 PyWinFreeze_ExeTerm();
74 #endif
75 Py_Finalize();
76 return sts;