Mercurial > cpython-lru_cache-weakref
annotate Mac/Python/macglue.c @ 2412:75ae104f7e6c legacy-trunk
ported to MPW, moved main() here
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 20 Feb 1995 23:45:53 +0000 |
| parents | 72c715c004c8 |
| children | 9bf18996eed8 |
| rev | line source |
|---|---|
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1 /*********************************************************** |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
3 The Netherlands. |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
4 |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
5 All Rights Reserved |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
6 |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
12 Centrum or CWI not be used in advertising or publicity pertaining to |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
13 distribution of the software without specific, written prior permission. |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
14 |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
22 |
|
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
23 ******************************************************************/ |
| 2035 | 24 |
| 25 #include "Python.h" | |
| 2337 | 26 |
| 2035 | 27 #include "macglue.h" |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
28 #include "marshal.h" |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
29 #include "import.h" |
| 2035 | 30 |
| 31 #include <OSUtils.h> /* for Set(Current)A5 */ | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
32 #include <Files.h> |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
33 #include <Aliases.h> |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
34 #include <Folders.h> |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
35 #include <StandardFile.h> |
| 2035 | 36 #include <Resources.h> |
| 37 #include <Memory.h> | |
| 38 #include <Events.h> | |
| 39 #include <Windows.h> | |
| 40 #include <Desk.h> | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
41 #include <Traps.h> |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
42 #include <Processes.h> |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
43 #include <Fonts.h> |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
44 #include <Menus.h> |
|
2265
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
45 #ifdef THINK_C |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
46 #include <OSEvents.h> /* For EvQElPtr */ |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
47 #endif |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
48 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
49 #ifndef HAVE_UNIVERSAL_HEADERS |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
50 #define GetResourceSizeOnDisk(x) SizeResource(x) |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
51 typedef DlgHookYDProcPtr DlgHookYDUPP; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
52 #define NewDlgHookYDProc(userRoutine) ((DlgHookYDUPP) (userRoutine)) |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
53 typedef FileFilterYDProcPtr FileFilterYDUPP; |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
54 #endif |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
55 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
56 #include <signal.h> |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
57 #include <stdio.h> |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
58 |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
59 /* The alert for "No Python directory, where is it?" */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
60 #define NOPYTHON_ALERT 128 |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
61 #define YES_ITEM 1 |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
62 #define NO_ITEM 2 |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
63 #define CURWD_ITEM 3 |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
64 |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
65 /* The alert for "this is an applet template" */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
66 #define NOPYC_ALERT 129 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
67 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
68 /* The dialog for our GetDirectory call */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
69 #define GETDIR_ID 130 /* Resource ID for our "get directory" */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
70 #define SELECTCUR_ITEM 10 /* "Select current directory" button */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
71 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
72 #ifdef __MWERKS__ |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
73 /* |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
74 ** With MW we can pass the event off to the console window, so |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
75 ** we might as well handle all events. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
76 */ |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
77 #include <SIOUX.h> |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
78 #define MAINLOOP_EVENTMASK everyEvent |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
79 #else |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
80 /* |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
81 ** For other compilers we're more careful, since we can't handle |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
82 ** things like updates (and they'll keep coming back if we don't |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
83 ** handle them) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
84 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
85 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask) |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
86 #endif /* __MWERKS__ */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
87 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
88 #include <signal.h> |
| 2035 | 89 |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
90 /* XXX We should include Errors.h here, but it has a name conflict |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
91 ** with the python errors.h. */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
92 #define fnfErr -43 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
93 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
94 /* Declared in macfsmodule.c: */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
95 extern FSSpec *mfs_GetFSSpecFSSpec(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
96 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
97 /* Interrupt code variables: */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
98 static int interrupted; /* Set to true when cmd-. seen */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
99 static RETSIGTYPE intcatcher Py_PROTO((int)); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
100 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
101 /* |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
102 ** We attempt to be a good citizen by giving up the CPU periodically. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
103 ** When in the foreground we do this less often and for shorter periods |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
104 ** than when in the background. At this time we also check for events and |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
105 ** pass them off to SIOUX, if compiling with mwerks. |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
106 ** The counts here are in ticks of 1/60th second. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
107 ** XXXX The initial values here are not based on anything. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
108 ** FG-python gives up the cpu for 1/60th 5 times per second, |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
109 ** BG-python for .2 second 10 times per second. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
110 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
111 static long interval_fg = 12; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
112 static long interval_bg = 6; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
113 static long yield_fg = 1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
114 static long yield_bg = 12; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
115 static long lastyield; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
116 static int in_foreground; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
117 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
118 int PyMac_DoYieldEnabled = 1; /* Don't do eventloop when false */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
119 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
120 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
121 /* Convert C to Pascal string. Returns pointer to static buffer. */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
122 unsigned char * |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
123 Pstring(char *str) |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
124 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
125 static Str255 buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
126 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
127 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
128 len = strlen(str); |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
129 if (len > 255) |
|
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
130 len = 255; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
131 buf[0] = (unsigned char)len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
132 strncpy((char *)buf+1, str, len); |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
133 return buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
134 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
135 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
136 /* Like strerror() but for Mac OS error numbers */ |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
137 char *PyMac_StrError(int err) |
| 2035 | 138 { |
| 139 static char buf[256]; | |
| 140 Handle h; | |
| 141 char *str; | |
| 142 | |
| 143 h = GetResource('Estr', err); | |
| 144 if ( h ) { | |
| 145 HLock(h); | |
| 146 str = (char *)*h; | |
| 147 memcpy(buf, str+1, (unsigned char)str[0]); | |
|
2324
faaece7ccd6e
null-terminate the error string in macstrerror
Guido van Rossum <guido@python.org>
parents:
2312
diff
changeset
|
148 buf[(unsigned char)str[0]] = '\0'; |
| 2035 | 149 HUnlock(h); |
| 150 ReleaseResource(h); | |
| 151 } else { | |
| 152 sprintf(buf, "Mac OS error code %d", err); | |
| 153 } | |
| 154 return buf; | |
| 155 } | |
| 156 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
157 /* Exception object shared by all Mac specific modules for Mac OS errors */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
158 PyObject *PyMac_OSErrException; |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
159 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
160 /* Initialize and return PyMac_OSErrException */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
161 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
162 PyMac_GetOSErrException() |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
163 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
164 if (PyMac_OSErrException == NULL) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
165 PyMac_OSErrException = PyString_FromString("Mac OS Error"); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
166 return PyMac_OSErrException; |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
167 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
168 |
| 2035 | 169 /* Set a MAC-specific error from errno, and return NULL; return None if no error */ |
| 170 PyObject * | |
| 2136 | 171 PyErr_Mac(PyObject *eobj, int err) |
| 2035 | 172 { |
| 173 char *msg; | |
| 174 PyObject *v; | |
| 175 | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
176 if (err == 0 && !PyErr_Occurred()) { |
| 2035 | 177 Py_INCREF(Py_None); |
| 178 return Py_None; | |
| 179 } | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
180 if (err == -1 && PyErr_Occurred()) |
|
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
181 return NULL; |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
182 msg = PyMac_StrError(err); |
| 2035 | 183 v = Py_BuildValue("(is)", err, msg); |
| 184 PyErr_SetObject(eobj, v); | |
| 185 Py_DECREF(v); | |
| 186 return NULL; | |
| 187 } | |
| 188 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
189 /* Call PyErr_Mac with PyMac_OSErrException */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
190 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
191 PyMac_Error(OSErr err) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
192 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
193 return PyErr_Mac(PyMac_GetOSErrException(), err); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
194 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
195 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
196 /* The catcher routine (which may not be used for all compilers) */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
197 static RETSIGTYPE |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
198 intcatcher(sig) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
199 int sig; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
200 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
201 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
202 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
203 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
204 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
205 void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
206 PyOS_InitInterrupts() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
207 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
208 if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
209 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
210 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
211 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
212 /* |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
213 ** This routine scans the event queue looking for cmd-. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
214 ** This is the only way to get an interrupt under THINK (since it |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
215 ** doesn't do SIGINT handling), but is also used under MW, when |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
216 ** the full-fledged event loop is disabled. This way, we can at least |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
217 ** interrupt a runaway python program. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
218 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
219 static void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
220 scan_event_queue(flush) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
221 int flush; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
222 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
223 register EvQElPtr q; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
224 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
225 q = (EvQElPtr) GetEvQHdr()->qHead; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
226 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
227 for (; q; q = (EvQElPtr)q->qLink) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
228 if (q->evtQWhat == keyDown && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
229 (char)q->evtQMessage == '.' && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
230 (q->evtQModifiers & cmdKey) != 0) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
231 if ( flush ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
232 FlushEvents(keyDownMask, 0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
233 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
234 break; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
235 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
236 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
237 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
238 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
239 int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
240 PyOS_InterruptOccurred() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
241 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
242 #ifdef THINK_C |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
243 scan_event_queue(1); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
244 #endif |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
245 PyMac_Yield(); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
246 if (interrupted) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
247 interrupted = 0; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
248 return 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
249 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
250 return 0; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
251 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
252 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
253 /* intrpeek() is like intrcheck(), but it doesn't flush the events. The |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
254 ** idea is that you call intrpeek() somewhere in a busy-wait loop, and return |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
255 ** None as soon as it returns 1. The mainloop will then pick up the cmd-. soon |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
256 ** thereafter. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
257 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
258 static int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
259 intrpeek() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
260 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
261 #ifdef THINK_C |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
262 scan_event_queue(0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
263 #endif |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
264 return interrupted; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
265 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
266 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
267 /* Check whether we are in the foreground */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
268 int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
269 PyMac_InForeground() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
270 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
271 static ProcessSerialNumber ours; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
272 static inited; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
273 ProcessSerialNumber curfg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
274 Boolean eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
275 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
276 if ( inited == 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
277 (void)GetCurrentProcess(&ours); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
278 inited = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
279 if ( GetFrontProcess(&curfg) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
280 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
281 else if ( SameProcess(&ours, &curfg, &eq) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
282 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
283 return (int)eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
284 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
285 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
286 |
| 2035 | 287 /* |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
288 ** Set yield timeouts |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
289 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
290 void |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
291 PyMac_SetYield(long fgi, long fgy, long bgi, long bgy) |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
292 { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
293 interval_fg = fgi; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
294 yield_fg = fgy; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
295 interval_bg = bgi; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
296 yield_bg = bgy; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
297 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
298 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
299 /* |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
300 ** Handle an event, either one found in the mainloop eventhandler or |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
301 ** one passed back from the python program. |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
302 */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
303 void |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
304 PyMac_HandleEvent(evp) |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
305 EventRecord *evp; |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
306 { |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
307 WindowPtr wp; |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
308 |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
309 #ifdef __MWERKS__ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
310 /* If SIOUX wants it we're done */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
311 (void)SIOUXHandleOneEvent(evp); |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
312 #else |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
313 /* Other compilers are just unlucky: we only weed out clicks in other applications */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
314 if ( evp->what == mouseDown ) { |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
315 if ( FindWindow(evp->where, &wp) == inSysWindow ) |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
316 SystemClick(evp, wp); |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
317 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
318 #endif /* !__MWERKS__ */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
319 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
320 |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
321 /* |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
322 ** Yield the CPU to other tasks. |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
323 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
324 static |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
325 PyMac_DoYield() |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
326 { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
327 EventRecord ev; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
328 long yield; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
329 static int no_waitnextevent = -1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
330 int gotone; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
331 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
332 if ( no_waitnextevent < 0 ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
333 no_waitnextevent = (NGetTrapAddress(_WaitNextEvent, ToolTrap) == |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
334 NGetTrapAddress(_Unimplemented, ToolTrap)); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
335 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
336 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
337 if ( !PyMac_DoYieldEnabled ) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
338 #ifndef THINK_C |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
339 /* Under think this has been done before in intrcheck() or intrpeek() */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
340 scan_event_queue(0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
341 #endif |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
342 return; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
343 } |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
344 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
345 in_foreground = PyMac_InForeground(); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
346 if ( in_foreground ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
347 yield = yield_fg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
348 else |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
349 yield = yield_bg; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
350 while ( 1 ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
351 if ( no_waitnextevent ) { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
352 SystemTask(); |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
353 gotone = GetNextEvent(MAINLOOP_EVENTMASK, &ev); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
354 } else { |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
355 gotone = WaitNextEvent(MAINLOOP_EVENTMASK, &ev, yield, NULL); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
356 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
357 /* Get out quickly if nothing interesting is happening */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
358 if ( !gotone || ev.what == nullEvent ) |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
359 break; |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
360 PyMac_HandleEvent(&ev); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
361 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
362 lastyield = TickCount(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
363 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
364 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
365 /* |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
366 ** Yield the CPU to other tasks if opportune |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
367 */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
368 void |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
369 PyMac_Yield() { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
370 long iv; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
371 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
372 if ( in_foreground ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
373 iv = interval_fg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
374 else |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
375 iv = interval_bg; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
376 if ( TickCount() > lastyield + iv ) |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
377 PyMac_DoYield(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
378 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
379 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
380 /* |
| 2035 | 381 ** Idle routine for busy-wait loops. |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
382 ** Gives up CPU, handles events and returns true if an interrupt is pending |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
383 ** (but not actually handled yet). |
| 2035 | 384 */ |
| 385 int | |
| 386 PyMac_Idle() | |
| 387 { | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
388 PyMac_DoYield(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
389 return intrpeek(); |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
390 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
391 |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
392 /* |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
393 ** Return the name of the Python directory |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
394 */ |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
395 char * |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
396 PyMac_GetPythonDir() |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
397 { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
398 int item; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
399 static char name[256]; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
400 AliasHandle handle; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
401 FSSpec dirspec; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
402 int ok = 0, exists = 0; |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
403 Boolean modified = 0, cannotmodify = 0; |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
404 short oldrh, prefrh; |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
405 short prefdirRefNum; |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
406 long prefdirDirID; |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
407 |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
408 /* |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
409 ** Remember old resource file and try to open preferences file |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
410 ** in the preferences folder. If it doesn't exist we try to create |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
411 ** it. If anything fails here we limp on, but set cannotmodify so |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
412 ** we don't try to store things later on. |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
413 */ |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
414 oldrh = CurResFile(); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
415 if ( FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &prefdirRefNum, |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
416 &prefdirDirID) != noErr ) { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
417 /* Something wrong with preferences folder */ |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
418 cannotmodify = 1; |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
419 } else { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
420 (void)FSMakeFSSpec(prefdirRefNum, prefdirDirID, "\pPython Preferences", &dirspec); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
421 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
422 if ( prefrh == -1 ) { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
423 /* It doesn't exist. Try to create it */ |
| 2337 | 424 FSpCreateResFile(&dirspec, 'PYTH', 'pref', 0); |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
425 prefrh = FSpOpenResFile(&dirspec, fsRdWrShPerm); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
426 if ( prefrh == -1 ) { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
427 cannotmodify = 1; |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
428 } else { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
429 UseResFile(prefrh); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
430 } |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
431 } |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
432 } |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
433 /* So, we've opened our preferences file, we hope. Look for the alias */ |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
434 handle = (AliasHandle)Get1Resource('alis', 128); |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
435 if ( handle ) { |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
436 /* It exists. Resolve it (possibly updating it) */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
437 if ( ResolveAlias(NULL, handle, &dirspec, &modified) == noErr ) |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
438 ok = 1; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
439 exists = 1; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
440 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
441 if ( !ok ) { |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
442 /* No luck, so far. ask the user for help */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
443 item = Alert(NOPYTHON_ALERT, NULL); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
444 if ( item == YES_ITEM ) { |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
445 /* The user wants to point us to a directory. Let her do so */ |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
446 ok = PyMac_GetDirectory(&dirspec); |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
447 if ( ok ) |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
448 modified = 1; |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
449 } else if ( item == CURWD_ITEM ) { |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
450 /* The user told us the current directory is fine. Build an FSSpec for it */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
451 if ( getwd(name) ) { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
452 if ( FSMakeFSSpec(0, 0, Pstring(name), &dirspec) == 0 ) { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
453 ok = 1; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
454 modified = 1; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
455 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
456 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
457 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
458 } |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
459 if ( ok && modified && !cannotmodify) { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
460 /* We have a new, valid fsspec and we can update the preferences file. Do so. */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
461 if ( !exists ) { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
462 if (NewAlias(NULL, &dirspec, &handle) == 0 ) |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
463 AddResource((Handle)handle, 'alis', 128, "\p"); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
464 } else { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
465 ChangedResource((Handle)handle); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
466 } |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
467 UpdateResFile(prefrh); |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
468 } |
|
2333
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
469 if ( !cannotmodify ) { |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
470 /* This means we have the resfile open. Close it. */ |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
471 CloseResFile(prefrh); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
472 } |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
473 /* Back to the old resource file */ |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
474 UseResFile(oldrh); |
|
6468fd0251d2
Changed PyMac_GetPythonDir to use a preferences file to store the
Jack Jansen <jack.jansen@cwi.nl>
parents:
2324
diff
changeset
|
475 /* Now turn the fsspec into a path to give back to our caller */ |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
476 if ( ok ) { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
477 ok = (nfullpath(&dirspec, name) == 0); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
478 if ( ok ) strcat(name, ":"); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
479 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
480 if ( !ok ) { |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
481 /* If all fails, we return the current directory */ |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
482 name[0] = 0; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
483 (void)getwd(name); |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
484 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
485 return name; |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
486 } |
|
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
487 |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
488 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
489 ** Returns true if the argument has a resource fork, and it contains |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
490 ** a 'PYC ' resource of the correct name |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
491 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
492 int |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
493 PyMac_FindResourceModule(module, filename) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
494 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
495 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
496 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
497 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
498 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
499 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
500 int ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
501 Handle h; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
502 |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
503 if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
504 return 0; /* It doesn't exist */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
505 if ( FSpGetFInfo(&fss, &finfo) != noErr ) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
506 return 0; /* shouldn't happen, I guess */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
507 oldrh = CurResFile(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
508 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
509 if ( filerh == -1 ) |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
510 return 0; |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
511 UseResFile(filerh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
512 SetResLoad(0); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
513 h = Get1NamedResource('PYC ', Pstring(module)); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
514 SetResLoad(1); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
515 ok = (h != NULL); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
516 CloseResFile(filerh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
517 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
518 return ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
519 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
520 |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
521 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
522 ** Load the specified module from a resource |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
523 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
524 PyObject * |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
525 PyMac_LoadResourceModule(module, filename) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
526 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
527 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
528 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
529 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
530 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
531 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
532 int ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
533 Handle h; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
534 OSErr err; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
535 PyObject *m, *co; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
536 long num, size; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
537 |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
538 if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
539 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
540 if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
541 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
542 oldrh = CurResFile(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
543 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
544 if ( filerh == -1 ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
545 err = ResError(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
546 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
547 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
548 UseResFile(filerh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
549 h = Get1NamedResource('PYC ', Pstring(module)); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
550 if ( h == NULL ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
551 err = ResError(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
552 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
553 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
554 HLock(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
555 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
556 ** XXXX The next few lines are intimately tied to the format of pyc |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
557 ** files. I'm not sure whether this code should be here or in import.c -- Jack |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
558 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
559 size = GetHandleSize(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
560 if ( size < 8 ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
561 PyErr_SetString(PyExc_ImportError, "Resource too small"); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
562 co = NULL; |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
563 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
564 num = (*h)[0] & 0xff; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
565 num = num | (((*h)[1] & 0xff) << 8); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
566 num = num | (((*h)[2] & 0xff) << 16); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
567 num = num | (((*h)[3] & 0xff) << 24); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
568 if ( num != PyImport_GetMagicNumber() ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
569 PyErr_SetString(PyExc_ImportError, "Bad MAGIC in resource"); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
570 co = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
571 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
572 co = PyMarshal_ReadObjectFromString((*h)+8, size-8); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
573 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
574 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
575 HUnlock(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
576 CloseResFile(filerh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
577 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
578 if ( co ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
579 m = PyImport_ExecCodeModule(module, co); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
580 Py_DECREF(co); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
581 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
582 m = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
583 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
584 return m; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
585 error: |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
586 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
587 char buf[512]; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
588 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
589 sprintf(buf, "%s: %s", filename, PyMac_StrError(err)); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
590 PyErr_SetString(PyExc_ImportError, buf); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
591 return NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
592 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
593 } |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
594 |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
595 /* |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
596 ** Helper routine for GetDirectory |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
597 */ |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
598 static pascal short |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
599 myhook_proc(short item, DialogPtr theDialog, void *dataptr) |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
600 { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
601 if ( item == SELECTCUR_ITEM ) { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
602 item = sfItemCancelButton; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
603 * (int *)dataptr = 1; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
604 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
605 return item; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
606 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
607 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
608 /* |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
609 ** Ask the user for a directory. I still can't understand |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
610 ** why Apple doesn't provide a standard solution for this... |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
611 */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
612 int |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
613 PyMac_GetDirectory(dirfss) |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
614 FSSpec *dirfss; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
615 { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
616 static SFTypeList list = {'fldr', 0, 0, 0}; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
617 static Point where = {-1, -1}; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
618 static DlgHookYDUPP myhook_upp; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
619 static int upp_inited = 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
620 StandardFileReply reply; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
621 int select_clicked = 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
622 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
623 if ( !upp_inited ) { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
624 myhook_upp = NewDlgHookYDProc(myhook_proc); |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
625 upp_inited = 1; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
626 } |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
627 CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp, |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
628 NULL, NULL, NULL, (void *)&select_clicked); |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
629 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
630 reply.sfFile.name[0] = 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
631 if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) ) |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
632 return 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
633 return select_clicked; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
634 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
635 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
636 /* Convert a 4-char string object argument to an OSType value */ |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
637 int |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
638 PyMac_GetOSType(PyObject *v, OSType *pr) |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
639 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
640 if (!PyString_Check(v) || PyString_Size(v) != 4) { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
641 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
642 "OSType arg must be string of 4 chars"); |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
643 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
644 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
645 memcpy((char *)pr, PyString_AsString(v), 4); |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
646 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
647 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
648 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
649 /* Convert an OSType value to a 4-char string object */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
650 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
651 PyMac_BuildOSType(OSType t) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
652 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
653 return PyString_FromStringAndSize((char *)&t, 4); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
654 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
655 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
656 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
657 /* Convert a Python string object to a Str255 */ |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
658 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
659 PyMac_GetStr255(PyObject *v, Str255 pbuf) |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
660 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
661 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
662 if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
663 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
664 "Str255 arg must be string of at most 255 chars"); |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
665 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
666 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
667 pbuf[0] = len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
668 memcpy((char *)(pbuf+1), PyString_AsString(v), len); |
| 2035 | 669 return 1; |
| 670 } | |
| 671 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
672 /* Convert a Str255 to a Python string object */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
673 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
674 PyMac_BuildStr255(Str255 s) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
675 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
676 return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
677 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
678 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
679 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
680 /* |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
681 ** Convert a Python object to an FSSpec. |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
682 ** The object may either be a full pathname or a triple |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
683 ** (vrefnum, dirid, path). |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
684 ** NOTE: This routine will fail on pre-sys7 machines. |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
685 ** The caller is responsible for not calling this routine |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
686 ** in those cases (which is fine, since everyone calling |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
687 ** this is probably sys7 dependent anyway). |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
688 */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
689 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
690 PyMac_GetFSSpec(PyObject *v, FSSpec *fs) |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
691 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
692 Str255 path; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
693 short refnum; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
694 long parid; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
695 OSErr err; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
696 FSSpec *fs2; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
697 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
698 /* first check whether it already is an FSSpec */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
699 fs2 = mfs_GetFSSpecFSSpec(v); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
700 if ( fs2 ) { |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
701 (void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
702 return 1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
703 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
704 if ( PyString_Check(v) ) { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
705 /* It's a pathname */ |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
706 if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
707 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
708 refnum = 0; /* XXXX Should get CurWD here... */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
709 parid = 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
710 } else { |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
711 if( !PyArg_Parse(v, "(hlO&); FSSpec should be fullpath or (vrefnum,dirid,path)", |
|
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
712 &refnum, &parid, PyMac_GetStr255, &path)) { |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
713 return 0; |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
714 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
715 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
716 err = FSMakeFSSpec(refnum, parid, path, fs); |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
717 if ( err && err != fnfErr ) { |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
718 PyErr_Mac(PyExc_ValueError, err); |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
719 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
720 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
721 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
722 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
723 |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
724 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
725 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
726 /* Convert a Python object to a Rect. |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
727 The object must be a (left, top, right, bottom) tuple. |
|
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
728 (This differs from the order in the struct but is consistent with |
|
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
729 the arguments to SetRect(), and also with STDWIN). */ |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
730 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
731 PyMac_GetRect(PyObject *v, Rect *r) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
732 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
733 return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom); |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
734 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
735 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
736 /* Convert a Rect to a Python object */ |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
737 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
738 PyMac_BuildRect(Rect *r) |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
739 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
740 return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom); |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
741 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
742 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
743 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
744 /* Convert a Python object to a Point. |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
745 The object must be a (h, v) tuple. |
|
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
746 (This differs from the order in the struct but is consistent with |
|
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
747 the arguments to SetPoint(), and also with STDWIN). */ |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
748 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
749 PyMac_GetPoint(PyObject *v, Point *p) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
750 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
751 return PyArg_Parse(v, "(hh)", &p->h, &p->v); |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
752 } |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
753 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
754 /* Convert a Point to a Python object */ |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
755 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
756 PyMac_BuildPoint(Point p) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
757 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
758 return Py_BuildValue("(hh)", p.h, p.v); |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
759 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
760 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
761 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
762 /* Convert a Python object to an EventRecord. |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
763 The object must be a (what, message, when, (v, h), modifiers) tuple. */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
764 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
765 PyMac_GetEventRecord(PyObject *v, EventRecord *e) |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
766 { |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
767 return PyArg_Parse(v, "(hll(hh)h)", |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
768 &e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
769 &e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
770 &e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
771 &e->where.h, |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
772 &e->where.v, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
773 &e->modifiers); |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
774 } |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
775 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
776 /* Convert a Rect to an EventRecord object */ |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
777 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
778 PyMac_BuildEventRecord(EventRecord *e) |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
779 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
780 return Py_BuildValue("(hll(hh)h)", |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
781 e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
782 e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
783 e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
784 e->where.h, |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
785 e->where.v, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
786 e->modifiers); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
787 } |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
788 |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
789 |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
790 #ifndef USE_MAC_SHARED_LIBRARY |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
791 |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
792 /* For normal application */ |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
793 void |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
794 main() |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
795 { |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
796 int argc; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
797 char **argv; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
798 |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
799 #ifdef __MWERKS__ |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
800 SIOUXSettings.asktosaveonclose = 0; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
801 SIOUXSettings.showstatusline = 0; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
802 SIOUXSettings.tabspaces = 4; |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
803 #endif |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
804 argc = PyMac_GetArgv(&argv); |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
805 Py_Main(argc, argv); |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
806 } |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
807 |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
808 #else /* USE_MAC_SHARED_LIBRARY */ |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
809 |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
810 /* Applet support */ |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
811 |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
812 /* Run a compiled Python Python script from 'PYC ' resource __main__ */ |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
813 static int |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
814 run_main_resource() |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
815 { |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
816 Handle h; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
817 long size; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
818 PyObject *code; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
819 PyObject *result; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
820 |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
821 h = GetNamedResource('PYC ', "\p__main__"); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
822 if (h == NULL) { |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
823 Alert(NOPYC_ALERT, NULL); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
824 return 1; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
825 } |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
826 size = GetResourceSizeOnDisk(h); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
827 HLock(h); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
828 code = PyMarshal_ReadObjectFromString(*h + 8, (int)(size - 8)); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
829 HUnlock(h); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
830 ReleaseResource(h); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
831 if (code == NULL) { |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
832 PyErr_Print(); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
833 return 1; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
834 } |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
835 result = PyImport_ExecCodeModule("__main__", code); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
836 Py_DECREF(code); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
837 if (result == NULL) { |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
838 PyErr_Print(); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
839 return 1; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
840 } |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
841 Py_DECREF(result); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
842 return 0; |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
843 } |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
844 |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
845 /* Initialization sequence for applets */ |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
846 void |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
847 PyMac_InitApplet() |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
848 { |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
849 int argc; |
|
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
850 char **argv; |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
851 int err; |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
852 |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
853 #ifdef USE_MAC_SHARED_LIBRARY |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
854 PyMac_AddLibResources(); |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
855 #endif |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
856 #ifdef __MWERKS__ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
857 SIOUXSettings.asktosaveonclose = 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
858 SIOUXSettings.showstatusline = 0; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
859 SIOUXSettings.tabspaces = 4; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
860 #endif |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
861 argc = PyMac_GetArgv(&argv); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
862 Py_Initialize(); |
|
2394
fa8cdd3cc545
use PyMac_GetArgv (in macgetargv.c) for applet inits
Guido van Rossum <guido@python.org>
parents:
2382
diff
changeset
|
863 PySys_SetArgv(argc, argv); |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
864 err = run_main_resource(); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
865 fflush(stderr); |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
866 fflush(stdout); |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
867 #ifdef __MWERKS__ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
868 if (!err) |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
869 SIOUXSettings.autocloseonquit = 1; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
870 else |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
871 SIOUXSettings.showstatusline = 1; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
872 #endif |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
873 /* XXX Should we bother to Py_Exit(sts)? */ |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
874 } |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
875 |
|
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
876 #endif /* USE_MAC_SHARED_LIBRARY */ |
