Guido van Rossum | 40d94e0 | 1995-02-19 15:51:11 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 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 | |
| 27 | #include "allobjects.h" |
| 28 | #include "modsupport.h" |
| 29 | |
| 30 | #include <Types.h> |
| 31 | #include <GestaltEqu.h> |
| 32 | |
| 33 | static object * |
| 34 | gestalt_gestalt(self, args) |
| 35 | object *self; |
| 36 | object *args; |
| 37 | { |
| 38 | OSErr iErr; |
| 39 | char *str; |
| 40 | int size; |
| 41 | OSType selector; |
| 42 | long response; |
| 43 | if (!getargs(args, "s#", &str, &size)) |
| 44 | return NULL; |
| 45 | if (size != 4) { |
| 46 | err_setstr(TypeError, "gestalt arg must be 4-char string"); |
| 47 | return NULL; |
| 48 | } |
| 49 | selector = *(OSType*)str; |
| 50 | iErr = Gestalt ( selector, &response ); |
| 51 | if (iErr != 0) { |
| 52 | char buf[100]; |
| 53 | sprintf(buf, "Gestalt error code %d", iErr); |
| 54 | err_setstr(RuntimeError, buf); |
| 55 | return NULL; |
| 56 | } |
| 57 | return newintobject(response); |
| 58 | } |
| 59 | |
| 60 | static struct methodlist gestalt_methods[] = { |
| 61 | {"gestalt", gestalt_gestalt}, |
| 62 | {NULL, NULL} /* Sentinel */ |
| 63 | }; |
| 64 | |
| 65 | void |
| 66 | initgestalt() |
| 67 | { |
| 68 | initmodule("gestalt", gestalt_methods); |
| 69 | } |