Last set of CW Pro 5 projects (probably)
[python/dscho.git] / Python / frozenmain.c
blob576baacc6b91ee1e1ad2c25d8d4cab451005ca41
1 /***********************************************************
2 Copyright (c) 2000, BeOpen.com.
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5 All rights reserved.
7 See the file "Misc/COPYRIGHT" for information on usage and
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9 ******************************************************************/
11 /* Python interpreter main program for frozen scripts */
13 #include "Python.h"
15 #ifdef MS_WIN32
16 extern void PyWinFreeze_ExeInit(void);
17 extern void PyWinFreeze_ExeTerm(void);
18 extern int PyInitFrozenExtensions(void);
19 #endif
21 #ifdef HAVE_UNISTD_H
22 #include <unistd.h> /* For isatty() */
23 #endif
25 /* For isatty()'s proto. - [cjh] */
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
30 /* Main program */
32 int
33 Py_FrozenMain(int argc, char **argv)
35 char *p;
36 int n, sts;
37 int inspect = 0;
38 int unbuffered = 0;
40 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
42 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
43 inspect = 1;
44 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
45 unbuffered = 1;
47 if (unbuffered) {
48 setbuf(stdin, (char *)NULL);
49 setbuf(stdout, (char *)NULL);
50 setbuf(stderr, (char *)NULL);
53 #ifdef MS_WIN32
54 PyInitFrozenExtensions();
55 #endif /* MS_WIN32 */
56 Py_SetProgramName(argv[0]);
57 Py_Initialize();
58 #ifdef MS_WIN32
59 PyWinFreeze_ExeInit();
60 #endif
62 if (Py_VerboseFlag)
63 fprintf(stderr, "Python %s\n%s\n",
64 Py_GetVersion(), Py_GetCopyright());
66 PySys_SetArgv(argc, argv);
68 n = PyImport_ImportFrozenModule("__main__");
69 if (n == 0)
70 Py_FatalError("__main__ not frozen");
71 if (n < 0) {
72 PyErr_Print();
73 sts = 1;
75 else
76 sts = 0;
78 if (inspect && isatty((int)fileno(stdin)))
79 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
81 #ifdef MS_WIN32
82 PyWinFreeze_ExeTerm();
83 #endif
84 Py_Finalize();
85 return sts;