summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1994-12-14 14:07:50 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1994-12-14 14:07:50 (GMT)
commitf93c72a4b0bab30aac779aa3e957e9143764bda2 (patch)
tree25de1c889c793ed4ec01441c53885c628dc41e95 /Mac
parent34e7cae6634d89fbf160e1e8249c56012914bfe6 (diff)
downloadcpython-f93c72a4b0bab30aac779aa3e957e9143764bda2.zip
cpython-f93c72a4b0bab30aac779aa3e957e9143764bda2.tar.gz
cpython-f93c72a4b0bab30aac779aa3e957e9143764bda2.tar.bz2
New routines:
macstrerror - strerror which uses 'Estr' resource to convert numerical MacOS errors to strings. PyErr_Mac - Raise exception with MacOS error in string form. PyMac_Idle - better idle-loop routine, which allows the user to switch applications.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Include/macglue.h3
-rw-r--r--Mac/Python/macglue.c86
2 files changed, 89 insertions, 0 deletions
diff --git a/Mac/Include/macglue.h b/Mac/Include/macglue.h
new file mode 100644
index 0000000..1f5d98d
--- /dev/null
+++ b/Mac/Include/macglue.h
@@ -0,0 +1,3 @@
+char *macstrerror PROTO((int)); /* strerror with mac errors */
+object *PyErr_Mac PROTO((object *, int)); /* Exception with a mac error */
+int PyMac_Idle PROTO((void)); /* Idle routine */ \ No newline at end of file
diff --git a/Mac/Python/macglue.c b/Mac/Python/macglue.c
new file mode 100644
index 0000000..e5e224b
--- /dev/null
+++ b/Mac/Python/macglue.c
@@ -0,0 +1,86 @@
+/*
+** macglue - A couple of mac-specific routines often needed.
+**
+** Jack Jansen, CWI, 1994.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "Python.h"
+#include "macglue.h"
+
+#include <OSUtils.h> /* for Set(Current)A5 */
+#include <Resources.h>
+#include <Memory.h>
+#include <Events.h>
+#include <Windows.h>
+#include <Desk.h>
+
+/* Replace strerror with something that might work */
+char *macstrerror(int err)
+{
+ static char buf[256];
+ Handle h;
+ char *str;
+
+ h = GetResource('Estr', err);
+ if ( h ) {
+ HLock(h);
+ str = (char *)*h;
+ memcpy(buf, str+1, (unsigned char)str[0]);
+ HUnlock(h);
+ ReleaseResource(h);
+ } else {
+ sprintf(buf, "Mac OS error code %d", err);
+ }
+ return buf;
+}
+
+/* Set a MAC-specific error from errno, and return NULL; return None if no error */
+PyObject *
+PyErr_Mac(object *eobj, int err)
+{
+ char *msg;
+ PyObject *v;
+ Handle h;
+
+ if (err == 0) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ msg = macstrerror(err);
+ v = Py_BuildValue("(is)", err, msg);
+ PyErr_SetObject(eobj, v);
+ Py_DECREF(v);
+ return NULL;
+}
+
+/*
+** Idle routine for busy-wait loops.
+** This is rather tricky: if we see an event we check whether it is
+** for somebody else (i.e. a click outside our windows) and, if so,
+** we pass the event on (so the user can switch processes). However,
+** by doing this we loose events meant for our windows. Too bad, I guess...
+*/
+int
+PyMac_Idle()
+{
+ EventRecord ev;
+ WindowPtr wp;
+
+#if 0
+ SystemTask();
+ if ( intrcheck() )
+ return 0;
+ if ( GetNextEvent(0xffff, &ev) ) {
+ if ( ev.what == mouseDown ) {
+ if ( FindWindow(ev.where, &wp) == inSysWindow )
+ SystemClick(&ev, wp);
+ }
+ }
+#endif
+ return 1;
+}
+