Clarify portability and main program.
[python/dscho.git] / Python / frozenmain.c
blobcb46d65944acf09f37e19f3cc1281850ee335f8a
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
32 /* Python interpreter main program for frozen scripts */
34 #include "Python.h"
36 #ifdef MS_WIN32
37 extern void PyWinFreeze_ExeInit();
38 extern void PyWinFreeze_ExeTerm();
39 #endif
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h> /* For isatty() */
43 #endif
45 /* For isatty()'s proto. - [cjh] */
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
50 /* Main program */
52 int
53 Py_FrozenMain(argc, argv)
54 int argc;
55 char **argv;
57 char *p;
58 int n, sts;
59 int inspect = 0;
60 int unbuffered = 0;
62 Py_FrozenFlag = 1; /* Suppress errors from getpath.c */
64 if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
65 inspect = 1;
66 if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
67 unbuffered = 1;
69 if (unbuffered) {
70 setbuf(stdin, (char *)NULL);
71 setbuf(stdout, (char *)NULL);
72 setbuf(stderr, (char *)NULL);
75 Py_SetProgramName(argv[0]);
76 Py_Initialize();
77 #ifdef MS_WIN32
78 PyWinFreeze_ExeInit();
79 #endif
81 if (Py_VerboseFlag)
82 fprintf(stderr, "Python %s\n%s\n",
83 Py_GetVersion(), Py_GetCopyright());
85 PySys_SetArgv(argc, argv);
87 n = PyImport_ImportFrozenModule("__main__");
88 if (n == 0)
89 Py_FatalError("__main__ not frozen");
90 if (n < 0) {
91 PyErr_Print();
92 sts = 1;
94 else
95 sts = 0;
97 if (inspect && isatty((int)fileno(stdin)))
98 sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
100 #ifdef MS_WIN32
101 PyWinFreeze_ExeTerm();
102 #endif
103 Py_Finalize();
104 return sts;