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