|
2361
|
1 /***********************************************************
|
|
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
|
|
|
3 The Netherlands.
|
|
|
4
|
|
|
5 All Rights Reserved
|
|
|
6
|
|
|
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 not be used in advertising or publicity pertaining to
|
|
|
13 distribution of the software without specific, written prior permission.
|
|
|
14
|
|
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
|
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
|
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
22
|
|
|
23 ******************************************************************/
|
|
|
24
|
|
|
25 /* Macintosh Applet Python main program */
|
|
|
26
|
|
|
27 #include "Python.h"
|
|
|
28 #include "marshal.h"
|
|
|
29 #include "import.h"
|
|
|
30
|
|
|
31 #include <Memory.h>
|
|
|
32 #include <Resources.h>
|
|
|
33 #include <QuickDraw.h>
|
|
|
34 #include <Fonts.h>
|
|
|
35 #include <Windows.h>
|
|
|
36 #include <TextEdit.h>
|
|
|
37 #include <Dialogs.h>
|
|
|
38 #include <Menus.h>
|
|
|
39
|
|
|
40 static void
|
|
|
41 init_mac_world()
|
|
|
42 {
|
|
|
43 MaxApplZone();
|
|
|
44 InitGraf(&qd.thePort);
|
|
|
45 InitFonts();
|
|
|
46 InitWindows();
|
|
|
47 TEInit();
|
|
|
48 InitDialogs((long)0);
|
|
|
49 InitMenus();
|
|
|
50 InitCursor();
|
|
|
51 }
|
|
|
52
|
|
|
53 static int
|
|
|
54 run_main_resource()
|
|
|
55 {
|
|
|
56 Handle h;
|
|
|
57 long size;
|
|
|
58 PyObject *code;
|
|
|
59 PyObject *result;
|
|
|
60
|
|
|
61 h = GetNamedResource('PYC ', "\p__main__");
|
|
|
62 if (h == NULL) {
|
|
|
63 fprintf(stderr, "No 'PYC ' resource named __main__ found\n");
|
|
|
64 return 1;
|
|
|
65 }
|
|
|
66 size = GetResourceSizeOnDisk(h);
|
|
|
67 HLock(h);
|
|
|
68 code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8));
|
|
|
69 HUnlock(h);
|
|
|
70 ReleaseResource(h);
|
|
|
71 if (code == NULL) {
|
|
|
72 PyErr_Print();
|
|
|
73 return 1;
|
|
|
74 }
|
|
|
75 result = PyImport_ExecCodeModule("__main__", code);
|
|
|
76 Py_DECREF(code);
|
|
|
77 if (result == NULL) {
|
|
|
78 PyErr_Print();
|
|
|
79 return 1;
|
|
|
80 }
|
|
|
81 Py_DECREF(result);
|
|
|
82 return 0;
|
|
|
83 }
|
|
|
84
|
|
|
85 main()
|
|
|
86 {
|
|
|
87 static char *argv[] = {"__main__", NULL};
|
|
|
88
|
|
|
89 init_mac_world();
|
|
|
90 Py_Initialize();
|
|
|
91 PySys_SetArgv((sizeof argv / sizeof argv[0]) - 1, argv);
|
|
|
92 run_main_resource();
|
|
|
93 fflush(stderr);
|
|
|
94 fflush(stdout);
|
|
|
95 /* XXX Should we bother to Py_Exit(sts)? */
|
|
|
96 }
|