| 1 | n/a | /*********************************************************** |
|---|
| 2 | n/a | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
|---|
| 3 | n/a | The Netherlands. |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | All Rights Reserved |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | Permission to use, copy, modify, and distribute this software and its |
|---|
| 8 | n/a | documentation for any purpose and without fee is hereby granted, |
|---|
| 9 | n/a | provided that the above copyright notice appear in all copies and that |
|---|
| 10 | n/a | both that copyright notice and this permission notice appear in |
|---|
| 11 | n/a | supporting documentation, and that the names of Stichting Mathematisch |
|---|
| 12 | n/a | Centrum or CWI or Corporation for National Research Initiatives or |
|---|
| 13 | n/a | CNRI not be used in advertising or publicity pertaining to |
|---|
| 14 | n/a | distribution of the software without specific, written prior |
|---|
| 15 | n/a | permission. |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | While CWI is the initial source for this software, a modified version |
|---|
| 18 | n/a | is made available by the Corporation for National Research Initiatives |
|---|
| 19 | n/a | (CNRI) at the Internet address ftp://ftp.python.org. |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|---|
| 22 | n/a | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|---|
| 23 | n/a | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|---|
| 24 | n/a | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|---|
| 25 | n/a | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|---|
| 26 | n/a | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|---|
| 27 | n/a | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|---|
| 28 | n/a | PERFORMANCE OF THIS SOFTWARE. |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | ******************************************************************/ |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | #include "Python.h" |
|---|
| 33 | n/a | #include "pymactoolbox.h" |
|---|
| 34 | n/a | |
|---|
| 35 | n/a | extern int ResObj_Convert(PyObject *, Handle *); /* From Resmodule.c */ |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | #include <Carbon/Carbon.h> |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | static PyObject *ErrorObject; |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | /* ----------------------------------------------------- */ |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | /* Declarations for objects of type ic_instance */ |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | typedef struct { |
|---|
| 46 | n/a | PyObject_HEAD |
|---|
| 47 | n/a | ICInstance inst; |
|---|
| 48 | n/a | } iciobject; |
|---|
| 49 | n/a | |
|---|
| 50 | n/a | static PyTypeObject Icitype; |
|---|
| 51 | n/a | |
|---|
| 52 | n/a | |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | /* ---------------------------------------------------------------- */ |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | |
|---|
| 57 | n/a | static char ici_ICGetSeed__doc__[] = |
|---|
| 58 | n/a | "()->int; Returns int that changes when configuration does" |
|---|
| 59 | n/a | ; |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | static PyObject * |
|---|
| 62 | n/a | ici_ICGetSeed(iciobject *self, PyObject *args) |
|---|
| 63 | n/a | { |
|---|
| 64 | n/a | OSStatus err; |
|---|
| 65 | n/a | long seed; |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 68 | n/a | return NULL; |
|---|
| 69 | n/a | if ((err=ICGetSeed(self->inst, &seed)) != 0 ) |
|---|
| 70 | n/a | return PyMac_Error(err); |
|---|
| 71 | n/a | return Py_BuildValue("i", (int)seed); |
|---|
| 72 | n/a | } |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | |
|---|
| 75 | n/a | static char ici_ICBegin__doc__[] = |
|---|
| 76 | n/a | "(perm)->None; Lock config file for read/write" |
|---|
| 77 | n/a | ; |
|---|
| 78 | n/a | |
|---|
| 79 | n/a | static PyObject * |
|---|
| 80 | n/a | ici_ICBegin(iciobject *self, PyObject *args) |
|---|
| 81 | n/a | { |
|---|
| 82 | n/a | OSStatus err; |
|---|
| 83 | n/a | int perm; |
|---|
| 84 | n/a | |
|---|
| 85 | n/a | if (!PyArg_ParseTuple(args, "i", &perm)) |
|---|
| 86 | n/a | return NULL; |
|---|
| 87 | n/a | if ((err=ICBegin(self->inst, (ICPerm)perm)) != 0 ) |
|---|
| 88 | n/a | return PyMac_Error(err); |
|---|
| 89 | n/a | Py_INCREF(Py_None); |
|---|
| 90 | n/a | return Py_None; |
|---|
| 91 | n/a | } |
|---|
| 92 | n/a | |
|---|
| 93 | n/a | |
|---|
| 94 | n/a | static char ici_ICFindPrefHandle__doc__[] = |
|---|
| 95 | n/a | "(key, handle)->attrs; Lookup key, store result in handle, return attributes" |
|---|
| 96 | n/a | ; |
|---|
| 97 | n/a | |
|---|
| 98 | n/a | static PyObject * |
|---|
| 99 | n/a | ici_ICFindPrefHandle(iciobject *self, PyObject *args) |
|---|
| 100 | n/a | { |
|---|
| 101 | n/a | OSStatus err; |
|---|
| 102 | n/a | Str255 key; |
|---|
| 103 | n/a | ICAttr attr; |
|---|
| 104 | n/a | Handle h; |
|---|
| 105 | n/a | |
|---|
| 106 | n/a | if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetStr255, &key, ResObj_Convert, &h)) |
|---|
| 107 | n/a | return NULL; |
|---|
| 108 | n/a | if ((err=ICFindPrefHandle(self->inst, key, &attr, h)) != 0 ) |
|---|
| 109 | n/a | return PyMac_Error(err); |
|---|
| 110 | n/a | return Py_BuildValue("i", (int)attr); |
|---|
| 111 | n/a | } |
|---|
| 112 | n/a | |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | static char ici_ICSetPref__doc__[] = |
|---|
| 115 | n/a | "(key, attr, data)->None; Set preference key to data with attributes" |
|---|
| 116 | n/a | ; |
|---|
| 117 | n/a | |
|---|
| 118 | n/a | static PyObject * |
|---|
| 119 | n/a | ici_ICSetPref(iciobject *self, PyObject *args) |
|---|
| 120 | n/a | { |
|---|
| 121 | n/a | OSStatus err; |
|---|
| 122 | n/a | Str255 key; |
|---|
| 123 | n/a | int attr; |
|---|
| 124 | n/a | char *data; |
|---|
| 125 | n/a | int datalen; |
|---|
| 126 | n/a | |
|---|
| 127 | n/a | if (!PyArg_ParseTuple(args, "O&is#", PyMac_GetStr255, &key, &attr, |
|---|
| 128 | n/a | &data, &datalen)) |
|---|
| 129 | n/a | return NULL; |
|---|
| 130 | n/a | if ((err=ICSetPref(self->inst, key, (ICAttr)attr, (Ptr)data, |
|---|
| 131 | n/a | (long)datalen)) != 0) |
|---|
| 132 | n/a | return PyMac_Error(err); |
|---|
| 133 | n/a | Py_INCREF(Py_None); |
|---|
| 134 | n/a | return Py_None; |
|---|
| 135 | n/a | } |
|---|
| 136 | n/a | |
|---|
| 137 | n/a | |
|---|
| 138 | n/a | static char ici_ICCountPref__doc__[] = |
|---|
| 139 | n/a | "()->int; Return number of preferences" |
|---|
| 140 | n/a | ; |
|---|
| 141 | n/a | |
|---|
| 142 | n/a | static PyObject * |
|---|
| 143 | n/a | ici_ICCountPref(iciobject *self, PyObject *args) |
|---|
| 144 | n/a | { |
|---|
| 145 | n/a | OSStatus err; |
|---|
| 146 | n/a | long count; |
|---|
| 147 | n/a | |
|---|
| 148 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 149 | n/a | return NULL; |
|---|
| 150 | n/a | if ((err=ICCountPref(self->inst, &count)) != 0 ) |
|---|
| 151 | n/a | return PyMac_Error(err); |
|---|
| 152 | n/a | return Py_BuildValue("i", (int)count); |
|---|
| 153 | n/a | } |
|---|
| 154 | n/a | |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | static char ici_ICGetIndPref__doc__[] = |
|---|
| 157 | n/a | "(num)->key; Return key of preference with given index" |
|---|
| 158 | n/a | ; |
|---|
| 159 | n/a | |
|---|
| 160 | n/a | static PyObject * |
|---|
| 161 | n/a | ici_ICGetIndPref(iciobject *self, PyObject *args) |
|---|
| 162 | n/a | { |
|---|
| 163 | n/a | OSStatus err; |
|---|
| 164 | n/a | long num; |
|---|
| 165 | n/a | Str255 key; |
|---|
| 166 | n/a | |
|---|
| 167 | n/a | if (!PyArg_ParseTuple(args, "l", &num)) |
|---|
| 168 | n/a | return NULL; |
|---|
| 169 | n/a | if ((err=ICGetIndPref(self->inst, num, key)) != 0 ) |
|---|
| 170 | n/a | return PyMac_Error(err); |
|---|
| 171 | n/a | return Py_BuildValue("O&", PyMac_BuildStr255, key); |
|---|
| 172 | n/a | } |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | |
|---|
| 175 | n/a | static char ici_ICDeletePref__doc__[] = |
|---|
| 176 | n/a | "(key)->None; Delete preference" |
|---|
| 177 | n/a | ; |
|---|
| 178 | n/a | |
|---|
| 179 | n/a | static PyObject * |
|---|
| 180 | n/a | ici_ICDeletePref(iciobject *self, PyObject *args) |
|---|
| 181 | n/a | { |
|---|
| 182 | n/a | OSStatus err; |
|---|
| 183 | n/a | Str255 key; |
|---|
| 184 | n/a | |
|---|
| 185 | n/a | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
|---|
| 186 | n/a | return NULL; |
|---|
| 187 | n/a | if ((err=ICDeletePref(self->inst, key)) != 0 ) |
|---|
| 188 | n/a | return PyMac_Error(err); |
|---|
| 189 | n/a | Py_INCREF(Py_None); |
|---|
| 190 | n/a | return Py_None; |
|---|
| 191 | n/a | } |
|---|
| 192 | n/a | |
|---|
| 193 | n/a | |
|---|
| 194 | n/a | static char ici_ICEnd__doc__[] = |
|---|
| 195 | n/a | "()->None; Unlock file after ICBegin call" |
|---|
| 196 | n/a | ; |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | static PyObject * |
|---|
| 199 | n/a | ici_ICEnd(iciobject *self, PyObject *args) |
|---|
| 200 | n/a | { |
|---|
| 201 | n/a | OSStatus err; |
|---|
| 202 | n/a | |
|---|
| 203 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 204 | n/a | return NULL; |
|---|
| 205 | n/a | if ((err=ICEnd(self->inst)) != 0 ) |
|---|
| 206 | n/a | return PyMac_Error(err); |
|---|
| 207 | n/a | Py_INCREF(Py_None); |
|---|
| 208 | n/a | return Py_None; |
|---|
| 209 | n/a | } |
|---|
| 210 | n/a | |
|---|
| 211 | n/a | |
|---|
| 212 | n/a | static char ici_ICEditPreferences__doc__[] = |
|---|
| 213 | n/a | "(key)->None; Ask user to edit preferences, staring with key" |
|---|
| 214 | n/a | ; |
|---|
| 215 | n/a | |
|---|
| 216 | n/a | static PyObject * |
|---|
| 217 | n/a | ici_ICEditPreferences(iciobject *self, PyObject *args) |
|---|
| 218 | n/a | { |
|---|
| 219 | n/a | OSStatus err; |
|---|
| 220 | n/a | Str255 key; |
|---|
| 221 | n/a | |
|---|
| 222 | n/a | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, key)) |
|---|
| 223 | n/a | return NULL; |
|---|
| 224 | n/a | if ((err=ICEditPreferences(self->inst, key)) != 0 ) |
|---|
| 225 | n/a | return PyMac_Error(err); |
|---|
| 226 | n/a | Py_INCREF(Py_None); |
|---|
| 227 | n/a | return Py_None; |
|---|
| 228 | n/a | } |
|---|
| 229 | n/a | |
|---|
| 230 | n/a | |
|---|
| 231 | n/a | static char ici_ICParseURL__doc__[] = |
|---|
| 232 | n/a | "(hint, data, selStart, selEnd, handle)->selStart, selEnd; Find an URL, return in handle" |
|---|
| 233 | n/a | ; |
|---|
| 234 | n/a | |
|---|
| 235 | n/a | static PyObject * |
|---|
| 236 | n/a | ici_ICParseURL(iciobject *self, PyObject *args) |
|---|
| 237 | n/a | { |
|---|
| 238 | n/a | OSStatus err; |
|---|
| 239 | n/a | Str255 hint; |
|---|
| 240 | n/a | char *data; |
|---|
| 241 | n/a | int datalen; |
|---|
| 242 | n/a | long selStart, selEnd; |
|---|
| 243 | n/a | Handle h; |
|---|
| 244 | n/a | |
|---|
| 245 | n/a | if (!PyArg_ParseTuple(args, "O&s#llO&", PyMac_GetStr255, hint, &data, &datalen, |
|---|
| 246 | n/a | &selStart, &selEnd, ResObj_Convert, &h)) |
|---|
| 247 | n/a | return NULL; |
|---|
| 248 | n/a | if ((err=ICParseURL(self->inst, hint, (Ptr)data, (long)datalen, |
|---|
| 249 | n/a | &selStart, &selEnd, h)) != 0 ) |
|---|
| 250 | n/a | return PyMac_Error(err); |
|---|
| 251 | n/a | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
|---|
| 252 | n/a | } |
|---|
| 253 | n/a | |
|---|
| 254 | n/a | |
|---|
| 255 | n/a | static char ici_ICLaunchURL__doc__[] = |
|---|
| 256 | n/a | "(hint, data, selStart, selEnd)->None; Find an URL and launch the correct app" |
|---|
| 257 | n/a | ; |
|---|
| 258 | n/a | |
|---|
| 259 | n/a | static PyObject * |
|---|
| 260 | n/a | ici_ICLaunchURL(iciobject *self, PyObject *args) |
|---|
| 261 | n/a | { |
|---|
| 262 | n/a | OSStatus err; |
|---|
| 263 | n/a | Str255 hint; |
|---|
| 264 | n/a | char *data; |
|---|
| 265 | n/a | int datalen; |
|---|
| 266 | n/a | long selStart, selEnd; |
|---|
| 267 | n/a | |
|---|
| 268 | n/a | if (!PyArg_ParseTuple(args, "O&s#ll", PyMac_GetStr255, hint, &data, &datalen, |
|---|
| 269 | n/a | &selStart, &selEnd)) |
|---|
| 270 | n/a | return NULL; |
|---|
| 271 | n/a | if ((err=ICLaunchURL(self->inst, hint, (Ptr)data, (long)datalen, |
|---|
| 272 | n/a | &selStart, &selEnd)) != 0 ) |
|---|
| 273 | n/a | return PyMac_Error(err); |
|---|
| 274 | n/a | return Py_BuildValue("ii", (int)selStart, (int)selEnd); |
|---|
| 275 | n/a | } |
|---|
| 276 | n/a | |
|---|
| 277 | n/a | |
|---|
| 278 | n/a | static char ici_ICMapFilename__doc__[] = |
|---|
| 279 | n/a | "(filename)->mapinfo; Get filemap info for given filename" |
|---|
| 280 | n/a | ; |
|---|
| 281 | n/a | |
|---|
| 282 | n/a | static PyObject * |
|---|
| 283 | n/a | ici_ICMapFilename(iciobject *self, PyObject *args) |
|---|
| 284 | n/a | { |
|---|
| 285 | n/a | OSStatus err; |
|---|
| 286 | n/a | Str255 filename; |
|---|
| 287 | n/a | ICMapEntry entry; |
|---|
| 288 | n/a | |
|---|
| 289 | n/a | if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, filename)) |
|---|
| 290 | n/a | return NULL; |
|---|
| 291 | n/a | if ((err=ICMapFilename(self->inst, filename, &entry)) != 0 ) |
|---|
| 292 | n/a | return PyMac_Error(err); |
|---|
| 293 | n/a | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
|---|
| 294 | n/a | PyMac_BuildOSType, entry.fileType, |
|---|
| 295 | n/a | PyMac_BuildOSType, entry.fileCreator, |
|---|
| 296 | n/a | PyMac_BuildOSType, entry.postCreator, |
|---|
| 297 | n/a | entry.flags, |
|---|
| 298 | n/a | PyMac_BuildStr255, entry.extension, |
|---|
| 299 | n/a | PyMac_BuildStr255, entry.creatorAppName, |
|---|
| 300 | n/a | PyMac_BuildStr255, entry.postAppName, |
|---|
| 301 | n/a | PyMac_BuildStr255, entry.MIMEType, |
|---|
| 302 | n/a | PyMac_BuildStr255, entry.entryName); |
|---|
| 303 | n/a | } |
|---|
| 304 | n/a | |
|---|
| 305 | n/a | |
|---|
| 306 | n/a | static char ici_ICMapTypeCreator__doc__[] = |
|---|
| 307 | n/a | "(type, creator, filename)->mapinfo; Get filemap info for given tp/cr/filename" |
|---|
| 308 | n/a | ; |
|---|
| 309 | n/a | |
|---|
| 310 | n/a | static PyObject * |
|---|
| 311 | n/a | ici_ICMapTypeCreator(iciobject *self, PyObject *args) |
|---|
| 312 | n/a | { |
|---|
| 313 | n/a | OSStatus err; |
|---|
| 314 | n/a | OSType type, creator; |
|---|
| 315 | n/a | Str255 filename; |
|---|
| 316 | n/a | ICMapEntry entry; |
|---|
| 317 | n/a | |
|---|
| 318 | n/a | if (!PyArg_ParseTuple(args, "O&O&O&", |
|---|
| 319 | n/a | PyMac_GetOSType, &type, |
|---|
| 320 | n/a | PyMac_GetOSType, &creator, |
|---|
| 321 | n/a | PyMac_GetStr255, filename)) |
|---|
| 322 | n/a | return NULL; |
|---|
| 323 | n/a | if ((err=ICMapTypeCreator(self->inst, type, creator, filename, &entry)) != 0 ) |
|---|
| 324 | n/a | return PyMac_Error(err); |
|---|
| 325 | n/a | return Py_BuildValue("hO&O&O&lO&O&O&O&O&", entry.version, |
|---|
| 326 | n/a | PyMac_BuildOSType, entry.fileType, |
|---|
| 327 | n/a | PyMac_BuildOSType, entry.fileCreator, |
|---|
| 328 | n/a | PyMac_BuildOSType, entry.postCreator, |
|---|
| 329 | n/a | entry.flags, |
|---|
| 330 | n/a | PyMac_BuildStr255, entry.extension, |
|---|
| 331 | n/a | PyMac_BuildStr255, entry.creatorAppName, |
|---|
| 332 | n/a | PyMac_BuildStr255, entry.postAppName, |
|---|
| 333 | n/a | PyMac_BuildStr255, entry.MIMEType, |
|---|
| 334 | n/a | PyMac_BuildStr255, entry.entryName); |
|---|
| 335 | n/a | } |
|---|
| 336 | n/a | |
|---|
| 337 | n/a | |
|---|
| 338 | n/a | static struct PyMethodDef ici_methods[] = { |
|---|
| 339 | n/a | {"ICGetSeed", (PyCFunction)ici_ICGetSeed, METH_VARARGS, ici_ICGetSeed__doc__}, |
|---|
| 340 | n/a | {"ICBegin", (PyCFunction)ici_ICBegin, METH_VARARGS, ici_ICBegin__doc__}, |
|---|
| 341 | n/a | {"ICFindPrefHandle", (PyCFunction)ici_ICFindPrefHandle, METH_VARARGS, ici_ICFindPrefHandle__doc__}, |
|---|
| 342 | n/a | {"ICSetPref", (PyCFunction)ici_ICSetPref, METH_VARARGS, ici_ICSetPref__doc__}, |
|---|
| 343 | n/a | {"ICCountPref", (PyCFunction)ici_ICCountPref, METH_VARARGS, ici_ICCountPref__doc__}, |
|---|
| 344 | n/a | {"ICGetIndPref", (PyCFunction)ici_ICGetIndPref, METH_VARARGS, ici_ICGetIndPref__doc__}, |
|---|
| 345 | n/a | {"ICDeletePref", (PyCFunction)ici_ICDeletePref, METH_VARARGS, ici_ICDeletePref__doc__}, |
|---|
| 346 | n/a | {"ICEnd", (PyCFunction)ici_ICEnd, METH_VARARGS, ici_ICEnd__doc__}, |
|---|
| 347 | n/a | {"ICEditPreferences", (PyCFunction)ici_ICEditPreferences, METH_VARARGS, ici_ICEditPreferences__doc__}, |
|---|
| 348 | n/a | {"ICParseURL", (PyCFunction)ici_ICParseURL, METH_VARARGS, ici_ICParseURL__doc__}, |
|---|
| 349 | n/a | {"ICLaunchURL", (PyCFunction)ici_ICLaunchURL, METH_VARARGS, ici_ICLaunchURL__doc__}, |
|---|
| 350 | n/a | {"ICMapFilename", (PyCFunction)ici_ICMapFilename, METH_VARARGS, ici_ICMapFilename__doc__}, |
|---|
| 351 | n/a | {"ICMapTypeCreator", (PyCFunction)ici_ICMapTypeCreator, METH_VARARGS, ici_ICMapTypeCreator__doc__}, |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | {NULL, NULL} /* sentinel */ |
|---|
| 354 | n/a | }; |
|---|
| 355 | n/a | |
|---|
| 356 | n/a | /* ---------- */ |
|---|
| 357 | n/a | |
|---|
| 358 | n/a | |
|---|
| 359 | n/a | static iciobject * |
|---|
| 360 | n/a | newiciobject(OSType creator) |
|---|
| 361 | n/a | { |
|---|
| 362 | n/a | iciobject *self; |
|---|
| 363 | n/a | OSStatus err; |
|---|
| 364 | n/a | |
|---|
| 365 | n/a | self = PyObject_NEW(iciobject, &Icitype); |
|---|
| 366 | n/a | if (self == NULL) |
|---|
| 367 | n/a | return NULL; |
|---|
| 368 | n/a | if ((err=ICStart(&self->inst, creator)) != 0 ) { |
|---|
| 369 | n/a | (void)PyMac_Error(err); |
|---|
| 370 | n/a | PyObject_DEL(self); |
|---|
| 371 | n/a | return NULL; |
|---|
| 372 | n/a | } |
|---|
| 373 | n/a | return self; |
|---|
| 374 | n/a | } |
|---|
| 375 | n/a | |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | static void |
|---|
| 378 | n/a | ici_dealloc(iciobject *self) |
|---|
| 379 | n/a | { |
|---|
| 380 | n/a | (void)ICStop(self->inst); |
|---|
| 381 | n/a | PyObject_DEL(self); |
|---|
| 382 | n/a | } |
|---|
| 383 | n/a | |
|---|
| 384 | n/a | static PyObject * |
|---|
| 385 | n/a | ici_getattr(iciobject *self, char *name) |
|---|
| 386 | n/a | { |
|---|
| 387 | n/a | return Py_FindMethod(ici_methods, (PyObject *)self, name); |
|---|
| 388 | n/a | } |
|---|
| 389 | n/a | |
|---|
| 390 | n/a | static char Icitype__doc__[] = |
|---|
| 391 | n/a | "Internet Config instance" |
|---|
| 392 | n/a | ; |
|---|
| 393 | n/a | |
|---|
| 394 | n/a | static PyTypeObject Icitype = { |
|---|
| 395 | n/a | PyObject_HEAD_INIT(&PyType_Type) |
|---|
| 396 | n/a | 0, /*ob_size*/ |
|---|
| 397 | n/a | "icglue.ic_instance", /*tp_name*/ |
|---|
| 398 | n/a | sizeof(iciobject), /*tp_basicsize*/ |
|---|
| 399 | n/a | 0, /*tp_itemsize*/ |
|---|
| 400 | n/a | /* methods */ |
|---|
| 401 | n/a | (destructor)ici_dealloc, /*tp_dealloc*/ |
|---|
| 402 | n/a | (printfunc)0, /*tp_print*/ |
|---|
| 403 | n/a | (getattrfunc)ici_getattr, /*tp_getattr*/ |
|---|
| 404 | n/a | (setattrfunc)0, /*tp_setattr*/ |
|---|
| 405 | n/a | (cmpfunc)0, /*tp_compare*/ |
|---|
| 406 | n/a | (reprfunc)0, /*tp_repr*/ |
|---|
| 407 | n/a | 0, /*tp_as_number*/ |
|---|
| 408 | n/a | 0, /*tp_as_sequence*/ |
|---|
| 409 | n/a | 0, /*tp_as_mapping*/ |
|---|
| 410 | n/a | (hashfunc)0, /*tp_hash*/ |
|---|
| 411 | n/a | (ternaryfunc)0, /*tp_call*/ |
|---|
| 412 | n/a | (reprfunc)0, /*tp_str*/ |
|---|
| 413 | n/a | |
|---|
| 414 | n/a | /* Space for future expansion */ |
|---|
| 415 | n/a | 0L,0L,0L,0L, |
|---|
| 416 | n/a | Icitype__doc__ /* Documentation string */ |
|---|
| 417 | n/a | }; |
|---|
| 418 | n/a | |
|---|
| 419 | n/a | /* End of code for ic_instance objects */ |
|---|
| 420 | n/a | /* -------------------------------------------------------- */ |
|---|
| 421 | n/a | |
|---|
| 422 | n/a | |
|---|
| 423 | n/a | static char ic_ICStart__doc__[] = |
|---|
| 424 | n/a | "(OSType)->ic_instance; Create an Internet Config instance" |
|---|
| 425 | n/a | ; |
|---|
| 426 | n/a | |
|---|
| 427 | n/a | static PyObject * |
|---|
| 428 | n/a | ic_ICStart(PyObject *self, PyObject *args) |
|---|
| 429 | n/a | { |
|---|
| 430 | n/a | OSType creator; |
|---|
| 431 | n/a | |
|---|
| 432 | n/a | if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &creator)) |
|---|
| 433 | n/a | return NULL; |
|---|
| 434 | n/a | return (PyObject *)newiciobject(creator); |
|---|
| 435 | n/a | } |
|---|
| 436 | n/a | |
|---|
| 437 | n/a | /* List of methods defined in the module */ |
|---|
| 438 | n/a | |
|---|
| 439 | n/a | static struct PyMethodDef ic_methods[] = { |
|---|
| 440 | n/a | {"ICStart", (PyCFunction)ic_ICStart, METH_VARARGS, ic_ICStart__doc__}, |
|---|
| 441 | n/a | |
|---|
| 442 | n/a | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
|---|
| 443 | n/a | }; |
|---|
| 444 | n/a | |
|---|
| 445 | n/a | |
|---|
| 446 | n/a | /* Initialization function for the module (*must* be called initicglue) */ |
|---|
| 447 | n/a | |
|---|
| 448 | n/a | static char icglue_module_documentation[] = |
|---|
| 449 | n/a | "Implements low-level Internet Config interface" |
|---|
| 450 | n/a | ; |
|---|
| 451 | n/a | |
|---|
| 452 | n/a | void |
|---|
| 453 | n/a | initicglue(void) |
|---|
| 454 | n/a | { |
|---|
| 455 | n/a | PyObject *m, *d; |
|---|
| 456 | n/a | |
|---|
| 457 | n/a | if (PyErr_WarnPy3k("In 3.x, the icglue module is removed.", 1)) |
|---|
| 458 | n/a | return; |
|---|
| 459 | n/a | |
|---|
| 460 | n/a | /* Create the module and add the functions */ |
|---|
| 461 | n/a | m = Py_InitModule4("icglue", ic_methods, |
|---|
| 462 | n/a | icglue_module_documentation, |
|---|
| 463 | n/a | (PyObject*)NULL,PYTHON_API_VERSION); |
|---|
| 464 | n/a | |
|---|
| 465 | n/a | /* Add some symbolic constants to the module */ |
|---|
| 466 | n/a | d = PyModule_GetDict(m); |
|---|
| 467 | n/a | ErrorObject = PyMac_GetOSErrException(); |
|---|
| 468 | n/a | if (ErrorObject == NULL || |
|---|
| 469 | n/a | PyDict_SetItemString(d, "error", ErrorObject) != 0) |
|---|
| 470 | n/a | return; |
|---|
| 471 | n/a | |
|---|
| 472 | n/a | /* XXXX Add constants here */ |
|---|
| 473 | n/a | |
|---|
| 474 | n/a | /* Check for errors */ |
|---|
| 475 | n/a | if (PyErr_Occurred()) |
|---|
| 476 | n/a | Py_FatalError("can't initialize module icglue"); |
|---|
| 477 | n/a | } |
|---|
| 478 | n/a | |
|---|