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 * |
Jack Jansen | f894f6f | 2001-09-04 22:29:31 +0000 | [diff] [blame] | 38 | gestalt_gestalt(PyObject *self, PyObject *args) |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 39 | { |
| 40 | OSErr iErr; |
| 41 | char *str; |
| 42 | int size; |
| 43 | OSType selector; |
| 44 | long response; |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 45 | if (!PyArg_Parse(args, "s#", &str, &size)) |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 46 | return NULL; |
| 47 | if (size != 4) { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 48 | PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string"); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 49 | return NULL; |
| 50 | } |
| 51 | selector = *(OSType*)str; |
| 52 | iErr = Gestalt ( selector, &response ); |
Jack Jansen | 9502692 | 1999-08-23 11:37:51 +0000 | [diff] [blame] | 53 | if (iErr != 0) |
| 54 | return PyMac_Error(iErr); |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 55 | return PyInt_FromLong(response); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 58 | static struct PyMethodDef gestalt_methods[] = { |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 59 | {"gestalt", gestalt_gestalt}, |
| 60 | {NULL, NULL} /* Sentinel */ |
| 61 | }; |
| 62 | |
| 63 | void |
Jack Jansen | f894f6f | 2001-09-04 22:29:31 +0000 | [diff] [blame] | 64 | initgestalt(void) |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 65 | { |
Jack Jansen | f5c2057 | 1997-01-30 15:48:07 +0000 | [diff] [blame] | 66 | Py_InitModule("gestalt", gestalt_methods); |
Guido van Rossum | 2d16703 | 1994-09-16 10:54:21 +0000 | [diff] [blame] | 67 | } |