annotate Mac/Python/macglue.c @ 17813:8cd8741ebec0 legacy-trunk

Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
author Jack Jansen <jack.jansen@cwi.nl>
date Sat, 12 May 2001 21:31:34 +0000
parents a9485d404f05
children 2211c8995a5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
4024
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
25 #ifdef __CFM68K__
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
26 /* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
27 ** and defines it as GetEvQHdr (which is correct for PPC). This fix is for
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
28 ** CW9, check that the workaround is still needed for the next release.
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
29 */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
30 #define GetEvQHdr GetEventQueue
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
31 #endif /* __CFM68K__ */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
32
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
33 #include <Events.h>
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
34
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
35 #if !TARGET_API_MAC_OS8
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
36 /* Unfortunately this call is probably slower... */
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
37 #define LMGetTicks() TickCount()
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
38 #endif
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
39
4024
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
40 #ifdef __CFM68K__
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
41 #undef GetEventQueue
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
42 #endif /* __CFM68K__ */
53d511c0029f Fixed command-. handling
Jack Jansen <jack.jansen@cwi.nl>
parents: 4018
diff changeset
43
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 #include "Python.h"
2337
71e60871c681 ported to Think C
Guido van Rossum <guido@python.org>
parents: 2333
diff changeset
45
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 #include "macglue.h"
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
47 #include "marshal.h"
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
48 #include "import.h"
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
49 #include "importdl.h"
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
51 #include "pythonresources.h"
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
52
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53 #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
54 #include <Files.h>
2312
40aec48cd1e2 Added PyMac_GetPythonDir routine which obtains python home directory
Jack Jansen <jack.jansen@cwi.nl>
parents: 2276
diff changeset
55 #include <StandardFile.h>
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 #include <Resources.h>
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 #include <Memory.h>
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58 #include <Windows.h>
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
59 #include <Traps.h>
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
60 #include <Processes.h>
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
61 #include <Fonts.h>
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
62 #include <Menus.h>
2747
e41669a1dea0 Added code to obtain sys.path from a resource
Jack Jansen <jack.jansen@cwi.nl>
parents: 2668
diff changeset
63 #include <TextUtils.h>
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
64 #ifdef __MWERKS__
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
65 #include <SIOUX.h>
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
66 extern void SIOUXSetupMenus(void);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
67 extern void SIOUXDoAboutBox(void);
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
68 #endif
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
69 #ifdef USE_GUSI
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
70 /* Functions we redefine because they're in obscure libraries */
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
71 extern void SpinCursor(short x);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
72 extern void RotateCursor(short x);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
73 extern pascal void PLstrcpy(unsigned char *, unsigned char *);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
74 extern pascal int PLstrcmp(unsigned char *, unsigned char *);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
75 extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
76
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
77 #endif
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
78
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
79 #ifdef USE_GUSI1
3431
26bec9e22e5d Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents: 3278
diff changeset
80 #include <TFileSpec.h> /* For Path2FSSpec */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
81 #include <GUSI.h>
3431
26bec9e22e5d Added code to make fsspecs work for gusi-python
Jack Jansen <jack.jansen@cwi.nl>
parents: 3278
diff changeset
82 #endif
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
83 #include <LowMem.h>
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
84
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
85 /* 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
86 #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
87
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
88 #include <signal.h>
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
89 #include <stdio.h>
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
90
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
91 /*
3914
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
92 ** 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
93 ** raise a MemoryError.
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
94 */
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
95 #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
96 #ifdef __powerc
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
97 #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
98 #else
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
99 #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
100 #endif
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
101 #endif
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
102
16437
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
103 #if TARGET_API_MAC_CARBON
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
104 /*
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
105 ** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
106 ** but the stack cannot grow that far due to rlimit values. We cannot get at this value
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
107 ** from Carbon, so we set a maximum to the stack here that is based on the default
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
108 ** stack limit of 512K.
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
109 */
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
110 #define MAXIMUM_STACK_SIZE (256*1024)
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
111 #endif
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
112
3914
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
113 /*
2443
2dcf7538347a Under MW also be more conservative about events to request
Jack Jansen <jack.jansen@cwi.nl>
parents: 2429
diff changeset
114 ** 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
115 ** 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
116 ** 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
117 ** 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
118 */
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
119 #define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
120
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
121 #include <signal.h>
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
123 /* 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
124 ** with the python errors.h. */
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
125 #define fnfErr -43
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
126
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
127 /* Declared in macfsmodule.c: */
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
128 extern FSSpec *mfs_GetFSSpecFSSpec(PyObject *);
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
129 extern PyObject *newmfssobject(FSSpec *);
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
130
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
131 /* Interrupt code variables: */
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
132 static int interrupted; /* Set to true when cmd-. seen */
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
133 static RETSIGTYPE intcatcher(int);
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
134
13542
ddd6138c9e6f ANSIfication step 1: get rid of Py_PROTO and Py_FPROTO.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12855
diff changeset
135 static int PyMac_Yield(void);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
136
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
137 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
138 ** 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
139 ** 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
140 ** from pyMac_SchedParamStruct.
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
141 */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
142
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
143 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
144 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
145 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
146 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
147 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
148 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
149 /* 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
150 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
151 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
152 };
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
153
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
154 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
155 { 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
156
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
157 /*
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
158 ** Workaround for sioux/gusi combo: set when we are exiting
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
159 */
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
160 int PyMac_ConsoleIsDead;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
161
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
162 /*
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
163 ** 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
164 */
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
165 static MenuBarHandle 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
166
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
167 /*
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
168 ** 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
169 */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
170 struct hook_args {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
171 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
172 char *prompt; /* The prompt */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
173 };
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
174 #if !TARGET_API_MAC_OS8
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
175 /* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
176 ** but the macfsn code will replace it by a NavServices version anyway.
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
177 */
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
178 #define myhook_upp NULL
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
179 #else
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
180 static DlgHookYDUPP myhook_upp;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
181 static int upp_inited = 0;
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
182 #endif
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
183
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
184 /*
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
185 ** 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
186 */
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
187 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
188
11529
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
189 /*
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
190 ** Set to true if we're appearance-compliant
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
191 */
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
192 int PyMac_AppearanceCompliant;
f83b74273da2 First bits and pieces of appearance support: an init routine, a global flag PyMac_AppearanceCompliant (exported thru MacOS). If USE_APPEARANCE
Jack Jansen <jack.jansen@cwi.nl>
parents: 8790
diff changeset
193
13701
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
194 /*
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
195 ** Find out what the current script is.
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
196 ** Donated by Fredrik Lund.
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
197 */
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
198 char *PyMac_getscript()
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
199 {
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
200 int font, script, lang;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
201 font = 0;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
202 font = GetSysFont();
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
203 script = FontToScript(font);
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
204 switch (script) {
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
205 case smRoman:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
206 lang = GetScriptVariable(script, smScriptLang);
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
207 if (lang == langIcelandic)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
208 return "mac-iceland";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
209 else if (lang == langTurkish)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
210 return "mac-turkish";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
211 else if (lang == langGreek)
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
212 return "mac-greek";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
213 else
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
214 return "mac-roman";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
215 break;
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
216 case smJapanese:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
217 return "mac-japan";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
218 case smGreek:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
219 return "mac-greek";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
220 case smCyrillic:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
221 return "mac-cyrillic";
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
222 default:
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
223 return "mac-roman"; /* better than nothing */
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
224 }
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
225 }
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
226
c68003efb796 Added PyMac_getscript() which returns the pythonic name of the current script. Not ideal and not complete, but good enough for the time being. Idea and most of the code by Fredrik Lund.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13608
diff changeset
227
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
228 #ifdef USE_GUSI1
3433
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
229 /*
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
230 ** 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
231 ** 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
232 ** 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
233 */
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
234 void
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
235 PyMac_FixGUSIcd()
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
236 {
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
237 WDPBRec pb;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
238 FSSpec curdirfss;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
239
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
240 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
241 return;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
242
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
243 /* 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
244 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
245 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
246 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
247 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
248 return;
578ca302a598 Replaced previous gusi-chdir() fix by a call to PyMac_FixGUSIcd()
Jack Jansen <jack.jansen@cwi.nl>
parents: 3431
diff changeset
249 }
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
250 #endif
4013
aa9548885b3f Dummy SpinCursor() if __CFM68K__ is defined
Jack Jansen <jack.jansen@cwi.nl>
parents: 3914
diff changeset
251
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
252 #ifdef USE_GUSI
4238
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
253 /*
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
254 ** 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
255 ** provide a dummy here.
6c86d9136c09 - Put all options in a struct
Jack Jansen <jack.jansen@cwi.nl>
parents: 4215
diff changeset
256 */
4018
Jack Jansen <jack.jansen@cwi.nl>
parents: 4013
diff changeset
257 void SpinCursor(short x) { /* Dummy */ }
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
258 void RotateCursor(short x) { /* Dummy */ }
4018
Jack Jansen <jack.jansen@cwi.nl>
parents: 4013
diff changeset
259
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
260 /*
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
261 ** Replacement GUSI Spin function
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
262 */
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
263 #ifdef USE_GUSI1
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
264 static int
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
265 PyMac_GUSISpin(spin_msg msg, long arg)
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
266 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
267 static Boolean inForeground = true;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
268 int maxsleep = 6; /* 6 ticks is "normal" sleeptime */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
269
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
270 if (PyMac_ConsoleIsDead) return 0;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
271 #if 0
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
272 if (inForeground)
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
273 SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
274 #endif
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
275
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
276 if (interrupted) return -1;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
277
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
278 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
279 maxsleep = 0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
280 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
281 maxsleep = arg;
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
282
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
283 PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
284
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
285 return 0;
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
286 }
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
287
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
288 void
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
289 PyMac_SetGUSISpin() {
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
290 GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
291 }
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
292 #endif
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
293
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
294 /* Called at exit() time thru atexit(), to stop event processing */
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
295 void
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
296 PyMac_StopGUSISpin() {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
297 PyMac_ConsoleIsDead = 1;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
298 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
299
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
300 #if TARGET_API_MAC_OS8
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
301 /*
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
302 ** Replacement routines for the PLstr... functions so we don't need
15825
4328ffe647bf Disabled a few other routines that are available in CarbonLib.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15786
diff changeset
303 ** StdCLib.
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
304 */
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
305 pascal void
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
306 PLstrcpy(unsigned char *to, unsigned char *fr)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
307 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
308 memcpy(to, fr, fr[0]+1);
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
309 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
310
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
311 pascal int
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
312 PLstrcmp(unsigned char *s1, unsigned char *s2)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
313 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
314 int res;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
315 int l = s1[0] < s2[0] ? s1[0] : s2[0];
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
316
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
317 res = memcmp(s1+1, s2+1, l);
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
318 if ( res != 0 )
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
319 return res;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
320
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
321 if ( s1[0] < s2[0] )
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
322 return -1;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
323 else if ( s1[0] > s2[0] )
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
324 return 1;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
325 else
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
326 return 0;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
327 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
328
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
329 pascal unsigned char *
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
330 PLstrrchr(unsigned char *str, unsigned char chr)
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
331 {
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
332 unsigned char *ptr = 0;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
333 unsigned char *p;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
334
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
335 for(p=str+1; p<str+str[0]; p++)
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
336 if ( *p == chr )
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
337 ptr = p;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
338 return ptr;
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
339 }
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
340
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
341 #endif /* TARGET_API_MAC_OS8 */
5617
70855574516b - Added Py_GetProgramFullPath
Jack Jansen <jack.jansen@cwi.nl>
parents: 5270
diff changeset
342 #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
343
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
344
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
345 /* 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
346 unsigned char *
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
347 Pstring(char *str)
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
348 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
349 static Str255 buf;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
350 int len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
351
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
352 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
353 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
354 len = 255;
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
355 buf[0] = (unsigned char)len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
356 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
357 return buf;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
358 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
359
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
360 #if TARGET_API_MAC_OS8
15529
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
361 void
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
362 c2pstrcpy(unsigned char *dst, const char *src)
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
363 {
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
364 int len;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
365
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
366 len = strlen(src);
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
367 if ( len > 255 ) len = 255;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
368 strncpy((char *)dst+1, src, len);
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
369 dst[0] = len;
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
370 }
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
371 #endif /* TARGET_API_MAC_OS8 */
15529
a93d79da4f8c Added a c2pstrcpy() function.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14476
diff changeset
372
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
373 /* Like strerror() but for Mac OS error numbers */
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
374 char *PyMac_StrError(int err)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
375 {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
376 static char buf[256];
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
377 Handle h;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 char *str;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
379
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
380 h = GetResource('Estr', err);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381 if ( h ) {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 HLock(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383 str = (char *)*h;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
384 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
385 buf[(unsigned char)str[0]] = '\0';
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
386 HUnlock(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
387 ReleaseResource(h);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 } else {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 sprintf(buf, "Mac OS error code %d", err);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 return buf;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
392 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
393
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
394 /* 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
395 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
396
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
397 /* 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
398 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
399 PyMac_GetOSErrException()
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
400 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
401 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
402 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
403 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
404 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
405
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
406 /* Set a MAC-specific error from errno, and return NULL; return None if no error */
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
407 PyObject *
2136
c57b5c50a2d2 rename2 changes
Guido van Rossum <guido@python.org>
parents: 2035
diff changeset
408 PyErr_Mac(PyObject *eobj, int err)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 {
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410 char *msg;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411 PyObject *v;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
413 if (err == 0 && !PyErr_Occurred()) {
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 Py_INCREF(Py_None);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415 return Py_None;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 }
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
417 if (err == -1 && PyErr_Occurred())
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
418 return NULL;
2382
6450d8828d2b added applet initialization;
Guido van Rossum <guido@python.org>
parents: 2350
diff changeset
419 msg = PyMac_StrError(err);
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
420 v = Py_BuildValue("(is)", err, msg);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
421 PyErr_SetObject(eobj, v);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422 Py_DECREF(v);
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
423 return NULL;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
424 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
426 /* 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
427 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
428 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
429 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
430 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
431 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
432
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
433 #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
434 /* 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
435 int
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
436 PyOS_CheckStack()
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
437 {
14197
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
438 char here;
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
439 static char *sentinel = 0;
14476
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
440 static PyThreadState *thread_for_sentinel = 0;
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
441
16437
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
442 if ( sentinel == 0 ) {
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
443 unsigned long stackspace = StackSpace();
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
444
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
445 #ifdef MAXIMUM_STACK_SIZE
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
446 /* See the comment at the definition */
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
447 if ( stackspace > MAXIMUM_STACK_SIZE )
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
448 stackspace = MAXIMUM_STACK_SIZE;
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
449 #endif
679f826b24ca On MacOSX StackSpace() may lie because it doesn't know about the stack rlimit. For now we set a hard limit of 256K (default rlimit is 512K).
Jack Jansen <jack.jansen@cwi.nl>
parents: 15839
diff changeset
450 sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
14197
2787e93817c6 Cheaper implementation of PyOS_CheckStack: only call StackSpace once and keep a sentinel in a static variable.
Jack Jansen <jack.jansen@cwi.nl>
parents: 13701
diff changeset
451 }
14476
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
452 if ( thread_for_sentinel == 0 ) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
453 thread_for_sentinel = PyThreadState_Get();
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
454 }
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
455 if ( &here < sentinel ) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
456 if (thread_for_sentinel == PyThreadState_Get()) {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
457 return -1;
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
458 #if 0
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
459 } else {
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
460 /* Else we are unsure... */
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
461 fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
462 #endif
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
463 }
71456782d8fd PyOS_CheckStack now understands multiple threads. Other threads are not stack-checked, but at least they don't appear to always be out of stack.
Jack Jansen <jack.jansen@cwi.nl>
parents: 14197
diff changeset
464 }
3786
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
465 return 0;
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
466 }
718c8af7be2a Added PyOS_CheckStack() function which returns -1 when we are running
Jack Jansen <jack.jansen@cwi.nl>
parents: 3655
diff changeset
467 #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
468
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
469 /* 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
470 static RETSIGTYPE
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
471 intcatcher(sig)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
472 int sig;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
473 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
474 interrupted = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
475 signal(SIGINT, intcatcher);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
476 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
477
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
478 void
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
479 PyOS_InitInterrupts()
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
480 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
481 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
482 signal(SIGINT, intcatcher);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
483 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
484
5962
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
485 void
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
486 PyOS_FiniInterrupts()
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
487 {
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
488 }
23e014839ab0 Added (dummy) PyOS_FiniInterrupts
Jack Jansen <jack.jansen@cwi.nl>
parents: 5744
diff changeset
489
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
490 /*
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
491 ** 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
492 ** 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
493 ** 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
494 ** 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
495 ** interrupt a runaway python program.
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
496 */
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
497 static void
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
498 scan_event_queue(flush)
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
499 int flush;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
500 {
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
501 #if !TARGET_API_MAC_OS8
15839
3b643653e078 Fixed Carbon command-dot handling. There is still a problem, though, and you may have to hit it repeatedly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15825
diff changeset
502 if ( CheckEventQueueForUserCancel() )
3b643653e078 Fixed Carbon command-dot handling. There is still a problem, though, and you may have to hit it repeatedly.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15825
diff changeset
503 interrupted = 1;
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
504 #else
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
505 register EvQElPtr q;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
506
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
507 q = (EvQElPtr) LMGetEventQueue()->qHead;
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
508
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
509 for (; q; q = (EvQElPtr)q->qLink) {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
510 if (q->evtQWhat == keyDown &&
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
511 (char)q->evtQMessage == '.' &&
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
512 (q->evtQModifiers & cmdKey) != 0) {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
513 if ( flush )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
514 FlushEvents(keyDownMask, 0);
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
515 interrupted = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
516 break;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
517 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
518 }
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
519 #endif
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
520 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
521
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
522 int
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
523 PyErr_CheckSignals()
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
524 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
525 if (schedparams.enabled) {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
526 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
527 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
528 return -1;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
529 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
530 + schedparams.check_interval;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
531 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
532 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
533 interrupted = 0;
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
534 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
535 return -1;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
536 }
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
537 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
538 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
539 return 0;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
540 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
541
16557
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
542 #if 0
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
543 /*
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
544 ** This routine is called if we know that an external library yielded
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
545 ** to background tasks, so we shouldn't count that time in our computation
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
546 ** of how much CPU we used.
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
547 ** This happens with SIOUX, and the routine is called from our modified
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
548 ** GUSISIOUX.
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
549 */
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
550 void
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
551 PyMac_LibraryDidYield(int howlong)
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
552 {
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
553 unsigned long maxnextcheck = (unsigned long)LMGetTicks() + schedparams.check_interval;
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
554
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
555 schedparams.next_check = schedparams.next_check + howlong;
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
556 if (schedparams.next_check > maxnextcheck )
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
557 schedparams.next_check = maxnextcheck;
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
558 }
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
559 #endif
9ce9e0342cc1 Bit the bullet and added a private GUSISIOUX for Python. This makes the delayconsole and keepopen code neater. Also tells Sioux to behave better with events, and handles cmd-. during print better. The pythonpreferences have also changed due to this.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16437
diff changeset
560
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
561 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
562 PyOS_InterruptOccurred()
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
563 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
564 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
565 return interrupted;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
566 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
567 /* Check whether we are in the foreground */
13547
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
568 static int
db963a615bc9 ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents: 13542
diff changeset
569 PyMac_InForeground(void)
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
570 {
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
571 static ProcessSerialNumber ours;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
572 static inited;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
573 ProcessSerialNumber curfg;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
574 Boolean eq;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
575
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
576 if ( inited == 0 ) {
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
577 (void)GetCurrentProcess(&ours);
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
578 inited = 1;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
579 }
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
580 if ( GetFrontProcess(&curfg) < 0 )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
581 eq = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
582 else if ( SameProcess(&ours, &curfg, &eq) < 0 )
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
583 eq = 1;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
584 return (int)eq;
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
585
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
586 }
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
587
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
588 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
589 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
590 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
591 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
592 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
593 return 0;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
594 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
595 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
596 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
597 if ( evh )
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
598 Py_INCREF(evh);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
599 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
600 return 1;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
601 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
602
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
603 /*
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
604 ** 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
605 ** 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
606 */
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
607 void
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
608 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
609 EventRecord *evp;
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
610 {
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
611 #if TARGET_API_MAC_OS8
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
612 if ( evp->what == mouseDown ) {
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
613 WindowPtr wp;
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
614
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
615 if ( FindWindow(evp->where, &wp) == inSysWindow ) {
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
616 SystemClick(evp, wp);
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
617 return;
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
618 }
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
619 }
12833
41c0c60dcaf5 Removed (within an #ifdef) Carbon-incompatabilities:
Jack Jansen <jack.jansen@cwi.nl>
parents: 12281
diff changeset
620 #endif
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
621 #ifdef __MWERKS__
3248
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
622 {
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
623 int siouxdidit;
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
624
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
625 /* If SIOUX wants it we're done */
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
626 siouxdidit = SIOUXHandleOneEvent(evp);
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
627 if ( siouxdidit )
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
628 return;
5e101ead1e69 Cosmetic change to event handling.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3052
diff changeset
629 }
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
630 #else
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
631 /* Other compilers are just unlucky... */
2276
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
632 #endif /* !__MWERKS__ */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
633 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
634
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
635 /*
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
636 ** 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
637 ** event handler.
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
638 */
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
639 int
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
640 PyMac_HandleEvent(evp)
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
641 EventRecord *evp;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
642 {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
643 PyObject *rv;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
644
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
645 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
646 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
647 PyMac_BuildEventRecord, evp);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
648 if ( rv )
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
649 Py_DECREF(rv);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
650 else
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
651 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
652 } else {
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
653 PyMac_HandleEventIntern(evp);
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
654 }
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
655 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
656 }
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
657
66d6d13df4f8 Added HandleEvent method to macos, so python programs can hand back
Jack Jansen <jack.jansen@cwi.nl>
parents: 2265
diff changeset
658 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
659 ** 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
660 */
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
661 int
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
662 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
663 {
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
664 EventRecord ev;
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
665 int gotone;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
666 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
667 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
668
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
669 in_here++;
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
670 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
671 ** 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
672 ** 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
673 ** moment in the mainloop.
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
674 */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
675 if (schedparams.check_interrupt)
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
676 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
677
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
678 /* 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
679
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
680 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
681 ** 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
682 ** - process events
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
683 ** - 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
684 ** - do neither
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
685 */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
686 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
687 (python_event_handler && !maycallpython) ) {
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
688 if ( maxsleep >= 0 ) {
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
689 #if TARGET_API_MAC_OS8
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
690 SystemTask();
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
691 #else
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
692 int xxx = 0;
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
693 #endif
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
694 }
4197
b70baba1c789 - Fixed PyMac_DoYield:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4024
diff changeset
695 } else {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
696 latest_time_ready = LMGetTicks() + maxsleep;
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
697 do {
6162
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
698 /* XXXX Hack by Jack.
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
699 ** In time.sleep() you can click to another application
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
700 ** once only. If you come back to Python you cannot get away
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
701 ** again.
9183a3c6b85f Handle systemclicks ourselves, in stead of passing them to Sioux. This
Jack Jansen <jack.jansen@cwi.nl>
parents: 5962
diff changeset
702 **/
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
703 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
704 /* 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
705 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
706 break;
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
707 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
708 in_here--;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
709 return -1;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
710 }
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
711 maxsleep = latest_time_ready - LMGetTicks();
12281
51c0c3b6d919 Started on GUSI2 and threading support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11676
diff changeset
712 } while ( maxsleep > 0 );
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
713 }
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
714 in_here--;
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
715 return 0;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
716 }
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
717
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
718 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
719 ** 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
720 */
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
721 int
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
722 PyMac_Yield() {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
723 unsigned long maxsleep;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
724
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
725 if( PyMac_InForeground() )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
726 maxsleep = 0;
2262
03bd79432f06 - Moved interrupt code to macglue.c
Jack Jansen <jack.jansen@cwi.nl>
parents: 2255
diff changeset
727 else
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
728 maxsleep = schedparams.bg_yield;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
729
5744
ea8a0b090908 Added PyMac_SetEventHandler which allows you to replace complete event
Jack Jansen <jack.jansen@cwi.nl>
parents: 5737
diff changeset
730 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
731 }
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
732
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
733 /*
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
734 ** Return current scheduler parameters
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
735 */
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
736 void
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
737 PyMac_GetSchedParams(PyMacSchedParams *sp)
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
738 {
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
739 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
740 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
741 sp->besocial = schedparams.besocial;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
742 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
743 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
744 }
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
745
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
746 /*
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
747 ** Set current scheduler parameters
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
748 */
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
749 void
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
750 PyMac_SetSchedParams(PyMacSchedParams *sp)
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
751 {
5711
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
752 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
753 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
754 schedparams.besocial = sp->besocial;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
755 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
756 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
757 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
758 schedparams.besocial )
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
759 schedparams.enabled = 1;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
760 else
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
761 schedparams.enabled = 0;
fb170ce82951 Removed old scheduler parameterizing calls and replaced with something
Jack Jansen <jack.jansen@cwi.nl>
parents: 5617
diff changeset
762 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
763 }
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
764
2350
a2054933775b Added support for loading pyc code from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2337
diff changeset
765 /*
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
766 ** 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
767 */
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
768 void
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
769 PyMac_InitMenuBar()
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
770 {
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
771 MenuHandle applemenu;
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
772
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
773 if ( sioux_mbar ) return;
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
774 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
775 /* 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
776 SIOUXSetupMenus();
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
777 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
778 return;
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
779 }
5270
de9d0c5249b0 Changed the few old routine names still used to the new ones
Jack Jansen <jack.jansen@cwi.nl>
parents: 5153
diff changeset
780 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
781 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
782 }
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
783
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
784 /*
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
785 ** 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
786 */
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
787 void
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
788 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
789 {
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
790 #if 1
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
791 /* This doesn't seem to work anymore? Or only for Carbon? */
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
792 MenuBarHandle curmenubar;
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
793
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
794 curmenubar = GetMenuBar();
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
795 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
796 SetMenuBar(sioux_mbar);
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
797 DrawMenuBar();
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
798 } else {
7438
cd11690cb14b - Universal Headers 3 mods
Jack Jansen <jack.jansen@cwi.nl>
parents: 6461
diff changeset
799 PyMac_InitMenuBar();
16647
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
800 DrawMenuBar();
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
801 }
728c11562187 More changes to attempt to get the menubar back on exit. Without success:-(
Jack Jansen <jack.jansen@cwi.nl>
parents: 16557
diff changeset
802 #endif
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
803 }
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
804
17629
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
805 void
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
806 PyMac_RaiseConsoleWindow()
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
807 {
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
808 /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
809 ** and we happen to know that the first entry is the window pointer.
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
810 */
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
811 extern WindowRef *SIOUXTextWindow;
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
812
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
813 if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL )
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
814 return;
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
815 if ( FrontWindow() != *SIOUXTextWindow )
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
816 BringToFront(*SIOUXTextWindow);
a9485d404f05 - Raise console window on input. Fixes Carbon hang.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16647
diff changeset
817 }
5732
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
818
f027dd0a85e4 - Restore SIOUX menubar just before exiting, if the console window is kept
Jack Jansen <jack.jansen@cwi.nl>
parents: 5711
diff changeset
819 /*
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
820 ** 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
821 */
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
822
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
823 #include "patchlevel.h"
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
824
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
825 void
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
826 SIOUXDoAboutBox(void)
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
827 {
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
828 DialogPtr theDialog;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
829 WindowPtr theWindow;
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
830 short item;
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
831 short fontID;
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
832
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
833 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
834 return;
4325
12c3865aeaa0 Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
835 theWindow = GetDialogWindow(theDialog);
8790
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
836 SetPortWindowPort(theWindow);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
837 GetFNum("\pPython-Sans", &fontID);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
838 if (fontID == 0)
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
839 fontID = kFontIDGeneva;
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
840 TextFont(fontID);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
841 TextSize(9);
1076a028365a New about box, with the version mesage filled in in a text item, and
Jack Jansen <jack.jansen@cwi.nl>
parents: 8665
diff changeset
842 ParamText(Pstring(PATCHLEVEL), "\p", "\p", "\p");
4325
12c3865aeaa0 Changed default background yield time to 1 tick
Jack Jansen <jack.jansen@cwi.nl>
parents: 4238
diff changeset
843 ShowWindow(theWindow);
4215
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
844 ModalDialog(NULL, &item);
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
845 DisposeDialog(theDialog);
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
846 }
0410ed3808ee Python about box implemented. Slightly convoluted, since (a) we have
Jack Jansen <jack.jansen@cwi.nl>
parents: 4204
diff changeset
847
5737
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
848 #if 0
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
849 int
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
850 PyMac_FileExists(char *name)
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 FSSpec fss;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
853
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
854 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
855 return 1;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
856 return 0;
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
857 }
d0c6b49d7101 Make imports faster on the Mac, by
Jack Jansen <jack.jansen@cwi.nl>
parents: 5732
diff changeset
858 #endif
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 /*
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
861 ** 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
862 */
2412
75ae104f7e6c ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents: 2403
diff changeset
863 static pascal short
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
864 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
865 {
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
866 if ( item == sfHookFirstCall && dataptr->prompt) {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
867 Handle prompth;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
868 short type;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
869 Rect rect;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
870
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
871 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
872 if ( prompth )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
873 SetDialogItemText(prompth, (unsigned char *)dataptr->prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
874 } else
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
875 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
876 item = sfItemCancelButton;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
877 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
878 }
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
879 return item;
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
880 }
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
881 #if TARGET_API_MAC_OS8
2403
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
882 /*
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
883 ** 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
884 ** 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
885 */
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
886 int
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
887 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
888 FSSpec *dirfss;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
889 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
890 {
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
891 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
892 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
893 StandardFileReply reply;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
894 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
895
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
896 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
897 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
898 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
899 }
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
900 if ( prompt && *prompt )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
901 hook_args.prompt = (char *)Pstring(prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
902 else
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
903 hook_args.prompt = NULL;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
904 hook_args.selectcur_hit = 0;
2412
75ae104f7e6c ported to MPW, moved main() here
Guido van Rossum <guido@python.org>
parents: 2403
diff changeset
905 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
906 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
907
72c715c004c8 - Added PyMac_GetDirectory call which asks the user to select a
Jack Jansen <jack.jansen@cwi.nl>
parents: 2394
diff changeset
908 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
909 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
910 return 0;
2988
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
911 return hook_args.selectcur_hit;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
912 }
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
913
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
914 /*
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
915 ** Slightly extended StandardGetFile: accepts a prompt */
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
916 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
917 StandardFileReply *reply, char *prompt)
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
918 {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
919 static Point where = {-1, -1};
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
920 struct hook_args hook_args;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
921
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
922 if ( !upp_inited ) {
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
923 myhook_upp = NewDlgHookYDProc(myhook_proc);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
924 upp_inited = 1;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
925 }
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
926 if ( prompt && *prompt )
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
927 hook_args.prompt = (char *)Pstring(prompt);
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
928 else
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
929 hook_args.prompt = NULL;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
930 hook_args.selectcur_hit = 0;
2fe9d0371ecd Lots of stuff moved to other files.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2913
diff changeset
931 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
932 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
933 }
17813
8cd8741ebec0 Be more sensible about when to use TARGET_API_MAC_OS8 in stead of !TARGET_API_MAC_CARBON. This should greatly facilitate porting stuff to OSX in its MachO/BSD incarnation.
Jack Jansen <jack.jansen@cwi.nl>
parents: 17629
diff changeset
934 #endif /* TARGET_API_MAC_OS8 */
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
935
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
936 /* 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
937 int
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
938 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
939 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
940 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
941 PyErr_SetString(PyExc_TypeError,
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
942 "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
943 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
944 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
945 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
946 return 1;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
947 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
948
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
949 /* 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
950 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
951 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
952 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
953 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
954 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
955
3914
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
956 /* 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
957 PyObject *
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
958 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
959 {
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
960 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
961 }
524cf501c851 - Minimum stacksize is now 8K for PPC, 4K for 68K
Jack Jansen <jack.jansen@cwi.nl>
parents: 3786
diff changeset
962
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
963
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
964 /* 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
965 int
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
966 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
967 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
968 int len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
969 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
970 PyErr_SetString(PyExc_TypeError,
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
971 "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
972 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
973 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
974 pbuf[0] = len;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
975 memcpy((char *)(pbuf+1), PyString_AsString(v), len);
2035
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
976 return 1;
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
977 }
ce69742f2e77 New routines:
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
978
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
979 /* 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
980 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
981 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
982 {
11591
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
983 if ( s == NULL ) {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
984 PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL");
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
985 return NULL;
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
986 }
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
987 return PyString_FromStringAndSize((char *)&s[1], (int)s[0]);
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
988 }
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
989
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
990 PyObject *
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
991 PyMac_BuildOptStr255(Str255 s)
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
992 {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
993 if ( s == NULL ) {
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
994 Py_INCREF(Py_None);
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
995 return Py_None;
1131bfa1ad99 Added PyMac_BuildOptStr255, which returns None on a null pointer.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11548
diff changeset
996 }
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
997 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
998 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
999
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1000
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
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 ** 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
1003 ** 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
1004 ** (vrefnum, dirid, path).
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1005 ** 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
1006 ** 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
1007 ** 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
1008 ** 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
1009 */
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1010 int
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1011 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
1012 {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1013 Str255 path;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1014 short refnum;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1015 long parid;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1016 OSErr err;
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
1017 FSSpec *fs2;
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1018
2251
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
1019 /* 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
1020 fs2 = mfs_GetFSSpecFSSpec(v);
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
1021 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
1022 (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
1023 return 1;
e0a3242d5ae7 Added eventhandling in mainloop/busywait routine plus leaving some
Jack Jansen <jack.jansen@cwi.nl>
parents: 2231
diff changeset
1024 }
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1025 if ( PyString_Check(v) ) {
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1026 /* 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
1027 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
1028 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
1029 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
1030 parid = 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1031 } else {
2209
4053d4cb50e0 renamed Get routines to PyMac_Get; added macfs to config.c
Guido van Rossum <guido@python.org>
parents: 2183
diff changeset
1032 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
1033 &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
1034 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
1035 }
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1036 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1037 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
1038 if ( err && err != fnfErr ) {
11676
489483b65b3a If there's an error in an fsspec argument raise MacOS.Error, not ValueError.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11591
diff changeset
1039 PyMac_Error(err);
2176
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1040 return 0;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1041 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1042 return 1;
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1043 }
1e9e74944bb5 - Moved some useful routines from macosmodule.c here
Jack Jansen <jack.jansen@cwi.nl>
parents: 2136
diff changeset
1044
11548
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
1045 /* Convert FSSpec to PyObject */
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
1046 PyObject *PyMac_BuildFSSpec(FSSpec *v)
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
1047 {
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
1048 return newmfssobject(v);
c042e4140f1e Oops, PLstring funcs should be "pascal". Funny this never caused problems before...
Jack Jansen <jack.jansen@cwi.nl>
parents: 11529
diff changeset
1049 }
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1050
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1051 /* 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
1052 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
1053 (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
1054 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
1055 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1056 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
1057 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1058 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
1059 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1060
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1061 /* Convert a Rect to a Python object */
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1062 PyObject *
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1063 PyMac_BuildRect(Rect *r)
2183
62bdded5f00a modernized/rationalized, added PyMac_BuildOSType
Guido van Rossum <guido@python.org>
parents: 2176
diff changeset
1064 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1065 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
1066 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1067
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1068
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1069 /* 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
1070 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
1071 (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
1072 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
1073 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1074 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
1075 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1076 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
1077 }
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1078
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1079 /* Convert a Point to a Python object */
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1080 PyObject *
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1081 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
1082 {
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1083 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
1084 }
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1085
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 /* 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
1088 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
1089 int
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1090 PyMac_GetEventRecord(PyObject *v, EventRecord *e)
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1091 {
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1092 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
1093 &e->what,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1094 &e->message,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1095 &e->when,
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1096 &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
1097 &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
1098 &e->modifiers);
2224
32435d33f34a cosmetics: copyright, comments
Guido van Rossum <guido@python.org>
parents: 2209
diff changeset
1099 }
2231
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1100
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1101 /* 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
1102 PyObject *
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1103 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
1104 {
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1105 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
1106 e->what,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1107 e->message,
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1108 e->when,
2255
382edef2d6d7 reverse h/v in Point and Rect
Guido van Rossum <guido@python.org>
parents: 2251
diff changeset
1109 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
1110 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
1111 e->modifiers);
1e8b347a056c Some layout changes; added EventRecord Get/Build functions (as a tuple).
Guido van Rossum <guido@python.org>
parents: 2224
diff changeset
1112 }
3278
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1113
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1114 /* Convert Python object to Fixed */
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1115 int
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1116 PyMac_GetFixed(PyObject *v, Fixed *f)
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1117 {
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1118 double d;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1119
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1120 if( !PyArg_Parse(v, "d", &d))
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1121 return 0;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1122 *f = (Fixed)(d * 0x10000);
3655
f89fa7e95b84 PyMac_GetFixed() didn't return 1 on success
Jack Jansen <jack.jansen@cwi.nl>
parents: 3478
diff changeset
1123 return 1;
3278
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1124 }
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1125
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1126 /* Convert a Point to a Python object */
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1127 PyObject *
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1128 PyMac_BuildFixed(Fixed f)
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1129 {
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1130 double d;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1131
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1132 d = f;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1133 d = d / 0x10000;
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1134 return Py_BuildValue("d", d);
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1135 }
43c5e7a3fc1f Added converters for Fixed
Jack Jansen <jack.jansen@cwi.nl>
parents: 3248
diff changeset
1136
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1137 /* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1138 int
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1139 PyMac_Getwide(PyObject *v, wide *rv)
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1140 {
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1141 if (PyInt_Check(v)) {
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1142 rv->hi = 0;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1143 rv->lo = PyInt_AsLong(v);
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1144 if( rv->lo & 0x80000000 )
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1145 rv->hi = -1;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1146 return 1;
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1147 }
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1148 return PyArg_Parse(v, "(ll)", &rv->hi, &rv->lo);
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1149 }
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1150
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1151
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1152 PyObject *
8113
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1153 PyMac_Buildwide(wide *w)
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1154 {
8113
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1155 if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) ||
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1156 (w->hi == -1 && (w->lo & 0x80000000) ) )
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1157 return PyInt_FromLong(w->lo);
e2d33c0732bf Incorrect argument for PyMacBuildwide()
Jack Jansen <jack.jansen@cwi.nl>
parents: 8104
diff changeset
1158 return Py_BuildValue("(ll)", w->hi, w->lo);
8104
93348e5a85a2 Added PyMac_{Get,Build}wide. These should support python longints at
Jack Jansen <jack.jansen@cwi.nl>
parents: 7438
diff changeset
1159 }