blob: 11946a5ff7f3d93bae6b8f4353535be7a9cd4ede [file] [log] [blame]
Guido van Rossum40d94e01995-02-19 15:51:11 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossum40d94e01995-02-19 15:51:11 +00003The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum2d167031994-09-16 10:54:21 +000025/* Macintosh Gestalt interface */
26
Jack Jansenf5c20571997-01-30 15:48:07 +000027#include "Python.h"
Jack Jansen95026921999-08-23 11:37:51 +000028#include "macglue.h"
Guido van Rossum2d167031994-09-16 10:54:21 +000029
Jack Jansen0194ad52001-05-12 22:46:35 +000030#ifdef WITHOUT_FRAMEWORKS
Guido van Rossum2d167031994-09-16 10:54:21 +000031#include <Types.h>
Jack Jansen4a8c54e1997-02-24 13:56:59 +000032#include <Gestalt.h>
Jack Jansen0194ad52001-05-12 22:46:35 +000033#else
34#include <Carbon/Carbon.h>
35#endif
Guido van Rossum2d167031994-09-16 10:54:21 +000036
Jack Jansenf5c20571997-01-30 15:48:07 +000037static PyObject *
Jack Jansenf894f6f2001-09-04 22:29:31 +000038gestalt_gestalt(PyObject *self, PyObject *args)
Guido van Rossum2d167031994-09-16 10:54:21 +000039{
40 OSErr iErr;
41 char *str;
42 int size;
43 OSType selector;
44 long response;
Jack Jansenf5c20571997-01-30 15:48:07 +000045 if (!PyArg_Parse(args, "s#", &str, &size))
Guido van Rossum2d167031994-09-16 10:54:21 +000046 return NULL;
47 if (size != 4) {
Jack Jansenf5c20571997-01-30 15:48:07 +000048 PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
Guido van Rossum2d167031994-09-16 10:54:21 +000049 return NULL;
50 }
51 selector = *(OSType*)str;
52 iErr = Gestalt ( selector, &response );
Jack Jansen95026921999-08-23 11:37:51 +000053 if (iErr != 0)
54 return PyMac_Error(iErr);
Jack Jansenf5c20571997-01-30 15:48:07 +000055 return PyInt_FromLong(response);
Guido van Rossum2d167031994-09-16 10:54:21 +000056}
57
Jack Jansenf5c20571997-01-30 15:48:07 +000058static struct PyMethodDef gestalt_methods[] = {
Guido van Rossum2d167031994-09-16 10:54:21 +000059 {"gestalt", gestalt_gestalt},
60 {NULL, NULL} /* Sentinel */
61};
62
63void
Jack Jansenf894f6f2001-09-04 22:29:31 +000064initgestalt(void)
Guido van Rossum2d167031994-09-16 10:54:21 +000065{
Jack Jansenf5c20571997-01-30 15:48:07 +000066 Py_InitModule("gestalt", gestalt_methods);
Guido van Rossum2d167031994-09-16 10:54:21 +000067}