Guido van Rossum | 40d94e0 | 1995-02-19 15:51:11 +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, |
Guido van Rossum | 40d94e0 | 1995-02-19 15:51:11 +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 not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 25 | /* Macintosh Gestalt interface */ |
| 26 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 27 | #include "Python.h" |
Jack Jansen | 9502692 | 1999-08-23 11:37:51 +0000 | [diff] [blame] | 28 | #include "macglue.h" |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 29 | |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 30 | #ifdef WITHOUT_FRAMEWORKS |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 31 | #include <Types.h> |
Jack Jansen | 4a8c54e | 1997-02-24 13:56:59 +0000 | [diff] [blame] | 32 | #include <Gestalt.h> |
Jack Jansen | 0194ad5 | 2001-05-12 22:46:35 +0000 | [diff] [blame] | 33 | #else |
| 34 | #include <Carbon/Carbon.h> |
| 35 | #endif |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 36 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 37 | static PyObject * |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 38 | gestalt_gestalt(self, args) |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 39 | PyObject *self; |
| 40 | PyObject *args; |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 41 | { |
| 42 | OSErr iErr; |
| 43 | char *str; |
| 44 | int size; |
| 45 | OSType selector; |
| 46 | long response; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 47 | if (!PyArg_Parse(args, "s#", &str, &size)) |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 48 | return NULL; |
| 49 | if (size != 4) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 50 | PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string"); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 51 | return NULL; |
| 52 | } |
| 53 | selector = *(OSType*)str; |
| 54 | iErr = Gestalt ( selector, &response ); |
Jack Jansen | 9502692 | 1999-08-23 11:37:51 +0000 | [diff] [blame] | 55 | if (iErr != 0) |
| 56 | return PyMac_Error(iErr); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 57 | return PyInt_FromLong(response); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 60 | static struct PyMethodDef gestalt_methods[] = { |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 61 | {"gestalt", gestalt_gestalt}, |
| 62 | {NULL, NULL} /* Sentinel */ |
| 63 | }; |
| 64 | |
| 65 | void |
| 66 | initgestalt() |
| 67 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 68 | Py_InitModule("gestalt", gestalt_methods); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 69 | } |