blob: 87225467427e98802c03034035625e949f031186 [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"
Guido van Rossum2d167031994-09-16 10:54:21 +000028
29#include <Types.h>
Jack Jansen4a8c54e1997-02-24 13:56:59 +000030#include <Gestalt.h>
Guido van Rossum2d167031994-09-16 10:54:21 +000031
Jack Jansenf5c20571997-01-30 15:48:07 +000032static PyObject *
Guido van Rossum2d167031994-09-16 10:54:21 +000033gestalt_gestalt(self, args)
Jack Jansenf5c20571997-01-30 15:48:07 +000034 PyObject *self;
35 PyObject *args;
Guido van Rossum2d167031994-09-16 10:54:21 +000036{
37 OSErr iErr;
38 char *str;
39 int size;
40 OSType selector;
41 long response;
Jack Jansenf5c20571997-01-30 15:48:07 +000042 if (!PyArg_Parse(args, "s#", &str, &size))
Guido van Rossum2d167031994-09-16 10:54:21 +000043 return NULL;
44 if (size != 4) {
Jack Jansenf5c20571997-01-30 15:48:07 +000045 PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
Guido van Rossum2d167031994-09-16 10:54:21 +000046 return NULL;
47 }
48 selector = *(OSType*)str;
49 iErr = Gestalt ( selector, &response );
50 if (iErr != 0) {
51 char buf[100];
52 sprintf(buf, "Gestalt error code %d", iErr);
Jack Jansenf5c20571997-01-30 15:48:07 +000053 PyErr_SetString(PyExc_RuntimeError, buf);
Guido van Rossum2d167031994-09-16 10:54:21 +000054 return NULL;
55 }
Jack Jansenf5c20571997-01-30 15:48:07 +000056 return PyInt_FromLong(response);
Guido van Rossum2d167031994-09-16 10:54:21 +000057}
58
Jack Jansenf5c20571997-01-30 15:48:07 +000059static struct PyMethodDef gestalt_methods[] = {
Guido van Rossum2d167031994-09-16 10:54:21 +000060 {"gestalt", gestalt_gestalt},
61 {NULL, NULL} /* Sentinel */
62};
63
64void
65initgestalt()
66{
Jack Jansenf5c20571997-01-30 15:48:07 +000067 Py_InitModule("gestalt", gestalt_methods);
Guido van Rossum2d167031994-09-16 10:54:21 +000068}