| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "Python.h" |
| 5 |
|
| 6 |
|
| 7 |
#include "pymactoolbox.h" |
| 8 |
|
| 9 |
|
| 10 |
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ |
| 11 |
PyErr_SetString(PyExc_NotImplementedError, \ |
| 12 |
"Not available in this shared library/OS version"); \ |
| 13 |
return NULL; \ |
| 14 |
}} while(0) |
| 15 |
|
| 16 |
|
| 17 |
#include <Carbon/Carbon.h> |
| 18 |
|
| 19 |
#ifdef USE_TOOLBOX_OBJECT_GLUE |
| 20 |
extern PyObject *_ResObj_New(Handle); |
| 21 |
extern int _ResObj_Convert(PyObject *, Handle *); |
| 22 |
extern PyObject *_OptResObj_New(Handle); |
| 23 |
extern int _OptResObj_Convert(PyObject *, Handle *); |
| 24 |
#define ResObj_New _ResObj_New |
| 25 |
#define ResObj_Convert _ResObj_Convert |
| 26 |
#define OptResObj_New _OptResObj_New |
| 27 |
#define OptResObj_Convert _OptResObj_Convert |
| 28 |
#endif |
| 29 |
|
| 30 |
|
| 31 |
static void |
| 32 |
PyMac_AutoDisposeHandle(Handle h) |
| 33 |
{ |
| 34 |
DisposeHandle(h); |
| 35 |
} |
| 36 |
|
| 37 |
static PyObject *Res_Error; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
PyTypeObject Resource_Type; |
| 42 |
|
| 43 |
#define ResObj_Check(x) ((x)->ob_type == &Resource_Type || PyObject_TypeCheck((x), &Resource_Type)) |
| 44 |
|
| 45 |
typedef struct ResourceObject { |
| 46 |
PyObject_HEAD |
| 47 |
Handle ob_itself; |
| 48 |
void (*ob_freeit)(Handle ptr); |
| 49 |
} ResourceObject; |
| 50 |
|
| 51 |
PyObject *ResObj_New(Handle itself) |
| 52 |
{ |
| 53 |
ResourceObject *it; |
| 54 |
if (itself == NULL) return PyMac_Error(resNotFound); |
| 55 |
it = PyObject_NEW(ResourceObject, &Resource_Type); |
| 56 |
if (it == NULL) return NULL; |
| 57 |
it->ob_itself = itself; |
| 58 |
it->ob_freeit = NULL; |
| 59 |
return (PyObject *)it; |
| 60 |
} |
| 61 |
|
| 62 |
int ResObj_Convert(PyObject *v, Handle *p_itself) |
| 63 |
{ |
| 64 |
if (!ResObj_Check(v)) |
| 65 |
{ |
| 66 |
PyObject *tmp; |
| 67 |
if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) |
| 68 |
{ |
| 69 |
*p_itself = ((ResourceObject *)tmp)->ob_itself; |
| 70 |
Py_DECREF(tmp); |
| 71 |
return 1; |
| 72 |
} |
| 73 |
PyErr_Clear(); |
| 74 |
} |
| 75 |
if (!ResObj_Check(v)) |
| 76 |
{ |
| 77 |
PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 78 |
return 0; |
| 79 |
} |
| 80 |
*p_itself = ((ResourceObject *)v)->ob_itself; |
| 81 |
return 1; |
| 82 |
} |
| 83 |
|
| 84 |
static void ResObj_dealloc(ResourceObject *self) |
| 85 |
{ |
| 86 |
if (self->ob_freeit && self->ob_itself) |
| 87 |
{ |
| 88 |
self->ob_freeit(self->ob_itself); |
| 89 |
} |
| 90 |
self->ob_itself = NULL; |
| 91 |
self->ob_type->tp_free((PyObject *)self); |
| 92 |
} |
| 93 |
|
| 94 |
static PyObject *ResObj_HomeResFile(ResourceObject *_self, PyObject *_args) |
| 95 |
{ |
| 96 |
PyObject *_res = NULL; |
| 97 |
short _rv; |
| 98 |
#ifndef HomeResFile |
| 99 |
PyMac_PRECHECK(HomeResFile); |
| 100 |
#endif |
| 101 |
if (!PyArg_ParseTuple(_args, "")) |
| 102 |
return NULL; |
| 103 |
_rv = HomeResFile(_self->ob_itself); |
| 104 |
{ |
| 105 |
OSErr _err = ResError(); |
| 106 |
if (_err != noErr) return PyMac_Error(_err); |
| 107 |
} |
| 108 |
_res = Py_BuildValue("h", |
| 109 |
_rv); |
| 110 |
return _res; |
| 111 |
} |
| 112 |
|
| 113 |
static PyObject *ResObj_MacLoadResource(ResourceObject *_self, PyObject *_args) |
| 114 |
{ |
| 115 |
PyObject *_res = NULL; |
| 116 |
#ifndef MacLoadResource |
| 117 |
PyMac_PRECHECK(MacLoadResource); |
| 118 |
#endif |
| 119 |
if (!PyArg_ParseTuple(_args, "")) |
| 120 |
return NULL; |
| 121 |
MacLoadResource(_self->ob_itself); |
| 122 |
{ |
| 123 |
OSErr _err = ResError(); |
| 124 |
if (_err != noErr) return PyMac_Error(_err); |
| 125 |
} |
| 126 |
Py_INCREF(Py_None); |
| 127 |
_res = Py_None; |
| 128 |
return _res; |
| 129 |
} |
| 130 |
|
| 131 |
static PyObject *ResObj_ReleaseResource(ResourceObject *_self, PyObject *_args) |
| 132 |
{ |
| 133 |
PyObject *_res = NULL; |
| 134 |
#ifndef ReleaseResource |
| 135 |
PyMac_PRECHECK(ReleaseResource); |
| 136 |
#endif |
| 137 |
if (!PyArg_ParseTuple(_args, "")) |
| 138 |
return NULL; |
| 139 |
ReleaseResource(_self->ob_itself); |
| 140 |
{ |
| 141 |
OSErr _err = ResError(); |
| 142 |
if (_err != noErr) return PyMac_Error(_err); |
| 143 |
} |
| 144 |
Py_INCREF(Py_None); |
| 145 |
_res = Py_None; |
| 146 |
return _res; |
| 147 |
} |
| 148 |
|
| 149 |
static PyObject *ResObj_DetachResource(ResourceObject *_self, PyObject *_args) |
| 150 |
{ |
| 151 |
PyObject *_res = NULL; |
| 152 |
#ifndef DetachResource |
| 153 |
PyMac_PRECHECK(DetachResource); |
| 154 |
#endif |
| 155 |
if (!PyArg_ParseTuple(_args, "")) |
| 156 |
return NULL; |
| 157 |
DetachResource(_self->ob_itself); |
| 158 |
{ |
| 159 |
OSErr _err = ResError(); |
| 160 |
if (_err != noErr) return PyMac_Error(_err); |
| 161 |
} |
| 162 |
Py_INCREF(Py_None); |
| 163 |
_res = Py_None; |
| 164 |
return _res; |
| 165 |
} |
| 166 |
|
| 167 |
static PyObject *ResObj_GetResAttrs(ResourceObject *_self, PyObject *_args) |
| 168 |
{ |
| 169 |
PyObject *_res = NULL; |
| 170 |
short _rv; |
| 171 |
#ifndef GetResAttrs |
| 172 |
PyMac_PRECHECK(GetResAttrs); |
| 173 |
#endif |
| 174 |
if (!PyArg_ParseTuple(_args, "")) |
| 175 |
return NULL; |
| 176 |
_rv = GetResAttrs(_self->ob_itself); |
| 177 |
{ |
| 178 |
OSErr _err = ResError(); |
| 179 |
if (_err != noErr) return PyMac_Error(_err); |
| 180 |
} |
| 181 |
_res = Py_BuildValue("h", |
| 182 |
_rv); |
| 183 |
return _res; |
| 184 |
} |
| 185 |
|
| 186 |
static PyObject *ResObj_GetResInfo(ResourceObject *_self, PyObject *_args) |
| 187 |
{ |
| 188 |
PyObject *_res = NULL; |
| 189 |
short theID; |
| 190 |
ResType theType; |
| 191 |
Str255 name; |
| 192 |
#ifndef GetResInfo |
| 193 |
PyMac_PRECHECK(GetResInfo); |
| 194 |
#endif |
| 195 |
if (!PyArg_ParseTuple(_args, "")) |
| 196 |
return NULL; |
| 197 |
GetResInfo(_self->ob_itself, |
| 198 |
&theID, |
| 199 |
&theType, |
| 200 |
name); |
| 201 |
{ |
| 202 |
OSErr _err = ResError(); |
| 203 |
if (_err != noErr) return PyMac_Error(_err); |
| 204 |
} |
| 205 |
_res = Py_BuildValue("hO&O&", |
| 206 |
theID, |
| 207 |
PyMac_BuildOSType, theType, |
| 208 |
PyMac_BuildStr255, name); |
| 209 |
return _res; |
| 210 |
} |
| 211 |
|
| 212 |
static PyObject *ResObj_SetResInfo(ResourceObject *_self, PyObject *_args) |
| 213 |
{ |
| 214 |
PyObject *_res = NULL; |
| 215 |
short theID; |
| 216 |
Str255 name; |
| 217 |
#ifndef SetResInfo |
| 218 |
PyMac_PRECHECK(SetResInfo); |
| 219 |
#endif |
| 220 |
if (!PyArg_ParseTuple(_args, "hO&", |
| 221 |
&theID, |
| 222 |
PyMac_GetStr255, name)) |
| 223 |
return NULL; |
| 224 |
SetResInfo(_self->ob_itself, |
| 225 |
theID, |
| 226 |
name); |
| 227 |
{ |
| 228 |
OSErr _err = ResError(); |
| 229 |
if (_err != noErr) return PyMac_Error(_err); |
| 230 |
} |
| 231 |
Py_INCREF(Py_None); |
| 232 |
_res = Py_None; |
| 233 |
return _res; |
| 234 |
} |
| 235 |
|
| 236 |
static PyObject *ResObj_AddResource(ResourceObject *_self, PyObject *_args) |
| 237 |
{ |
| 238 |
PyObject *_res = NULL; |
| 239 |
ResType theType; |
| 240 |
short theID; |
| 241 |
Str255 name; |
| 242 |
#ifndef AddResource |
| 243 |
PyMac_PRECHECK(AddResource); |
| 244 |
#endif |
| 245 |
if (!PyArg_ParseTuple(_args, "O&hO&", |
| 246 |
PyMac_GetOSType, &theType, |
| 247 |
&theID, |
| 248 |
PyMac_GetStr255, name)) |
| 249 |
return NULL; |
| 250 |
AddResource(_self->ob_itself, |
| 251 |
theType, |
| 252 |
theID, |
| 253 |
name); |
| 254 |
{ |
| 255 |
OSErr _err = ResError(); |
| 256 |
if (_err != noErr) return PyMac_Error(_err); |
| 257 |
} |
| 258 |
Py_INCREF(Py_None); |
| 259 |
_res = Py_None; |
| 260 |
return _res; |
| 261 |
} |
| 262 |
|
| 263 |
static PyObject *ResObj_GetResourceSizeOnDisk(ResourceObject *_self, PyObject *_args) |
| 264 |
{ |
| 265 |
PyObject *_res = NULL; |
| 266 |
long _rv; |
| 267 |
#ifndef GetResourceSizeOnDisk |
| 268 |
PyMac_PRECHECK(GetResourceSizeOnDisk); |
| 269 |
#endif |
| 270 |
if (!PyArg_ParseTuple(_args, "")) |
| 271 |
return NULL; |
| 272 |
_rv = GetResourceSizeOnDisk(_self->ob_itself); |
| 273 |
{ |
| 274 |
OSErr _err = ResError(); |
| 275 |
if (_err != noErr) return PyMac_Error(_err); |
| 276 |
} |
| 277 |
_res = Py_BuildValue("l", |
| 278 |
_rv); |
| 279 |
return _res; |
| 280 |
} |
| 281 |
|
| 282 |
static PyObject *ResObj_GetMaxResourceSize(ResourceObject *_self, PyObject *_args) |
| 283 |
{ |
| 284 |
PyObject *_res = NULL; |
| 285 |
long _rv; |
| 286 |
#ifndef GetMaxResourceSize |
| 287 |
PyMac_PRECHECK(GetMaxResourceSize); |
| 288 |
#endif |
| 289 |
if (!PyArg_ParseTuple(_args, "")) |
| 290 |
return NULL; |
| 291 |
_rv = GetMaxResourceSize(_self->ob_itself); |
| 292 |
{ |
| 293 |
OSErr _err = ResError(); |
| 294 |
if (_err != noErr) return PyMac_Error(_err); |
| 295 |
} |
| 296 |
_res = Py_BuildValue("l", |
| 297 |
_rv); |
| 298 |
return _res; |
| 299 |
} |
| 300 |
|
| 301 |
static PyObject *ResObj_SetResAttrs(ResourceObject *_self, PyObject *_args) |
| 302 |
{ |
| 303 |
PyObject *_res = NULL; |
| 304 |
short attrs; |
| 305 |
#ifndef SetResAttrs |
| 306 |
PyMac_PRECHECK(SetResAttrs); |
| 307 |
#endif |
| 308 |
if (!PyArg_ParseTuple(_args, "h", |
| 309 |
&attrs)) |
| 310 |
return NULL; |
| 311 |
SetResAttrs(_self->ob_itself, |
| 312 |
attrs); |
| 313 |
{ |
| 314 |
OSErr _err = ResError(); |
| 315 |
if (_err != noErr) return PyMac_Error(_err); |
| 316 |
} |
| 317 |
Py_INCREF(Py_None); |
| 318 |
_res = Py_None; |
| 319 |
return _res; |
| 320 |
} |
| 321 |
|
| 322 |
static PyObject *ResObj_ChangedResource(ResourceObject *_self, PyObject *_args) |
| 323 |
{ |
| 324 |
PyObject *_res = NULL; |
| 325 |
#ifndef ChangedResource |
| 326 |
PyMac_PRECHECK(ChangedResource); |
| 327 |
#endif |
| 328 |
if (!PyArg_ParseTuple(_args, "")) |
| 329 |
return NULL; |
| 330 |
ChangedResource(_self->ob_itself); |
| 331 |
{ |
| 332 |
OSErr _err = ResError(); |
| 333 |
if (_err != noErr) return PyMac_Error(_err); |
| 334 |
} |
| 335 |
Py_INCREF(Py_None); |
| 336 |
_res = Py_None; |
| 337 |
return _res; |
| 338 |
} |
| 339 |
|
| 340 |
static PyObject *ResObj_RemoveResource(ResourceObject *_self, PyObject *_args) |
| 341 |
{ |
| 342 |
PyObject *_res = NULL; |
| 343 |
#ifndef RemoveResource |
| 344 |
PyMac_PRECHECK(RemoveResource); |
| 345 |
#endif |
| 346 |
if (!PyArg_ParseTuple(_args, "")) |
| 347 |
return NULL; |
| 348 |
RemoveResource(_self->ob_itself); |
| 349 |
{ |
| 350 |
OSErr _err = ResError(); |
| 351 |
if (_err != noErr) return PyMac_Error(_err); |
| 352 |
} |
| 353 |
Py_INCREF(Py_None); |
| 354 |
_res = Py_None; |
| 355 |
return _res; |
| 356 |
} |
| 357 |
|
| 358 |
static PyObject *ResObj_WriteResource(ResourceObject *_self, PyObject *_args) |
| 359 |
{ |
| 360 |
PyObject *_res = NULL; |
| 361 |
#ifndef WriteResource |
| 362 |
PyMac_PRECHECK(WriteResource); |
| 363 |
#endif |
| 364 |
if (!PyArg_ParseTuple(_args, "")) |
| 365 |
return NULL; |
| 366 |
WriteResource(_self->ob_itself); |
| 367 |
{ |
| 368 |
OSErr _err = ResError(); |
| 369 |
if (_err != noErr) return PyMac_Error(_err); |
| 370 |
} |
| 371 |
Py_INCREF(Py_None); |
| 372 |
_res = Py_None; |
| 373 |
return _res; |
| 374 |
} |
| 375 |
|
| 376 |
static PyObject *ResObj_SetResourceSize(ResourceObject *_self, PyObject *_args) |
| 377 |
{ |
| 378 |
PyObject *_res = NULL; |
| 379 |
long newSize; |
| 380 |
#ifndef SetResourceSize |
| 381 |
PyMac_PRECHECK(SetResourceSize); |
| 382 |
#endif |
| 383 |
if (!PyArg_ParseTuple(_args, "l", |
| 384 |
&newSize)) |
| 385 |
return NULL; |
| 386 |
SetResourceSize(_self->ob_itself, |
| 387 |
newSize); |
| 388 |
{ |
| 389 |
OSErr _err = ResError(); |
| 390 |
if (_err != noErr) return PyMac_Error(_err); |
| 391 |
} |
| 392 |
Py_INCREF(Py_None); |
| 393 |
_res = Py_None; |
| 394 |
return _res; |
| 395 |
} |
| 396 |
|
| 397 |
static PyObject *ResObj_GetNextFOND(ResourceObject *_self, PyObject *_args) |
| 398 |
{ |
| 399 |
PyObject *_res = NULL; |
| 400 |
Handle _rv; |
| 401 |
#ifndef GetNextFOND |
| 402 |
PyMac_PRECHECK(GetNextFOND); |
| 403 |
#endif |
| 404 |
if (!PyArg_ParseTuple(_args, "")) |
| 405 |
return NULL; |
| 406 |
_rv = GetNextFOND(_self->ob_itself); |
| 407 |
{ |
| 408 |
OSErr _err = ResError(); |
| 409 |
if (_err != noErr) return PyMac_Error(_err); |
| 410 |
} |
| 411 |
_res = Py_BuildValue("O&", |
| 412 |
ResObj_New, _rv); |
| 413 |
return _res; |
| 414 |
} |
| 415 |
|
| 416 |
#ifndef __LP64__ |
| 417 |
static PyObject *ResObj_as_Control(ResourceObject *_self, PyObject *_args) |
| 418 |
{ |
| 419 |
PyObject *_res = NULL; |
| 420 |
|
| 421 |
_res = CtlObj_New((ControlHandle)_self->ob_itself); |
| 422 |
return _res; |
| 423 |
|
| 424 |
} |
| 425 |
|
| 426 |
static PyObject *ResObj_as_Menu(ResourceObject *_self, PyObject *_args) |
| 427 |
{ |
| 428 |
PyObject *_res = NULL; |
| 429 |
|
| 430 |
_res = MenuObj_New((MenuHandle)_self->ob_itself); |
| 431 |
return _res; |
| 432 |
|
| 433 |
} |
| 434 |
#endif |
| 435 |
|
| 436 |
static PyObject *ResObj_LoadResource(ResourceObject *_self, PyObject *_args) |
| 437 |
{ |
| 438 |
PyObject *_res = NULL; |
| 439 |
#ifndef LoadResource |
| 440 |
PyMac_PRECHECK(LoadResource); |
| 441 |
#endif |
| 442 |
if (!PyArg_ParseTuple(_args, "")) |
| 443 |
return NULL; |
| 444 |
LoadResource(_self->ob_itself); |
| 445 |
{ |
| 446 |
OSErr _err = ResError(); |
| 447 |
if (_err != noErr) return PyMac_Error(_err); |
| 448 |
} |
| 449 |
Py_INCREF(Py_None); |
| 450 |
_res = Py_None; |
| 451 |
return _res; |
| 452 |
} |
| 453 |
|
| 454 |
static PyObject *ResObj_AutoDispose(ResourceObject *_self, PyObject *_args) |
| 455 |
{ |
| 456 |
PyObject *_res = NULL; |
| 457 |
|
| 458 |
int onoff, old = 0; |
| 459 |
if (!PyArg_ParseTuple(_args, "i", &onoff)) |
| 460 |
return NULL; |
| 461 |
if ( _self->ob_freeit ) |
| 462 |
old = 1; |
| 463 |
if ( onoff ) |
| 464 |
_self->ob_freeit = PyMac_AutoDisposeHandle; |
| 465 |
else |
| 466 |
_self->ob_freeit = NULL; |
| 467 |
_res = Py_BuildValue("i", old); |
| 468 |
return _res; |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
static PyMethodDef ResObj_methods[] = { |
| 473 |
{"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, |
| 474 |
PyDoc_STR("() -> (short _rv)")}, |
| 475 |
{"MacLoadResource", (PyCFunction)ResObj_MacLoadResource, 1, |
| 476 |
PyDoc_STR("() -> None")}, |
| 477 |
{"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, |
| 478 |
PyDoc_STR("() -> None")}, |
| 479 |
{"DetachResource", (PyCFunction)ResObj_DetachResource, 1, |
| 480 |
PyDoc_STR("() -> None")}, |
| 481 |
{"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, |
| 482 |
PyDoc_STR("() -> (short _rv)")}, |
| 483 |
{"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, |
| 484 |
PyDoc_STR("() -> (short theID, ResType theType, Str255 name)")}, |
| 485 |
{"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, |
| 486 |
PyDoc_STR("(short theID, Str255 name) -> None")}, |
| 487 |
{"AddResource", (PyCFunction)ResObj_AddResource, 1, |
| 488 |
PyDoc_STR("(ResType theType, short theID, Str255 name) -> None")}, |
| 489 |
{"GetResourceSizeOnDisk", (PyCFunction)ResObj_GetResourceSizeOnDisk, 1, |
| 490 |
PyDoc_STR("() -> (long _rv)")}, |
| 491 |
{"GetMaxResourceSize", (PyCFunction)ResObj_GetMaxResourceSize, 1, |
| 492 |
PyDoc_STR("() -> (long _rv)")}, |
| 493 |
{"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, |
| 494 |
PyDoc_STR("(short attrs) -> None")}, |
| 495 |
{"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, |
| 496 |
PyDoc_STR("() -> None")}, |
| 497 |
{"RemoveResource", (PyCFunction)ResObj_RemoveResource, 1, |
| 498 |
PyDoc_STR("() -> None")}, |
| 499 |
{"WriteResource", (PyCFunction)ResObj_WriteResource, 1, |
| 500 |
PyDoc_STR("() -> None")}, |
| 501 |
{"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, |
| 502 |
PyDoc_STR("(long newSize) -> None")}, |
| 503 |
{"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1, |
| 504 |
PyDoc_STR("() -> (Handle _rv)")}, |
| 505 |
#ifndef __LP64__ |
| 506 |
{"as_Control", (PyCFunction)ResObj_as_Control, 1, |
| 507 |
PyDoc_STR("Return this resource/handle as a Control")}, |
| 508 |
{"as_Menu", (PyCFunction)ResObj_as_Menu, 1, |
| 509 |
PyDoc_STR("Return this resource/handle as a Menu")}, |
| 510 |
#endif |
| 511 |
{"LoadResource", (PyCFunction)ResObj_LoadResource, 1, |
| 512 |
PyDoc_STR("() -> None")}, |
| 513 |
{"AutoDispose", (PyCFunction)ResObj_AutoDispose, 1, |
| 514 |
PyDoc_STR("(int)->int. Automatically DisposeHandle the object on Python object cleanup")}, |
| 515 |
{NULL, NULL, 0} |
| 516 |
}; |
| 517 |
|
| 518 |
static PyObject *ResObj_get_data(ResourceObject *self, void *closure) |
| 519 |
{ |
| 520 |
|
| 521 |
PyObject *res; |
| 522 |
char state; |
| 523 |
|
| 524 |
state = HGetState(self->ob_itself); |
| 525 |
HLock(self->ob_itself); |
| 526 |
res = PyString_FromStringAndSize( |
| 527 |
*self->ob_itself, |
| 528 |
GetHandleSize(self->ob_itself)); |
| 529 |
HUnlock(self->ob_itself); |
| 530 |
HSetState(self->ob_itself, state); |
| 531 |
return res; |
| 532 |
|
| 533 |
} |
| 534 |
|
| 535 |
static int ResObj_set_data(ResourceObject *self, PyObject *v, void *closure) |
| 536 |
{ |
| 537 |
|
| 538 |
char *data; |
| 539 |
long size; |
| 540 |
|
| 541 |
if ( v == NULL ) |
| 542 |
return -1; |
| 543 |
if ( !PyString_Check(v) ) |
| 544 |
return -1; |
| 545 |
size = PyString_Size(v); |
| 546 |
data = PyString_AsString(v); |
| 547 |
|
| 548 |
SetHandleSize(self->ob_itself, size); |
| 549 |
if ( MemError()) |
| 550 |
return -1; |
| 551 |
HLock(self->ob_itself); |
| 552 |
memcpy((char *)*self->ob_itself, data, size); |
| 553 |
HUnlock(self->ob_itself); |
| 554 |
|
| 555 |
return 0; |
| 556 |
|
| 557 |
return 0; |
| 558 |
} |
| 559 |
|
| 560 |
static PyObject *ResObj_get_size(ResourceObject *self, void *closure) |
| 561 |
{ |
| 562 |
return PyInt_FromLong(GetHandleSize(self->ob_itself)); |
| 563 |
} |
| 564 |
|
| 565 |
#define ResObj_set_size NULL |
| 566 |
|
| 567 |
static PyGetSetDef ResObj_getsetlist[] = { |
| 568 |
{"data", (getter)ResObj_get_data, (setter)ResObj_set_data, "The resource data"}, |
| 569 |
{"size", (getter)ResObj_get_size, (setter)ResObj_set_size, "The length of the resource data"}, |
| 570 |
{NULL, NULL, NULL, NULL}, |
| 571 |
}; |
| 572 |
|
| 573 |
|
| 574 |
#define ResObj_compare NULL |
| 575 |
|
| 576 |
#define ResObj_repr NULL |
| 577 |
|
| 578 |
#define ResObj_hash NULL |
| 579 |
static int ResObj_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) |
| 580 |
{ |
| 581 |
char *srcdata = NULL; |
| 582 |
int srclen = 0; |
| 583 |
Handle itself; |
| 584 |
char *kw[] = {"itself", 0}; |
| 585 |
|
| 586 |
if (PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, ResObj_Convert, &itself)) |
| 587 |
{ |
| 588 |
((ResourceObject *)_self)->ob_itself = itself; |
| 589 |
return 0; |
| 590 |
} |
| 591 |
PyErr_Clear(); |
| 592 |
if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|s#", kw, &srcdata, &srclen)) return -1; |
| 593 |
if ((itself = NewHandle(srclen)) == NULL) |
| 594 |
{ |
| 595 |
PyErr_NoMemory(); |
| 596 |
return 0; |
| 597 |
} |
| 598 |
((ResourceObject *)_self)->ob_itself = itself; |
| 599 |
if (srclen && srcdata) |
| 600 |
{ |
| 601 |
HLock(itself); |
| 602 |
memcpy(*itself, srcdata, srclen); |
| 603 |
HUnlock(itself); |
| 604 |
} |
| 605 |
return 0; |
| 606 |
} |
| 607 |
|
| 608 |
#define ResObj_tp_alloc PyType_GenericAlloc |
| 609 |
|
| 610 |
static PyObject *ResObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) |
| 611 |
{ |
| 612 |
PyObject *self; |
| 613 |
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL; |
| 614 |
((ResourceObject *)self)->ob_itself = NULL; |
| 615 |
((ResourceObject *)self)->ob_freeit = NULL; |
| 616 |
return self; |
| 617 |
} |
| 618 |
|
| 619 |
#define ResObj_tp_free PyObject_Del |
| 620 |
|
| 621 |
|
| 622 |
PyTypeObject Resource_Type = { |
| 623 |
PyObject_HEAD_INIT(NULL) |
| 624 |
0, |
| 625 |
"_Res.Resource", |
| 626 |
sizeof(ResourceObject), |
| 627 |
0, |
| 628 |
|
| 629 |
(destructor) ResObj_dealloc, |
| 630 |
0, |
| 631 |
(getattrfunc)0, |
| 632 |
(setattrfunc)0, |
| 633 |
(cmpfunc) ResObj_compare, |
| 634 |
(reprfunc) ResObj_repr, |
| 635 |
(PyNumberMethods *)0, |
| 636 |
(PySequenceMethods *)0, |
| 637 |
(PyMappingMethods *)0, |
| 638 |
(hashfunc) ResObj_hash, |
| 639 |
0, |
| 640 |
0, |
| 641 |
PyObject_GenericGetAttr, |
| 642 |
PyObject_GenericSetAttr, |
| 643 |
0, |
| 644 |
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, |
| 645 |
0, |
| 646 |
0, |
| 647 |
0, |
| 648 |
0, |
| 649 |
0, |
| 650 |
0, |
| 651 |
0, |
| 652 |
ResObj_methods, |
| 653 |
0, |
| 654 |
ResObj_getsetlist, |
| 655 |
0, |
| 656 |
0, |
| 657 |
0, |
| 658 |
0, |
| 659 |
0, |
| 660 |
ResObj_tp_init, |
| 661 |
ResObj_tp_alloc, |
| 662 |
ResObj_tp_new, |
| 663 |
ResObj_tp_free, |
| 664 |
}; |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
static PyObject *Res_CloseResFile(PyObject *_self, PyObject *_args) |
| 670 |
{ |
| 671 |
PyObject *_res = NULL; |
| 672 |
short refNum; |
| 673 |
#ifndef CloseResFile |
| 674 |
PyMac_PRECHECK(CloseResFile); |
| 675 |
#endif |
| 676 |
if (!PyArg_ParseTuple(_args, "h", |
| 677 |
&refNum)) |
| 678 |
return NULL; |
| 679 |
CloseResFile(refNum); |
| 680 |
{ |
| 681 |
OSErr _err = ResError(); |
| 682 |
if (_err != noErr) return PyMac_Error(_err); |
| 683 |
} |
| 684 |
Py_INCREF(Py_None); |
| 685 |
_res = Py_None; |
| 686 |
return _res; |
| 687 |
} |
| 688 |
|
| 689 |
static PyObject *Res_ResError(PyObject *_self, PyObject *_args) |
| 690 |
{ |
| 691 |
PyObject *_res = NULL; |
| 692 |
OSErr _err; |
| 693 |
#ifndef ResError |
| 694 |
PyMac_PRECHECK(ResError); |
| 695 |
#endif |
| 696 |
if (!PyArg_ParseTuple(_args, "")) |
| 697 |
return NULL; |
| 698 |
_err = ResError(); |
| 699 |
if (_err != noErr) return PyMac_Error(_err); |
| 700 |
Py_INCREF(Py_None); |
| 701 |
_res = Py_None; |
| 702 |
return _res; |
| 703 |
} |
| 704 |
|
| 705 |
static PyObject *Res_CurResFile(PyObject *_self, PyObject *_args) |
| 706 |
{ |
| 707 |
PyObject *_res = NULL; |
| 708 |
short _rv; |
| 709 |
#ifndef CurResFile |
| 710 |
PyMac_PRECHECK(CurResFile); |
| 711 |
#endif |
| 712 |
if (!PyArg_ParseTuple(_args, "")) |
| 713 |
return NULL; |
| 714 |
_rv = CurResFile(); |
| 715 |
{ |
| 716 |
OSErr _err = ResError(); |
| 717 |
if (_err != noErr) return PyMac_Error(_err); |
| 718 |
} |
| 719 |
_res = Py_BuildValue("h", |
| 720 |
_rv); |
| 721 |
return _res; |
| 722 |
} |
| 723 |
|
| 724 |
static PyObject *Res_UseResFile(PyObject *_self, PyObject *_args) |
| 725 |
{ |
| 726 |
PyObject *_res = NULL; |
| 727 |
short refNum; |
| 728 |
#ifndef UseResFile |
| 729 |
PyMac_PRECHECK(UseResFile); |
| 730 |
#endif |
| 731 |
if (!PyArg_ParseTuple(_args, "h", |
| 732 |
&refNum)) |
| 733 |
return NULL; |
| 734 |
UseResFile(refNum); |
| 735 |
{ |
| 736 |
OSErr _err = ResError(); |
| 737 |
if (_err != noErr) return PyMac_Error(_err); |
| 738 |
} |
| 739 |
Py_INCREF(Py_None); |
| 740 |
_res = Py_None; |
| 741 |
return _res; |
| 742 |
} |
| 743 |
|
| 744 |
static PyObject *Res_CountTypes(PyObject *_self, PyObject *_args) |
| 745 |
{ |
| 746 |
PyObject *_res = NULL; |
| 747 |
short _rv; |
| 748 |
#ifndef CountTypes |
| 749 |
PyMac_PRECHECK(CountTypes); |
| 750 |
#endif |
| 751 |
if (!PyArg_ParseTuple(_args, "")) |
| 752 |
return NULL; |
| 753 |
_rv = CountTypes(); |
| 754 |
{ |
| 755 |
OSErr _err = ResError(); |
| 756 |
if (_err != noErr) return PyMac_Error(_err); |
| 757 |
} |
| 758 |
_res = Py_BuildValue("h", |
| 759 |
_rv); |
| 760 |
return _res; |
| 761 |
} |
| 762 |
|
| 763 |
static PyObject *Res_Count1Types(PyObject *_self, PyObject *_args) |
| 764 |
{ |
| 765 |
PyObject *_res = NULL; |
| 766 |
short _rv; |
| 767 |
#ifndef Count1Types |
| 768 |
PyMac_PRECHECK(Count1Types); |
| 769 |
#endif |
| 770 |
if (!PyArg_ParseTuple(_args, "")) |
| 771 |
return NULL; |
| 772 |
_rv = Count1Types(); |
| 773 |
{ |
| 774 |
OSErr _err = ResError(); |
| 775 |
if (_err != noErr) return PyMac_Error(_err); |
| 776 |
} |
| 777 |
_res = Py_BuildValue("h", |
| 778 |
_rv); |
| 779 |
return _res; |
| 780 |
} |
| 781 |
|
| 782 |
static PyObject *Res_GetIndType(PyObject *_self, PyObject *_args) |
| 783 |
{ |
| 784 |
PyObject *_res = NULL; |
| 785 |
ResType theType; |
| 786 |
short index; |
| 787 |
#ifndef GetIndType |
| 788 |
PyMac_PRECHECK(GetIndType); |
| 789 |
#endif |
| 790 |
if (!PyArg_ParseTuple(_args, "h", |
| 791 |
&index)) |
| 792 |
return NULL; |
| 793 |
GetIndType(&theType, |
| 794 |
index); |
| 795 |
{ |
| 796 |
OSErr _err = ResError(); |
| 797 |
if (_err != noErr) return PyMac_Error(_err); |
| 798 |
} |
| 799 |
_res = Py_BuildValue("O&", |
| 800 |
PyMac_BuildOSType, theType); |
| 801 |
return _res; |
| 802 |
} |
| 803 |
|
| 804 |
static PyObject *Res_Get1IndType(PyObject *_self, PyObject *_args) |
| 805 |
{ |
| 806 |
PyObject *_res = NULL; |
| 807 |
ResType theType; |
| 808 |
short index; |
| 809 |
#ifndef Get1IndType |
| 810 |
PyMac_PRECHECK(Get1IndType); |
| 811 |
#endif |
| 812 |
if (!PyArg_ParseTuple(_args, "h", |
| 813 |
&index)) |
| 814 |
return NULL; |
| 815 |
Get1IndType(&theType, |
| 816 |
index); |
| 817 |
{ |
| 818 |
OSErr _err = ResError(); |
| 819 |
if (_err != noErr) return PyMac_Error(_err); |
| 820 |
} |
| 821 |
_res = Py_BuildValue("O&", |
| 822 |
PyMac_BuildOSType, theType); |
| 823 |
return _res; |
| 824 |
} |
| 825 |
|
| 826 |
static PyObject *Res_SetResLoad(PyObject *_self, PyObject *_args) |
| 827 |
{ |
| 828 |
PyObject *_res = NULL; |
| 829 |
Boolean load; |
| 830 |
#ifndef SetResLoad |
| 831 |
PyMac_PRECHECK(SetResLoad); |
| 832 |
#endif |
| 833 |
if (!PyArg_ParseTuple(_args, "b", |
| 834 |
&load)) |
| 835 |
return NULL; |
| 836 |
SetResLoad(load); |
| 837 |
{ |
| 838 |
OSErr _err = ResError(); |
| 839 |
if (_err != noErr) return PyMac_Error(_err); |
| 840 |
} |
| 841 |
Py_INCREF(Py_None); |
| 842 |
_res = Py_None; |
| 843 |
return _res; |
| 844 |
} |
| 845 |
|
| 846 |
static PyObject *Res_CountResources(PyObject *_self, PyObject *_args) |
| 847 |
{ |
| 848 |
PyObject *_res = NULL; |
| 849 |
short _rv; |
| 850 |
ResType theType; |
| 851 |
#ifndef CountResources |
| 852 |
PyMac_PRECHECK(CountResources); |
| 853 |
#endif |
| 854 |
if (!PyArg_ParseTuple(_args, "O&", |
| 855 |
PyMac_GetOSType, &theType)) |
| 856 |
return NULL; |
| 857 |
_rv = CountResources(theType); |
| 858 |
{ |
| 859 |
OSErr _err = ResError(); |
| 860 |
if (_err != noErr) return PyMac_Error(_err); |
| 861 |
} |
| 862 |
_res = Py_BuildValue("h", |
| 863 |
_rv); |
| 864 |
return _res; |
| 865 |
} |
| 866 |
|
| 867 |
static PyObject *Res_Count1Resources(PyObject *_self, PyObject *_args) |
| 868 |
{ |
| 869 |
PyObject *_res = NULL; |
| 870 |
short _rv; |
| 871 |
ResType theType; |
| 872 |
#ifndef Count1Resources |
| 873 |
PyMac_PRECHECK(Count1Resources); |
| 874 |
#endif |
| 875 |
if (!PyArg_ParseTuple(_args, "O&", |
| 876 |
PyMac_GetOSType, &theType)) |
| 877 |
return NULL; |
| 878 |
_rv = Count1Resources(theType); |
| 879 |
{ |
| 880 |
OSErr _err = ResError(); |
| 881 |
if (_err != noErr) return PyMac_Error(_err); |
| 882 |
} |
| 883 |
_res = Py_BuildValue("h", |
| 884 |
_rv); |
| 885 |
return _res; |
| 886 |
} |
| 887 |
|
| 888 |
static PyObject *Res_GetIndResource(PyObject *_self, PyObject *_args) |
| 889 |
{ |
| 890 |
PyObject *_res = NULL; |
| 891 |
Handle _rv; |
| 892 |
ResType theType; |
| 893 |
short index; |
| 894 |
#ifndef GetIndResource |
| 895 |
PyMac_PRECHECK(GetIndResource); |
| 896 |
#endif |
| 897 |
if (!PyArg_ParseTuple(_args, "O&h", |
| 898 |
PyMac_GetOSType, &theType, |
| 899 |
&index)) |
| 900 |
return NULL; |
| 901 |
_rv = GetIndResource(theType, |
| 902 |
index); |
| 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_Get1IndResource(PyObject *_self, PyObject *_args) |
| 913 |
{ |
| 914 |
PyObject *_res = NULL; |
| 915 |
Handle _rv; |
| 916 |
ResType theType; |
| 917 |
short index; |
| 918 |
#ifndef Get1IndResource |
| 919 |
PyMac_PRECHECK(Get1IndResource); |
| 920 |
#endif |
| 921 |
if (!PyArg_ParseTuple(_args, "O&h", |
| 922 |
PyMac_GetOSType, &theType, |
| 923 |
&index)) |
| 924 |
return NULL; |
| 925 |
_rv = Get1IndResource(theType, |
| 926 |
index); |
| 927 |
{ |
| 928 |
OSErr _err = ResError(); |
| 929 |
if (_err != noErr) return PyMac_Error(_err); |
| 930 |
} |
| 931 |
_res = Py_BuildValue("O&", |
| 932 |
ResObj_New, _rv); |
| 933 |
return _res; |
| 934 |
} |
| 935 |
|
| 936 |
static PyObject *Res_GetResource(PyObject *_self, PyObject *_args) |
| 937 |
{ |
| 938 |
PyObject *_res = NULL; |
| 939 |
Handle _rv; |
| 940 |
ResType theType; |
| 941 |
short theID; |
| 942 |
#ifndef GetResource |
| 943 |
PyMac_PRECHECK(GetResource); |
| 944 |
#endif |
| 945 |
if (!PyArg_ParseTuple(_args, "O&h", |
| 946 |
PyMac_GetOSType, &theType, |
| 947 |
&theID)) |
| 948 |
return NULL; |
| 949 |
_rv = GetResource(theType, |
| 950 |
theID); |
| 951 |
{ |
| 952 |
OSErr _err = ResError(); |
| 953 |
if (_err != noErr) return PyMac_Error(_err); |
| 954 |
} |
| 955 |
_res = Py_BuildValue("O&", |
| 956 |
ResObj_New, _rv); |
| 957 |
return _res; |
| 958 |
} |
| 959 |
|
| 960 |
static PyObject *Res_Get1Resource(PyObject *_self, PyObject *_args) |
| 961 |
{ |
| 962 |
PyObject *_res = NULL; |
| 963 |
Handle _rv; |
| 964 |
ResType theType; |
| 965 |
short theID; |
| 966 |
#ifndef Get1Resource |
| 967 |
PyMac_PRECHECK(Get1Resource); |
| 968 |
#endif |
| 969 |
if (!PyArg_ParseTuple(_args, "O&h", |
| 970 |
PyMac_GetOSType, &theType, |
| 971 |
&theID)) |
| 972 |
return NULL; |
| 973 |
_rv = Get1Resource(theType, |
| 974 |
theID); |
| 975 |
{ |
| 976 |
OSErr _err = ResError(); |
| 977 |
if (_err != noErr) return PyMac_Error(_err); |
| 978 |
} |
| 979 |
_res = Py_BuildValue("O&", |
| 980 |
ResObj_New, _rv); |
| 981 |
return _res; |
| 982 |
} |
| 983 |
|
| 984 |
static PyObject *Res_GetNamedResource(PyObject *_self, PyObject *_args) |
| 985 |
{ |
| 986 |
PyObject *_res = NULL; |
| 987 |
Handle _rv; |
| 988 |
ResType theType; |
| 989 |
Str255 name; |
| 990 |
#ifndef GetNamedResource |
| 991 |
PyMac_PRECHECK(GetNamedResource); |
| 992 |
#endif |
| 993 |
if (!PyArg_ParseTuple(_args, "O&O&", |
| 994 |
PyMac_GetOSType, &theType, |
| 995 |
PyMac_GetStr255, name)) |
| 996 |
return NULL; |
| 997 |
_rv = GetNamedResource(theType, |
| 998 |
name); |
| 999 |
{ |
| 1000 |
OSErr _err = ResError(); |
| 1001 |
if (_err != noErr) return PyMac_Error(_err); |
| 1002 |
} |
| 1003 |
_res = Py_BuildValue("O&", |
| 1004 |
ResObj_New, _rv); |
| 1005 |
return _res; |
| 1006 |
} |
| 1007 |
|
| 1008 |
static PyObject *Res_Get1NamedResource(PyObject *_self, PyObject *_args) |
| 1009 |
{ |
| 1010 |
PyObject *_res = NULL; |
| 1011 |
Handle _rv; |
| 1012 |
ResType theType; |
| 1013 |
Str255 name; |
| 1014 |
#ifndef Get1NamedResource |
| 1015 |
PyMac_PRECHECK(Get1NamedResource); |
| 1016 |
#endif |
| 1017 |
if (!PyArg_ParseTuple(_args, "O&O&", |
| 1018 |
PyMac_GetOSType, &theType, |
| 1019 |
PyMac_GetStr255, name)) |
| 1020 |
return NULL; |
| 1021 |
_rv = Get1NamedResource(theType, |
| 1022 |
name); |
| 1023 |
{ |
| 1024 |
OSErr _err = ResError(); |
| 1025 |
if (_err != noErr) return PyMac_Error(_err); |
| 1026 |
} |
| 1027 |
_res = Py_BuildValue("O&", |
| 1028 |
ResObj_New, _rv); |
| 1029 |
return _res; |
| 1030 |
} |
| 1031 |
|
| 1032 |
static PyObject *Res_UniqueID(PyObject *_self, PyObject *_args) |
| 1033 |
{ |
| 1034 |
PyObject *_res = NULL; |
| 1035 |
short _rv; |
| 1036 |
ResType theType; |
| 1037 |
#ifndef UniqueID |
| 1038 |
PyMac_PRECHECK(UniqueID); |
| 1039 |
#endif |
| 1040 |
if (!PyArg_ParseTuple(_args, "O&", |
| 1041 |
PyMac_GetOSType, &theType)) |
| 1042 |
return NULL; |
| 1043 |
_rv = UniqueID(theType); |
| 1044 |
{ |
| 1045 |
OSErr _err = ResError(); |
| 1046 |
if (_err != noErr) return PyMac_Error(_err); |
| 1047 |
} |
| 1048 |
_res = Py_BuildValue("h", |
| 1049 |
_rv); |
| 1050 |
return _res; |
| 1051 |
} |
| 1052 |
|
| 1053 |
static PyObject *Res_Unique1ID(PyObject *_self, PyObject *_args) |
| 1054 |
{ |
| 1055 |
PyObject *_res = NULL; |
| 1056 |
short _rv; |
| 1057 |
ResType theType; |
| 1058 |
#ifndef Unique1ID |
| 1059 |
PyMac_PRECHECK(Unique1ID); |
| 1060 |
#endif |
| 1061 |
if (!PyArg_ParseTuple(_args, "O&", |
| 1062 |
PyMac_GetOSType, &theType)) |
| 1063 |
return NULL; |
| 1064 |
_rv = Unique1ID(theType); |
| 1065 |
{ |
| 1066 |
OSErr _err = ResError(); |
| 1067 |
if (_err != noErr) return PyMac_Error(_err); |
| 1068 |
} |
| 1069 |
_res = Py_BuildValue("h", |
| 1070 |
_rv); |
| 1071 |
return _res; |
| 1072 |
} |
| 1073 |
|
| 1074 |
static PyObject *Res_UpdateResFile(PyObject *_self, PyObject *_args) |
| 1075 |
{ |
| 1076 |
PyObject *_res = NULL; |
| 1077 |
short refNum; |
| 1078 |
#ifndef UpdateResFile |
| 1079 |
PyMac_PRECHECK(UpdateResFile); |
| 1080 |
#endif |
| 1081 |
if (!PyArg_ParseTuple(_args, "h", |
| 1082 |
&refNum)) |
| 1083 |
return NULL; |
| 1084 |
UpdateResFile(refNum); |
| 1085 |
{ |
| 1086 |
OSErr _err = ResError(); |
| 1087 |
if (_err != noErr) return PyMac_Error(_err); |
| 1088 |
} |
| 1089 |
Py_INCREF(Py_None); |
| 1090 |
_res = Py_None; |
| 1091 |
return _res; |
| 1092 |
} |
| 1093 |
|
| 1094 |
static PyObject *Res_SetResPurge(PyObject *_self, PyObject *_args) |
| 1095 |
{ |
| 1096 |
PyObject *_res = NULL; |
| 1097 |
Boolean install; |
| 1098 |
#ifndef SetResPurge |
| 1099 |
PyMac_PRECHECK(SetResPurge); |
| 1100 |
#endif |
| 1101 |
if (!PyArg_ParseTuple(_args, "b", |
| 1102 |
&install)) |
| 1103 |
return NULL; |
| 1104 |
SetResPurge(install); |
| 1105 |
{ |
| 1106 |
OSErr _err = ResError(); |
| 1107 |
if (_err != noErr) return PyMac_Error(_err); |
| 1108 |
} |
| 1109 |
Py_INCREF(Py_None); |
| 1110 |
_res = Py_None; |
| 1111 |
return _res; |
| 1112 |
} |
| 1113 |
|
| 1114 |
static PyObject *Res_GetResFileAttrs(PyObject *_self, PyObject *_args) |
| 1115 |
{ |
| 1116 |
PyObject *_res = NULL; |
| 1117 |
short _rv; |
| 1118 |
short refNum; |
| 1119 |
#ifndef GetResFileAttrs |
| 1120 |
PyMac_PRECHECK(GetResFileAttrs); |
| 1121 |
#endif |
| 1122 |
if (!PyArg_ParseTuple(_args, "h", |
| 1123 |
&refNum)) |
| 1124 |
return NULL; |
| 1125 |
_rv = GetResFileAttrs(refNum); |
| 1126 |
{ |
| 1127 |
OSErr _err = ResError(); |
| 1128 |
if (_err != noErr) return PyMac_Error(_err); |
| 1129 |
} |
| 1130 |
_res = Py_BuildValue("h", |
| 1131 |
_rv); |
| 1132 |
return _res; |
| 1133 |
} |
| 1134 |
|
| 1135 |
static PyObject *Res_SetResFileAttrs(PyObject *_self, PyObject *_args) |
| 1136 |
{ |
| 1137 |
PyObject *_res = NULL; |
| 1138 |
short refNum; |
| 1139 |
short attrs; |
| 1140 |
#ifndef SetResFileAttrs |
| 1141 |
PyMac_PRECHECK(SetResFileAttrs); |
| 1142 |
#endif |
| 1143 |
if (!PyArg_ParseTuple(_args, "hh", |
| 1144 |
&refNum, |
| 1145 |
&attrs)) |
| 1146 |
return NULL; |
| 1147 |
SetResFileAttrs(refNum, |
| 1148 |
attrs); |
| 1149 |
{ |
| 1150 |
OSErr _err = ResError(); |
| 1151 |
if (_err != noErr) return PyMac_Error(_err); |
| 1152 |
} |
| 1153 |
Py_INCREF(Py_None); |
| 1154 |
_res = Py_None; |
| 1155 |
return _res; |
| 1156 |
} |
| 1157 |
|
| 1158 |
#ifndef __LP64__ |
| 1159 |
static PyObject *Res_OpenRFPerm(PyObject *_self, PyObject *_args) |
| 1160 |
{ |
| 1161 |
PyObject *_res = NULL; |
| 1162 |
short _rv; |
| 1163 |
Str255 fileName; |
| 1164 |
short vRefNum; |
| 1165 |
SignedByte permission; |
| 1166 |
#ifndef OpenRFPerm |
| 1167 |
PyMac_PRECHECK(OpenRFPerm); |
| 1168 |
#endif |
| 1169 |
if (!PyArg_ParseTuple(_args, "O&hb", |
| 1170 |
PyMac_GetStr255, fileName, |
| 1171 |
&vRefNum, |
| 1172 |
&permission)) |
| 1173 |
return NULL; |
| 1174 |
_rv = OpenRFPerm(fileName, |
| 1175 |
vRefNum, |
| 1176 |
permission); |
| 1177 |
{ |
| 1178 |
OSErr _err = ResError(); |
| 1179 |
if (_err != noErr) return PyMac_Error(_err); |
| 1180 |
} |
| 1181 |
_res = Py_BuildValue("h", |
| 1182 |
_rv); |
| 1183 |
return _res; |
| 1184 |
} |
| 1185 |
|
| 1186 |
static PyObject *Res_HOpenResFile(PyObject *_self, PyObject *_args) |
| 1187 |
{ |
| 1188 |
PyObject *_res = NULL; |
| 1189 |
short _rv; |
| 1190 |
short vRefNum; |
| 1191 |
long dirID; |
| 1192 |
Str255 fileName; |
| 1193 |
SignedByte permission; |
| 1194 |
#ifndef HOpenResFile |
| 1195 |
PyMac_PRECHECK(HOpenResFile); |
| 1196 |
#endif |
| 1197 |
if (!PyArg_ParseTuple(_args, "hlO&b", |
| 1198 |
&vRefNum, |
| 1199 |
&dirID, |
| 1200 |
PyMac_GetStr255, fileName, |
| 1201 |
&permission)) |
| 1202 |
return NULL; |
| 1203 |
_rv = HOpenResFile(vRefNum, |
| 1204 |
dirID, |
| 1205 |
fileName, |
| 1206 |
permission); |
| 1207 |
{ |
| 1208 |
OSErr _err = ResError(); |
| 1209 |
if (_err != noErr) return PyMac_Error(_err); |
| 1210 |
} |
| 1211 |
_res = Py_BuildValue("h", |
| 1212 |
_rv); |
| 1213 |
return _res; |
| 1214 |
} |
| 1215 |
|
| 1216 |
static PyObject *Res_HCreateResFile(PyObject *_self, PyObject *_args) |
| 1217 |
{ |
| 1218 |
PyObject *_res = NULL; |
| 1219 |
short vRefNum; |
| 1220 |
long dirID; |
| 1221 |
Str255 fileName; |
| 1222 |
#ifndef HCreateResFile |
| 1223 |
PyMac_PRECHECK(HCreateResFile); |
| 1224 |
#endif |
| 1225 |
if (!PyArg_ParseTuple(_args, "hlO&", |
| 1226 |
&vRefNum, |
| 1227 |
&dirID, |
| 1228 |
PyMac_GetStr255, fileName)) |
| 1229 |
return NULL; |
| 1230 |
HCreateResFile(vRefNum, |
| 1231 |
dirID, |
| 1232 |
fileName); |
| 1233 |
{ |
| 1234 |
OSErr _err = ResError(); |
| 1235 |
if (_err != noErr) return PyMac_Error(_err); |
| 1236 |
} |
| 1237 |
Py_INCREF(Py_None); |
| 1238 |
_res = Py_None; |
| 1239 |
return _res; |
| 1240 |
} |
| 1241 |
|
| 1242 |
static PyObject *Res_FSpOpenResFile(PyObject *_self, PyObject *_args) |
| 1243 |
{ |
| 1244 |
PyObject *_res = NULL; |
| 1245 |
short _rv; |
| 1246 |
FSSpec spec; |
| 1247 |
SignedByte permission; |
| 1248 |
#ifndef FSpOpenResFile |
| 1249 |
PyMac_PRECHECK(FSpOpenResFile); |
| 1250 |
#endif |
| 1251 |
if (!PyArg_ParseTuple(_args, "O&b", |
| 1252 |
PyMac_GetFSSpec, &spec, |
| 1253 |
&permission)) |
| 1254 |
return NULL; |
| 1255 |
_rv = FSpOpenResFile(&spec, |
| 1256 |
permission); |
| 1257 |
{ |
| 1258 |
OSErr _err = ResError(); |
| 1259 |
if (_err != noErr) return PyMac_Error(_err); |
| 1260 |
} |
| 1261 |
_res = Py_BuildValue("h", |
| 1262 |
_rv); |
| 1263 |
return _res; |
| 1264 |
} |
| 1265 |
|
| 1266 |
static PyObject *Res_FSpCreateResFile(PyObject *_self, PyObject *_args) |
| 1267 |
{ |
| 1268 |
PyObject *_res = NULL; |
| 1269 |
FSSpec spec; |
| 1270 |
OSType creator; |
| 1271 |
OSType fileType; |
| 1272 |
ScriptCode scriptTag; |
| 1273 |
#ifndef FSpCreateResFile |
| 1274 |
PyMac_PRECHECK(FSpCreateResFile); |
| 1275 |
#endif |
| 1276 |
if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 1277 |
PyMac_GetFSSpec, &spec, |
| 1278 |
PyMac_GetOSType, &creator, |
| 1279 |
PyMac_GetOSType, &fileType, |
| 1280 |
&scriptTag)) |
| 1281 |
return NULL; |
| 1282 |
FSpCreateResFile(&spec, |
| 1283 |
creator, |
| 1284 |
fileType, |
| 1285 |
scriptTag); |
| 1286 |
{ |
| 1287 |
OSErr _err = ResError(); |
| 1288 |
if (_err != noErr) return PyMac_Error(_err); |
| 1289 |
} |
| 1290 |
Py_INCREF(Py_None); |
| 1291 |
_res = Py_None; |
| 1292 |
return _res; |
| 1293 |
} |
| 1294 |
#endif |
| 1295 |
|
| 1296 |
static PyObject *Res_InsertResourceFile(PyObject *_self, PyObject *_args) |
| 1297 |
{ |
| 1298 |
PyObject *_res = NULL; |
| 1299 |
OSErr _err; |
| 1300 |
SInt16 refNum; |
| 1301 |
RsrcChainLocation where; |
| 1302 |
#ifndef InsertResourceFile |
| 1303 |
PyMac_PRECHECK(InsertResourceFile); |
| 1304 |
#endif |
| 1305 |
if (!PyArg_ParseTuple(_args, "hh", |
| 1306 |
&refNum, |
| 1307 |
&where)) |
| 1308 |
return NULL; |
| 1309 |
_err = InsertResourceFile(refNum, |
| 1310 |
where); |
| 1311 |
if (_err != noErr) return PyMac_Error(_err); |
| 1312 |
Py_INCREF(Py_None); |
| 1313 |
_res = Py_None; |
| 1314 |
return _res; |
| 1315 |
} |
| 1316 |
|
| 1317 |
static PyObject *Res_DetachResourceFile(PyObject *_self, PyObject *_args) |
| 1318 |
{ |
| 1319 |
PyObject *_res = NULL; |
| 1320 |
OSErr _err; |
| 1321 |
SInt16 refNum; |
| 1322 |
#ifndef DetachResourceFile |
| 1323 |
PyMac_PRECHECK(DetachResourceFile); |
| 1324 |
#endif |
| 1325 |
if (!PyArg_ParseTuple(_args, "h", |
| 1326 |
&refNum)) |
| 1327 |
return NULL; |
| 1328 |
_err = DetachResourceFile(refNum); |
| 1329 |
if (_err != noErr) return PyMac_Error(_err); |
| 1330 |
Py_INCREF(Py_None); |
| 1331 |
_res = Py_None; |
| 1332 |
return _res; |
| 1333 |
} |
| 1334 |
|
| 1335 |
#ifndef __LP64__ |
| 1336 |
static PyObject *Res_FSpResourceFileAlreadyOpen(PyObject *_self, PyObject *_args) |
| 1337 |
{ |
| 1338 |
PyObject *_res = NULL; |
| 1339 |
Boolean _rv; |
| 1340 |
FSSpec resourceFile; |
| 1341 |
Boolean inChain; |
| 1342 |
SInt16 refNum; |
| 1343 |
#ifndef FSpResourceFileAlreadyOpen |
| 1344 |
PyMac_PRECHECK(FSpResourceFileAlreadyOpen); |
| 1345 |
#endif |
| 1346 |
if (!PyArg_ParseTuple(_args, "O&", |
| 1347 |
PyMac_GetFSSpec, &resourceFile)) |
| 1348 |
return NULL; |
| 1349 |
_rv = FSpResourceFileAlreadyOpen(&resourceFile, |
| 1350 |
&inChain, |
| 1351 |
&refNum); |
| 1352 |
{ |
| 1353 |
OSErr _err = ResError(); |
| 1354 |
if (_err != noErr) return PyMac_Error(_err); |
| 1355 |
} |
| 1356 |
_res = Py_BuildValue("bbh", |
| 1357 |
_rv, |
| 1358 |
inChain, |
| 1359 |
refNum); |
| 1360 |
return _res; |
| 1361 |
} |
| 1362 |
|
| 1363 |
static PyObject *Res_FSpOpenOrphanResFile(PyObject *_self, PyObject *_args) |
| 1364 |
{ |
| 1365 |
PyObject *_res = NULL; |
| 1366 |
OSErr _err; |
| 1367 |
FSSpec spec; |
| 1368 |
SignedByte permission; |
| 1369 |
SInt16 refNum; |
| 1370 |
#ifndef FSpOpenOrphanResFile |
| 1371 |
PyMac_PRECHECK(FSpOpenOrphanResFile); |
| 1372 |
#endif |
| 1373 |
if (!PyArg_ParseTuple(_args, "O&b", |
| 1374 |
PyMac_GetFSSpec, &spec, |
| 1375 |
&permission)) |
| 1376 |
return NULL; |
| 1377 |
_err = FSpOpenOrphanResFile(&spec, |
| 1378 |
permission, |
| 1379 |
&refNum); |
| 1380 |
if (_err != noErr) return PyMac_Error(_err); |
| 1381 |
_res = Py_BuildValue("h", |
| 1382 |
refNum); |
| 1383 |
return _res; |
| 1384 |
} |
| 1385 |
|
| 1386 |
static PyObject *Res_GetTopResourceFile(PyObject *_self, PyObject *_args) |
| 1387 |
{ |
| 1388 |
PyObject *_res = NULL; |
| 1389 |
OSErr _err; |
| 1390 |
SInt16 refNum; |
| 1391 |
#ifndef GetTopResourceFile |
| 1392 |
PyMac_PRECHECK(GetTopResourceFile); |
| 1393 |
#endif |
| 1394 |
if (!PyArg_ParseTuple(_args, "")) |
| 1395 |
return NULL; |
| 1396 |
_err = GetTopResourceFile(&refNum); |
| 1397 |
if (_err != noErr) return PyMac_Error(_err); |
| 1398 |
_res = Py_BuildValue("h", |
| 1399 |
refNum); |
| 1400 |
return _res; |
| 1401 |
} |
| 1402 |
|
| 1403 |
|
| 1404 |
static PyObject *Res_GetNextResourceFile(PyObject *_self, PyObject *_args) |
| 1405 |
{ |
| 1406 |
PyObject *_res = NULL; |
| 1407 |
OSErr _err; |
| 1408 |
SInt16 curRefNum; |
| 1409 |
SInt16 nextRefNum; |
| 1410 |
#ifndef GetNextResourceFile |
| 1411 |
PyMac_PRECHECK(GetNextResourceFile); |
| 1412 |
#endif |
| 1413 |
if (!PyArg_ParseTuple(_args, "h", |
| 1414 |
&curRefNum)) |
| 1415 |
return NULL; |
| 1416 |
_err = GetNextResourceFile(curRefNum, |
| 1417 |
&nextRefNum); |
| 1418 |
if (_err != noErr) return PyMac_Error(_err); |
| 1419 |
_res = Py_BuildValue("h", |
| 1420 |
nextRefNum); |
| 1421 |
return _res; |
| 1422 |
} |
| 1423 |
#endif |
| 1424 |
|
| 1425 |
static PyObject *Res_FSOpenResFile(PyObject *_self, PyObject *_args) |
| 1426 |
{ |
| 1427 |
PyObject *_res = NULL; |
| 1428 |
short _rv; |
| 1429 |
FSRef ref; |
| 1430 |
SignedByte permission; |
| 1431 |
#ifndef FSOpenResFile |
| 1432 |
PyMac_PRECHECK(FSOpenResFile); |
| 1433 |
#endif |
| 1434 |
if (!PyArg_ParseTuple(_args, "O&b", |
| 1435 |
PyMac_GetFSRef, &ref, |
| 1436 |
&permission)) |
| 1437 |
return NULL; |
| 1438 |
_rv = FSOpenResFile(&ref, |
| 1439 |
permission); |
| 1440 |
{ |
| 1441 |
OSErr _err = ResError(); |
| 1442 |
if (_err != noErr) return PyMac_Error(_err); |
| 1443 |
} |
| 1444 |
_res = Py_BuildValue("h", |
| 1445 |
_rv); |
| 1446 |
return _res; |
| 1447 |
} |
| 1448 |
|
| 1449 |
|
| 1450 |
#ifndef __LP64__ |
| 1451 |
static PyObject *Res_FSCreateResFile(PyObject *_self, PyObject *_args) |
| 1452 |
{ |
| 1453 |
PyObject *_res = NULL; |
| 1454 |
FSRef parentRef; |
| 1455 |
UniChar *nameLength__in__; |
| 1456 |
UniCharCount nameLength__len__; |
| 1457 |
int nameLength__in_len__; |
| 1458 |
FSRef newRef; |
| 1459 |
FSSpec newSpec; |
| 1460 |
#ifndef FSCreateResFile |
| 1461 |
PyMac_PRECHECK(FSCreateResFile); |
| 1462 |
#endif |
| 1463 |
if (!PyArg_ParseTuple(_args, "O&u#", |
| 1464 |
PyMac_GetFSRef, &parentRef, |
| 1465 |
&nameLength__in__, &nameLength__in_len__)) |
| 1466 |
return NULL; |
| 1467 |
nameLength__len__ = nameLength__in_len__; |
| 1468 |
FSCreateResFile(&parentRef, |
| 1469 |
nameLength__len__, nameLength__in__, |
| 1470 |
0, |
| 1471 |
(FSCatalogInfo *)0, |
| 1472 |
&newRef, |
| 1473 |
&newSpec); |
| 1474 |
{ |
| 1475 |
OSErr _err = ResError(); |
| 1476 |
if (_err != noErr) return PyMac_Error(_err); |
| 1477 |
} |
| 1478 |
_res = Py_BuildValue("O&O&", |
| 1479 |
PyMac_BuildFSRef, &newRef, |
| 1480 |
PyMac_BuildFSSpec, &newSpec); |
| 1481 |
return _res; |
| 1482 |
} |
| 1483 |
|
| 1484 |
static PyObject *Res_FSResourceFileAlreadyOpen(PyObject *_self, PyObject *_args) |
| 1485 |
{ |
| 1486 |
PyObject *_res = NULL; |
| 1487 |
Boolean _rv; |
| 1488 |
FSRef resourceFileRef; |
| 1489 |
Boolean inChain; |
| 1490 |
SInt16 refNum; |
| 1491 |
#ifndef FSResourceFileAlreadyOpen |
| 1492 |
PyMac_PRECHECK(FSResourceFileAlreadyOpen); |
| 1493 |
#endif |
| 1494 |
if (!PyArg_ParseTuple(_args, "O&", |
| 1495 |
PyMac_GetFSRef, &resourceFileRef)) |
| 1496 |
return NULL; |
| 1497 |
_rv = FSResourceFileAlreadyOpen(&resourceFileRef, |
| 1498 |
&inChain, |
| 1499 |
&refNum); |
| 1500 |
{ |
| 1501 |
OSErr _err = ResError(); |
| 1502 |
if (_err != noErr) return PyMac_Error(_err); |
| 1503 |
} |
| 1504 |
_res = Py_BuildValue("bbh", |
| 1505 |
_rv, |
| 1506 |
inChain, |
| 1507 |
refNum); |
| 1508 |
return _res; |
| 1509 |
} |
| 1510 |
|
| 1511 |
static PyObject *Res_FSCreateResourceFile(PyObject *_self, PyObject *_args) |
| 1512 |
{ |
| 1513 |
PyObject *_res = NULL; |
| 1514 |
OSErr _err; |
| 1515 |
FSRef parentRef; |
| 1516 |
UniChar *nameLength__in__; |
| 1517 |
UniCharCount nameLength__len__; |
| 1518 |
int nameLength__in_len__; |
| 1519 |
UniChar *forkNameLength__in__; |
| 1520 |
UniCharCount forkNameLength__len__; |
| 1521 |
int forkNameLength__in_len__; |
| 1522 |
FSRef newRef; |
| 1523 |
FSSpec newSpec; |
| 1524 |
#ifndef FSCreateResourceFile |
| 1525 |
PyMac_PRECHECK(FSCreateResourceFile); |
| 1526 |
#endif |
| 1527 |
if (!PyArg_ParseTuple(_args, "O&u#u#", |
| 1528 |
PyMac_GetFSRef, &parentRef, |
| 1529 |
&nameLength__in__, &nameLength__in_len__, |
| 1530 |
&forkNameLength__in__, &forkNameLength__in_len__)) |
| 1531 |
return NULL; |
| 1532 |
nameLength__len__ = nameLength__in_len__; |
| 1533 |
forkNameLength__len__ = forkNameLength__in_len__; |
| 1534 |
_err = FSCreateResourceFile(&parentRef, |
| 1535 |
nameLength__len__, nameLength__in__, |
| 1536 |
0, |
| 1537 |
(FSCatalogInfo *)0, |
| 1538 |
forkNameLength__len__, forkNameLength__in__, |
| 1539 |
&newRef, |
| 1540 |
&newSpec); |
| 1541 |
if (_err != noErr) return PyMac_Error(_err); |
| 1542 |
_res = Py_BuildValue("O&O&", |
| 1543 |
PyMac_BuildFSRef, &newRef, |
| 1544 |
PyMac_BuildFSSpec, &newSpec); |
| 1545 |
return _res; |
| 1546 |
} |
| 1547 |
#endif |
| 1548 |
|
| 1549 |
static PyObject *Res_FSOpenResourceFile(PyObject *_self, PyObject *_args) |
| 1550 |
{ |
| 1551 |
PyObject *_res = NULL; |
| 1552 |
OSErr _err; |
| 1553 |
FSRef ref; |
| 1554 |
UniChar *forkNameLength__in__; |
| 1555 |
UniCharCount forkNameLength__len__; |
| 1556 |
int forkNameLength__in_len__; |
| 1557 |
SignedByte permissions; |
| 1558 |
ResFileRefNum refNum; |
| 1559 |
#ifndef FSOpenResourceFile |
| 1560 |
PyMac_PRECHECK(FSOpenResourceFile); |
| 1561 |
#endif |
| 1562 |
if (!PyArg_ParseTuple(_args, "O&u#b", |
| 1563 |
PyMac_GetFSRef, &ref, |
| 1564 |
&forkNameLength__in__, &forkNameLength__in_len__, |
| 1565 |
&permissions)) |
| 1566 |
return NULL; |
| 1567 |
forkNameLength__len__ = forkNameLength__in_len__; |
| 1568 |
_err = FSOpenResourceFile(&ref, |
| 1569 |
forkNameLength__len__, forkNameLength__in__, |
| 1570 |
permissions, |
| 1571 |
&refNum); |
| 1572 |
if (_err != noErr) return PyMac_Error(_err); |
| 1573 |
_res = Py_BuildValue("h", |
| 1574 |
refNum); |
| 1575 |
return _res; |
| 1576 |
} |
| 1577 |
|
| 1578 |
static PyObject *Res_Handle(PyObject *_self, PyObject *_args) |
| 1579 |
{ |
| 1580 |
PyObject *_res = NULL; |
| 1581 |
|
| 1582 |
char *buf; |
| 1583 |
int len; |
| 1584 |
Handle h; |
| 1585 |
ResourceObject *rv; |
| 1586 |
|
| 1587 |
if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
| 1588 |
return NULL; |
| 1589 |
h = NewHandle(len); |
| 1590 |
if ( h == NULL ) { |
| 1591 |
PyErr_NoMemory(); |
| 1592 |
return NULL; |
| 1593 |
} |
| 1594 |
HLock(h); |
| 1595 |
memcpy(*h, buf, len); |
| 1596 |
HUnlock(h); |
| 1597 |
rv = (ResourceObject *)ResObj_New(h); |
| 1598 |
rv->ob_freeit = PyMac_AutoDisposeHandle; |
| 1599 |
_res = (PyObject *)rv; |
| 1600 |
return _res; |
| 1601 |
|
| 1602 |
} |
| 1603 |
|
| 1604 |
static PyMethodDef Res_methods[] = { |
| 1605 |
{"CloseResFile", (PyCFunction)Res_CloseResFile, 1, |
| 1606 |
PyDoc_STR("(short refNum) -> None")}, |
| 1607 |
{"ResError", (PyCFunction)Res_ResError, 1, |
| 1608 |
PyDoc_STR("() -> None")}, |
| 1609 |
{"CurResFile", (PyCFunction)Res_CurResFile, 1, |
| 1610 |
PyDoc_STR("() -> (short _rv)")}, |
| 1611 |
{"UseResFile", (PyCFunction)Res_UseResFile, 1, |
| 1612 |
PyDoc_STR("(short refNum) -> None")}, |
| 1613 |
{"CountTypes", (PyCFunction)Res_CountTypes, 1, |
| 1614 |
PyDoc_STR("() -> (short _rv)")}, |
| 1615 |
{"Count1Types", (PyCFunction)Res_Count1Types, 1, |
| 1616 |
PyDoc_STR("() -> (short _rv)")}, |
| 1617 |
{"GetIndType", (PyCFunction)Res_GetIndType, 1, |
| 1618 |
PyDoc_STR("(short index) -> (ResType theType)")}, |
| 1619 |
{"Get1IndType", (PyCFunction)Res_Get1IndType, 1, |
| 1620 |
PyDoc_STR("(short index) -> (ResType theType)")}, |
| 1621 |
{"SetResLoad", (PyCFunction)Res_SetResLoad, 1, |
| 1622 |
PyDoc_STR("(Boolean load) -> None")}, |
| 1623 |
{"CountResources", (PyCFunction)Res_CountResources, 1, |
| 1624 |
PyDoc_STR("(ResType theType) -> (short _rv)")}, |
| 1625 |
{"Count1Resources", (PyCFunction)Res_Count1Resources, 1, |
| 1626 |
PyDoc_STR("(ResType theType) -> (short _rv)")}, |
| 1627 |
{"GetIndResource", (PyCFunction)Res_GetIndResource, 1, |
| 1628 |
PyDoc_STR("(ResType theType, short index) -> (Handle _rv)")}, |
| 1629 |
{"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, |
| 1630 |
PyDoc_STR("(ResType theType, short index) -> (Handle _rv)")}, |
| 1631 |
{"GetResource", (PyCFunction)Res_GetResource, 1, |
| 1632 |
PyDoc_STR("(ResType theType, short theID) -> (Handle _rv)")}, |
| 1633 |
{"Get1Resource", (PyCFunction)Res_Get1Resource, 1, |
| 1634 |
PyDoc_STR("(ResType theType, short theID) -> (Handle _rv)")}, |
| 1635 |
{"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, |
| 1636 |
PyDoc_STR("(ResType theType, Str255 name) -> (Handle _rv)")}, |
| 1637 |
{"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, |
| 1638 |
PyDoc_STR("(ResType theType, Str255 name) -> (Handle _rv)")}, |
| 1639 |
{"UniqueID", (PyCFunction)Res_UniqueID, 1, |
| 1640 |
PyDoc_STR("(ResType theType) -> (short _rv)")}, |
| 1641 |
{"Unique1ID", (PyCFunction)Res_Unique1ID, 1, |
| 1642 |
PyDoc_STR("(ResType theType) -> (short _rv)")}, |
| 1643 |
{"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, |
| 1644 |
PyDoc_STR("(short refNum) -> None")}, |
| 1645 |
{"SetResPurge", (PyCFunction)Res_SetResPurge, 1, |
| 1646 |
PyDoc_STR("(Boolean install) -> None")}, |
| 1647 |
{"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, |
| 1648 |
PyDoc_STR("(short refNum) -> (short _rv)")}, |
| 1649 |
{"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, |
| 1650 |
PyDoc_STR("(short refNum, short attrs) -> None")}, |
| 1651 |
#ifndef __LP64__ |
| 1652 |
{"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, |
| 1653 |
PyDoc_STR("(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)")}, |
| 1654 |
{"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, |
| 1655 |
PyDoc_STR("(short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv)")}, |
| 1656 |
{"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, |
| 1657 |
PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> None")}, |
| 1658 |
{"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, |
| 1659 |
PyDoc_STR("(FSSpec spec, SignedByte permission) -> (short _rv)")}, |
| 1660 |
{"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, |
| 1661 |
PyDoc_STR("(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None")}, |
| 1662 |
#endif |
| 1663 |
{"InsertResourceFile", (PyCFunction)Res_InsertResourceFile, 1, |
| 1664 |
PyDoc_STR("(SInt16 refNum, RsrcChainLocation where) -> None")}, |
| 1665 |
{"DetachResourceFile", (PyCFunction)Res_DetachResourceFile, 1, |
| 1666 |
PyDoc_STR("(SInt16 refNum) -> None")}, |
| 1667 |
#ifndef __LP64__ |
| 1668 |
{"FSpResourceFileAlreadyOpen", (PyCFunction)Res_FSpResourceFileAlreadyOpen, 1, |
| 1669 |
PyDoc_STR("(FSSpec resourceFile) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")}, |
| 1670 |
{"FSpOpenOrphanResFile", (PyCFunction)Res_FSpOpenOrphanResFile, 1, |
| 1671 |
PyDoc_STR("(FSSpec spec, SignedByte permission) -> (SInt16 refNum)")}, |
| 1672 |
{"GetTopResourceFile", (PyCFunction)Res_GetTopResourceFile, 1, |
| 1673 |
PyDoc_STR("() -> (SInt16 refNum)")}, |
| 1674 |
{"GetNextResourceFile", (PyCFunction)Res_GetNextResourceFile, 1, |
| 1675 |
PyDoc_STR("(SInt16 curRefNum) -> (SInt16 nextRefNum)")}, |
| 1676 |
#endif |
| 1677 |
{"FSOpenResFile", (PyCFunction)Res_FSOpenResFile, 1, |
| 1678 |
PyDoc_STR("(FSRef ref, SignedByte permission) -> (short _rv)")}, |
| 1679 |
#ifndef __LP64__ |
| 1680 |
{"FSCreateResFile", (PyCFunction)Res_FSCreateResFile, 1, |
| 1681 |
PyDoc_STR("(FSRef parentRef, Buffer nameLength) -> (FSRef newRef, FSSpec newSpec)")}, |
| 1682 |
{"FSResourceFileAlreadyOpen", (PyCFunction)Res_FSResourceFileAlreadyOpen, 1, |
| 1683 |
PyDoc_STR("(FSRef resourceFileRef) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")}, |
| 1684 |
{"FSCreateResourceFile", (PyCFunction)Res_FSCreateResourceFile, 1, |
| 1685 |
PyDoc_STR("(FSRef parentRef, Buffer nameLength, Buffer forkNameLength) -> (FSRef newRef, FSSpec newSpec)")}, |
| 1686 |
#endif |
| 1687 |
{"FSOpenResourceFile", (PyCFunction)Res_FSOpenResourceFile, 1, |
| 1688 |
PyDoc_STR("(FSRef ref, Buffer forkNameLength, SignedByte permissions) -> (SInt16 refNum)")}, |
| 1689 |
{"Handle", (PyCFunction)Res_Handle, 1, |
| 1690 |
PyDoc_STR("Convert a string to a Handle object.\n\nResource() and Handle() are very similar, but objects created with Handle() are\nby default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()\nto change this.\n")}, |
| 1691 |
{NULL, NULL, 0} |
| 1692 |
}; |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
PyObject *OptResObj_New(Handle itself) |
| 1698 |
{ |
| 1699 |
if (itself == NULL) { |
| 1700 |
Py_INCREF(Py_None); |
| 1701 |
return Py_None; |
| 1702 |
} |
| 1703 |
return ResObj_New(itself); |
| 1704 |
} |
| 1705 |
|
| 1706 |
int OptResObj_Convert(PyObject *v, Handle *p_itself) |
| 1707 |
{ |
| 1708 |
PyObject *tmp; |
| 1709 |
|
| 1710 |
if ( v == Py_None ) { |
| 1711 |
*p_itself = NULL; |
| 1712 |
return 1; |
| 1713 |
} |
| 1714 |
if (ResObj_Check(v)) |
| 1715 |
{ |
| 1716 |
*p_itself = ((ResourceObject *)v)->ob_itself; |
| 1717 |
return 1; |
| 1718 |
} |
| 1719 |
|
| 1720 |
if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) { |
| 1721 |
*p_itself = ((ResourceObject *)tmp)->ob_itself; |
| 1722 |
Py_DECREF(tmp); |
| 1723 |
return 1; |
| 1724 |
} |
| 1725 |
PyErr_Clear(); |
| 1726 |
PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 1727 |
return 0; |
| 1728 |
} |
| 1729 |
|
| 1730 |
|
| 1731 |
void init_Res(void) |
| 1732 |
{ |
| 1733 |
PyObject *m; |
| 1734 |
PyObject *d; |
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, ResObj_New); |
| 1739 |
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, ResObj_Convert); |
| 1740 |
PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, OptResObj_New); |
| 1741 |
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, OptResObj_Convert); |
| 1742 |
|
| 1743 |
|
| 1744 |
m = Py_InitModule("_Res", Res_methods); |
| 1745 |
d = PyModule_GetDict(m); |
| 1746 |
Res_Error = PyMac_GetOSErrException(); |
| 1747 |
if (Res_Error == NULL || |
| 1748 |
PyDict_SetItemString(d, "Error", Res_Error) != 0) |
| 1749 |
return; |
| 1750 |
Resource_Type.ob_type = &PyType_Type; |
| 1751 |
if (PyType_Ready(&Resource_Type) < 0) return; |
| 1752 |
Py_INCREF(&Resource_Type); |
| 1753 |
PyModule_AddObject(m, "Resource", (PyObject *)&Resource_Type); |
| 1754 |
|
| 1755 |
Py_INCREF(&Resource_Type); |
| 1756 |
PyModule_AddObject(m, "ResourceType", (PyObject *)&Resource_Type); |
| 1757 |
} |
| 1758 |
|
| 1759 |
|
| 1760 |
|