gestaltmodule.c 1.93 KB
Newer Older
1
/***********************************************************
2
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
The Netherlands.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.

STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

******************************************************************/

25 26
/* Macintosh Gestalt interface */

Jack Jansen's avatar
Jack Jansen committed
27
#include "Python.h"
28
#include "pymactoolbox.h"
29

30
#include <Carbon/Carbon.h>
31

Jack Jansen's avatar
Jack Jansen committed
32
static PyObject *
33
gestalt_gestalt(PyObject *self, PyObject *args)
34 35 36 37 38 39
{
	OSErr iErr;
	char *str;
	int size;
	OSType selector;
	long response;
Jack Jansen's avatar
Jack Jansen committed
40
	if (!PyArg_Parse(args, "s#", &str, &size))
41 42
		return NULL;
	if (size != 4) {
Jack Jansen's avatar
Jack Jansen committed
43
		PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
44 45 46 47
		return NULL;
	}
	selector = *(OSType*)str;
	iErr = Gestalt ( selector, &response );
48 49
	if (iErr != 0) 
		return PyMac_Error(iErr);
Jack Jansen's avatar
Jack Jansen committed
50
	return PyInt_FromLong(response);
51 52
}

Jack Jansen's avatar
Jack Jansen committed
53
static struct PyMethodDef gestalt_methods[] = {
54 55 56 57 58
	{"gestalt", gestalt_gestalt},
	{NULL, NULL} /* Sentinel */
};

void
59
initgestalt(void)
60
{
Jack Jansen's avatar
Jack Jansen committed
61
	Py_InitModule("gestalt", gestalt_methods);
62
}