Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI or Corporation for National Research Initiatives or |
| 13 | CNRI not be used in advertising or publicity pertaining to |
| 14 | distribution of the software without specific, written prior |
| 15 | permission. |
| 16 | |
| 17 | While CWI is the initial source for this software, a modified version |
| 18 | is made available by the Corporation for National Research Initiatives |
| 19 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 22 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 23 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 24 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 25 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 26 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 27 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 28 | PERFORMANCE OF THIS SOFTWARE. |
| 29 | |
| 30 | ******************************************************************/ |
| 31 | |
| 32 | #include "Python.h" |
| 33 | #include "macglue.h" |
| 34 | |
| 35 | extern int ResObj_Convert(PyObject *, Handle *); /* From Resmodule.c */ |
| 36 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 37 | #ifdef WITHOUT_FRAMEWORKS |
| 38 | #if !TARGET_API_MAC_OS8 |
Jack Jansen | 726d873 | 2001-01-19 23:45:57 +0000 | [diff] [blame] | 39 | /* The Carbon headers define PRAGMA_ALIGN_SUPPORT to something illegal, |
| 40 | ** because you shouldn't use it for Carbon. All good and well, but portable |
| 41 | ** code still needs it. So, we undefine it here. |
| 42 | */ |
| 43 | #undef PRAGMA_ALIGN_SUPPORTED |
| 44 | #define PRAGMA_ALIGN_SUPPORTED 0 |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 45 | #endif /* !TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 46 | |
| 47 | #include "ICAPI.h" |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 48 | #else |
| 49 | #include <Carbon/Carbon.h> |
| 50 | typedef OSStatus ICError; |
| 51 | /* Some fields in ICMapEntry have changed names. */ |
| 52 | #define file_type fileType |
| 53 | #define file_creator fileCreator |
| 54 | #define post_creator postCreator |
| 55 | #define creator_app_name creatorAppName |
| 56 | #define post_app_name postAppName |
| 57 | #define MIME_type MIMEType |
| 58 | #define entry_name entryName |
| 59 | #endif |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 60 | |
| 61 | static PyObject *ErrorObject; |
| 62 | |
| 63 | static PyObject * |
| 64 | ici_error(ICError err) |
| 65 | { |
| 66 | PyErr_SetObject(ErrorObject, PyInt_FromLong((long)err)); |
| 67 | return NULL; |
| 68 | } |
| 69 | |
| 70 | /* ----------------------------------------------------- */ |
| 71 | |
| 72 | /* Declarations for objects of type ic_instance */ |
| 73 | |
| 74 | typedef struct { |
| 75 | PyObject_HEAD |
| 76 | ICInstance inst; |
| 77 | } iciobject; |
| 78 | |
| 79 | staticforward PyTypeObject Icitype; |
| 80 | |
| 81 | |
| 82 | |
| 83 | /* ---------------------------------------------------------------- */ |
| 84 | |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 85 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 86 | static char ici_ICFindConfigFile__doc__[] = |
| 87 | "()->None; Find config file in standard places" |
| 88 | ; |
| 89 | |
| 90 | static PyObject * |
| 91 | ici_ICFindConfigFile(self, args) |
| 92 | iciobject *self; |
| 93 | PyObject *args; |
| 94 | { |
| 95 | ICError err; |
| 96 | |
| 97 | if (!PyArg_ParseTuple(args, "")) |
| 98 | return NULL; |
| 99 | if ((err=ICFindConfigFile(self->inst, 0, NULL)) != 0 ) |
| 100 | return ici_error(err); |
| 101 | Py_INCREF(Py_None); |
| 102 | return Py_None; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | static char ici_ICFindUserConfigFile__doc__[] = |
| 107 | "(vRefNum, dirID)->None; Find config file in specified place" |
| 108 | ; |
| 109 | |
| 110 | static PyObject * |
| 111 | ici_ICFindUserConfigFile(self, args) |
| 112 | iciobject *self; |
| 113 | PyObject *args; |
| 114 | { |
| 115 | ICError err; |
| 116 | ICDirSpec where; |
| 117 | |
| 118 | if (!PyArg_ParseTuple(args, "sl", &where.vRefNum, &where.dirID)) |
| 119 | return NULL; |
| 120 | if ((err=ICFindUserConfigFile(self->inst, &where)) != 0 ) |
| 121 | return ici_error(err); |
| 122 | Py_INCREF(Py_None); |
| 123 | return Py_None; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | static char ici_ICChooseConfig__doc__[] = |
| 128 | "()->None; Let the user choose a config file" |
| 129 | ; |
| 130 | |
| 131 | static PyObject * |
| 132 | ici_ICChooseConfig(self, args) |
| 133 | iciobject *self; |
| 134 | PyObject *args; |
| 135 | { |
| 136 | ICError err; |
| 137 | |
| 138 | if (!PyArg_ParseTuple(args, "")) |
| 139 | return NULL; |
| 140 | if ((err=ICChooseConfig(self->inst)) != 0 ) |
| 141 | return ici_error(err); |
| 142 | Py_INCREF(Py_None); |
| 143 | return Py_None; |
| 144 | } |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 145 | |
| 146 | static char ici_ICChooseNewConfig__doc__[] = |
| 147 | "()->None; Let the user choose a new config file" |
| 148 | ; |
| 149 | |
| 150 | static PyObject * |
| 151 | ici_ICChooseNewConfig(self, args) |
| 152 | iciobject *self; |
| 153 | PyObject *args; |
| 154 | { |
| 155 | ICError err; |
| 156 | |
| 157 | if (!PyArg_ParseTuple(args, "")) |
| 158 | return NULL; |
| 159 | if ((err=ICChooseNewConfig(self->inst)) != 0 ) |
| 160 | return ici_error(err); |
| 161 | Py_INCREF(Py_None); |
| 162 | return Py_None; |
| 163 | } |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 164 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 165 | |
| 166 | |
| 167 | static char ici_ICGetSeed__doc__[] = |
| 168 | "()->int; Returns int that changes when configuration does" |
| 169 | ; |
| 170 | |
| 171 | static PyObject * |
| 172 | ici_ICGetSeed(self, args) |
| 173 | iciobject *self; |
| 174 | PyObject *args; |
| 175 | { |
| 176 | ICError err; |
| 177 | long seed; |
| 178 | |
| 179 | if (!PyArg_ParseTuple(args, "")) |
| 180 | return NULL; |
| 181 | if ((err=ICGetSeed(self->inst, &seed)) != 0 ) |
| 182 | return ici_error(err); |
| 183 | return Py_BuildValue("i", (int)seed); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | static char ici_ICBegin__doc__[] = |
| 188 | "(perm)->None; Lock config file for read/write" |
| 189 | ; |
| 190 | |
| 191 | static PyObject * |
| 192 | ici_ICBegin(self, args) |
| 193 | iciobject *self; |
| 194 | PyObject *args; |
| 195 | { |
| 196 | ICError err; |
| 197 | int perm; |
| 198 | |
| 199 | if (!PyArg_ParseTuple(args, "i", &perm)) |
| 200 | return NULL; |
| 201 | if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 ) |
| 202 | return ici_error(err); |
| 203 | Py_INCREF(Py_None); |
| 204 | return Py_None; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | static char ici_ICFindPrefHandle__doc__[] = |
| 209 | "(key, handle)->attrs; Lookup key, store result in handle, return attributes" |
| 210 | ; |
| 211 | |
| 212 | static PyObject * |
| 213 | ici_ICFindPrefHandle(self, args) |
| 214 | iciobject *self; |
| 215 | PyObject *args; |
| 216 | { |
| 217 | ICError err; |
| 218 | Str255 key; |
| 219 | ICAttr attr; |
| 220 | Handle h; |
| 221 | |
| 222 | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, &key, ResObj_Convert, &h)) |
| 223 | return NULL; |
| 224 | if ((err=ICFindPrefHandle(self->inst, key, &attr, h)) != 0 ) |
| 225 | return ici_error(err); |
| 226 | return Py_BuildValue("i", (int)attr); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | static char ici_ICSetPref__doc__[] = |
| 231 | "(key, attr, data)->None; Set preference key to data with attributes" |
| 232 | ; |
| 233 | |
| 234 | static PyObject * |
| 235 | ici_ICSetPref(self, args) |
| 236 | iciobject *self; |
| 237 | PyObject *args; |
| 238 | { |
| 239 | ICError err; |
| 240 | Str255 key; |
| 241 | int attr; |
| 242 | char *data; |
| 243 | int datalen; |
| 244 | |
| 245 | if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, |
| 246 | &data, &datalen)) |
| 247 | return NULL; |
| 248 | if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, |
| 249 | (long)datalen)) != 0) |
| 250 | return ici_error(err); |
| 251 | Py_INCREF(Py_None); |
| 252 | return Py_None; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | static char ici_ICCountPref__doc__[] = |
| 257 | "()->int; Return number of preferences" |
| 258 | ; |
| 259 | |
| 260 | static PyObject * |
| 261 | ici_ICCountPref(self, args) |
| 262 | iciobject *self; |
| 263 | PyObject *args; |
| 264 | { |
| 265 | ICError err; |
| 266 | long count; |
| 267 | |
| 268 | if (!PyArg_ParseTuple(args, "")) |
| 269 | return NULL; |
| 270 | if ((err=ICCountPref(self->inst, &count)) != 0 ) |
| 271 | return ici_error(err); |
| 272 | return Py_BuildValue("i", (int)count); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | static char ici_ICGetIndPref__doc__[] = |
| 277 | "(num)->key; Return key of preference with given index" |
| 278 | ; |
| 279 | |
| 280 | static PyObject * |
| 281 | ici_ICGetIndPref(self, args) |
| 282 | iciobject *self; |
| 283 | PyObject *args; |
| 284 | { |
| 285 | ICError err; |
| 286 | long num; |
| 287 | Str255 key; |
| 288 | |
| 289 | if (!PyArg_ParseTuple(args, "l", &num)) |
| 290 | return NULL; |
| 291 | if ((err=ICGetIndPref(self->inst, num, key)) != 0 ) |
| 292 | return ici_error(err); |
| 293 | return Py_BuildValue("O&", PyMac_BuildStr255, key); |
| 294 | } |
| 295 | |
| 296 | |
| 297 | static char ici_ICDeletePref__doc__[] = |
| 298 | "(key)->None; Delete preference" |
| 299 | ; |
| 300 | |
| 301 | static PyObject * |
| 302 | ici_ICDeletePref(self, args) |
| 303 | iciobject *self; |
| 304 | PyObject *args; |
| 305 | { |
| 306 | ICError err; |
| 307 | Str255 key; |
| 308 | |
| 309 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 310 | return NULL; |
| 311 | if ((err=ICDeletePref(self->inst, key)) != 0 ) |
| 312 | return ici_error(err); |
| 313 | Py_INCREF(Py_None); |
| 314 | return Py_None; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | static char ici_ICEnd__doc__[] = |
| 319 | "()->None; Unlock file after ICBegin call" |
| 320 | ; |
| 321 | |
| 322 | static PyObject * |
| 323 | ici_ICEnd(self, args) |
| 324 | iciobject *self; |
| 325 | PyObject *args; |
| 326 | { |
| 327 | ICError err; |
| 328 | |
| 329 | if (!PyArg_ParseTuple(args, "")) |
| 330 | return NULL; |
| 331 | if ((err=ICEnd(self->inst)) != 0 ) |
| 332 | return ici_error(err); |
| 333 | Py_INCREF(Py_None); |
| 334 | return Py_None; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | static char ici_ICEditPreferences__doc__[] = |
| 339 | "(key)->None; Ask user to edit preferences, staring with key" |
| 340 | ; |
| 341 | |
| 342 | static PyObject * |
| 343 | ici_ICEditPreferences(self, args) |
| 344 | iciobject *self; |
| 345 | PyObject *args; |
| 346 | { |
| 347 | ICError err; |
| 348 | Str255 key; |
| 349 | |
| 350 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 351 | return NULL; |
| 352 | if ((err=ICEditPreferences(self->inst, key)) != 0 ) |
| 353 | return ici_error(err); |
| 354 | Py_INCREF(Py_None); |
| 355 | return Py_None; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | static char ici_ICParseURL__doc__[] = |
| 360 | "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" |
| 361 | ; |
| 362 | |
| 363 | static PyObject * |
| 364 | ici_ICParseURL(self, args) |
| 365 | iciobject *self; |
| 366 | PyObject *args; |
| 367 | { |
| 368 | ICError err; |
| 369 | Str255 hint; |
| 370 | char *data; |
| 371 | int datalen; |
| 372 | long selStart, selEnd; |
| 373 | Handle h; |
| 374 | |
| 375 | if (!PyArg_ParseTuple(args, "O&s#llO&", PyMac_GetStr255, hint, &data, &datalen, |
| 376 | &selStart, &selEnd, ResObj_Convert, &h)) |
| 377 | return NULL; |
| 378 | if ((err=ICParseURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 379 | &selStart, &selEnd, h)) != 0 ) |
| 380 | return ici_error(err); |
| 381 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | static char ici_ICLaunchURL__doc__[] = |
| 386 | "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" |
| 387 | ; |
| 388 | |
| 389 | static PyObject * |
| 390 | ici_ICLaunchURL(self, args) |
| 391 | iciobject *self; |
| 392 | PyObject *args; |
| 393 | { |
| 394 | ICError err; |
| 395 | Str255 hint; |
| 396 | char *data; |
| 397 | int datalen; |
| 398 | long selStart, selEnd; |
| 399 | |
| 400 | if (!PyArg_ParseTuple(args, "O&s#ll", PyMac_GetStr255, hint, &data, &datalen, |
| 401 | &selStart, &selEnd)) |
| 402 | return NULL; |
| 403 | if ((err=ICLaunchURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 404 | &selStart, &selEnd)) != 0 ) |
| 405 | return ici_error(err); |
| 406 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | static char ici_ICMapFilename__doc__[] = |
| 411 | "(filename)->mapinfo; Get filemap info for given filename" |
| 412 | ; |
| 413 | |
| 414 | static PyObject * |
| 415 | ici_ICMapFilename(self, args) |
| 416 | iciobject *self; |
| 417 | PyObject *args; |
| 418 | { |
| 419 | ICError err; |
| 420 | Str255 filename; |
| 421 | ICMapEntry entry; |
| 422 | |
| 423 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, filename)) |
| 424 | return NULL; |
| 425 | if ((err=ICMapFilename(self->inst, filename, &entry)) != 0 ) |
| 426 | return ici_error(err); |
| 427 | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
| 428 | PyMac_BuildOSType, entry.file_type, |
| 429 | PyMac_BuildOSType, entry.file_creator, |
| 430 | PyMac_BuildOSType, entry.post_creator, |
| 431 | entry.flags, |
| 432 | PyMac_BuildStr255, entry.extension, |
| 433 | PyMac_BuildStr255, entry.creator_app_name, |
| 434 | PyMac_BuildStr255, entry.post_app_name, |
| 435 | PyMac_BuildStr255, entry.MIME_type, |
| 436 | PyMac_BuildStr255, entry.entry_name); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | static char ici_ICMapTypeCreator__doc__[] = |
| 441 | "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename" |
| 442 | ; |
| 443 | |
| 444 | static PyObject * |
| 445 | ici_ICMapTypeCreator(self, args) |
| 446 | iciobject *self; |
| 447 | PyObject *args; |
| 448 | { |
| 449 | ICError err; |
| 450 | OSType type, creator; |
| 451 | Str255 filename; |
| 452 | ICMapEntry entry; |
| 453 | |
| 454 | if (!PyArg_ParseTuple(args, "O&O&O&", |
| 455 | PyMac_GetOSType, &type, |
| 456 | PyMac_GetOSType, &creator, |
| 457 | PyMac_GetStr255, filename)) |
| 458 | return NULL; |
| 459 | if ((err=ICMapTypeCreator(self->inst, type, creator, filename, &entry)) != 0 ) |
| 460 | return ici_error(err); |
| 461 | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
| 462 | PyMac_BuildOSType, entry.file_type, |
| 463 | PyMac_BuildOSType, entry.file_creator, |
| 464 | PyMac_BuildOSType, entry.post_creator, |
| 465 | entry.flags, |
| 466 | PyMac_BuildStr255, entry.extension, |
| 467 | PyMac_BuildStr255, entry.creator_app_name, |
| 468 | PyMac_BuildStr255, entry.post_app_name, |
| 469 | PyMac_BuildStr255, entry.MIME_type, |
| 470 | PyMac_BuildStr255, entry.entry_name); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | static struct PyMethodDef ici_methods[] = { |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 475 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 5a8115c | 2001-01-29 13:27:46 +0000 | [diff] [blame] | 476 | {"ICFindConfigFile", (PyCFunction)ici_ICFindConfigFile, METH_VARARGS, ici_ICFindConfigFile__doc__}, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 477 | {"ICFindUserConfigFile", (PyCFunction)ici_ICFindUserConfigFile, METH_VARARGS, ici_ICFindUserConfigFile__doc__}, |
| 478 | {"ICChooseConfig", (PyCFunction)ici_ICChooseConfig, METH_VARARGS, ici_ICChooseConfig__doc__}, |
| 479 | {"ICChooseNewConfig", (PyCFunction)ici_ICChooseNewConfig, METH_VARARGS, ici_ICChooseNewConfig__doc__}, |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 480 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 481 | {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS, ici_ICGetSeed__doc__}, |
| 482 | {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS, ici_ICBegin__doc__}, |
| 483 | {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS, ici_ICFindPrefHandle__doc__}, |
| 484 | {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS, ici_ICSetPref__doc__}, |
| 485 | {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS, ici_ICCountPref__doc__}, |
| 486 | {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS, ici_ICGetIndPref__doc__}, |
| 487 | {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS, ici_ICDeletePref__doc__}, |
| 488 | {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS, ici_ICEnd__doc__}, |
| 489 | {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS, ici_ICEditPreferences__doc__}, |
| 490 | {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS, ici_ICParseURL__doc__}, |
| 491 | {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS, ici_ICLaunchURL__doc__}, |
| 492 | {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS, ici_ICMapFilename__doc__}, |
| 493 | {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS, ici_ICMapTypeCreator__doc__}, |
| 494 | |
| 495 | {NULL, NULL} /* sentinel */ |
| 496 | }; |
| 497 | |
| 498 | /* ---------- */ |
| 499 | |
| 500 | |
| 501 | static iciobject * |
| 502 | newiciobject(OSType creator) |
| 503 | { |
| 504 | iciobject *self; |
| 505 | ICError err; |
| 506 | |
| 507 | self = PyObject_NEW(iciobject, &Icitype); |
| 508 | if (self == NULL) |
| 509 | return NULL; |
| 510 | if ((err=ICStart(&self->inst, creator)) != 0 ) { |
| 511 | (void)ici_error(err); |
| 512 | PyMem_DEL(self); |
| 513 | return NULL; |
| 514 | } |
| 515 | return self; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | static void |
| 520 | ici_dealloc(self) |
| 521 | iciobject *self; |
| 522 | { |
| 523 | (void)ICStop(self->inst); |
| 524 | PyMem_DEL(self); |
| 525 | } |
| 526 | |
| 527 | static PyObject * |
| 528 | ici_getattr(self, name) |
| 529 | iciobject *self; |
| 530 | char *name; |
| 531 | { |
| 532 | return Py_FindMethod(ici_methods, (PyObject *)self, name); |
| 533 | } |
| 534 | |
| 535 | static char Icitype__doc__[] = |
| 536 | "Internet Config instance" |
| 537 | ; |
| 538 | |
| 539 | static PyTypeObject Icitype = { |
| 540 | PyObject_HEAD_INIT(&PyType_Type) |
| 541 | 0, /*ob_size*/ |
| 542 | "ic_instance", /*tp_name*/ |
| 543 | sizeof(iciobject), /*tp_basicsize*/ |
| 544 | 0, /*tp_itemsize*/ |
| 545 | /* methods */ |
| 546 | (destructor)ici_dealloc, /*tp_dealloc*/ |
| 547 | (printfunc)0, /*tp_print*/ |
| 548 | (getattrfunc)ici_getattr, /*tp_getattr*/ |
| 549 | (setattrfunc)0, /*tp_setattr*/ |
| 550 | (cmpfunc)0, /*tp_compare*/ |
| 551 | (reprfunc)0, /*tp_repr*/ |
| 552 | 0, /*tp_as_number*/ |
| 553 | 0, /*tp_as_sequence*/ |
| 554 | 0, /*tp_as_mapping*/ |
| 555 | (hashfunc)0, /*tp_hash*/ |
| 556 | (ternaryfunc)0, /*tp_call*/ |
| 557 | (reprfunc)0, /*tp_str*/ |
| 558 | |
| 559 | /* Space for future expansion */ |
| 560 | 0L,0L,0L,0L, |
| 561 | Icitype__doc__ /* Documentation string */ |
| 562 | }; |
| 563 | |
| 564 | /* End of code for ic_instance objects */ |
| 565 | /* -------------------------------------------------------- */ |
| 566 | |
| 567 | |
| 568 | static char ic_ICStart__doc__[] = |
| 569 | "(OSType)->ic_instance; Create an Internet Config instance" |
| 570 | ; |
| 571 | |
| 572 | static PyObject * |
| 573 | ic_ICStart(self, args) |
| 574 | PyObject *self; /* Not used */ |
| 575 | PyObject *args; |
| 576 | { |
| 577 | OSType creator; |
| 578 | |
| 579 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &creator)) |
| 580 | return NULL; |
| 581 | return (PyObject *)newiciobject(creator); |
| 582 | } |
| 583 | |
| 584 | /* List of methods defined in the module */ |
| 585 | |
| 586 | static struct PyMethodDef ic_methods[] = { |
| 587 | {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS, ic_ICStart__doc__}, |
| 588 | |
| 589 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
| 590 | }; |
| 591 | |
| 592 | |
| 593 | /* Initialization function for the module (*must* be called initicglue) */ |
| 594 | |
| 595 | static char icglue_module_documentation[] = |
| 596 | "Implements low-level Internet Config interface" |
| 597 | ; |
| 598 | |
| 599 | void |
| 600 | initicglue() |
| 601 | { |
| 602 | PyObject *m, *d; |
| 603 | |
| 604 | /* Create the module and add the functions */ |
| 605 | m = Py_InitModule4("icglue", ic_methods, |
| 606 | icglue_module_documentation, |
| 607 | (PyObject*)NULL,PYTHON_API_VERSION); |
| 608 | |
| 609 | /* Add some symbolic constants to the module */ |
| 610 | d = PyModule_GetDict(m); |
| 611 | ErrorObject = PyString_FromString("icglue.error"); |
| 612 | PyDict_SetItemString(d, "error", ErrorObject); |
| 613 | |
| 614 | /* XXXX Add constants here */ |
| 615 | |
| 616 | /* Check for errors */ |
| 617 | if (PyErr_Occurred()) |
| 618 | Py_FatalError("can't initialize module icglue"); |
| 619 | } |
| 620 | |