Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f93c72a

Browse files
committed
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.
1 parent 34e7cae commit f93c72a

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Mac/Include/macglue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
char *macstrerror PROTO((int)); /* strerror with mac errors */
2+
object *PyErr_Mac PROTO((object *, int)); /* Exception with a mac error */
3+
int PyMac_Idle PROTO((void)); /* Idle routine */

Mac/Python/macglue.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
** macglue - A couple of mac-specific routines often needed.
3+
**
4+
** Jack Jansen, CWI, 1994.
5+
*/
6+
7+
#ifdef HAVE_CONFIG_H
8+
#include "config.h"
9+
#endif
10+
11+
#include "Python.h"
12+
#include "macglue.h"
13+
14+
#include <OSUtils.h> /* for Set(Current)A5 */
15+
#include <Resources.h>
16+
#include <Memory.h>
17+
#include <Events.h>
18+
#include <Windows.h>
19+
#include <Desk.h>
20+
21+
/* Replace strerror with something that might work */
22+
char *macstrerror(int err)
23+
{
24+
static char buf[256];
25+
Handle h;
26+
char *str;
27+
28+
h = GetResource('Estr', err);
29+
if ( h ) {
30+
HLock(h);
31+
str = (char *)*h;
32+
memcpy(buf, str+1, (unsigned char)str[0]);
33+
HUnlock(h);
34+
ReleaseResource(h);
35+
} else {
36+
sprintf(buf, "Mac OS error code %d", err);
37+
}
38+
return buf;
39+
}
40+
41+
/* Set a MAC-specific error from errno, and return NULL; return None if no error */
42+
PyObject *
43+
PyErr_Mac(object *eobj, int err)
44+
{
45+
char *msg;
46+
PyObject *v;
47+
Handle h;
48+
49+
if (err == 0) {
50+
Py_INCREF(Py_None);
51+
return Py_None;
52+
}
53+
msg = macstrerror(err);
54+
v = Py_BuildValue("(is)", err, msg);
55+
PyErr_SetObject(eobj, v);
56+
Py_DECREF(v);
57+
return NULL;
58+
}
59+
60+
/*
61+
** Idle routine for busy-wait loops.
62+
** This is rather tricky: if we see an event we check whether it is
63+
** for somebody else (i.e. a click outside our windows) and, if so,
64+
** we pass the event on (so the user can switch processes). However,
65+
** by doing this we loose events meant for our windows. Too bad, I guess...
66+
*/
67+
int
68+
PyMac_Idle()
69+
{
70+
EventRecord ev;
71+
WindowPtr wp;
72+
73+
#if 0
74+
SystemTask();
75+
if ( intrcheck() )
76+
return 0;
77+
if ( GetNextEvent(0xffff, &ev) ) {
78+
if ( ev.what == mouseDown ) {
79+
if ( FindWindow(ev.where, &wp) == inSysWindow )
80+
SystemClick(&ev, wp);
81+
}
82+
}
83+
#endif
84+
return 1;
85+
}
86+

0 commit comments

Comments
 (0)