Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Res =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 35 | #include <Resources.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
| 39 | static PyObject *Res_Error; |
| 40 | |
| 41 | /* ---------------------- Object type Resource ---------------------- */ |
| 42 | |
| 43 | PyTypeObject Resource_Type; |
| 44 | |
| 45 | #define ResObj_Check(x) ((x)->ob_type == &Resource_Type) |
| 46 | |
| 47 | typedef struct ResourceObject { |
| 48 | PyObject_HEAD |
| 49 | Handle ob_itself; |
| 50 | } ResourceObject; |
| 51 | |
| 52 | PyObject *ResObj_New(itself) |
Guido van Rossum | 227a423 | 1995-03-10 14:42:57 +0000 | [diff] [blame] | 53 | Handle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 54 | { |
| 55 | ResourceObject *it; |
| 56 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 57 | it = PyObject_NEW(ResourceObject, &Resource_Type); |
| 58 | if (it == NULL) return NULL; |
| 59 | it->ob_itself = itself; |
| 60 | return (PyObject *)it; |
| 61 | } |
| 62 | ResObj_Convert(v, p_itself) |
| 63 | PyObject *v; |
| 64 | Handle *p_itself; |
| 65 | { |
| 66 | if (!ResObj_Check(v)) |
| 67 | { |
| 68 | PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 69 | return 0; |
| 70 | } |
| 71 | *p_itself = ((ResourceObject *)v)->ob_itself; |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | static void ResObj_dealloc(self) |
| 76 | ResourceObject *self; |
| 77 | { |
| 78 | /* Cleanup of self->ob_itself goes here */ |
| 79 | PyMem_DEL(self); |
| 80 | } |
| 81 | |
| 82 | static PyObject *ResObj_HomeResFile(_self, _args) |
| 83 | ResourceObject *_self; |
| 84 | PyObject *_args; |
| 85 | { |
| 86 | PyObject *_res = NULL; |
| 87 | short _rv; |
| 88 | if (!PyArg_ParseTuple(_args, "")) |
| 89 | return NULL; |
| 90 | _rv = HomeResFile(_self->ob_itself); |
| 91 | { |
| 92 | OSErr _err = ResError(); |
| 93 | if (_err != noErr) return PyMac_Error(_err); |
| 94 | } |
| 95 | _res = Py_BuildValue("h", |
| 96 | _rv); |
| 97 | return _res; |
| 98 | } |
| 99 | |
| 100 | static PyObject *ResObj_LoadResource(_self, _args) |
| 101 | ResourceObject *_self; |
| 102 | PyObject *_args; |
| 103 | { |
| 104 | PyObject *_res = NULL; |
| 105 | if (!PyArg_ParseTuple(_args, "")) |
| 106 | return NULL; |
| 107 | LoadResource(_self->ob_itself); |
| 108 | { |
| 109 | OSErr _err = ResError(); |
| 110 | if (_err != noErr) return PyMac_Error(_err); |
| 111 | } |
| 112 | Py_INCREF(Py_None); |
| 113 | _res = Py_None; |
| 114 | return _res; |
| 115 | } |
| 116 | |
| 117 | static PyObject *ResObj_ReleaseResource(_self, _args) |
| 118 | ResourceObject *_self; |
| 119 | PyObject *_args; |
| 120 | { |
| 121 | PyObject *_res = NULL; |
| 122 | if (!PyArg_ParseTuple(_args, "")) |
| 123 | return NULL; |
| 124 | ReleaseResource(_self->ob_itself); |
| 125 | { |
| 126 | OSErr _err = ResError(); |
| 127 | if (_err != noErr) return PyMac_Error(_err); |
| 128 | } |
| 129 | Py_INCREF(Py_None); |
| 130 | _res = Py_None; |
| 131 | return _res; |
| 132 | } |
| 133 | |
| 134 | static PyObject *ResObj_DetachResource(_self, _args) |
| 135 | ResourceObject *_self; |
| 136 | PyObject *_args; |
| 137 | { |
| 138 | PyObject *_res = NULL; |
| 139 | if (!PyArg_ParseTuple(_args, "")) |
| 140 | return NULL; |
| 141 | DetachResource(_self->ob_itself); |
| 142 | { |
| 143 | OSErr _err = ResError(); |
| 144 | if (_err != noErr) return PyMac_Error(_err); |
| 145 | } |
| 146 | Py_INCREF(Py_None); |
| 147 | _res = Py_None; |
| 148 | return _res; |
| 149 | } |
| 150 | |
| 151 | static PyObject *ResObj_GetResAttrs(_self, _args) |
| 152 | ResourceObject *_self; |
| 153 | PyObject *_args; |
| 154 | { |
| 155 | PyObject *_res = NULL; |
| 156 | short _rv; |
| 157 | if (!PyArg_ParseTuple(_args, "")) |
| 158 | return NULL; |
| 159 | _rv = GetResAttrs(_self->ob_itself); |
| 160 | { |
| 161 | OSErr _err = ResError(); |
| 162 | if (_err != noErr) return PyMac_Error(_err); |
| 163 | } |
| 164 | _res = Py_BuildValue("h", |
| 165 | _rv); |
| 166 | return _res; |
| 167 | } |
| 168 | |
| 169 | static PyObject *ResObj_GetResInfo(_self, _args) |
| 170 | ResourceObject *_self; |
| 171 | PyObject *_args; |
| 172 | { |
| 173 | PyObject *_res = NULL; |
| 174 | short theID; |
| 175 | ResType theType; |
| 176 | Str255 name; |
| 177 | if (!PyArg_ParseTuple(_args, "")) |
| 178 | return NULL; |
| 179 | GetResInfo(_self->ob_itself, |
| 180 | &theID, |
| 181 | &theType, |
| 182 | name); |
| 183 | { |
| 184 | OSErr _err = ResError(); |
| 185 | if (_err != noErr) return PyMac_Error(_err); |
| 186 | } |
| 187 | _res = Py_BuildValue("hO&O&", |
| 188 | theID, |
| 189 | PyMac_BuildOSType, theType, |
| 190 | PyMac_BuildStr255, name); |
| 191 | return _res; |
| 192 | } |
| 193 | |
| 194 | static PyObject *ResObj_SetResInfo(_self, _args) |
| 195 | ResourceObject *_self; |
| 196 | PyObject *_args; |
| 197 | { |
| 198 | PyObject *_res = NULL; |
| 199 | short theID; |
| 200 | Str255 name; |
| 201 | if (!PyArg_ParseTuple(_args, "hO&", |
| 202 | &theID, |
| 203 | PyMac_GetStr255, name)) |
| 204 | return NULL; |
| 205 | SetResInfo(_self->ob_itself, |
| 206 | theID, |
| 207 | name); |
| 208 | { |
| 209 | OSErr _err = ResError(); |
| 210 | if (_err != noErr) return PyMac_Error(_err); |
| 211 | } |
| 212 | Py_INCREF(Py_None); |
| 213 | _res = Py_None; |
| 214 | return _res; |
| 215 | } |
| 216 | |
| 217 | static PyObject *ResObj_AddResource(_self, _args) |
| 218 | ResourceObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | ResType theType; |
| 223 | short theID; |
| 224 | Str255 name; |
| 225 | if (!PyArg_ParseTuple(_args, "O&hO&", |
| 226 | PyMac_GetOSType, &theType, |
| 227 | &theID, |
| 228 | PyMac_GetStr255, name)) |
| 229 | return NULL; |
| 230 | AddResource(_self->ob_itself, |
| 231 | theType, |
| 232 | theID, |
| 233 | name); |
| 234 | { |
| 235 | OSErr _err = ResError(); |
| 236 | if (_err != noErr) return PyMac_Error(_err); |
| 237 | } |
| 238 | Py_INCREF(Py_None); |
| 239 | _res = Py_None; |
| 240 | return _res; |
| 241 | } |
| 242 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 243 | static PyObject *ResObj_GetResourceSizeOnDisk(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 244 | ResourceObject *_self; |
| 245 | PyObject *_args; |
| 246 | { |
| 247 | PyObject *_res = NULL; |
| 248 | long _rv; |
| 249 | if (!PyArg_ParseTuple(_args, "")) |
| 250 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 251 | _rv = GetResourceSizeOnDisk(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 252 | { |
| 253 | OSErr _err = ResError(); |
| 254 | if (_err != noErr) return PyMac_Error(_err); |
| 255 | } |
| 256 | _res = Py_BuildValue("l", |
| 257 | _rv); |
| 258 | return _res; |
| 259 | } |
| 260 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 261 | static PyObject *ResObj_GetMaxResourceSize(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 262 | ResourceObject *_self; |
| 263 | PyObject *_args; |
| 264 | { |
| 265 | PyObject *_res = NULL; |
| 266 | long _rv; |
| 267 | if (!PyArg_ParseTuple(_args, "")) |
| 268 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 269 | _rv = GetMaxResourceSize(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 270 | { |
| 271 | OSErr _err = ResError(); |
| 272 | if (_err != noErr) return PyMac_Error(_err); |
| 273 | } |
| 274 | _res = Py_BuildValue("l", |
| 275 | _rv); |
| 276 | return _res; |
| 277 | } |
| 278 | |
| 279 | static PyObject *ResObj_RsrcMapEntry(_self, _args) |
| 280 | ResourceObject *_self; |
| 281 | PyObject *_args; |
| 282 | { |
| 283 | PyObject *_res = NULL; |
| 284 | long _rv; |
| 285 | if (!PyArg_ParseTuple(_args, "")) |
| 286 | return NULL; |
| 287 | _rv = RsrcMapEntry(_self->ob_itself); |
| 288 | { |
| 289 | OSErr _err = ResError(); |
| 290 | if (_err != noErr) return PyMac_Error(_err); |
| 291 | } |
| 292 | _res = Py_BuildValue("l", |
| 293 | _rv); |
| 294 | return _res; |
| 295 | } |
| 296 | |
| 297 | static PyObject *ResObj_SetResAttrs(_self, _args) |
| 298 | ResourceObject *_self; |
| 299 | PyObject *_args; |
| 300 | { |
| 301 | PyObject *_res = NULL; |
| 302 | short attrs; |
| 303 | if (!PyArg_ParseTuple(_args, "h", |
| 304 | &attrs)) |
| 305 | return NULL; |
| 306 | SetResAttrs(_self->ob_itself, |
| 307 | attrs); |
| 308 | { |
| 309 | OSErr _err = ResError(); |
| 310 | if (_err != noErr) return PyMac_Error(_err); |
| 311 | } |
| 312 | Py_INCREF(Py_None); |
| 313 | _res = Py_None; |
| 314 | return _res; |
| 315 | } |
| 316 | |
| 317 | static PyObject *ResObj_ChangedResource(_self, _args) |
| 318 | ResourceObject *_self; |
| 319 | PyObject *_args; |
| 320 | { |
| 321 | PyObject *_res = NULL; |
| 322 | if (!PyArg_ParseTuple(_args, "")) |
| 323 | return NULL; |
| 324 | ChangedResource(_self->ob_itself); |
| 325 | { |
| 326 | OSErr _err = ResError(); |
| 327 | if (_err != noErr) return PyMac_Error(_err); |
| 328 | } |
| 329 | Py_INCREF(Py_None); |
| 330 | _res = Py_None; |
| 331 | return _res; |
| 332 | } |
| 333 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 334 | static PyObject *ResObj_RemoveResource(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 335 | ResourceObject *_self; |
| 336 | PyObject *_args; |
| 337 | { |
| 338 | PyObject *_res = NULL; |
| 339 | if (!PyArg_ParseTuple(_args, "")) |
| 340 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 341 | RemoveResource(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 342 | { |
| 343 | OSErr _err = ResError(); |
| 344 | if (_err != noErr) return PyMac_Error(_err); |
| 345 | } |
| 346 | Py_INCREF(Py_None); |
| 347 | _res = Py_None; |
| 348 | return _res; |
| 349 | } |
| 350 | |
| 351 | static PyObject *ResObj_WriteResource(_self, _args) |
| 352 | ResourceObject *_self; |
| 353 | PyObject *_args; |
| 354 | { |
| 355 | PyObject *_res = NULL; |
| 356 | if (!PyArg_ParseTuple(_args, "")) |
| 357 | return NULL; |
| 358 | WriteResource(_self->ob_itself); |
| 359 | { |
| 360 | OSErr _err = ResError(); |
| 361 | if (_err != noErr) return PyMac_Error(_err); |
| 362 | } |
| 363 | Py_INCREF(Py_None); |
| 364 | _res = Py_None; |
| 365 | return _res; |
| 366 | } |
| 367 | |
| 368 | static PyObject *ResObj_SetResourceSize(_self, _args) |
| 369 | ResourceObject *_self; |
| 370 | PyObject *_args; |
| 371 | { |
| 372 | PyObject *_res = NULL; |
| 373 | long newSize; |
| 374 | if (!PyArg_ParseTuple(_args, "l", |
| 375 | &newSize)) |
| 376 | return NULL; |
| 377 | SetResourceSize(_self->ob_itself, |
| 378 | newSize); |
| 379 | { |
| 380 | OSErr _err = ResError(); |
| 381 | if (_err != noErr) return PyMac_Error(_err); |
| 382 | } |
| 383 | Py_INCREF(Py_None); |
| 384 | _res = Py_None; |
| 385 | return _res; |
| 386 | } |
| 387 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 388 | static PyObject *ResObj_GetNextFOND(_self, _args) |
| 389 | ResourceObject *_self; |
| 390 | PyObject *_args; |
| 391 | { |
| 392 | PyObject *_res = NULL; |
| 393 | Handle _rv; |
| 394 | if (!PyArg_ParseTuple(_args, "")) |
| 395 | return NULL; |
| 396 | _rv = GetNextFOND(_self->ob_itself); |
| 397 | { |
| 398 | OSErr _err = ResError(); |
| 399 | if (_err != noErr) return PyMac_Error(_err); |
| 400 | } |
| 401 | _res = Py_BuildValue("O&", |
| 402 | ResObj_New, _rv); |
| 403 | return _res; |
| 404 | } |
| 405 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 406 | static PyMethodDef ResObj_methods[] = { |
| 407 | {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, |
| 408 | "() -> (short _rv)"}, |
| 409 | {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, |
| 410 | "() -> None"}, |
| 411 | {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, |
| 412 | "() -> None"}, |
| 413 | {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, |
| 414 | "() -> None"}, |
| 415 | {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, |
| 416 | "() -> (short _rv)"}, |
| 417 | {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, |
| 418 | "() -> (short theID, ResType theType, Str255 name)"}, |
| 419 | {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, |
| 420 | "(short theID, Str255 name) -> None"}, |
| 421 | {"AddResource", (PyCFunction)ResObj_AddResource, 1, |
| 422 | "(ResType theType, short theID, Str255 name) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 423 | {"GetResourceSizeOnDisk", (PyCFunction)ResObj_GetResourceSizeOnDisk, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 424 | "() -> (long _rv)"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 425 | {"GetMaxResourceSize", (PyCFunction)ResObj_GetMaxResourceSize, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 426 | "() -> (long _rv)"}, |
| 427 | {"RsrcMapEntry", (PyCFunction)ResObj_RsrcMapEntry, 1, |
| 428 | "() -> (long _rv)"}, |
| 429 | {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, |
| 430 | "(short attrs) -> None"}, |
| 431 | {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, |
| 432 | "() -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 433 | {"RemoveResource", (PyCFunction)ResObj_RemoveResource, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 434 | "() -> None"}, |
| 435 | {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, |
| 436 | "() -> None"}, |
| 437 | {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, |
| 438 | "(long newSize) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 439 | {"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1, |
| 440 | "() -> (Handle _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 441 | {NULL, NULL, 0} |
| 442 | }; |
| 443 | |
| 444 | PyMethodChain ResObj_chain = { ResObj_methods, NULL }; |
| 445 | |
| 446 | static PyObject *ResObj_getattr(self, name) |
| 447 | ResourceObject *self; |
| 448 | char *name; |
| 449 | { |
| 450 | |
| 451 | if (strcmp(name, "size") == 0) |
| 452 | return PyInt_FromLong(GetHandleSize(self->ob_itself)); |
| 453 | if (strcmp(name, "data") == 0) { |
| 454 | PyObject *res; |
| 455 | char state; |
| 456 | state = HGetState(self->ob_itself); |
| 457 | HLock(self->ob_itself); |
| 458 | res = PyString_FromStringAndSize( |
| 459 | *self->ob_itself, |
| 460 | GetHandleSize(self->ob_itself)); |
| 461 | HUnlock(self->ob_itself); |
| 462 | HSetState(self->ob_itself, state); |
| 463 | return res; |
| 464 | } |
| 465 | if (strcmp(name, "__members__") == 0) |
| 466 | return Py_BuildValue("[ss]", "data", "size"); |
| 467 | |
| 468 | return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name); |
| 469 | } |
| 470 | |
| 471 | #define ResObj_setattr NULL |
| 472 | |
| 473 | PyTypeObject Resource_Type = { |
| 474 | PyObject_HEAD_INIT(&PyType_Type) |
| 475 | 0, /*ob_size*/ |
| 476 | "Resource", /*tp_name*/ |
| 477 | sizeof(ResourceObject), /*tp_basicsize*/ |
| 478 | 0, /*tp_itemsize*/ |
| 479 | /* methods */ |
| 480 | (destructor) ResObj_dealloc, /*tp_dealloc*/ |
| 481 | 0, /*tp_print*/ |
| 482 | (getattrfunc) ResObj_getattr, /*tp_getattr*/ |
| 483 | (setattrfunc) ResObj_setattr, /*tp_setattr*/ |
| 484 | }; |
| 485 | |
| 486 | /* -------------------- End object type Resource -------------------- */ |
| 487 | |
| 488 | |
| 489 | static PyObject *Res_InitResources(_self, _args) |
| 490 | PyObject *_self; |
| 491 | PyObject *_args; |
| 492 | { |
| 493 | PyObject *_res = NULL; |
| 494 | short _rv; |
| 495 | if (!PyArg_ParseTuple(_args, "")) |
| 496 | return NULL; |
| 497 | _rv = InitResources(); |
| 498 | { |
| 499 | OSErr _err = ResError(); |
| 500 | if (_err != noErr) return PyMac_Error(_err); |
| 501 | } |
| 502 | _res = Py_BuildValue("h", |
| 503 | _rv); |
| 504 | return _res; |
| 505 | } |
| 506 | |
| 507 | static PyObject *Res_RsrcZoneInit(_self, _args) |
| 508 | PyObject *_self; |
| 509 | PyObject *_args; |
| 510 | { |
| 511 | PyObject *_res = NULL; |
| 512 | if (!PyArg_ParseTuple(_args, "")) |
| 513 | return NULL; |
| 514 | RsrcZoneInit(); |
| 515 | { |
| 516 | OSErr _err = ResError(); |
| 517 | if (_err != noErr) return PyMac_Error(_err); |
| 518 | } |
| 519 | Py_INCREF(Py_None); |
| 520 | _res = Py_None; |
| 521 | return _res; |
| 522 | } |
| 523 | |
| 524 | static PyObject *Res_CloseResFile(_self, _args) |
| 525 | PyObject *_self; |
| 526 | PyObject *_args; |
| 527 | { |
| 528 | PyObject *_res = NULL; |
| 529 | short refNum; |
| 530 | if (!PyArg_ParseTuple(_args, "h", |
| 531 | &refNum)) |
| 532 | return NULL; |
| 533 | CloseResFile(refNum); |
| 534 | { |
| 535 | OSErr _err = ResError(); |
| 536 | if (_err != noErr) return PyMac_Error(_err); |
| 537 | } |
| 538 | Py_INCREF(Py_None); |
| 539 | _res = Py_None; |
| 540 | return _res; |
| 541 | } |
| 542 | |
| 543 | static PyObject *Res_ResError(_self, _args) |
| 544 | PyObject *_self; |
| 545 | PyObject *_args; |
| 546 | { |
| 547 | PyObject *_res = NULL; |
| 548 | short _rv; |
| 549 | if (!PyArg_ParseTuple(_args, "")) |
| 550 | return NULL; |
| 551 | _rv = ResError(); |
| 552 | { |
| 553 | OSErr _err = ResError(); |
| 554 | if (_err != noErr) return PyMac_Error(_err); |
| 555 | } |
| 556 | _res = Py_BuildValue("h", |
| 557 | _rv); |
| 558 | return _res; |
| 559 | } |
| 560 | |
| 561 | static PyObject *Res_CurResFile(_self, _args) |
| 562 | PyObject *_self; |
| 563 | PyObject *_args; |
| 564 | { |
| 565 | PyObject *_res = NULL; |
| 566 | short _rv; |
| 567 | if (!PyArg_ParseTuple(_args, "")) |
| 568 | return NULL; |
| 569 | _rv = CurResFile(); |
| 570 | { |
| 571 | OSErr _err = ResError(); |
| 572 | if (_err != noErr) return PyMac_Error(_err); |
| 573 | } |
| 574 | _res = Py_BuildValue("h", |
| 575 | _rv); |
| 576 | return _res; |
| 577 | } |
| 578 | |
| 579 | static PyObject *Res_CreateResFile(_self, _args) |
| 580 | PyObject *_self; |
| 581 | PyObject *_args; |
| 582 | { |
| 583 | PyObject *_res = NULL; |
| 584 | Str255 fileName; |
| 585 | if (!PyArg_ParseTuple(_args, "O&", |
| 586 | PyMac_GetStr255, fileName)) |
| 587 | return NULL; |
| 588 | CreateResFile(fileName); |
| 589 | { |
| 590 | OSErr _err = ResError(); |
| 591 | if (_err != noErr) return PyMac_Error(_err); |
| 592 | } |
| 593 | Py_INCREF(Py_None); |
| 594 | _res = Py_None; |
| 595 | return _res; |
| 596 | } |
| 597 | |
| 598 | static PyObject *Res_OpenResFile(_self, _args) |
| 599 | PyObject *_self; |
| 600 | PyObject *_args; |
| 601 | { |
| 602 | PyObject *_res = NULL; |
| 603 | short _rv; |
| 604 | Str255 fileName; |
| 605 | if (!PyArg_ParseTuple(_args, "O&", |
| 606 | PyMac_GetStr255, fileName)) |
| 607 | return NULL; |
| 608 | _rv = OpenResFile(fileName); |
| 609 | { |
| 610 | OSErr _err = ResError(); |
| 611 | if (_err != noErr) return PyMac_Error(_err); |
| 612 | } |
| 613 | _res = Py_BuildValue("h", |
| 614 | _rv); |
| 615 | return _res; |
| 616 | } |
| 617 | |
| 618 | static PyObject *Res_UseResFile(_self, _args) |
| 619 | PyObject *_self; |
| 620 | PyObject *_args; |
| 621 | { |
| 622 | PyObject *_res = NULL; |
| 623 | short refNum; |
| 624 | if (!PyArg_ParseTuple(_args, "h", |
| 625 | &refNum)) |
| 626 | return NULL; |
| 627 | UseResFile(refNum); |
| 628 | { |
| 629 | OSErr _err = ResError(); |
| 630 | if (_err != noErr) return PyMac_Error(_err); |
| 631 | } |
| 632 | Py_INCREF(Py_None); |
| 633 | _res = Py_None; |
| 634 | return _res; |
| 635 | } |
| 636 | |
| 637 | static PyObject *Res_CountTypes(_self, _args) |
| 638 | PyObject *_self; |
| 639 | PyObject *_args; |
| 640 | { |
| 641 | PyObject *_res = NULL; |
| 642 | short _rv; |
| 643 | if (!PyArg_ParseTuple(_args, "")) |
| 644 | return NULL; |
| 645 | _rv = CountTypes(); |
| 646 | { |
| 647 | OSErr _err = ResError(); |
| 648 | if (_err != noErr) return PyMac_Error(_err); |
| 649 | } |
| 650 | _res = Py_BuildValue("h", |
| 651 | _rv); |
| 652 | return _res; |
| 653 | } |
| 654 | |
| 655 | static PyObject *Res_Count1Types(_self, _args) |
| 656 | PyObject *_self; |
| 657 | PyObject *_args; |
| 658 | { |
| 659 | PyObject *_res = NULL; |
| 660 | short _rv; |
| 661 | if (!PyArg_ParseTuple(_args, "")) |
| 662 | return NULL; |
| 663 | _rv = Count1Types(); |
| 664 | { |
| 665 | OSErr _err = ResError(); |
| 666 | if (_err != noErr) return PyMac_Error(_err); |
| 667 | } |
| 668 | _res = Py_BuildValue("h", |
| 669 | _rv); |
| 670 | return _res; |
| 671 | } |
| 672 | |
| 673 | static PyObject *Res_GetIndType(_self, _args) |
| 674 | PyObject *_self; |
| 675 | PyObject *_args; |
| 676 | { |
| 677 | PyObject *_res = NULL; |
| 678 | ResType theType; |
| 679 | short index; |
| 680 | if (!PyArg_ParseTuple(_args, "h", |
| 681 | &index)) |
| 682 | return NULL; |
| 683 | GetIndType(&theType, |
| 684 | index); |
| 685 | { |
| 686 | OSErr _err = ResError(); |
| 687 | if (_err != noErr) return PyMac_Error(_err); |
| 688 | } |
| 689 | _res = Py_BuildValue("O&", |
| 690 | PyMac_BuildOSType, theType); |
| 691 | return _res; |
| 692 | } |
| 693 | |
| 694 | static PyObject *Res_Get1IndType(_self, _args) |
| 695 | PyObject *_self; |
| 696 | PyObject *_args; |
| 697 | { |
| 698 | PyObject *_res = NULL; |
| 699 | ResType theType; |
| 700 | short index; |
| 701 | if (!PyArg_ParseTuple(_args, "h", |
| 702 | &index)) |
| 703 | return NULL; |
| 704 | Get1IndType(&theType, |
| 705 | index); |
| 706 | { |
| 707 | OSErr _err = ResError(); |
| 708 | if (_err != noErr) return PyMac_Error(_err); |
| 709 | } |
| 710 | _res = Py_BuildValue("O&", |
| 711 | PyMac_BuildOSType, theType); |
| 712 | return _res; |
| 713 | } |
| 714 | |
| 715 | static PyObject *Res_SetResLoad(_self, _args) |
| 716 | PyObject *_self; |
| 717 | PyObject *_args; |
| 718 | { |
| 719 | PyObject *_res = NULL; |
| 720 | Boolean load; |
| 721 | if (!PyArg_ParseTuple(_args, "b", |
| 722 | &load)) |
| 723 | return NULL; |
| 724 | SetResLoad(load); |
| 725 | { |
| 726 | OSErr _err = ResError(); |
| 727 | if (_err != noErr) return PyMac_Error(_err); |
| 728 | } |
| 729 | Py_INCREF(Py_None); |
| 730 | _res = Py_None; |
| 731 | return _res; |
| 732 | } |
| 733 | |
| 734 | static PyObject *Res_CountResources(_self, _args) |
| 735 | PyObject *_self; |
| 736 | PyObject *_args; |
| 737 | { |
| 738 | PyObject *_res = NULL; |
| 739 | short _rv; |
| 740 | ResType theType; |
| 741 | if (!PyArg_ParseTuple(_args, "O&", |
| 742 | PyMac_GetOSType, &theType)) |
| 743 | return NULL; |
| 744 | _rv = CountResources(theType); |
| 745 | { |
| 746 | OSErr _err = ResError(); |
| 747 | if (_err != noErr) return PyMac_Error(_err); |
| 748 | } |
| 749 | _res = Py_BuildValue("h", |
| 750 | _rv); |
| 751 | return _res; |
| 752 | } |
| 753 | |
| 754 | static PyObject *Res_Count1Resources(_self, _args) |
| 755 | PyObject *_self; |
| 756 | PyObject *_args; |
| 757 | { |
| 758 | PyObject *_res = NULL; |
| 759 | short _rv; |
| 760 | ResType theType; |
| 761 | if (!PyArg_ParseTuple(_args, "O&", |
| 762 | PyMac_GetOSType, &theType)) |
| 763 | return NULL; |
| 764 | _rv = Count1Resources(theType); |
| 765 | { |
| 766 | OSErr _err = ResError(); |
| 767 | if (_err != noErr) return PyMac_Error(_err); |
| 768 | } |
| 769 | _res = Py_BuildValue("h", |
| 770 | _rv); |
| 771 | return _res; |
| 772 | } |
| 773 | |
| 774 | static PyObject *Res_GetIndResource(_self, _args) |
| 775 | PyObject *_self; |
| 776 | PyObject *_args; |
| 777 | { |
| 778 | PyObject *_res = NULL; |
| 779 | Handle _rv; |
| 780 | ResType theType; |
| 781 | short index; |
| 782 | if (!PyArg_ParseTuple(_args, "O&h", |
| 783 | PyMac_GetOSType, &theType, |
| 784 | &index)) |
| 785 | return NULL; |
| 786 | _rv = GetIndResource(theType, |
| 787 | index); |
| 788 | { |
| 789 | OSErr _err = ResError(); |
| 790 | if (_err != noErr) return PyMac_Error(_err); |
| 791 | } |
| 792 | _res = Py_BuildValue("O&", |
| 793 | ResObj_New, _rv); |
| 794 | return _res; |
| 795 | } |
| 796 | |
| 797 | static PyObject *Res_Get1IndResource(_self, _args) |
| 798 | PyObject *_self; |
| 799 | PyObject *_args; |
| 800 | { |
| 801 | PyObject *_res = NULL; |
| 802 | Handle _rv; |
| 803 | ResType theType; |
| 804 | short index; |
| 805 | if (!PyArg_ParseTuple(_args, "O&h", |
| 806 | PyMac_GetOSType, &theType, |
| 807 | &index)) |
| 808 | return NULL; |
| 809 | _rv = Get1IndResource(theType, |
| 810 | index); |
| 811 | { |
| 812 | OSErr _err = ResError(); |
| 813 | if (_err != noErr) return PyMac_Error(_err); |
| 814 | } |
| 815 | _res = Py_BuildValue("O&", |
| 816 | ResObj_New, _rv); |
| 817 | return _res; |
| 818 | } |
| 819 | |
| 820 | static PyObject *Res_GetResource(_self, _args) |
| 821 | PyObject *_self; |
| 822 | PyObject *_args; |
| 823 | { |
| 824 | PyObject *_res = NULL; |
| 825 | Handle _rv; |
| 826 | ResType theType; |
| 827 | short theID; |
| 828 | if (!PyArg_ParseTuple(_args, "O&h", |
| 829 | PyMac_GetOSType, &theType, |
| 830 | &theID)) |
| 831 | return NULL; |
| 832 | _rv = GetResource(theType, |
| 833 | theID); |
| 834 | { |
| 835 | OSErr _err = ResError(); |
| 836 | if (_err != noErr) return PyMac_Error(_err); |
| 837 | } |
| 838 | _res = Py_BuildValue("O&", |
| 839 | ResObj_New, _rv); |
| 840 | return _res; |
| 841 | } |
| 842 | |
| 843 | static PyObject *Res_Get1Resource(_self, _args) |
| 844 | PyObject *_self; |
| 845 | PyObject *_args; |
| 846 | { |
| 847 | PyObject *_res = NULL; |
| 848 | Handle _rv; |
| 849 | ResType theType; |
| 850 | short theID; |
| 851 | if (!PyArg_ParseTuple(_args, "O&h", |
| 852 | PyMac_GetOSType, &theType, |
| 853 | &theID)) |
| 854 | return NULL; |
| 855 | _rv = Get1Resource(theType, |
| 856 | theID); |
| 857 | { |
| 858 | OSErr _err = ResError(); |
| 859 | if (_err != noErr) return PyMac_Error(_err); |
| 860 | } |
| 861 | _res = Py_BuildValue("O&", |
| 862 | ResObj_New, _rv); |
| 863 | return _res; |
| 864 | } |
| 865 | |
| 866 | static PyObject *Res_GetNamedResource(_self, _args) |
| 867 | PyObject *_self; |
| 868 | PyObject *_args; |
| 869 | { |
| 870 | PyObject *_res = NULL; |
| 871 | Handle _rv; |
| 872 | ResType theType; |
| 873 | Str255 name; |
| 874 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 875 | PyMac_GetOSType, &theType, |
| 876 | PyMac_GetStr255, name)) |
| 877 | return NULL; |
| 878 | _rv = GetNamedResource(theType, |
| 879 | name); |
| 880 | { |
| 881 | OSErr _err = ResError(); |
| 882 | if (_err != noErr) return PyMac_Error(_err); |
| 883 | } |
| 884 | _res = Py_BuildValue("O&", |
| 885 | ResObj_New, _rv); |
| 886 | return _res; |
| 887 | } |
| 888 | |
| 889 | static PyObject *Res_Get1NamedResource(_self, _args) |
| 890 | PyObject *_self; |
| 891 | PyObject *_args; |
| 892 | { |
| 893 | PyObject *_res = NULL; |
| 894 | Handle _rv; |
| 895 | ResType theType; |
| 896 | Str255 name; |
| 897 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 898 | PyMac_GetOSType, &theType, |
| 899 | PyMac_GetStr255, name)) |
| 900 | return NULL; |
| 901 | _rv = Get1NamedResource(theType, |
| 902 | name); |
| 903 | { |
| 904 | OSErr _err = ResError(); |
| 905 | if (_err != noErr) return PyMac_Error(_err); |
| 906 | } |
| 907 | _res = Py_BuildValue("O&", |
| 908 | ResObj_New, _rv); |
| 909 | return _res; |
| 910 | } |
| 911 | |
| 912 | static PyObject *Res_UniqueID(_self, _args) |
| 913 | PyObject *_self; |
| 914 | PyObject *_args; |
| 915 | { |
| 916 | PyObject *_res = NULL; |
| 917 | short _rv; |
| 918 | ResType theType; |
| 919 | if (!PyArg_ParseTuple(_args, "O&", |
| 920 | PyMac_GetOSType, &theType)) |
| 921 | return NULL; |
| 922 | _rv = UniqueID(theType); |
| 923 | { |
| 924 | OSErr _err = ResError(); |
| 925 | if (_err != noErr) return PyMac_Error(_err); |
| 926 | } |
| 927 | _res = Py_BuildValue("h", |
| 928 | _rv); |
| 929 | return _res; |
| 930 | } |
| 931 | |
| 932 | static PyObject *Res_Unique1ID(_self, _args) |
| 933 | PyObject *_self; |
| 934 | PyObject *_args; |
| 935 | { |
| 936 | PyObject *_res = NULL; |
| 937 | short _rv; |
| 938 | ResType theType; |
| 939 | if (!PyArg_ParseTuple(_args, "O&", |
| 940 | PyMac_GetOSType, &theType)) |
| 941 | return NULL; |
| 942 | _rv = Unique1ID(theType); |
| 943 | { |
| 944 | OSErr _err = ResError(); |
| 945 | if (_err != noErr) return PyMac_Error(_err); |
| 946 | } |
| 947 | _res = Py_BuildValue("h", |
| 948 | _rv); |
| 949 | return _res; |
| 950 | } |
| 951 | |
| 952 | static PyObject *Res_UpdateResFile(_self, _args) |
| 953 | PyObject *_self; |
| 954 | PyObject *_args; |
| 955 | { |
| 956 | PyObject *_res = NULL; |
| 957 | short refNum; |
| 958 | if (!PyArg_ParseTuple(_args, "h", |
| 959 | &refNum)) |
| 960 | return NULL; |
| 961 | UpdateResFile(refNum); |
| 962 | { |
| 963 | OSErr _err = ResError(); |
| 964 | if (_err != noErr) return PyMac_Error(_err); |
| 965 | } |
| 966 | Py_INCREF(Py_None); |
| 967 | _res = Py_None; |
| 968 | return _res; |
| 969 | } |
| 970 | |
| 971 | static PyObject *Res_SetResPurge(_self, _args) |
| 972 | PyObject *_self; |
| 973 | PyObject *_args; |
| 974 | { |
| 975 | PyObject *_res = NULL; |
| 976 | Boolean install; |
| 977 | if (!PyArg_ParseTuple(_args, "b", |
| 978 | &install)) |
| 979 | return NULL; |
| 980 | SetResPurge(install); |
| 981 | { |
| 982 | OSErr _err = ResError(); |
| 983 | if (_err != noErr) return PyMac_Error(_err); |
| 984 | } |
| 985 | Py_INCREF(Py_None); |
| 986 | _res = Py_None; |
| 987 | return _res; |
| 988 | } |
| 989 | |
| 990 | static PyObject *Res_GetResFileAttrs(_self, _args) |
| 991 | PyObject *_self; |
| 992 | PyObject *_args; |
| 993 | { |
| 994 | PyObject *_res = NULL; |
| 995 | short _rv; |
| 996 | short refNum; |
| 997 | if (!PyArg_ParseTuple(_args, "h", |
| 998 | &refNum)) |
| 999 | return NULL; |
| 1000 | _rv = GetResFileAttrs(refNum); |
| 1001 | { |
| 1002 | OSErr _err = ResError(); |
| 1003 | if (_err != noErr) return PyMac_Error(_err); |
| 1004 | } |
| 1005 | _res = Py_BuildValue("h", |
| 1006 | _rv); |
| 1007 | return _res; |
| 1008 | } |
| 1009 | |
| 1010 | static PyObject *Res_SetResFileAttrs(_self, _args) |
| 1011 | PyObject *_self; |
| 1012 | PyObject *_args; |
| 1013 | { |
| 1014 | PyObject *_res = NULL; |
| 1015 | short refNum; |
| 1016 | short attrs; |
| 1017 | if (!PyArg_ParseTuple(_args, "hh", |
| 1018 | &refNum, |
| 1019 | &attrs)) |
| 1020 | return NULL; |
| 1021 | SetResFileAttrs(refNum, |
| 1022 | attrs); |
| 1023 | { |
| 1024 | OSErr _err = ResError(); |
| 1025 | if (_err != noErr) return PyMac_Error(_err); |
| 1026 | } |
| 1027 | Py_INCREF(Py_None); |
| 1028 | _res = Py_None; |
| 1029 | return _res; |
| 1030 | } |
| 1031 | |
| 1032 | static PyObject *Res_OpenRFPerm(_self, _args) |
| 1033 | PyObject *_self; |
| 1034 | PyObject *_args; |
| 1035 | { |
| 1036 | PyObject *_res = NULL; |
| 1037 | short _rv; |
| 1038 | Str255 fileName; |
| 1039 | short vRefNum; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1040 | SignedByte permission; |
| 1041 | if (!PyArg_ParseTuple(_args, "O&hb", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1042 | PyMac_GetStr255, fileName, |
| 1043 | &vRefNum, |
| 1044 | &permission)) |
| 1045 | return NULL; |
| 1046 | _rv = OpenRFPerm(fileName, |
| 1047 | vRefNum, |
| 1048 | permission); |
| 1049 | { |
| 1050 | OSErr _err = ResError(); |
| 1051 | if (_err != noErr) return PyMac_Error(_err); |
| 1052 | } |
| 1053 | _res = Py_BuildValue("h", |
| 1054 | _rv); |
| 1055 | return _res; |
| 1056 | } |
| 1057 | |
| 1058 | static PyObject *Res_RGetResource(_self, _args) |
| 1059 | PyObject *_self; |
| 1060 | PyObject *_args; |
| 1061 | { |
| 1062 | PyObject *_res = NULL; |
| 1063 | Handle _rv; |
| 1064 | ResType theType; |
| 1065 | short theID; |
| 1066 | if (!PyArg_ParseTuple(_args, "O&h", |
| 1067 | PyMac_GetOSType, &theType, |
| 1068 | &theID)) |
| 1069 | return NULL; |
| 1070 | _rv = RGetResource(theType, |
| 1071 | theID); |
| 1072 | { |
| 1073 | OSErr _err = ResError(); |
| 1074 | if (_err != noErr) return PyMac_Error(_err); |
| 1075 | } |
| 1076 | _res = Py_BuildValue("O&", |
| 1077 | ResObj_New, _rv); |
| 1078 | return _res; |
| 1079 | } |
| 1080 | |
| 1081 | static PyObject *Res_HOpenResFile(_self, _args) |
| 1082 | PyObject *_self; |
| 1083 | PyObject *_args; |
| 1084 | { |
| 1085 | PyObject *_res = NULL; |
| 1086 | short _rv; |
| 1087 | short vRefNum; |
| 1088 | long dirID; |
| 1089 | Str255 fileName; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1090 | SignedByte permission; |
| 1091 | if (!PyArg_ParseTuple(_args, "hlO&b", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1092 | &vRefNum, |
| 1093 | &dirID, |
| 1094 | PyMac_GetStr255, fileName, |
| 1095 | &permission)) |
| 1096 | return NULL; |
| 1097 | _rv = HOpenResFile(vRefNum, |
| 1098 | dirID, |
| 1099 | fileName, |
| 1100 | permission); |
| 1101 | { |
| 1102 | OSErr _err = ResError(); |
| 1103 | if (_err != noErr) return PyMac_Error(_err); |
| 1104 | } |
| 1105 | _res = Py_BuildValue("h", |
| 1106 | _rv); |
| 1107 | return _res; |
| 1108 | } |
| 1109 | |
| 1110 | static PyObject *Res_HCreateResFile(_self, _args) |
| 1111 | PyObject *_self; |
| 1112 | PyObject *_args; |
| 1113 | { |
| 1114 | PyObject *_res = NULL; |
| 1115 | short vRefNum; |
| 1116 | long dirID; |
| 1117 | Str255 fileName; |
| 1118 | if (!PyArg_ParseTuple(_args, "hlO&", |
| 1119 | &vRefNum, |
| 1120 | &dirID, |
| 1121 | PyMac_GetStr255, fileName)) |
| 1122 | return NULL; |
| 1123 | HCreateResFile(vRefNum, |
| 1124 | dirID, |
| 1125 | fileName); |
| 1126 | { |
| 1127 | OSErr _err = ResError(); |
| 1128 | if (_err != noErr) return PyMac_Error(_err); |
| 1129 | } |
| 1130 | Py_INCREF(Py_None); |
| 1131 | _res = Py_None; |
| 1132 | return _res; |
| 1133 | } |
| 1134 | |
| 1135 | static PyObject *Res_FSpOpenResFile(_self, _args) |
| 1136 | PyObject *_self; |
| 1137 | PyObject *_args; |
| 1138 | { |
| 1139 | PyObject *_res = NULL; |
| 1140 | short _rv; |
| 1141 | FSSpec spec; |
| 1142 | SignedByte permission; |
| 1143 | if (!PyArg_ParseTuple(_args, "O&b", |
| 1144 | PyMac_GetFSSpec, &spec, |
| 1145 | &permission)) |
| 1146 | return NULL; |
| 1147 | _rv = FSpOpenResFile(&spec, |
| 1148 | permission); |
| 1149 | { |
| 1150 | OSErr _err = ResError(); |
| 1151 | if (_err != noErr) return PyMac_Error(_err); |
| 1152 | } |
| 1153 | _res = Py_BuildValue("h", |
| 1154 | _rv); |
| 1155 | return _res; |
| 1156 | } |
| 1157 | |
| 1158 | static PyObject *Res_FSpCreateResFile(_self, _args) |
| 1159 | PyObject *_self; |
| 1160 | PyObject *_args; |
| 1161 | { |
| 1162 | PyObject *_res = NULL; |
| 1163 | FSSpec spec; |
| 1164 | OSType creator; |
| 1165 | OSType fileType; |
| 1166 | ScriptCode scriptTag; |
| 1167 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 1168 | PyMac_GetFSSpec, &spec, |
| 1169 | PyMac_GetOSType, &creator, |
| 1170 | PyMac_GetOSType, &fileType, |
| 1171 | &scriptTag)) |
| 1172 | return NULL; |
| 1173 | FSpCreateResFile(&spec, |
| 1174 | creator, |
| 1175 | fileType, |
| 1176 | scriptTag); |
| 1177 | { |
| 1178 | OSErr _err = ResError(); |
| 1179 | if (_err != noErr) return PyMac_Error(_err); |
| 1180 | } |
| 1181 | Py_INCREF(Py_None); |
| 1182 | _res = Py_None; |
| 1183 | return _res; |
| 1184 | } |
| 1185 | |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1186 | static PyObject *Res_Resource(_self, _args) |
| 1187 | PyObject *_self; |
| 1188 | PyObject *_args; |
| 1189 | { |
| 1190 | PyObject *_res = NULL; |
| 1191 | |
| 1192 | char *buf; |
| 1193 | int len; |
| 1194 | Handle h; |
| 1195 | |
| 1196 | if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
| 1197 | return NULL; |
| 1198 | h = NewHandle(len); |
| 1199 | if ( h == NULL ) { |
| 1200 | PyErr_NoMemory(); |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | HLock(h); |
| 1204 | memcpy(*h, buf, len); |
| 1205 | HUnlock(h); |
| 1206 | return (PyObject *)ResObj_New(h); |
| 1207 | |
| 1208 | } |
| 1209 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1210 | static PyMethodDef Res_methods[] = { |
| 1211 | {"InitResources", (PyCFunction)Res_InitResources, 1, |
| 1212 | "() -> (short _rv)"}, |
| 1213 | {"RsrcZoneInit", (PyCFunction)Res_RsrcZoneInit, 1, |
| 1214 | "() -> None"}, |
| 1215 | {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, |
| 1216 | "(short refNum) -> None"}, |
| 1217 | {"ResError", (PyCFunction)Res_ResError, 1, |
| 1218 | "() -> (short _rv)"}, |
| 1219 | {"CurResFile", (PyCFunction)Res_CurResFile, 1, |
| 1220 | "() -> (short _rv)"}, |
| 1221 | {"CreateResFile", (PyCFunction)Res_CreateResFile, 1, |
| 1222 | "(Str255 fileName) -> None"}, |
| 1223 | {"OpenResFile", (PyCFunction)Res_OpenResFile, 1, |
| 1224 | "(Str255 fileName) -> (short _rv)"}, |
| 1225 | {"UseResFile", (PyCFunction)Res_UseResFile, 1, |
| 1226 | "(short refNum) -> None"}, |
| 1227 | {"CountTypes", (PyCFunction)Res_CountTypes, 1, |
| 1228 | "() -> (short _rv)"}, |
| 1229 | {"Count1Types", (PyCFunction)Res_Count1Types, 1, |
| 1230 | "() -> (short _rv)"}, |
| 1231 | {"GetIndType", (PyCFunction)Res_GetIndType, 1, |
| 1232 | "(short index) -> (ResType theType)"}, |
| 1233 | {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, |
| 1234 | "(short index) -> (ResType theType)"}, |
| 1235 | {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, |
| 1236 | "(Boolean load) -> None"}, |
| 1237 | {"CountResources", (PyCFunction)Res_CountResources, 1, |
| 1238 | "(ResType theType) -> (short _rv)"}, |
| 1239 | {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, |
| 1240 | "(ResType theType) -> (short _rv)"}, |
| 1241 | {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, |
| 1242 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1243 | {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, |
| 1244 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1245 | {"GetResource", (PyCFunction)Res_GetResource, 1, |
| 1246 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1247 | {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, |
| 1248 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1249 | {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, |
| 1250 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1251 | {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, |
| 1252 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1253 | {"UniqueID", (PyCFunction)Res_UniqueID, 1, |
| 1254 | "(ResType theType) -> (short _rv)"}, |
| 1255 | {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, |
| 1256 | "(ResType theType) -> (short _rv)"}, |
| 1257 | {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, |
| 1258 | "(short refNum) -> None"}, |
| 1259 | {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, |
| 1260 | "(Boolean install) -> None"}, |
| 1261 | {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, |
| 1262 | "(short refNum) -> (short _rv)"}, |
| 1263 | {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, |
| 1264 | "(short refNum, short attrs) -> None"}, |
| 1265 | {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1266 | "(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1267 | {"RGetResource", (PyCFunction)Res_RGetResource, 1, |
| 1268 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1269 | {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1270 | "(short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1271 | {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, |
| 1272 | "(short vRefNum, long dirID, Str255 fileName) -> None"}, |
| 1273 | {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, |
| 1274 | "(FSSpec spec, SignedByte permission) -> (short _rv)"}, |
| 1275 | {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, |
| 1276 | "(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"}, |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1277 | {"Resource", (PyCFunction)Res_Resource, 1, |
| 1278 | "Convert a string to a resource object.\n\nThe created resource object is actually just a handle.\nApply AddResource() to write it to a resource file.\n"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1279 | {NULL, NULL, 0} |
| 1280 | }; |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | void initRes() |
| 1287 | { |
| 1288 | PyObject *m; |
| 1289 | PyObject *d; |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | m = Py_InitModule("Res", Res_methods); |
| 1296 | d = PyModule_GetDict(m); |
| 1297 | Res_Error = PyMac_GetOSErrException(); |
| 1298 | if (Res_Error == NULL || |
| 1299 | PyDict_SetItemString(d, "Error", Res_Error) != 0) |
| 1300 | Py_FatalError("can't initialize Res.Error"); |
| 1301 | } |
| 1302 | |
| 1303 | /* ========================= End module Res ========================= */ |
| 1304 | |