blob: 3cba45b5d500f549093ec09069e96354b330b50f [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
30#include <Types.h>
Jack Jansen4a8c54e1997-02-24 13:56:59 +000031#include <Gestalt.h>
Guido van Rossum2d167031994-09-16 10:54:21 +000032
Jack Jansenf5c20571997-01-30 15:48:07 +000033static PyObject *
Guido van Rossum2d167031994-09-16 10:54:21 +000034gestalt_gestalt(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +000035 PyObject *self;
36 PyObject *args;
Guido van Rossum2d167031994-09-16 10:54:21 +000037{
38 OSErr iErr;
39 char *str;
40 int size;
41 OSType selector;
42 long response;
Jack Jansenf5c20571997-01-30 15:48:07 +000043 if (!PyArg_Parse(args, "s#", &str, &size))
Guido van Rossum2d167031994-09-16 10:54:21 +000044 return NULL;
45 if (size != 4) {
Jack Jansenf5c20571997-01-30 15:48:07 +000046 PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
Guido van Rossum2d167031994-09-16 10:54:21 +000047 return NULL;
48 }
49 selector = *(OSType*)str;
50 iErr = Gestalt ( selector, &response );
Jack Jansen95026921999-08-23 11:37:51 +000051 if (iErr != 0)
52 return PyMac_Error(iErr);
Jack Jansenf5c20571997-01-30 15:48:07 +000053 return PyInt_FromLong(response);
Guido van Rossum2d167031994-09-16 10:54:21 +000054}
55
Jack Jansenf5c20571997-01-30 15:48:07 +000056static struct PyMethodDef gestalt_methods[] = {
Guido van Rossum2d167031994-09-16 10:54:21 +000057 {"gestalt", gestalt_gestalt},
58 {NULL, NULL} /* Sentinel */
59};
60
61void
62initgestalt()
63{
Jack Jansenf5c20571997-01-30 15:48:07 +000064 Py_InitModule("gestalt", gestalt_methods);
Guido van Rossum2d167031994-09-16 10:54:21 +000065}