Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Guido van Rossum | 9954699 | 1995-01-08 14:33:34 +0000 | [diff] [blame] | 3 | The Netherlands. |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | /* Macintosh OS-specific interface */ |
| 26 | |
| 27 | #include "Python.h" |
Jack Jansen | 97ce361 | 1994-12-14 14:02:24 +0000 | [diff] [blame] | 28 | #include "macglue.h" |
Jack Jansen | b19c667 | 2000-10-12 21:24:05 +0000 | [diff] [blame] | 29 | #include "pythonresources.h" |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 30 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 31 | #ifdef WITHOUT_FRAMEWORKS |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 32 | #include <Windows.h> |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 33 | #include <Files.h> |
Jack Jansen | eb76b84 | 1996-09-30 14:43:22 +0000 | [diff] [blame] | 34 | #include <LowMem.h> |
Jack Jansen | cbe6a53 | 1998-02-20 15:59:59 +0000 | [diff] [blame] | 35 | #include <Sound.h> |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 36 | #include <Events.h> |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 37 | #else |
| 38 | #include <Carbon/Carbon.h> |
| 39 | #endif |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 41 | static PyObject *MacOS_Error; /* Exception MacOS.Error */ |
| 42 | |
Guido van Rossum | e6d9ccc | 1995-02-21 21:01:05 +0000 | [diff] [blame] | 43 | #ifdef MPW |
Guido van Rossum | 9fed183 | 1995-02-18 15:02:02 +0000 | [diff] [blame] | 44 | #define bufferIsSmall -607 /*error returns from Post and Accept */ |
| 45 | #endif |
| 46 | |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 47 | /* ----------------------------------------------------- */ |
| 48 | |
| 49 | /* Declarations for objects of type Resource fork */ |
| 50 | |
| 51 | typedef struct { |
| 52 | PyObject_HEAD |
| 53 | short fRefNum; |
| 54 | int isclosed; |
| 55 | } rfobject; |
| 56 | |
| 57 | staticforward PyTypeObject Rftype; |
| 58 | |
| 59 | |
| 60 | |
| 61 | /* ---------------------------------------------------------------- */ |
| 62 | |
| 63 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 64 | do_close(rfobject *self) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 65 | { |
| 66 | if (self->isclosed ) return; |
| 67 | (void)FSClose(self->fRefNum); |
| 68 | self->isclosed = 1; |
| 69 | } |
| 70 | |
| 71 | static char rf_read__doc__[] = |
| 72 | "Read data from resource fork" |
| 73 | ; |
| 74 | |
| 75 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 76 | rf_read(rfobject *self, PyObject *args) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 77 | { |
| 78 | long n; |
| 79 | PyObject *v; |
| 80 | OSErr err; |
| 81 | |
| 82 | if (self->isclosed) { |
| 83 | PyErr_SetString(PyExc_ValueError, "Operation on closed file"); |
| 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | if (!PyArg_ParseTuple(args, "l", &n)) |
| 88 | return NULL; |
| 89 | |
| 90 | v = PyString_FromStringAndSize((char *)NULL, n); |
| 91 | if (v == NULL) |
| 92 | return NULL; |
| 93 | |
| 94 | err = FSRead(self->fRefNum, &n, PyString_AsString(v)); |
| 95 | if (err && err != eofErr) { |
| 96 | PyMac_Error(err); |
| 97 | Py_DECREF(v); |
| 98 | return NULL; |
| 99 | } |
| 100 | _PyString_Resize(&v, n); |
| 101 | return v; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | static char rf_write__doc__[] = |
| 106 | "Write to resource fork" |
| 107 | ; |
| 108 | |
| 109 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 110 | rf_write(rfobject *self, PyObject *args) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 111 | { |
| 112 | char *buffer; |
| 113 | long size; |
| 114 | OSErr err; |
| 115 | |
| 116 | if (self->isclosed) { |
| 117 | PyErr_SetString(PyExc_ValueError, "Operation on closed file"); |
| 118 | return NULL; |
| 119 | } |
Jack Jansen | eeccca9 | 1997-05-07 15:46:31 +0000 | [diff] [blame] | 120 | if (!PyArg_ParseTuple(args, "s#", &buffer, &size)) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 121 | return NULL; |
| 122 | err = FSWrite(self->fRefNum, &size, buffer); |
| 123 | if (err) { |
| 124 | PyMac_Error(err); |
| 125 | return NULL; |
| 126 | } |
| 127 | Py_INCREF(Py_None); |
| 128 | return Py_None; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | static char rf_seek__doc__[] = |
| 133 | "Set file position" |
| 134 | ; |
| 135 | |
| 136 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 137 | rf_seek(rfobject *self, PyObject *args) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 138 | { |
| 139 | long amount, pos; |
| 140 | int whence = SEEK_SET; |
| 141 | long eof; |
| 142 | OSErr err; |
| 143 | |
| 144 | if (self->isclosed) { |
| 145 | PyErr_SetString(PyExc_ValueError, "Operation on closed file"); |
| 146 | return NULL; |
| 147 | } |
| 148 | if (!PyArg_ParseTuple(args, "l|i", &amount, &whence)) |
| 149 | return NULL; |
| 150 | |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 151 | if ((err = GetEOF(self->fRefNum, &eof))) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 152 | goto ioerr; |
| 153 | |
| 154 | switch (whence) { |
| 155 | case SEEK_CUR: |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 156 | if ((err = GetFPos(self->fRefNum, &pos))) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 157 | goto ioerr; |
| 158 | break; |
| 159 | case SEEK_END: |
| 160 | pos = eof; |
| 161 | break; |
| 162 | case SEEK_SET: |
| 163 | pos = 0; |
| 164 | break; |
| 165 | default: |
| 166 | PyErr_BadArgument(); |
| 167 | return NULL; |
| 168 | } |
| 169 | |
| 170 | pos += amount; |
| 171 | |
| 172 | /* Don't bother implementing seek past EOF */ |
| 173 | if (pos > eof || pos < 0) { |
| 174 | PyErr_BadArgument(); |
| 175 | return NULL; |
| 176 | } |
| 177 | |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 178 | if ((err = SetFPos(self->fRefNum, fsFromStart, pos)) ) { |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 179 | ioerr: |
| 180 | PyMac_Error(err); |
| 181 | return NULL; |
| 182 | } |
| 183 | Py_INCREF(Py_None); |
| 184 | return Py_None; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | static char rf_tell__doc__[] = |
| 189 | "Get file position" |
| 190 | ; |
| 191 | |
| 192 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 193 | rf_tell(rfobject *self, PyObject *args) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 194 | { |
| 195 | long where; |
| 196 | OSErr err; |
| 197 | |
| 198 | if (self->isclosed) { |
| 199 | PyErr_SetString(PyExc_ValueError, "Operation on closed file"); |
| 200 | return NULL; |
| 201 | } |
| 202 | if (!PyArg_ParseTuple(args, "")) |
| 203 | return NULL; |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 204 | if ((err = GetFPos(self->fRefNum, &where)) ) { |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 205 | PyMac_Error(err); |
| 206 | return NULL; |
| 207 | } |
| 208 | return PyInt_FromLong(where); |
| 209 | } |
| 210 | |
| 211 | static char rf_close__doc__[] = |
| 212 | "Close resource fork" |
| 213 | ; |
| 214 | |
| 215 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 216 | rf_close(rfobject *self, PyObject *args) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 217 | { |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 218 | if (!PyArg_ParseTuple(args, "")) |
| 219 | return NULL; |
| 220 | do_close(self); |
| 221 | Py_INCREF(Py_None); |
| 222 | return Py_None; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | static struct PyMethodDef rf_methods[] = { |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 227 | {"read", (PyCFunction)rf_read, 1, rf_read__doc__}, |
| 228 | {"write", (PyCFunction)rf_write, 1, rf_write__doc__}, |
| 229 | {"seek", (PyCFunction)rf_seek, 1, rf_seek__doc__}, |
| 230 | {"tell", (PyCFunction)rf_tell, 1, rf_tell__doc__}, |
| 231 | {"close", (PyCFunction)rf_close, 1, rf_close__doc__}, |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 232 | |
| 233 | {NULL, NULL} /* sentinel */ |
| 234 | }; |
| 235 | |
| 236 | /* ---------- */ |
| 237 | |
| 238 | |
| 239 | static rfobject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 240 | newrfobject(void) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 241 | { |
| 242 | rfobject *self; |
| 243 | |
| 244 | self = PyObject_NEW(rfobject, &Rftype); |
| 245 | if (self == NULL) |
| 246 | return NULL; |
| 247 | self->isclosed = 1; |
| 248 | return self; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | static void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 253 | rf_dealloc(rfobject *self) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 254 | { |
| 255 | do_close(self); |
| 256 | PyMem_DEL(self); |
| 257 | } |
| 258 | |
| 259 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 260 | rf_getattr(rfobject *self, char *name) |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 261 | { |
| 262 | return Py_FindMethod(rf_methods, (PyObject *)self, name); |
| 263 | } |
| 264 | |
| 265 | static char Rftype__doc__[] = |
| 266 | "Resource fork file object" |
| 267 | ; |
| 268 | |
| 269 | static PyTypeObject Rftype = { |
| 270 | PyObject_HEAD_INIT(&PyType_Type) |
| 271 | 0, /*ob_size*/ |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 272 | "ResourceFork", /*tp_name*/ |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 273 | sizeof(rfobject), /*tp_basicsize*/ |
| 274 | 0, /*tp_itemsize*/ |
| 275 | /* methods */ |
| 276 | (destructor)rf_dealloc, /*tp_dealloc*/ |
| 277 | (printfunc)0, /*tp_print*/ |
| 278 | (getattrfunc)rf_getattr, /*tp_getattr*/ |
| 279 | (setattrfunc)0, /*tp_setattr*/ |
| 280 | (cmpfunc)0, /*tp_compare*/ |
| 281 | (reprfunc)0, /*tp_repr*/ |
| 282 | 0, /*tp_as_number*/ |
| 283 | 0, /*tp_as_sequence*/ |
| 284 | 0, /*tp_as_mapping*/ |
| 285 | (hashfunc)0, /*tp_hash*/ |
| 286 | (ternaryfunc)0, /*tp_call*/ |
| 287 | (reprfunc)0, /*tp_str*/ |
| 288 | |
| 289 | /* Space for future expansion */ |
| 290 | 0L,0L,0L,0L, |
| 291 | Rftype__doc__ /* Documentation string */ |
| 292 | }; |
| 293 | |
| 294 | /* End of code for Resource fork objects */ |
| 295 | /* -------------------------------------------------------- */ |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 296 | |
| 297 | /*----------------------------------------------------------------------*/ |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 298 | /* Miscellaneous File System Operations */ |
| 299 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 300 | static char getcrtp_doc[] = "Obsolete, use macfs module"; |
| 301 | |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 302 | static PyObject * |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 303 | MacOS_GetCreatorAndType(PyObject *self, PyObject *args) |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 304 | { |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 305 | FSSpec fss; |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 306 | FInfo info; |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 307 | PyObject *creator, *type, *res; |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 308 | OSErr err; |
| 309 | |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 310 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 311 | return NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 312 | if ((err = FSpGetFInfo(&fss, &info)) != noErr) |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 313 | return PyErr_Mac(MacOS_Error, err); |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 314 | creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4); |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 315 | type = PyString_FromStringAndSize((char *)&info.fdType, 4); |
| 316 | res = Py_BuildValue("OO", creator, type); |
Guido van Rossum | fffb8bb | 1995-01-12 12:37:24 +0000 | [diff] [blame] | 317 | Py_DECREF(creator); |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 318 | Py_DECREF(type); |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 319 | return res; |
| 320 | } |
| 321 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 322 | static char setcrtp_doc[] = "Obsolete, use macfs module"; |
| 323 | |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 324 | static PyObject * |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 325 | MacOS_SetCreatorAndType(PyObject *self, PyObject *args) |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 326 | { |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 327 | FSSpec fss; |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 328 | ResType creator, type; |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 329 | FInfo info; |
| 330 | OSErr err; |
| 331 | |
| 332 | if (!PyArg_ParseTuple(args, "O&O&O&", |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 333 | PyMac_GetFSSpec, &fss, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 334 | return NULL; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 335 | if ((err = FSpGetFInfo(&fss, &info)) != noErr) |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 336 | return PyErr_Mac(MacOS_Error, err); |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 337 | info.fdCreator = creator; |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 338 | info.fdType = type; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 339 | if ((err = FSpSetFInfo(&fss, &info)) != noErr) |
Guido van Rossum | b7e79e5 | 1995-01-22 18:42:12 +0000 | [diff] [blame] | 340 | return PyErr_Mac(MacOS_Error, err); |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 341 | Py_INCREF(Py_None); |
| 342 | return Py_None; |
| 343 | } |
| 344 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 345 | #if TARGET_API_MAC_OS8 |
Guido van Rossum | e791c2e | 1995-01-09 13:20:04 +0000 | [diff] [blame] | 346 | /*----------------------------------------------------------------------*/ |
Guido van Rossum | f74d4e2 | 1995-01-18 23:58:07 +0000 | [diff] [blame] | 347 | /* STDWIN High Level Event interface */ |
| 348 | |
| 349 | #include <EPPC.h> |
| 350 | #include <Events.h> |
| 351 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 352 | static char accepthle_doc[] = "Get arguments of pending high-level event"; |
| 353 | |
Guido van Rossum | f74d4e2 | 1995-01-18 23:58:07 +0000 | [diff] [blame] | 354 | static PyObject * |
| 355 | MacOS_AcceptHighLevelEvent(self, args) |
| 356 | PyObject *self; |
| 357 | PyObject *args; |
| 358 | { |
| 359 | TargetID sender; |
| 360 | unsigned long refcon; |
| 361 | Ptr buf; |
| 362 | unsigned long len; |
| 363 | OSErr err; |
| 364 | PyObject *res; |
| 365 | |
| 366 | buf = NULL; |
| 367 | len = 0; |
| 368 | err = AcceptHighLevelEvent(&sender, &refcon, buf, &len); |
| 369 | if (err == bufferIsSmall) { |
| 370 | buf = malloc(len); |
| 371 | if (buf == NULL) |
| 372 | return PyErr_NoMemory(); |
| 373 | err = AcceptHighLevelEvent(&sender, &refcon, buf, &len); |
| 374 | if (err != noErr) { |
| 375 | free(buf); |
| 376 | return PyErr_Mac(MacOS_Error, (int)err); |
| 377 | } |
| 378 | } |
| 379 | else if (err != noErr) |
| 380 | return PyErr_Mac(MacOS_Error, (int)err); |
| 381 | res = Py_BuildValue("s#ls#", |
| 382 | (char *)&sender, (int)(sizeof sender), refcon, (char *)buf, (int)len); |
| 383 | free(buf); |
| 384 | return res; |
| 385 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 386 | #endif |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 387 | |
| 388 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 389 | static char schedparams_doc[] = "Set/return mainloop interrupt check flag, etc"; |
| 390 | |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 391 | /* |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 392 | ** Set scheduler parameters |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 393 | */ |
| 394 | static PyObject * |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 395 | MacOS_SchedParams(PyObject *self, PyObject *args) |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 396 | { |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 397 | PyMacSchedParams old, new; |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 398 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 399 | PyMac_GetSchedParams(&old); |
| 400 | new = old; |
| 401 | if (!PyArg_ParseTuple(args, "|iiidd", &new.check_interrupt, &new.process_events, |
| 402 | &new.besocial, &new.check_interval, &new.bg_yield)) |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 403 | return NULL; |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 404 | PyMac_SetSchedParams(&new); |
| 405 | return Py_BuildValue("iiidd", old.check_interrupt, old.process_events, |
| 406 | old.besocial, old.check_interval, old.bg_yield); |
Jack Jansen | e8e8ae0 | 1995-01-26 16:36:45 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 409 | static char appswitch_doc[] = "Obsolete, use SchedParams"; |
| 410 | |
| 411 | /* Obsolete, for backward compatability */ |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 412 | static PyObject * |
| 413 | MacOS_EnableAppswitch(PyObject *self, PyObject *args) |
| 414 | { |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 415 | int new, old; |
| 416 | PyMacSchedParams schp; |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 417 | |
Guido van Rossum | e7134aa | 1995-02-26 10:20:53 +0000 | [diff] [blame] | 418 | if (!PyArg_ParseTuple(args, "i", &new)) |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 419 | return NULL; |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 420 | PyMac_GetSchedParams(&schp); |
| 421 | if ( schp.process_events ) |
| 422 | old = 1; |
| 423 | else if ( schp.check_interrupt ) |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 424 | old = 0; |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 425 | else |
| 426 | old = -1; |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 427 | if ( new > 0 ) { |
| 428 | schp.process_events = mDownMask|keyDownMask|osMask; |
| 429 | schp.check_interrupt = 1; |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 430 | } else if ( new == 0 ) { |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 431 | schp.process_events = 0; |
| 432 | schp.check_interrupt = 1; |
| 433 | } else { |
| 434 | schp.process_events = 0; |
| 435 | schp.check_interrupt = 0; |
| 436 | } |
| 437 | PyMac_SetSchedParams(&schp); |
Guido van Rossum | e7134aa | 1995-02-26 10:20:53 +0000 | [diff] [blame] | 438 | return Py_BuildValue("i", old); |
Jack Jansen | ee23d6e | 1995-01-27 14:43:25 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Jack Jansen | 883765e | 1997-06-20 16:19:38 +0000 | [diff] [blame] | 441 | static char setevh_doc[] = "Set python event handler to be called in mainloop"; |
| 442 | |
| 443 | static PyObject * |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 444 | MacOS_SetEventHandler(PyObject *self, PyObject *args) |
Jack Jansen | 883765e | 1997-06-20 16:19:38 +0000 | [diff] [blame] | 445 | { |
| 446 | PyObject *evh = NULL; |
| 447 | |
| 448 | if (!PyArg_ParseTuple(args, "|O", &evh)) |
| 449 | return NULL; |
| 450 | if (evh == Py_None) |
| 451 | evh = NULL; |
| 452 | if ( evh && !PyCallable_Check(evh) ) { |
| 453 | PyErr_SetString(PyExc_ValueError, "SetEventHandler argument must be callable"); |
| 454 | return NULL; |
| 455 | } |
| 456 | if ( !PyMac_SetEventHandler(evh) ) |
| 457 | return NULL; |
| 458 | Py_INCREF(Py_None); |
| 459 | return Py_None; |
| 460 | } |
| 461 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 462 | static char handleev_doc[] = "Pass event to other interested parties like sioux"; |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 463 | |
| 464 | static PyObject * |
| 465 | MacOS_HandleEvent(PyObject *self, PyObject *args) |
| 466 | { |
| 467 | EventRecord ev; |
| 468 | |
| 469 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetEventRecord, &ev)) |
| 470 | return NULL; |
Jack Jansen | 883765e | 1997-06-20 16:19:38 +0000 | [diff] [blame] | 471 | PyMac_HandleEventIntern(&ev); |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 472 | Py_INCREF(Py_None); |
| 473 | return Py_None; |
| 474 | } |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 475 | #endif /* !TARGET_API_MAC_OSX */ |
Jack Jansen | a76382a | 1995-02-02 14:25:56 +0000 | [diff] [blame] | 476 | |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 477 | static char geterr_doc[] = "Convert OSErr number to string"; |
| 478 | |
Jack Jansen | 829f88c | 1995-07-17 11:36:01 +0000 | [diff] [blame] | 479 | static PyObject * |
| 480 | MacOS_GetErrorString(PyObject *self, PyObject *args) |
| 481 | { |
| 482 | int errn; |
| 483 | |
| 484 | if (!PyArg_ParseTuple(args, "i", &errn)) |
| 485 | return NULL; |
| 486 | return Py_BuildValue("s", PyMac_StrError(errn)); |
| 487 | } |
| 488 | |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 489 | static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)"; |
| 490 | |
| 491 | static PyObject * |
| 492 | MacOS_splash(PyObject *self, PyObject *args) |
| 493 | { |
Jack Jansen | df34cf1 | 1996-09-15 22:12:00 +0000 | [diff] [blame] | 494 | int resid = -1; |
Jack Jansen | 450ae9f | 1997-05-13 15:41:48 +0000 | [diff] [blame] | 495 | static DialogPtr curdialog = NULL; |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 496 | DialogPtr olddialog; |
Jack Jansen | 04df9d5 | 1996-09-23 15:49:43 +0000 | [diff] [blame] | 497 | WindowRef theWindow; |
| 498 | CGrafPtr thePort; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 499 | #if 0 |
Jack Jansen | 04df9d5 | 1996-09-23 15:49:43 +0000 | [diff] [blame] | 500 | short xpos, ypos, width, height, swidth, sheight; |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 501 | #endif |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 502 | |
Jack Jansen | df34cf1 | 1996-09-15 22:12:00 +0000 | [diff] [blame] | 503 | if (!PyArg_ParseTuple(args, "|i", &resid)) |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 504 | return NULL; |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 505 | olddialog = curdialog; |
Jack Jansen | cbe6a53 | 1998-02-20 15:59:59 +0000 | [diff] [blame] | 506 | curdialog = NULL; |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 507 | |
Jack Jansen | df34cf1 | 1996-09-15 22:12:00 +0000 | [diff] [blame] | 508 | if ( resid != -1 ) { |
| 509 | curdialog = GetNewDialog(resid, NULL, (WindowPtr)-1); |
Jack Jansen | 04df9d5 | 1996-09-23 15:49:43 +0000 | [diff] [blame] | 510 | if ( curdialog ) { |
| 511 | theWindow = GetDialogWindow(curdialog); |
| 512 | thePort = GetWindowPort(theWindow); |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 513 | #if 0 |
Jack Jansen | 04df9d5 | 1996-09-23 15:49:43 +0000 | [diff] [blame] | 514 | width = thePort->portRect.right - thePort->portRect.left; |
| 515 | height = thePort->portRect.bottom - thePort->portRect.top; |
| 516 | swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left; |
| 517 | sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight(); |
| 518 | xpos = (swidth-width)/2; |
| 519 | ypos = (sheight-height)/5 + LMGetMBarHeight(); |
| 520 | MoveWindow(theWindow, xpos, ypos, 0); |
| 521 | ShowWindow(theWindow); |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 522 | #endif |
Jack Jansen | df34cf1 | 1996-09-15 22:12:00 +0000 | [diff] [blame] | 523 | DrawDialog(curdialog); |
Jack Jansen | 04df9d5 | 1996-09-23 15:49:43 +0000 | [diff] [blame] | 524 | } |
Jack Jansen | df34cf1 | 1996-09-15 22:12:00 +0000 | [diff] [blame] | 525 | } |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 526 | if (olddialog) |
| 527 | DisposeDialog(olddialog); |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 528 | Py_INCREF(Py_None); |
| 529 | return Py_None; |
| 530 | } |
| 531 | |
Jack Jansen | eb76b84 | 1996-09-30 14:43:22 +0000 | [diff] [blame] | 532 | static char DebugStr_doc[] = "Switch to low-level debugger with a message"; |
| 533 | |
| 534 | static PyObject * |
| 535 | MacOS_DebugStr(PyObject *self, PyObject *args) |
| 536 | { |
| 537 | Str255 message; |
| 538 | PyObject *object = 0; |
| 539 | |
| 540 | if (!PyArg_ParseTuple(args, "O&|O", PyMac_GetStr255, message, &object)) |
| 541 | return NULL; |
| 542 | DebugStr(message); |
| 543 | Py_INCREF(Py_None); |
| 544 | return Py_None; |
| 545 | } |
Jack Jansen | ab7fcdd | 1996-05-20 11:32:00 +0000 | [diff] [blame] | 546 | |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 547 | static char SysBeep_doc[] = "BEEEEEP!!!"; |
| 548 | |
| 549 | static PyObject * |
| 550 | MacOS_SysBeep(PyObject *self, PyObject *args) |
| 551 | { |
| 552 | int duration = 6; |
| 553 | |
| 554 | if (!PyArg_ParseTuple(args, "|i", &duration)) |
| 555 | return NULL; |
| 556 | SysBeep(duration); |
| 557 | Py_INCREF(Py_None); |
| 558 | return Py_None; |
| 559 | } |
| 560 | |
Jack Jansen | 898ac1b | 1997-09-01 15:38:12 +0000 | [diff] [blame] | 561 | static char GetTicks_doc[] = "Return number of ticks since bootup"; |
| 562 | |
| 563 | static PyObject * |
| 564 | MacOS_GetTicks(PyObject *self, PyObject *args) |
| 565 | { |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 566 | return Py_BuildValue("i", (int)TickCount()); |
Jack Jansen | 898ac1b | 1997-09-01 15:38:12 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 569 | static char openrf_doc[] = "Open resource fork of a file"; |
| 570 | |
| 571 | static PyObject * |
| 572 | MacOS_openrf(PyObject *self, PyObject *args) |
| 573 | { |
| 574 | OSErr err; |
| 575 | char *mode = "r"; |
| 576 | FSSpec fss; |
| 577 | SignedByte permission = 1; |
| 578 | rfobject *fp; |
| 579 | |
| 580 | if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSSpec, &fss, &mode)) |
| 581 | return NULL; |
| 582 | while (*mode) { |
| 583 | switch (*mode++) { |
| 584 | case '*': break; |
| 585 | case 'r': permission = 1; break; |
| 586 | case 'w': permission = 2; break; |
| 587 | case 'b': break; |
| 588 | default: |
| 589 | PyErr_BadArgument(); |
| 590 | return NULL; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if ( (fp = newrfobject()) == NULL ) |
| 595 | return NULL; |
| 596 | |
| 597 | err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum); |
| 598 | |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 599 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 600 | if ( err == fnfErr ) { |
| 601 | /* In stead of doing complicated things here to get creator/type |
| 602 | ** correct we let the standard i/o library handle it |
| 603 | */ |
| 604 | FILE *tfp; |
| 605 | char pathname[257]; |
| 606 | |
Jack Jansen | 84fb1fa | 1996-11-09 18:46:57 +0000 | [diff] [blame] | 607 | if ( err=PyMac_GetFullPath(&fss, pathname) ) { |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 608 | PyMac_Error(err); |
| 609 | Py_DECREF(fp); |
| 610 | return NULL; |
| 611 | } |
| 612 | |
| 613 | if ( (tfp = fopen(pathname, "w")) == NULL ) { |
| 614 | PyMac_Error(fnfErr); /* What else... */ |
| 615 | Py_DECREF(fp); |
| 616 | return NULL; |
| 617 | } |
| 618 | fclose(tfp); |
| 619 | err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum); |
| 620 | } |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 621 | #endif |
Jack Jansen | 76a0589 | 1996-02-29 16:11:32 +0000 | [diff] [blame] | 622 | if ( err ) { |
| 623 | Py_DECREF(fp); |
| 624 | PyMac_Error(err); |
| 625 | return NULL; |
| 626 | } |
| 627 | fp->isclosed = 0; |
| 628 | return (PyObject *)fp; |
| 629 | } |
| 630 | |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 631 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 957d07a | 2000-02-21 11:07:37 +0000 | [diff] [blame] | 632 | static char FreeMem_doc[] = "Return the total amount of free space in the heap"; |
| 633 | |
| 634 | static PyObject * |
| 635 | MacOS_FreeMem(PyObject *self, PyObject *args) |
| 636 | { |
| 637 | long rv; |
| 638 | |
| 639 | if (!PyArg_ParseTuple(args, "")) |
| 640 | return NULL; |
| 641 | rv = FreeMem(); |
| 642 | return Py_BuildValue("l", rv); |
| 643 | } |
| 644 | |
| 645 | static char MaxBlock_doc[] = "Return the largest contiguous block of free space in the heap"; |
| 646 | |
| 647 | static PyObject * |
| 648 | MacOS_MaxBlock(PyObject *self, PyObject *args) |
| 649 | { |
| 650 | long rv; |
| 651 | |
| 652 | if (!PyArg_ParseTuple(args, "")) |
| 653 | return NULL; |
| 654 | rv = MaxBlock(); |
| 655 | return Py_BuildValue("l", rv); |
| 656 | } |
| 657 | |
| 658 | static char CompactMem_doc[] = "(wanted size)->actual largest block after compacting"; |
| 659 | |
| 660 | static PyObject * |
| 661 | MacOS_CompactMem(PyObject *self, PyObject *args) |
| 662 | { |
| 663 | long value; |
| 664 | long rv; |
| 665 | |
| 666 | if (!PyArg_ParseTuple(args, "l", &value)) |
| 667 | return NULL; |
| 668 | rv = CompactMem(value); |
| 669 | return Py_BuildValue("l", rv); |
| 670 | } |
| 671 | |
Jack Jansen | b19c667 | 2000-10-12 21:24:05 +0000 | [diff] [blame] | 672 | static char KeepConsole_doc[] = "(flag) Keep console open 0:never, 1:on output 2:on error, 3:always"; |
| 673 | |
| 674 | static PyObject * |
| 675 | MacOS_KeepConsole(PyObject *self, PyObject *args) |
| 676 | { |
| 677 | int value; |
| 678 | |
| 679 | if (!PyArg_ParseTuple(args, "i", &value)) |
| 680 | return NULL; |
| 681 | PyMac_options.keep_console = value; |
| 682 | Py_INCREF(Py_None); |
| 683 | return Py_None; |
| 684 | } |
| 685 | |
Jack Jansen | 8413b47 | 2000-10-19 22:02:16 +0000 | [diff] [blame] | 686 | static char OutputSeen_doc[] = "Call to reset the 'unseen output' flag for the keep-console-open option"; |
| 687 | |
| 688 | static PyObject * |
| 689 | MacOS_OutputSeen(PyObject *self, PyObject *args) |
| 690 | { |
| 691 | if (!PyArg_ParseTuple(args, "")) |
| 692 | return NULL; |
| 693 | PyMac_OutputSeen(); |
| 694 | Py_INCREF(Py_None); |
| 695 | return Py_None; |
| 696 | } |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 697 | #endif /* !TARGET_API_MAC_OSX */ |
Jack Jansen | 8413b47 | 2000-10-19 22:02:16 +0000 | [diff] [blame] | 698 | |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 699 | static PyMethodDef MacOS_Methods[] = { |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 700 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 701 | {"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1, accepthle_doc}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 702 | #endif |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 703 | {"GetCreatorAndType", MacOS_GetCreatorAndType, 1, getcrtp_doc}, |
| 704 | {"SetCreatorAndType", MacOS_SetCreatorAndType, 1, setcrtp_doc}, |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 705 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 706 | {"SchedParams", MacOS_SchedParams, 1, schedparams_doc}, |
| 707 | {"EnableAppswitch", MacOS_EnableAppswitch, 1, appswitch_doc}, |
Jack Jansen | 883765e | 1997-06-20 16:19:38 +0000 | [diff] [blame] | 708 | {"SetEventHandler", MacOS_SetEventHandler, 1, setevh_doc}, |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 709 | {"HandleEvent", MacOS_HandleEvent, 1, handleev_doc}, |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 710 | #endif |
Jack Jansen | 120a105 | 1997-06-03 15:29:41 +0000 | [diff] [blame] | 711 | {"GetErrorString", MacOS_GetErrorString, 1, geterr_doc}, |
| 712 | {"openrf", MacOS_openrf, 1, openrf_doc}, |
| 713 | {"splash", MacOS_splash, 1, splash_doc}, |
| 714 | {"DebugStr", MacOS_DebugStr, 1, DebugStr_doc}, |
Jack Jansen | 898ac1b | 1997-09-01 15:38:12 +0000 | [diff] [blame] | 715 | {"GetTicks", MacOS_GetTicks, 1, GetTicks_doc}, |
Jack Jansen | 2e871e4 | 1997-09-08 13:23:19 +0000 | [diff] [blame] | 716 | {"SysBeep", MacOS_SysBeep, 1, SysBeep_doc}, |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 717 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 957d07a | 2000-02-21 11:07:37 +0000 | [diff] [blame] | 718 | {"FreeMem", MacOS_FreeMem, 1, FreeMem_doc}, |
| 719 | {"MaxBlock", MacOS_MaxBlock, 1, MaxBlock_doc}, |
| 720 | {"CompactMem", MacOS_CompactMem, 1, CompactMem_doc}, |
Jack Jansen | b19c667 | 2000-10-12 21:24:05 +0000 | [diff] [blame] | 721 | {"KeepConsole", MacOS_KeepConsole, 1, KeepConsole_doc}, |
Jack Jansen | 8413b47 | 2000-10-19 22:02:16 +0000 | [diff] [blame] | 722 | {"OutputSeen", MacOS_OutputSeen, 1, OutputSeen_doc}, |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 723 | #endif |
Guido van Rossum | f74d4e2 | 1995-01-18 23:58:07 +0000 | [diff] [blame] | 724 | {NULL, NULL} /* Sentinel */ |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 725 | }; |
| 726 | |
| 727 | |
| 728 | void |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 729 | initMacOS(void) |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 730 | { |
| 731 | PyObject *m, *d; |
| 732 | |
| 733 | m = Py_InitModule("MacOS", MacOS_Methods); |
| 734 | d = PyModule_GetDict(m); |
| 735 | |
| 736 | /* Initialize MacOS.Error exception */ |
Guido van Rossum | bf068b1 | 1995-01-25 23:09:20 +0000 | [diff] [blame] | 737 | MacOS_Error = PyMac_GetOSErrException(); |
Guido van Rossum | e433c97 | 1994-09-29 10:02:56 +0000 | [diff] [blame] | 738 | if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0) |
Jack Jansen | fa1e27d | 2000-09-08 10:21:44 +0000 | [diff] [blame] | 739 | return; |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 740 | Rftype.ob_type = &PyType_Type; |
| 741 | Py_INCREF(&Rftype); |
| 742 | if (PyDict_SetItemString(d, "ResourceForkType", (PyObject *)&Rftype) != 0) |
Jack Jansen | fa1e27d | 2000-09-08 10:21:44 +0000 | [diff] [blame] | 743 | return; |
Jack Jansen | f73bab7 | 1997-04-03 14:51:03 +0000 | [diff] [blame] | 744 | /* |
| 745 | ** This is a hack: the following constant added to the id() of a string |
| 746 | ** object gives you the address of the data. Unfortunately, it is needed for |
| 747 | ** some of the image and sound processing interfaces on the mac:-( |
| 748 | */ |
| 749 | { |
| 750 | PyStringObject *p = 0; |
| 751 | long off = (long)&(p->ob_sval[0]); |
| 752 | |
| 753 | if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0) |
Jack Jansen | fa1e27d | 2000-09-08 10:21:44 +0000 | [diff] [blame] | 754 | return; |
Jack Jansen | f73bab7 | 1997-04-03 14:51:03 +0000 | [diff] [blame] | 755 | } |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 756 | #if !TARGET_API_MAC_OSX |
Jack Jansen | 8f5725a | 1999-12-07 23:08:10 +0000 | [diff] [blame] | 757 | if (PyDict_SetItemString(d, "AppearanceCompliant", |
| 758 | Py_BuildValue("i", PyMac_AppearanceCompliant)) != 0) |
Jack Jansen | fa1e27d | 2000-09-08 10:21:44 +0000 | [diff] [blame] | 759 | return; |
Jack Jansen | deefbe5 | 2001-08-08 13:46:49 +0000 | [diff] [blame] | 760 | #endif |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 761 | #if TARGET_API_MAC_OSX |
| 762 | #define PY_RUNTIMEMODEL "macho" |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 763 | #elif TARGET_API_MAC_OS8 |
Jack Jansen | 193509b | 2001-01-23 22:38:23 +0000 | [diff] [blame] | 764 | #define PY_RUNTIMEMODEL "ppc" |
Jack Jansen | f316330 | 2001-05-19 12:50:05 +0000 | [diff] [blame] | 765 | #elif TARGET_API_MAC_CARBON |
| 766 | #define PY_RUNTIMEMODEL "carbon" |
Jack Jansen | 6e68a7e | 2001-05-12 21:31:34 +0000 | [diff] [blame] | 767 | #else |
| 768 | #error "None of the TARGET_API_MAC_XXX I know about is set" |
Jack Jansen | 193509b | 2001-01-23 22:38:23 +0000 | [diff] [blame] | 769 | #endif |
| 770 | if (PyDict_SetItemString(d, "runtimemodel", |
| 771 | Py_BuildValue("s", PY_RUNTIMEMODEL)) != 0) |
| 772 | return; |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 773 | } |
Guido van Rossum | e7134aa | 1995-02-26 10:20:53 +0000 | [diff] [blame] | 774 | |