Mercurial > cpython-lru_cache-weakref
annotate Mac/Python/macglue.c @ 5744:ea8a0b090908 legacy-trunk
Added PyMac_SetEventHandler which allows you to replace complete event
handling in inner loop with python code. Also move (previously
machine independent) PyErr_CheckSignals here, so we can propagate
exceptions in event handling code.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Fri, 20 Jun 1997 16:18:15 +0000 |
| parents | d0c6b49d7101 |
| children | 23e014839ab0 |
| rev | line source |
|---|---|
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1 /*********************************************************** |
|
5079
d6b292a33cfe
Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents:
4522
diff
changeset
|
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
|
2224
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 |
| 4024 | 25 #ifdef __CFM68K__ |
| 26 /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this | |
| 27 ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for | |
| 28 ** CW9, check that the workaround is still needed for the next release. | |
| 29 */ | |
| 30 #define GetEvQHdr GetEventQueue | |
| 31 #endif /* __CFM68K__ */ | |
| 32 | |
| 33 #include <Events.h> | |
| 34 | |
| 35 #ifdef __CFM68K__ | |
| 36 #undef GetEventQueue | |
| 37 #endif /* __CFM68K__ */ | |
| 38 | |
| 2035 | 39 #include "Python.h" |
| 2337 | 40 |
| 2035 | 41 #include "macglue.h" |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
42 #include "marshal.h" |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
43 #include "import.h" |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
44 #include "importdl.h" |
| 2035 | 45 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
46 #include "pythonresources.h" |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
47 |
| 2035 | 48 #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
|
49 #include <Files.h> |
|
2312
40aec48cd1e2
Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents:
2276
diff
changeset
|
50 #include <StandardFile.h> |
| 2035 | 51 #include <Resources.h> |
| 52 #include <Memory.h> | |
| 53 #include <Windows.h> | |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
54 #include <Traps.h> |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
55 #include <Processes.h> |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
56 #include <Fonts.h> |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
57 #include <Menus.h> |
|
2747
e41669a1dea0
Added code to obtain sys.path from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2668
diff
changeset
|
58 #include <TextUtils.h> |
|
2265
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
59 #ifdef THINK_C |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
60 #include <OSEvents.h> /* For EvQElPtr */ |
|
4bcc92916fab
added <OSEvents.h> for Think C
Guido van Rossum <guido@python.org>
parents:
2262
diff
changeset
|
61 #endif |
|
2443
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
62 #ifdef __MWERKS__ |
|
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
63 #include <SIOUX.h> |
|
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
64 #endif |
|
3431
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
65 #ifdef USE_GUSI |
|
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
66 #include <TFileSpec.h> /* For Path2FSSpec */ |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
67 #include <LowMem.h> /* For SetSFCurDir, etc */ |
| 4197 | 68 #include <GUSI.h> |
|
3431
26bec9e22e5d
Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents:
3278
diff
changeset
|
69 #endif |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
70 |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
71 /* The ID of the Sioux apple menu */ |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
72 #define SIOUX_APPLEID 32000 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
73 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
74 #include <signal.h> |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
75 #include <stdio.h> |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
76 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
77 /* |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
78 ** When less than this amount of stackspace is left we |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
79 ** raise a MemoryError. |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
80 */ |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
81 #ifndef MINIMUM_STACK_SIZE |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
82 #ifdef __powerc |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
83 #define MINIMUM_STACK_SIZE 8192 |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
84 #else |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
85 #define MINIMUM_STACK_SIZE 4096 |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
86 #endif |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
87 #endif |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
88 |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
89 /* |
|
2443
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
90 ** We have to be careful, since we can't handle |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
91 ** things like updates (and they'll keep coming back if we don't |
|
2443
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
92 ** handle them). Note that we don't know who has windows open, so |
|
2dcf7538347a
Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents:
2429
diff
changeset
|
93 ** even handing updates off to SIOUX under MW isn't going to work. |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
94 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
95 #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
|
96 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
97 #include <signal.h> |
| 2035 | 98 |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
99 /* 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
|
100 ** with the python errors.h. */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
101 #define fnfErr -43 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
102 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
103 /* Declared in macfsmodule.c: */ |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
104 extern FSSpec *mfs_GetFSSpecFSSpec(); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
105 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
106 /* Interrupt code variables: */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
107 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
|
108 static RETSIGTYPE intcatcher Py_PROTO((int)); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
109 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
110 static int PyMac_DoYield Py_PROTO((int, int)); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
111 static int PyMac_Yield Py_PROTO((void)); |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
112 |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
113 /* |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
114 ** These are the real scheduling parameters that control what we check |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
115 ** in the event loop, and how often we check. The values are initialized |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
116 ** from pyMac_SchedParamStruct. |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
117 */ |
| 4197 | 118 |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
119 struct real_sched_param_struct { |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
120 int check_interrupt; /* if true check for command-dot */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
121 int process_events; /* if nonzero enable evt processing, this mask */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
122 int besocial; /* if nonzero be a little social with CPU */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
123 unsigned long check_interval; /* how often to check, in ticks */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
124 unsigned long bg_yield; /* yield so long when in background */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
125 /* these are computed from previous and clock and such */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
126 int enabled; /* check_interrupt OR process_event OR yield */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
127 unsigned long next_check; /* when to check/yield next, in ticks */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
128 }; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
129 |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
130 static struct real_sched_param_struct schedparams = |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
131 { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0}; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
132 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
133 /* |
| 4197 | 134 ** Workaround for sioux/gusi combo: set when we are exiting |
| 135 */ | |
| 136 int PyMac_ConsoleIsDead; | |
| 137 | |
| 138 /* | |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
139 ** Sioux menu bar, saved early so we can restore it |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
140 */ |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
141 static Handle sioux_mbar; |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
142 |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
143 /* |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
144 ** Some stuff for our GetDirectory and PromptGetFile routines |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
145 */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
146 struct hook_args { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
147 int selectcur_hit; /* Set to true when "select current" selected */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
148 char *prompt; /* The prompt */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
149 }; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
150 static DlgHookYDUPP myhook_upp; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
151 static int upp_inited = 0; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
152 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
153 /* |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
154 ** The python-code event handler |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
155 */ |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
156 static PyObject *python_event_handler; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
157 |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
158 #ifdef USE_GUSI |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
159 /* |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
160 ** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
161 ** the working directory. Hence, we call this routine after each call |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
162 ** to chdir() to rectify things. |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
163 */ |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
164 void |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
165 PyMac_FixGUSIcd() |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
166 { |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
167 WDPBRec pb; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
168 FSSpec curdirfss; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
169 |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
170 if ( Path2FSSpec(":x", &curdirfss) != noErr ) |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
171 return; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
172 |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
173 /* Set MacOS "working directory" */ |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
174 pb.ioNamePtr= "\p"; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
175 pb.ioVRefNum= curdirfss.vRefNum; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
176 pb.ioWDDirID= curdirfss.parID; |
|
5270
de9d0c5249b0
Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents:
5153
diff
changeset
|
177 if (PBHSetVolSync(&pb) != noErr) |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
178 return; |
|
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
179 } |
|
4013
aa9548885b3f
Dummy SpinCursor() if __CFM68K__ is defined
Jack Jansen <jack.jansen@cwi.nl>
parents:
3914
diff
changeset
|
180 |
|
4238
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
181 /* |
|
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
182 ** SpinCursor (needed by GUSI) drags in heaps of stuff, so we |
|
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
183 ** provide a dummy here. |
|
6c86d9136c09
- Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents:
4215
diff
changeset
|
184 */ |
| 4018 | 185 void SpinCursor(short x) { /* Dummy */ } |
| 186 | |
| 4197 | 187 /* |
| 188 ** Replacement GUSI Spin function | |
| 189 */ | |
| 190 static int | |
| 191 PyMac_GUSISpin(spin_msg msg, long arg) | |
| 192 { | |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
193 static Boolean inForeground = true; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
194 int maxsleep = 6; /* 6 ticks is "normal" sleeptime */ |
| 4197 | 195 |
| 196 if (PyMac_ConsoleIsDead) return 0; | |
| 197 #if 0 | |
| 198 if (inForeground) | |
| 199 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1); | |
| 200 #endif | |
| 201 | |
| 202 if (interrupted) return -1; | |
| 203 | |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
204 if ( msg == SP_AUTO_SPIN ) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
205 maxsleep = 0; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
206 if ( msg==SP_SLEEP||msg==SP_SELECT ) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
207 maxsleep = arg; |
| 4197 | 208 |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
209 PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */ |
| 4197 | 210 |
| 211 return 0; | |
| 212 } | |
| 213 | |
| 214 void | |
| 215 PyMac_SetGUSISpin() { | |
| 216 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); | |
| 217 } | |
| 218 | |
|
5617
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
219 /* Called at exit() time thru atexit(), to stop event processing */ |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
220 void |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
221 PyMac_StopGUSISpin() { |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
222 PyMac_ConsoleIsDead = 1; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
223 } |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
224 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
225 /* |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
226 ** Replacement routines for the PLstr... functions so we don't need |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
227 ** StdCLib. Moreover, that implementation is broken under cfm68k... |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
228 */ |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
229 void |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
230 PLstrcpy(to, fr) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
231 unsigned char *to, *fr; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
232 { |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
233 memcpy(to, fr, fr[0]+1); |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
234 } |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
235 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
236 int |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
237 PLstrcmp(s1, s2) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
238 unsigned char *s1, *s2; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
239 { |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
240 int res; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
241 int l = s1[0] < s2[0] ? s1[0] : s2[0]; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
242 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
243 res = memcmp(s1+1, s2+1, l); |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
244 if ( res != 0 ) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
245 return res; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
246 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
247 if ( s1 < s2 ) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
248 return -1; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
249 else if ( s1 > s2 ) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
250 return 1; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
251 else |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
252 return 0; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
253 } |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
254 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
255 unsigned char * |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
256 PLstrrchr(str, chr) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
257 unsigned char *str; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
258 unsigned char chr; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
259 { |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
260 unsigned char *ptr = 0; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
261 unsigned char *p; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
262 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
263 for(p=str+1; p<str+str[0]; p++) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
264 if ( *p == chr ) |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
265 ptr = p; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
266 return ptr; |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
267 } |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
268 |
|
70855574516b
- Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents:
5270
diff
changeset
|
269 #endif /* USE_GUSI */ |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
270 |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
271 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
272 /* 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
|
273 unsigned char * |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
274 Pstring(char *str) |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
275 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
276 static Str255 buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
277 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
278 |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
279 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
|
280 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
|
281 len = 255; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
282 buf[0] = (unsigned char)len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
283 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
|
284 return buf; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
285 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
286 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
287 /* Like strerror() but for Mac OS error numbers */ |
|
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
288 char *PyMac_StrError(int err) |
| 2035 | 289 { |
| 290 static char buf[256]; | |
| 291 Handle h; | |
| 292 char *str; | |
| 293 | |
| 294 h = GetResource('Estr', err); | |
| 295 if ( h ) { | |
| 296 HLock(h); | |
| 297 str = (char *)*h; | |
| 298 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
|
299 buf[(unsigned char)str[0]] = '\0'; |
| 2035 | 300 HUnlock(h); |
| 301 ReleaseResource(h); | |
| 302 } else { | |
| 303 sprintf(buf, "Mac OS error code %d", err); | |
| 304 } | |
| 305 return buf; | |
| 306 } | |
| 307 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
308 /* 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
|
309 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
|
310 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
311 /* 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
|
312 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
313 PyMac_GetOSErrException() |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
314 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
319 |
| 2035 | 320 /* Set a MAC-specific error from errno, and return NULL; return None if no error */ |
| 321 PyObject * | |
| 2136 | 322 PyErr_Mac(PyObject *eobj, int err) |
| 2035 | 323 { |
| 324 char *msg; | |
| 325 PyObject *v; | |
| 326 | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
327 if (err == 0 && !PyErr_Occurred()) { |
| 2035 | 328 Py_INCREF(Py_None); |
| 329 return Py_None; | |
| 330 } | |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
331 if (err == -1 && PyErr_Occurred()) |
|
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
332 return NULL; |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
333 msg = PyMac_StrError(err); |
| 2035 | 334 v = Py_BuildValue("(is)", err, msg); |
| 335 PyErr_SetObject(eobj, v); | |
| 336 Py_DECREF(v); | |
| 337 return NULL; | |
| 338 } | |
| 339 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
340 /* 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
|
341 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
342 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
|
343 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
344 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
|
345 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
346 |
|
3786
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
347 #ifdef USE_STACKCHECK |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
348 /* Check for stack overflow */ |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
349 int |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
350 PyOS_CheckStack() |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
351 { |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
352 long left; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
353 |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
354 left = StackSpace(); |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
355 if ( left < MINIMUM_STACK_SIZE ) |
|
3786
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
356 return -1; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
357 return 0; |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
358 } |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
359 #endif /* USE_STACKCHECK */ |
|
718c8af7be2a
Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents:
3655
diff
changeset
|
360 |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
361 /* 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
|
362 static RETSIGTYPE |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
363 intcatcher(sig) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
364 int sig; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
365 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
366 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
367 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
368 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
369 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
370 void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
371 PyOS_InitInterrupts() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
372 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
373 if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
374 signal(SIGINT, intcatcher); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
375 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
376 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
377 /* |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
378 ** 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
|
379 ** 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
|
380 ** 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
|
381 ** 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
|
382 ** interrupt a runaway python program. |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
383 */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
384 static void |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
385 scan_event_queue(flush) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
386 int flush; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
387 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
388 register EvQElPtr q; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
389 |
| 4018 | 390 q = (EvQElPtr) GetEventQueue()->qHead; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
391 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
392 for (; q; q = (EvQElPtr)q->qLink) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
393 if (q->evtQWhat == keyDown && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
394 (char)q->evtQMessage == '.' && |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
395 (q->evtQModifiers & cmdKey) != 0) { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
396 if ( flush ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
397 FlushEvents(keyDownMask, 0); |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
398 interrupted = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
399 break; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
400 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
401 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
402 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
403 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
404 int |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
405 PyErr_CheckSignals() |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
406 { |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
407 if (schedparams.enabled) { |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
408 if ( (unsigned long)LMGetTicks() > schedparams.next_check ) { |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
409 if ( PyMac_Yield() < 0) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
410 return -1; |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
411 schedparams.next_check = (unsigned long)LMGetTicks() |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
412 + schedparams.check_interval; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
413 if (interrupted) { |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
414 scan_event_queue(1); /* Eat events up to cmd-. */ |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
415 interrupted = 0; |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
416 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
417 return -1; |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
418 } |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
419 } |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
420 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
421 return 0; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
422 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
423 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
424 int |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
425 PyOS_InterruptOccurred() |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
426 { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
427 scan_event_queue(1); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
428 return interrupted; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
429 } |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
430 /* Check whether we are in the foreground */ |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
431 int |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
432 PyMac_InForeground() |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
433 { |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
434 static ProcessSerialNumber ours; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
435 static inited; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
436 ProcessSerialNumber curfg; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
437 Boolean eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
438 |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
439 if ( inited == 0 ) { |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
440 (void)GetCurrentProcess(&ours); |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
441 inited = 1; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
442 } |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
443 if ( GetFrontProcess(&curfg) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
444 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
445 else if ( SameProcess(&ours, &curfg, &eq) < 0 ) |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
446 eq = 1; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
447 return (int)eq; |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
448 |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
449 } |
|
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
450 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
451 int |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
452 PyMac_SetEventHandler(PyObject *evh) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
453 { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
454 if ( evh && python_event_handler ) { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
455 PyErr_SetString(PyExc_RuntimeError, "Python event handler already set"); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
456 return 0; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
457 } |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
458 if ( python_event_handler ) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
459 Py_DECREF(python_event_handler); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
460 if ( evh ) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
461 Py_INCREF(evh); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
462 python_event_handler = evh; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
463 return 1; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
464 } |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
465 |
| 2035 | 466 /* |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
467 ** 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
|
468 ** 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
|
469 */ |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
470 void |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
471 PyMac_HandleEventIntern(evp) |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
472 EventRecord *evp; |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
473 { |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
474 #ifdef __MWERKS__ |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
475 { |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
476 int siouxdidit; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
477 |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
478 /* If SIOUX wants it we're done */ |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
479 siouxdidit = SIOUXHandleOneEvent(evp); |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
480 if ( siouxdidit ) |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
481 return; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
482 } |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
483 #else |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
484 /* 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
|
485 if ( evp->what == mouseDown ) { |
| 3052 | 486 WindowPtr wp; |
| 487 | |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
488 if ( FindWindow(evp->where, &wp) == inSysWindow ) { |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
489 SystemClick(evp, wp); |
|
3248
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
490 return; |
|
5e101ead1e69
Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3052
diff
changeset
|
491 } |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
492 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
493 #endif /* !__MWERKS__ */ |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
494 } |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
495 |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
496 /* |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
497 ** Handle an event, either through HandleEvent or by passing it to the Python |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
498 ** event handler. |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
499 */ |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
500 int |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
501 PyMac_HandleEvent(evp) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
502 EventRecord *evp; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
503 { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
504 PyObject *rv; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
505 |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
506 if ( python_event_handler ) { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
507 rv = PyObject_CallFunction(python_event_handler, "(O&)", |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
508 PyMac_BuildEventRecord, evp); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
509 if ( rv ) |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
510 Py_DECREF(rv); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
511 else |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
512 return -1; /* Propagate exception */ |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
513 } else { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
514 PyMac_HandleEventIntern(evp); |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
515 } |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
516 return 0; |
|
2276
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
517 } |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
518 |
|
66d6d13df4f8
Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents:
2265
diff
changeset
|
519 /* |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
520 ** Yield the CPU to other tasks without processing events. |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
521 */ |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
522 static int |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
523 PyMac_DoYield(int maxsleep, int maycallpython) |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
524 { |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
525 EventRecord ev; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
526 int gotone; |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
527 long latest_time_ready; |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
528 static int in_here = 0; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
529 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
530 in_here++; |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
531 /* |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
532 ** First check for interrupts, if wanted. |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
533 ** This sets a flag that will be picked up at an appropriate |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
534 ** moment in the mainloop. |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
535 */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
536 if (schedparams.check_interrupt) |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
537 scan_event_queue(0); |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
538 |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
539 /* XXXX Implementing an idle routine goes here */ |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
540 |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
541 /* |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
542 ** Check which of the eventloop cases we have: |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
543 ** - process events |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
544 ** - don't process events but do yield |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
545 ** - do neither |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
546 */ |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
547 if( in_here > 1 || !schedparams.process_events || |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
548 (python_event_handler && !maycallpython) ) { |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
549 if ( maxsleep >= 0 ) { |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
550 SystemTask(); |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
551 } |
| 4197 | 552 } else { |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
553 latest_time_ready = LMGetTicks() + maxsleep; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
554 while ( maxsleep >= 0 ) { |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
555 gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL); |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
556 /* Get out quickly if nothing interesting is happening */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
557 if ( !gotone || ev.what == nullEvent ) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
558 break; |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
559 if ( PyMac_HandleEvent(&ev) < 0 ) { |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
560 in_here--; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
561 return -1; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
562 } |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
563 maxsleep = latest_time_ready - LMGetTicks(); |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
564 } |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
565 } |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
566 in_here--; |
|
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
567 return 0; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
568 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
569 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
570 /* |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
571 ** Process events and/or yield the CPU to other tasks if opportune |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
572 */ |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
573 int |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
574 PyMac_Yield() { |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
575 unsigned long maxsleep; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
576 |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
577 if( PyMac_InForeground() ) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
578 maxsleep = 0; |
|
2262
03bd79432f06
- Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
2255
diff
changeset
|
579 else |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
580 maxsleep = schedparams.bg_yield; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
581 |
|
5744
ea8a0b090908
Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents:
5737
diff
changeset
|
582 return PyMac_DoYield(maxsleep, 1); |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
583 } |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
584 |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
585 /* |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
586 ** Return current scheduler parameters |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
587 */ |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
588 void |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
589 PyMac_GetSchedParams(PyMacSchedParams *sp) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
590 { |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
591 sp->check_interrupt = schedparams.check_interrupt; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
592 sp->process_events = schedparams.process_events; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
593 sp->besocial = schedparams.besocial; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
594 sp->check_interval = schedparams.check_interval / 60.0; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
595 sp->bg_yield = schedparams.bg_yield / 60.0; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
596 } |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
597 |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
598 /* |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
599 ** Set current scheduler parameters |
| 2035 | 600 */ |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
601 void |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
602 PyMac_SetSchedParams(PyMacSchedParams *sp) |
| 2035 | 603 { |
|
5711
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
604 schedparams.check_interrupt = sp->check_interrupt; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
605 schedparams.process_events = sp->process_events; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
606 schedparams.besocial = sp->besocial; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
607 schedparams.check_interval = (unsigned long)(sp->check_interval*60); |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
608 schedparams.bg_yield = (unsigned long)(sp->bg_yield*60); |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
609 if ( schedparams.check_interrupt || schedparams.process_events || |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
610 schedparams.besocial ) |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
611 schedparams.enabled = 1; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
612 else |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
613 schedparams.enabled = 0; |
|
fb170ce82951
Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents:
5617
diff
changeset
|
614 schedparams.next_check = 0; /* Check immedeately */ |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
615 } |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
616 |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
617 /* |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
618 ** Install our menu bar. |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
619 */ |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
620 void |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
621 PyMac_InitMenuBar() |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
622 { |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
623 MenuHandle applemenu; |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
624 |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
625 if ( (sioux_mbar=GetMenuBar()) == NULL ) { |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
626 /* Sioux menu not installed yet. Do so */ |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
627 SIOUXSetupMenus(); |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
628 if ( (sioux_mbar=GetMenuBar()) == NULL ) |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
629 return; |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
630 } |
|
5270
de9d0c5249b0
Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents:
5153
diff
changeset
|
631 if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return; |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
632 SetMenuItemText(applemenu, 1, "\pAbout Python..."); |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
633 } |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
634 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
635 /* |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
636 ** Restore sioux menu bar |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
637 */ |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
638 void |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
639 PyMac_RestoreMenuBar() |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
640 { |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
641 if ( sioux_mbar ) { |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
642 SetMenuBar(sioux_mbar); |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
643 DrawMenuBar(); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
644 } |
|
5732
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
645 } |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
646 |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
647 |
|
f027dd0a85e4
- Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents:
5711
diff
changeset
|
648 /* |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
649 ** Our replacement about box |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
650 */ |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
651 void |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
652 SIOUXDoAboutBox(void) |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
653 { |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
654 DialogPtr theDialog; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
655 WindowRef theWindow; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
656 CGrafPtr thePort; |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
657 short item; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
658 short xpos, ypos, width, height, swidth, sheight; |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
659 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
660 if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL ) |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
661 return; |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
662 theWindow = GetDialogWindow(theDialog); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
663 thePort = GetWindowPort(theWindow); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
664 width = thePort->portRect.right - thePort->portRect.left; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
665 height = thePort->portRect.bottom - thePort->portRect.top; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
666 swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left; |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
667 sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight(); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
668 xpos = (swidth-width)/2; |
|
4329
a240be5be6b4
About boxes should be at 20% of screen height, not halfway
Jack Jansen <jack.jansen@cwi.nl>
parents:
4325
diff
changeset
|
669 ypos = (sheight-height)/5 + LMGetMBarHeight(); |
|
4325
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
670 MoveWindow(theWindow, xpos, ypos, 0); |
|
12c3865aeaa0
Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents:
4238
diff
changeset
|
671 ShowWindow(theWindow); |
|
4215
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
672 ModalDialog(NULL, &item); |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
673 DisposeDialog(theDialog); |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
674 } |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
675 |
|
0410ed3808ee
Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents:
4204
diff
changeset
|
676 /* |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
677 ** 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
|
678 ** 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
|
679 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
680 int |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
681 PyMac_FindResourceModule(obj, module, filename) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
682 PyStringObject *obj; |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
683 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
684 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
685 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
686 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
687 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
688 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
689 int ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
690 Handle h; |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
691 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
692 #ifdef INTERN_STRINGS |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
693 /* |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
694 ** If we have interning find_module takes care of interning all |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
695 ** sys.path components. We then keep a record of all sys.path |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
696 ** components for which GetFInfo has failed (usually because the |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
697 ** component in question is a folder), and we don't try opening these |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
698 ** as resource files again. |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
699 */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
700 #define MAXPATHCOMPONENTS 32 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
701 static PyStringObject *not_a_file[MAXPATHCOMPONENTS]; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
702 static int max_not_a_file = 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
703 int i; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
704 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
705 if ( obj->ob_sinterned ) { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
706 for( i=0; i< max_not_a_file; i++ ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
707 if ( obj == not_a_file[i] ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
708 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
709 } |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
710 #endif /* INTERN_STRINGS */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
711 |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
712 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
713 /* |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
714 ** Special case: the application itself. Use a shortcut to |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
715 ** forestall opening and closing the application numerous times |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
716 ** (which is dead slow when running from CDROM) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
717 */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
718 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
719 UseResFile(PyMac_AppRefNum); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
720 filerh = -1; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
721 } else { |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
722 if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr || |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
723 FSpGetFInfo(&fss, &finfo) != noErr ) { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
724 #ifdef INTERN_STRINGS |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
725 if ( max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
726 not_a_file[max_not_a_file++] = obj; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
727 #endif /* INTERN_STRINGS */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
728 /* doesn't exist or is folder */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
729 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
730 } |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
731 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
732 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
733 if ( filerh == -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
734 return 0; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
735 UseResFile(filerh); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
736 } |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
737 SetResLoad(0); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
738 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
|
739 SetResLoad(1); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
740 ok = (h != NULL); |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
741 if ( filerh != -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
742 CloseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
743 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
744 return ok; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
745 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
746 |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
747 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
748 ** 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
|
749 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
750 PyObject * |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
751 PyMac_LoadResourceModule(module, filename) |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
752 char *module; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
753 char *filename; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
754 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
755 FSSpec fss; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
756 FInfo finfo; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
757 short oldrh, filerh; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
758 Handle h; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
759 OSErr err; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
760 PyObject *m, *co; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
761 long num, size; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
762 |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
763 if ( strcmp(filename, PyMac_ApplicationPath) == 0 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
764 /* |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
765 ** Special case: the application itself. Use a shortcut to |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
766 ** forestall opening and closing the application numerous times |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
767 ** (which is dead slow when running from CDROM) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
768 */ |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
769 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
770 UseResFile(PyMac_AppRefNum); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
771 filerh = -1; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
772 } else { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
773 if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
774 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
775 if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
776 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
777 oldrh = CurResFile(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
778 filerh = FSpOpenResFile(&fss, fsRdPerm); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
779 if ( filerh == -1 ) { |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
780 err = ResError(); |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
781 goto error; |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
782 } |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
783 UseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
784 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
785 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
|
786 if ( h == NULL ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
787 err = ResError(); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
788 goto error; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
789 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
790 HLock(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
791 /* |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
792 ** 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
|
793 ** 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
|
794 */ |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
795 size = GetHandleSize(h); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
796 if ( size < 8 ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
797 PyErr_SetString(PyExc_ImportError, "Resource too small"); |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
798 co = NULL; |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
799 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
800 num = (*h)[0] & 0xff; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
801 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
|
802 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
|
803 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
|
804 if ( num != PyImport_GetMagicNumber() ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
805 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
|
806 co = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
807 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
808 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
|
809 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
810 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
811 HUnlock(h); |
|
4522
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
812 if ( filerh != -1 ) |
|
d25a0ccbfd6b
When loading a PYC resource check whether the filename is the
Jack Jansen <jack.jansen@cwi.nl>
parents:
4329
diff
changeset
|
813 CloseResFile(filerh); |
|
2350
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
814 UseResFile(oldrh); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
815 if ( co ) { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
816 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
|
817 Py_DECREF(co); |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
818 } else { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
819 m = NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
820 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
821 return m; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
822 error: |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
823 { |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
824 char buf[512]; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
825 |
|
2382
6450d8828d2b
added applet initialization;
Guido van Rossum <guido@python.org>
parents:
2350
diff
changeset
|
826 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
|
827 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
|
828 return NULL; |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
829 } |
|
a2054933775b
Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2337
diff
changeset
|
830 } |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
831 |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
832 /* |
|
5737
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
833 ** Look for a module in a single folder. Upon entry buf and len |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
834 ** point to the folder to search, upon exit they refer to the full |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
835 ** pathname of the module found (if any). |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
836 */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
837 struct filedescr * |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
838 PyMac_FindModuleExtension(char *buf, int *lenp, char *module) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
839 { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
840 struct filedescr *fdp; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
841 unsigned char fnbuf[64]; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
842 int modnamelen = strlen(module); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
843 FSSpec fss; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
844 short refnum; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
845 long dirid; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
846 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
847 /* |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
848 ** Copy the module name to the buffer (already :-terminated) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
849 ** We also copy the first suffix, if this matches immedeately we're |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
850 ** lucky and return immedeately. |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
851 */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
852 if ( !_PyImport_Filetab[0].suffix ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
853 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
854 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
855 strcpy(buf+*lenp, module); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
856 strcpy(buf+*lenp+modnamelen, _PyImport_Filetab[0].suffix); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
857 if ( FSMakeFSSpec(0, 0, Pstring(buf), &fss) == noErr ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
858 return _PyImport_Filetab; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
859 /* |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
860 ** We cannot check for fnfErr (unfortunately), it can mean either that |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
861 ** the file doesn't exist (fine, we try others) or the path leading to it. |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
862 */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
863 refnum = fss.vRefNum; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
864 dirid = fss.parID; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
865 if ( refnum == 0 || dirid == 0 ) /* Fail on nonexistent dir */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
866 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
867 /* |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
868 ** We now have the folder parameters. Setup the field for the filename |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
869 */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
870 if ( modnamelen > 54 ) return 0; /* Leave room for extension */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
871 strcpy((char *)fnbuf+1, module); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
872 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
873 for( fdp = _PyImport_Filetab+1; fdp->suffix; fdp++ ) { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
874 strcpy((char *)fnbuf+1+modnamelen, fdp->suffix); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
875 fnbuf[0] = strlen((char *)fnbuf+1); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
876 if (Py_VerboseFlag > 1) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
877 fprintf(stderr, "# trying %s%s\n", buf, fdp->suffix); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
878 if ( FSMakeFSSpec(refnum, dirid, fnbuf, &fss) == noErr ) { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
879 /* Found it. */ |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
880 strcpy(buf+*lenp+modnamelen, fdp->suffix); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
881 *lenp = strlen(buf); |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
882 return fdp; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
883 } |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
884 } |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
885 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
886 } |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
887 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
888 #if 0 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
889 int |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
890 PyMac_FileExists(char *name) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
891 { |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
892 FSSpec fss; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
893 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
894 if ( FSMakeFSSpec(0, 0, Pstring(name), &fss) == noErr ) |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
895 return 1; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
896 return 0; |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
897 } |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
898 #endif |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
899 |
|
d0c6b49d7101
Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents:
5732
diff
changeset
|
900 /* |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
901 ** 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
|
902 */ |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
903 static pascal short |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
904 myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr) |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
905 { |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
906 if ( item == sfHookFirstCall && dataptr->prompt) { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
907 Handle prompth; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
908 short type; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
909 Rect rect; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
910 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
911 GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
912 if ( prompth ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
913 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
914 } else |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
915 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
|
916 item = sfItemCancelButton; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
917 dataptr->selectcur_hit = 1; |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
918 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
919 return item; |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
920 } |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
921 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
922 /* |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
923 ** 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
|
924 ** 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
|
925 */ |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
926 int |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
927 PyMac_GetDirectory(dirfss, prompt) |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
928 FSSpec *dirfss; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
929 char *prompt; |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
930 { |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
931 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
|
932 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
|
933 StandardFileReply reply; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
934 struct hook_args hook_args; |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
935 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
936 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
|
937 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
|
938 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
|
939 } |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
940 if ( prompt && *prompt ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
941 hook_args.prompt = (char *)Pstring(prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
942 else |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
943 hook_args.prompt = NULL; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
944 hook_args.selectcur_hit = 0; |
|
2412
75ae104f7e6c
ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents:
2403
diff
changeset
|
945 CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp, |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
946 NULL, NULL, NULL, (void *)&hook_args); |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
947 |
|
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
948 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
|
949 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
|
950 return 0; |
|
2988
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
951 return hook_args.selectcur_hit; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
952 } |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
953 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
954 /* |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
955 ** Slightly extended StandardGetFile: accepts a prompt */ |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
956 void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList, |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
957 StandardFileReply *reply, char *prompt) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
958 { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
959 static Point where = {-1, -1}; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
960 struct hook_args hook_args; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
961 |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
962 if ( !upp_inited ) { |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
963 myhook_upp = NewDlgHookYDProc(myhook_proc); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
964 upp_inited = 1; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
965 } |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
966 if ( prompt && *prompt ) |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
967 hook_args.prompt = (char *)Pstring(prompt); |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
968 else |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
969 hook_args.prompt = NULL; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
970 hook_args.selectcur_hit = 0; |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
971 CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where, |
|
2fe9d0371ecd
Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents:
2913
diff
changeset
|
972 myhook_upp, NULL, NULL, NULL, (void *)&hook_args); |
|
2403
72c715c004c8
- Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents:
2394
diff
changeset
|
973 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
974 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
975 /* 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
|
976 int |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
977 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
|
978 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
979 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
|
980 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
981 "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
|
982 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
983 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
984 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
|
985 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
986 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
987 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
988 /* 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
|
989 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
990 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
|
991 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
992 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
|
993 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
994 |
|
3914
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
995 /* Convert an NumVersion value to a 4-element tuple */ |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
996 PyObject * |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
997 PyMac_BuildNumVersion(NumVersion t) |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
998 { |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
999 return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev); |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
1000 } |
|
524cf501c851
- Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents:
3786
diff
changeset
|
1001 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1002 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1003 /* 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
|
1004 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
1005 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
|
1006 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1007 int len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1008 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
|
1009 PyErr_SetString(PyExc_TypeError, |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1010 "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
|
1011 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1012 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1013 pbuf[0] = len; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1014 memcpy((char *)(pbuf+1), PyString_AsString(v), len); |
| 2035 | 1015 return 1; |
| 1016 } | |
| 1017 | |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1018 /* 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
|
1019 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1020 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
|
1021 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1022 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
|
1023 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1024 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1025 |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1026 /* |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1027 ** 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
|
1028 ** 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
|
1029 ** (vrefnum, dirid, path). |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1030 ** 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
|
1031 ** 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
|
1032 ** 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
|
1033 ** 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
|
1034 */ |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1035 int |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
1036 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
|
1037 { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1038 Str255 path; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1039 short refnum; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1040 long parid; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1041 OSErr err; |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
1042 FSSpec *fs2; |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1043 |
|
2251
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
1044 /* 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
|
1045 fs2 = mfs_GetFSSpecFSSpec(v); |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
1046 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
|
1047 (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
|
1048 return 1; |
|
e0a3242d5ae7
Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents:
2231
diff
changeset
|
1049 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1050 if ( PyString_Check(v) ) { |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1051 /* 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
|
1052 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
|
1053 return 0; |
|
3433
578ca302a598
Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents:
3431
diff
changeset
|
1054 refnum = 0; /* XXXX Should get CurWD here?? */ |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1055 parid = 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1056 } else { |
|
2209
4053d4cb50e0
renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents:
2183
diff
changeset
|
1057 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
|
1058 &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
|
1059 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
|
1060 } |
|
2176
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1061 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1062 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
|
1063 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
|
1064 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
|
1065 return 0; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1066 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1067 return 1; |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1068 } |
|
1e9e74944bb5
- Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents:
2136
diff
changeset
|
1069 |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
1070 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1071 /* 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
|
1072 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
|
1073 (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
|
1074 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
|
1075 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1076 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
|
1077 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1078 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
|
1079 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1080 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1081 /* Convert a Rect to a Python object */ |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
1082 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1083 PyMac_BuildRect(Rect *r) |
|
2183
62bdded5f00a
modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents:
2176
diff
changeset
|
1084 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1085 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
|
1086 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1087 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1088 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1089 /* 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
|
1090 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
|
1091 (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
|
1092 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
|
1093 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1094 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
|
1095 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1096 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
|
1097 } |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1098 |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1099 /* Convert a Point to a Python object */ |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1100 PyObject * |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1101 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
|
1102 { |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1103 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
|
1104 } |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1105 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1106 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1107 /* 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
|
1108 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
|
1109 int |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1110 PyMac_GetEventRecord(PyObject *v, EventRecord *e) |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1111 { |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1112 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
|
1113 &e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1114 &e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1115 &e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1116 &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
|
1117 &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
|
1118 &e->modifiers); |
|
2224
32435d33f34a
cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents:
2209
diff
changeset
|
1119 } |
|
2231
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1120 |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1121 /* 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
|
1122 PyObject * |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1123 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
|
1124 { |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1125 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
|
1126 e->what, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1127 e->message, |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1128 e->when, |
|
2255
382edef2d6d7
reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents:
2251
diff
changeset
|
1129 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
|
1130 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
|
1131 e->modifiers); |
|
1e8b347a056c
Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents:
2224
diff
changeset
|
1132 } |
|
3278
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1133 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1134 /* Convert Python object to Fixed */ |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1135 int |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1136 PyMac_GetFixed(PyObject *v, Fixed *f) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1137 { |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1138 double d; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1139 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1140 if( !PyArg_Parse(v, "d", &d)) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1141 return 0; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1142 *f = (Fixed)(d * 0x10000); |
|
3655
f89fa7e95b84
PyMac_GetFixed() didn't return 1 on success
Jack Jansen <jack.jansen@cwi.nl>
parents:
3478
diff
changeset
|
1143 return 1; |
|
3278
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1144 } |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1145 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1146 /* Convert a Point to a Python object */ |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1147 PyObject * |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1148 PyMac_BuildFixed(Fixed f) |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1149 { |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1150 double d; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1151 |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1152 d = f; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1153 d = d / 0x10000; |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1154 return Py_BuildValue("d", d); |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1155 } |
|
43c5e7a3fc1f
Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents:
3248
diff
changeset
|
1156 |
