]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
New routines:
authorJack Jansen <jack.jansen@cwi.nl>
Wed, 14 Dec 1994 14:07:50 +0000 (14:07 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Wed, 14 Dec 1994 14:07:50 +0000 (14:07 +0000)
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.

Mac/Include/macglue.h [new file with mode: 0644]
Mac/Python/macglue.c [new file with mode: 0644]

diff --git a/Mac/Include/macglue.h b/Mac/Include/macglue.h
new file mode 100644 (file)
index 0000000..1f5d98d
--- /dev/null
@@ -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 (file)
index 0000000..e5e224b
--- /dev/null
@@ -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;
+}
+