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 * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 91 | ici_ICFindConfigFile(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 92 | { |
| 93 | ICError err; |
| 94 | |
| 95 | if (!PyArg_ParseTuple(args, "")) |
| 96 | return NULL; |
| 97 | if ((err=ICFindConfigFile(self->inst, 0, NULL)) != 0 ) |
| 98 | return ici_error(err); |
| 99 | Py_INCREF(Py_None); |
| 100 | return Py_None; |
| 101 | } |
| 102 | |
| 103 | |
| 104 | static char ici_ICFindUserConfigFile__doc__[] = |
| 105 | "(vRefNum, dirID)->None; Find config file in specified place" |
| 106 | ; |
| 107 | |
| 108 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 109 | ici_ICFindUserConfigFile(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 110 | { |
| 111 | ICError err; |
| 112 | ICDirSpec where; |
| 113 | |
| 114 | if (!PyArg_ParseTuple(args, "sl", &where.vRefNum, &where.dirID)) |
| 115 | return NULL; |
| 116 | if ((err=ICFindUserConfigFile(self->inst, &where)) != 0 ) |
| 117 | return ici_error(err); |
| 118 | Py_INCREF(Py_None); |
| 119 | return Py_None; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | static char ici_ICChooseConfig__doc__[] = |
| 124 | "()->None; Let the user choose a config file" |
| 125 | ; |
| 126 | |
| 127 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 128 | ici_ICChooseConfig(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 129 | { |
| 130 | ICError err; |
| 131 | |
| 132 | if (!PyArg_ParseTuple(args, "")) |
| 133 | return NULL; |
| 134 | if ((err=ICChooseConfig(self->inst)) != 0 ) |
| 135 | return ici_error(err); |
| 136 | Py_INCREF(Py_None); |
| 137 | return Py_None; |
| 138 | } |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 139 | |
| 140 | static char ici_ICChooseNewConfig__doc__[] = |
| 141 | "()->None; Let the user choose a new config file" |
| 142 | ; |
| 143 | |
| 144 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 145 | ici_ICChooseNewConfig(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 146 | { |
| 147 | ICError err; |
| 148 | |
| 149 | if (!PyArg_ParseTuple(args, "")) |
| 150 | return NULL; |
| 151 | if ((err=ICChooseNewConfig(self->inst)) != 0 ) |
| 152 | return ici_error(err); |
| 153 | Py_INCREF(Py_None); |
| 154 | return Py_None; |
| 155 | } |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 156 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 157 | |
| 158 | |
| 159 | static char ici_ICGetSeed__doc__[] = |
| 160 | "()->int; Returns int that changes when configuration does" |
| 161 | ; |
| 162 | |
| 163 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 164 | ici_ICGetSeed(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 165 | { |
| 166 | ICError err; |
| 167 | long seed; |
| 168 | |
| 169 | if (!PyArg_ParseTuple(args, "")) |
| 170 | return NULL; |
| 171 | if ((err=ICGetSeed(self->inst, &seed)) != 0 ) |
| 172 | return ici_error(err); |
| 173 | return Py_BuildValue("i", (int)seed); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | static char ici_ICBegin__doc__[] = |
| 178 | "(perm)->None; Lock config file for read/write" |
| 179 | ; |
| 180 | |
| 181 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 182 | ici_ICBegin(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 183 | { |
| 184 | ICError err; |
| 185 | int perm; |
| 186 | |
| 187 | if (!PyArg_ParseTuple(args, "i", &perm)) |
| 188 | return NULL; |
| 189 | if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 ) |
| 190 | return ici_error(err); |
| 191 | Py_INCREF(Py_None); |
| 192 | return Py_None; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | static char ici_ICFindPrefHandle__doc__[] = |
| 197 | "(key, handle)->attrs; Lookup key, store result in handle, return attributes" |
| 198 | ; |
| 199 | |
| 200 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 201 | ici_ICFindPrefHandle(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 202 | { |
| 203 | ICError err; |
| 204 | Str255 key; |
| 205 | ICAttr attr; |
| 206 | Handle h; |
| 207 | |
| 208 | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, &key, ResObj_Convert, &h)) |
| 209 | return NULL; |
| 210 | if ((err=ICFindPrefHandle(self->inst, key, &attr, h)) != 0 ) |
| 211 | return ici_error(err); |
| 212 | return Py_BuildValue("i", (int)attr); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | static char ici_ICSetPref__doc__[] = |
| 217 | "(key, attr, data)->None; Set preference key to data with attributes" |
| 218 | ; |
| 219 | |
| 220 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 221 | ici_ICSetPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 222 | { |
| 223 | ICError err; |
| 224 | Str255 key; |
| 225 | int attr; |
| 226 | char *data; |
| 227 | int datalen; |
| 228 | |
| 229 | if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, |
| 230 | &data, &datalen)) |
| 231 | return NULL; |
| 232 | if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, |
| 233 | (long)datalen)) != 0) |
| 234 | return ici_error(err); |
| 235 | Py_INCREF(Py_None); |
| 236 | return Py_None; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | static char ici_ICCountPref__doc__[] = |
| 241 | "()->int; Return number of preferences" |
| 242 | ; |
| 243 | |
| 244 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 245 | ici_ICCountPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 246 | { |
| 247 | ICError err; |
| 248 | long count; |
| 249 | |
| 250 | if (!PyArg_ParseTuple(args, "")) |
| 251 | return NULL; |
| 252 | if ((err=ICCountPref(self->inst, &count)) != 0 ) |
| 253 | return ici_error(err); |
| 254 | return Py_BuildValue("i", (int)count); |
| 255 | } |
| 256 | |
| 257 | |
| 258 | static char ici_ICGetIndPref__doc__[] = |
| 259 | "(num)->key; Return key of preference with given index" |
| 260 | ; |
| 261 | |
| 262 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 263 | ici_ICGetIndPref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 264 | { |
| 265 | ICError err; |
| 266 | long num; |
| 267 | Str255 key; |
| 268 | |
| 269 | if (!PyArg_ParseTuple(args, "l", &num)) |
| 270 | return NULL; |
| 271 | if ((err=ICGetIndPref(self->inst, num, key)) != 0 ) |
| 272 | return ici_error(err); |
| 273 | return Py_BuildValue("O&", PyMac_BuildStr255, key); |
| 274 | } |
| 275 | |
| 276 | |
| 277 | static char ici_ICDeletePref__doc__[] = |
| 278 | "(key)->None; Delete preference" |
| 279 | ; |
| 280 | |
| 281 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 282 | ici_ICDeletePref(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 283 | { |
| 284 | ICError err; |
| 285 | Str255 key; |
| 286 | |
| 287 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 288 | return NULL; |
| 289 | if ((err=ICDeletePref(self->inst, key)) != 0 ) |
| 290 | return ici_error(err); |
| 291 | Py_INCREF(Py_None); |
| 292 | return Py_None; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | static char ici_ICEnd__doc__[] = |
| 297 | "()->None; Unlock file after ICBegin call" |
| 298 | ; |
| 299 | |
| 300 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 301 | ici_ICEnd(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 302 | { |
| 303 | ICError err; |
| 304 | |
| 305 | if (!PyArg_ParseTuple(args, "")) |
| 306 | return NULL; |
| 307 | if ((err=ICEnd(self->inst)) != 0 ) |
| 308 | return ici_error(err); |
| 309 | Py_INCREF(Py_None); |
| 310 | return Py_None; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | static char ici_ICEditPreferences__doc__[] = |
| 315 | "(key)->None; Ask user to edit preferences, staring with key" |
| 316 | ; |
| 317 | |
| 318 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 319 | ici_ICEditPreferences(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 320 | { |
| 321 | ICError err; |
| 322 | Str255 key; |
| 323 | |
| 324 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
| 325 | return NULL; |
| 326 | if ((err=ICEditPreferences(self->inst, key)) != 0 ) |
| 327 | return ici_error(err); |
| 328 | Py_INCREF(Py_None); |
| 329 | return Py_None; |
| 330 | } |
| 331 | |
| 332 | |
| 333 | static char ici_ICParseURL__doc__[] = |
| 334 | "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" |
| 335 | ; |
| 336 | |
| 337 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 338 | ici_ICParseURL(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 339 | { |
| 340 | ICError err; |
| 341 | Str255 hint; |
| 342 | char *data; |
| 343 | int datalen; |
| 344 | long selStart, selEnd; |
| 345 | Handle h; |
| 346 | |
| 347 | if (!PyArg_ParseTuple(args, "O&s#llO&", PyMac_GetStr255, hint, &data, &datalen, |
| 348 | &selStart, &selEnd, ResObj_Convert, &h)) |
| 349 | return NULL; |
| 350 | if ((err=ICParseURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 351 | &selStart, &selEnd, h)) != 0 ) |
| 352 | return ici_error(err); |
| 353 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | static char ici_ICLaunchURL__doc__[] = |
| 358 | "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" |
| 359 | ; |
| 360 | |
| 361 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 362 | ici_ICLaunchURL(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 363 | { |
| 364 | ICError err; |
| 365 | Str255 hint; |
| 366 | char *data; |
| 367 | int datalen; |
| 368 | long selStart, selEnd; |
| 369 | |
| 370 | if (!PyArg_ParseTuple(args, "O&s#ll", PyMac_GetStr255, hint, &data, &datalen, |
| 371 | &selStart, &selEnd)) |
| 372 | return NULL; |
| 373 | if ((err=ICLaunchURL(self->inst, hint, (Ptr)data, (long)datalen, |
| 374 | &selStart, &selEnd)) != 0 ) |
| 375 | return ici_error(err); |
| 376 | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | static char ici_ICMapFilename__doc__[] = |
| 381 | "(filename)->mapinfo; Get filemap info for given filename" |
| 382 | ; |
| 383 | |
| 384 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 385 | ici_ICMapFilename(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 386 | { |
| 387 | ICError err; |
| 388 | Str255 filename; |
| 389 | ICMapEntry entry; |
| 390 | |
| 391 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, filename)) |
| 392 | return NULL; |
| 393 | if ((err=ICMapFilename(self->inst, filename, &entry)) != 0 ) |
| 394 | return ici_error(err); |
| 395 | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
| 396 | PyMac_BuildOSType, entry.file_type, |
| 397 | PyMac_BuildOSType, entry.file_creator, |
| 398 | PyMac_BuildOSType, entry.post_creator, |
| 399 | entry.flags, |
| 400 | PyMac_BuildStr255, entry.extension, |
| 401 | PyMac_BuildStr255, entry.creator_app_name, |
| 402 | PyMac_BuildStr255, entry.post_app_name, |
| 403 | PyMac_BuildStr255, entry.MIME_type, |
| 404 | PyMac_BuildStr255, entry.entry_name); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | static char ici_ICMapTypeCreator__doc__[] = |
| 409 | "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename" |
| 410 | ; |
| 411 | |
| 412 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 413 | ici_ICMapTypeCreator(iciobject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 414 | { |
| 415 | ICError err; |
| 416 | OSType type, creator; |
| 417 | Str255 filename; |
| 418 | ICMapEntry entry; |
| 419 | |
| 420 | if (!PyArg_ParseTuple(args, "O&O&O&", |
| 421 | PyMac_GetOSType, &type, |
| 422 | PyMac_GetOSType, &creator, |
| 423 | PyMac_GetStr255, filename)) |
| 424 | return NULL; |
| 425 | if ((err=ICMapTypeCreator(self->inst, type, creator, 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 struct PyMethodDef ici_methods[] = { |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 441 | #if TARGET_API_MAC_OS8 |
Jack Jansen | 5a8115c | 2001-01-29 13:27:46 +0000 | [diff] [blame] | 442 | {"ICFindConfigFile", (PyCFunction)ici_ICFindConfigFile, METH_VARARGS, ici_ICFindConfigFile__doc__}, |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 443 | {"ICFindUserConfigFile", (PyCFunction)ici_ICFindUserConfigFile, METH_VARARGS, ici_ICFindUserConfigFile__doc__}, |
| 444 | {"ICChooseConfig", (PyCFunction)ici_ICChooseConfig, METH_VARARGS, ici_ICChooseConfig__doc__}, |
| 445 | {"ICChooseNewConfig", (PyCFunction)ici_ICChooseNewConfig, METH_VARARGS, ici_ICChooseNewConfig__doc__}, |
Jack Jansen | 6143d53 | 2001-05-19 12:34:59 +0000 | [diff] [blame] | 446 | #endif /* TARGET_API_MAC_OS8 */ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 447 | {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS, ici_ICGetSeed__doc__}, |
| 448 | {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS, ici_ICBegin__doc__}, |
| 449 | {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS, ici_ICFindPrefHandle__doc__}, |
| 450 | {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS, ici_ICSetPref__doc__}, |
| 451 | {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS, ici_ICCountPref__doc__}, |
| 452 | {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS, ici_ICGetIndPref__doc__}, |
| 453 | {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS, ici_ICDeletePref__doc__}, |
| 454 | {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS, ici_ICEnd__doc__}, |
| 455 | {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS, ici_ICEditPreferences__doc__}, |
| 456 | {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS, ici_ICParseURL__doc__}, |
| 457 | {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS, ici_ICLaunchURL__doc__}, |
| 458 | {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS, ici_ICMapFilename__doc__}, |
| 459 | {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS, ici_ICMapTypeCreator__doc__}, |
| 460 | |
| 461 | {NULL, NULL} /* sentinel */ |
| 462 | }; |
| 463 | |
| 464 | /* ---------- */ |
| 465 | |
| 466 | |
| 467 | static iciobject * |
| 468 | newiciobject(OSType creator) |
| 469 | { |
| 470 | iciobject *self; |
| 471 | ICError err; |
| 472 | |
| 473 | self = PyObject_NEW(iciobject, &Icitype); |
| 474 | if (self == NULL) |
| 475 | return NULL; |
| 476 | if ((err=ICStart(&self->inst, creator)) != 0 ) { |
| 477 | (void)ici_error(err); |
| 478 | PyMem_DEL(self); |
| 479 | return NULL; |
| 480 | } |
| 481 | return self; |
| 482 | } |
| 483 | |
| 484 | |
| 485 | static void |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 486 | ici_dealloc(iciobject *self) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 487 | { |
| 488 | (void)ICStop(self->inst); |
| 489 | PyMem_DEL(self); |
| 490 | } |
| 491 | |
| 492 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 493 | ici_getattr(iciobject *self, char *name) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 494 | { |
| 495 | return Py_FindMethod(ici_methods, (PyObject *)self, name); |
| 496 | } |
| 497 | |
| 498 | static char Icitype__doc__[] = |
| 499 | "Internet Config instance" |
| 500 | ; |
| 501 | |
| 502 | static PyTypeObject Icitype = { |
| 503 | PyObject_HEAD_INIT(&PyType_Type) |
| 504 | 0, /*ob_size*/ |
Guido van Rossum | 1464839 | 2001-12-08 18:02:58 +0000 | [diff] [blame^] | 505 | "icglue.ic_instance", /*tp_name*/ |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 506 | sizeof(iciobject), /*tp_basicsize*/ |
| 507 | 0, /*tp_itemsize*/ |
| 508 | /* methods */ |
| 509 | (destructor)ici_dealloc, /*tp_dealloc*/ |
| 510 | (printfunc)0, /*tp_print*/ |
| 511 | (getattrfunc)ici_getattr, /*tp_getattr*/ |
| 512 | (setattrfunc)0, /*tp_setattr*/ |
| 513 | (cmpfunc)0, /*tp_compare*/ |
| 514 | (reprfunc)0, /*tp_repr*/ |
| 515 | 0, /*tp_as_number*/ |
| 516 | 0, /*tp_as_sequence*/ |
| 517 | 0, /*tp_as_mapping*/ |
| 518 | (hashfunc)0, /*tp_hash*/ |
| 519 | (ternaryfunc)0, /*tp_call*/ |
| 520 | (reprfunc)0, /*tp_str*/ |
| 521 | |
| 522 | /* Space for future expansion */ |
| 523 | 0L,0L,0L,0L, |
| 524 | Icitype__doc__ /* Documentation string */ |
| 525 | }; |
| 526 | |
| 527 | /* End of code for ic_instance objects */ |
| 528 | /* -------------------------------------------------------- */ |
| 529 | |
| 530 | |
| 531 | static char ic_ICStart__doc__[] = |
| 532 | "(OSType)->ic_instance; Create an Internet Config instance" |
| 533 | ; |
| 534 | |
| 535 | static PyObject * |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 536 | ic_ICStart(PyObject *self, PyObject *args) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 537 | { |
| 538 | OSType creator; |
| 539 | |
| 540 | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &creator)) |
| 541 | return NULL; |
| 542 | return (PyObject *)newiciobject(creator); |
| 543 | } |
| 544 | |
| 545 | /* List of methods defined in the module */ |
| 546 | |
| 547 | static struct PyMethodDef ic_methods[] = { |
| 548 | {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS, ic_ICStart__doc__}, |
| 549 | |
| 550 | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
| 551 | }; |
| 552 | |
| 553 | |
| 554 | /* Initialization function for the module (*must* be called initicglue) */ |
| 555 | |
| 556 | static char icglue_module_documentation[] = |
| 557 | "Implements low-level Internet Config interface" |
| 558 | ; |
| 559 | |
| 560 | void |
Jack Jansen | 1767f93 | 2001-09-04 22:20:39 +0000 | [diff] [blame] | 561 | initicglue(void) |
Jack Jansen | 8ce72f5 | 1997-01-07 16:18:32 +0000 | [diff] [blame] | 562 | { |
| 563 | PyObject *m, *d; |
| 564 | |
| 565 | /* Create the module and add the functions */ |
| 566 | m = Py_InitModule4("icglue", ic_methods, |
| 567 | icglue_module_documentation, |
| 568 | (PyObject*)NULL,PYTHON_API_VERSION); |
| 569 | |
| 570 | /* Add some symbolic constants to the module */ |
| 571 | d = PyModule_GetDict(m); |
| 572 | ErrorObject = PyString_FromString("icglue.error"); |
| 573 | PyDict_SetItemString(d, "error", ErrorObject); |
| 574 | |
| 575 | /* XXXX Add constants here */ |
| 576 | |
| 577 | /* Check for errors */ |
| 578 | if (PyErr_Occurred()) |
| 579 | Py_FatalError("can't initialize module icglue"); |
| 580 | } |
| 581 | |