mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Renamed
This commit is contained in:
parent
22023f4b77
commit
f5c20575cb
5 changed files with 615 additions and 619 deletions
|
@ -26,7 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* ctbcm objects */
|
/* ctbcm objects */
|
||||||
|
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
|
|
||||||
|
@ -46,19 +46,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#define _CommToolboxTrap 0x8B
|
#define _CommToolboxTrap 0x8B
|
||||||
#define _UnimplementedOSTrap 0x9F
|
#define _UnimplementedOSTrap 0x9F
|
||||||
|
|
||||||
extern object *PyErr_Mac(object *,int);
|
extern PyObject *PyErr_Mac(PyObject *,int);
|
||||||
|
|
||||||
static object *ErrorObject;
|
static PyObject *ErrorObject;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
ConnHandle hdl; /* The handle to the connection */
|
ConnHandle hdl; /* The handle to the connection */
|
||||||
object *callback; /* Python callback routine */
|
PyObject *callback; /* Python callback routine */
|
||||||
int has_callback; /* True if callback not None */
|
int has_callback; /* True if callback not None */
|
||||||
int err; /* Error to pass to the callback */
|
int err; /* Error to pass to the callback */
|
||||||
} ctbcmobject;
|
} ctbcmobject;
|
||||||
|
|
||||||
staticforward typeobject ctbcmtype;
|
staticforward PyTypeObject ctbcmtype;
|
||||||
|
|
||||||
#define is_ctbcmobject(v) ((v)->ob_type == &ctbcmtype)
|
#define is_ctbcmobject(v) ((v)->ob_type == &ctbcmtype)
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ initialize_ctb()
|
||||||
initialized = 0;
|
initialized = 0;
|
||||||
|
|
||||||
if ( !TrapAvailable(_CommToolboxTrap, OSTrap) ) {
|
if ( !TrapAvailable(_CommToolboxTrap, OSTrap) ) {
|
||||||
err_setstr(ErrorObject, "CTB not available");
|
PyErr_SetString(ErrorObject, "CTB not available");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ( (err=InitCTBUtilities()) ) {
|
if ( (err=InitCTBUtilities()) ) {
|
||||||
|
@ -110,16 +110,16 @@ ctbcm_pycallback(arg)
|
||||||
void *arg;
|
void *arg;
|
||||||
{
|
{
|
||||||
ctbcmobject *self = (ctbcmobject *)arg;
|
ctbcmobject *self = (ctbcmobject *)arg;
|
||||||
object *args, *rv;
|
PyObject *args, *rv;
|
||||||
|
|
||||||
if ( !self->has_callback ) /* It could have been removed in the meantime */
|
if ( !self->has_callback ) /* It could have been removed in the meantime */
|
||||||
return 0;
|
return 0;
|
||||||
args = mkvalue("(i)", self->err);
|
args = Py_BuildValue("(i)", self->err);
|
||||||
rv = call_object(self->callback, args);
|
rv = PyEval_CallObject(self->callback, args);
|
||||||
DECREF(args);
|
Py_DECREF(args);
|
||||||
if( rv == NULL )
|
if( rv == NULL )
|
||||||
return -1;
|
return -1;
|
||||||
DECREF(rv);
|
Py_DECREF(rv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,15 +139,15 @@ ctbcm_ctbcallback(hconn)
|
||||||
|
|
||||||
static ctbcmobject *
|
static ctbcmobject *
|
||||||
newctbcmobject(arg)
|
newctbcmobject(arg)
|
||||||
object *arg;
|
PyObject *arg;
|
||||||
{
|
{
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
self = NEWOBJ(ctbcmobject, &ctbcmtype);
|
self = PyObject_NEW(ctbcmobject, &ctbcmtype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->hdl = NULL;
|
self->hdl = NULL;
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
self->callback = None;
|
self->callback = Py_None;
|
||||||
self->has_callback = 0;
|
self->has_callback = 0;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -164,104 +164,104 @@ ctbcm_dealloc(self)
|
||||||
CMDispose(self->hdl);
|
CMDispose(self->hdl);
|
||||||
self->hdl = NULL;
|
self->hdl = NULL;
|
||||||
}
|
}
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_open(self, args)
|
ctbcm_open(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
long timeout;
|
long timeout;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "l", &timeout))
|
if (!PyArg_Parse(args, "l", &timeout))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (err=CMOpen(self->hdl, self->has_callback, cb_upp, timeout)) < 0)
|
if ( (err=CMOpen(self->hdl, self->has_callback, cb_upp, timeout)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_listen(self, args)
|
ctbcm_listen(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
long timeout;
|
long timeout;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "l", &timeout))
|
if (!PyArg_Parse(args, "l", &timeout))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (err=CMListen(self->hdl,self->has_callback, cb_upp, timeout)) < 0)
|
if ( (err=CMListen(self->hdl,self->has_callback, cb_upp, timeout)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_accept(self, args)
|
ctbcm_accept(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int accept;
|
int accept;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!getargs(args, "i", &accept))
|
if (!PyArg_Parse(args, "i", &accept))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (err=CMAccept(self->hdl, accept)) < 0)
|
if ( (err=CMAccept(self->hdl, accept)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_close(self, args)
|
ctbcm_close(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int now;
|
int now;
|
||||||
long timeout;
|
long timeout;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "(li)", &timeout, &now))
|
if (!PyArg_Parse(args, "(li)", &timeout, &now))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (err=CMClose(self->hdl, self->has_callback, cb_upp, timeout, now)) < 0)
|
if ( (err=CMClose(self->hdl, self->has_callback, cb_upp, timeout, now)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_read(self, args)
|
ctbcm_read(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
long timeout, len;
|
long timeout, len;
|
||||||
int chan;
|
int chan;
|
||||||
CMFlags flags;
|
CMFlags flags;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
object *rv;
|
PyObject *rv;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "(lil)", &len, &chan, &timeout))
|
if (!PyArg_Parse(args, "(lil)", &len, &chan, &timeout))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((rv=newsizedstringobject(NULL, len)) == NULL)
|
if ((rv=PyString_FromStringAndSize(NULL, len)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=CMRead(self->hdl, (Ptr)getstringvalue(rv), &len, (CMChannel)chan,
|
if ((err=CMRead(self->hdl, (Ptr)PyString_AsString(rv), &len, (CMChannel)chan,
|
||||||
self->has_callback, cb_upp, timeout, &flags)) < 0)
|
self->has_callback, cb_upp, timeout, &flags)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
resizestring(&rv, len);
|
_PyString_Resize(&rv, len);
|
||||||
return mkvalue("(Oi)", rv, (int)flags);
|
return Py_BuildValue("(Oi)", rv, (int)flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_write(self, args)
|
ctbcm_write(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
long timeout, len;
|
long timeout, len;
|
||||||
int chan, ilen, flags;
|
int chan, ilen, flags;
|
||||||
|
@ -269,184 +269,184 @@ ctbcm_write(self, args)
|
||||||
char *buf;
|
char *buf;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "(s#ili)", &buf, &ilen, &chan, &timeout, &flags))
|
if (!PyArg_Parse(args, "(s#ili)", &buf, &ilen, &chan, &timeout, &flags))
|
||||||
return NULL;
|
return NULL;
|
||||||
len = ilen;
|
len = ilen;
|
||||||
if ((err=CMWrite(self->hdl, (Ptr)buf, &len, (CMChannel)chan,
|
if ((err=CMWrite(self->hdl, (Ptr)buf, &len, (CMChannel)chan,
|
||||||
self->has_callback, cb_upp, timeout, (CMFlags)flags)) < 0)
|
self->has_callback, cb_upp, timeout, (CMFlags)flags)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
return newintobject((int)len);
|
return PyInt_FromLong((int)len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_status(self, args)
|
ctbcm_status(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
CMBufferSizes sizes;
|
CMBufferSizes sizes;
|
||||||
CMStatFlags flags;
|
CMStatFlags flags;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
object *rv;
|
PyObject *rv;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=CMStatus(self->hdl, sizes, &flags)) < 0)
|
if ((err=CMStatus(self->hdl, sizes, &flags)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, (int)err);
|
return PyErr_Mac(ErrorObject, (int)err);
|
||||||
rv = mkvalue("(llllll)", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5]);
|
rv = Py_BuildValue("(llllll)", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5]);
|
||||||
if ( rv == NULL )
|
if ( rv == NULL )
|
||||||
return NULL;
|
return NULL;
|
||||||
return mkvalue("(Ol)", rv, (long)flags);
|
return Py_BuildValue("(Ol)", rv, (long)flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_getconfig(self, args)
|
ctbcm_getconfig(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *rv;
|
char *rv;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((rv=(char *)CMGetConfig(self->hdl)) == NULL ) {
|
if ((rv=(char *)CMGetConfig(self->hdl)) == NULL ) {
|
||||||
err_setstr(ErrorObject, "CMGetConfig failed");
|
PyErr_SetString(ErrorObject, "CMGetConfig failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return newstringobject(rv);
|
return PyString_FromString(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_setconfig(self, args)
|
ctbcm_setconfig(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *cfg;
|
char *cfg;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!getargs(args, "s", &cfg))
|
if (!PyArg_Parse(args, "s", &cfg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=CMSetConfig(self->hdl, (Ptr)cfg)) < 0)
|
if ((err=CMSetConfig(self->hdl, (Ptr)cfg)) < 0)
|
||||||
return PyErr_Mac(ErrorObject, err);
|
return PyErr_Mac(ErrorObject, err);
|
||||||
return newintobject((int)err);
|
return PyInt_FromLong((int)err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_choose(self, args)
|
ctbcm_choose(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
Point pt;
|
Point pt;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
pt.v = 40;
|
pt.v = 40;
|
||||||
pt.h = 40;
|
pt.h = 40;
|
||||||
rv=CMChoose(&self->hdl, pt, (ConnectionChooseIdleUPP)0);
|
rv=CMChoose(&self->hdl, pt, (ConnectionChooseIdleUPP)0);
|
||||||
return newintobject(rv);
|
return PyInt_FromLong(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_idle(self, args)
|
ctbcm_idle(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
CMIdle(self->hdl);
|
CMIdle(self->hdl);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_abort(self, args)
|
ctbcm_abort(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
CMAbort(self->hdl);
|
CMAbort(self->hdl);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_reset(self, args)
|
ctbcm_reset(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
CMReset(self->hdl);
|
CMReset(self->hdl);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_break(self, args)
|
ctbcm_break(self, args)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
long duration;
|
long duration;
|
||||||
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
|
||||||
|
|
||||||
if (!getargs(args, "l", &duration))
|
if (!PyArg_Parse(args, "l", &duration))
|
||||||
return NULL;
|
return NULL;
|
||||||
CMBreak(self->hdl, duration,self->has_callback, cb_upp);
|
CMBreak(self->hdl, duration,self->has_callback, cb_upp);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist ctbcm_methods[] = {
|
static struct PyMethodDef ctbcm_methods[] = {
|
||||||
{"Open", (method)ctbcm_open},
|
{"Open", (PyCFunction)ctbcm_open},
|
||||||
{"Close", (method)ctbcm_close},
|
{"Close", (PyCFunction)ctbcm_close},
|
||||||
{"Read", (method)ctbcm_read},
|
{"Read", (PyCFunction)ctbcm_read},
|
||||||
{"Write", (method)ctbcm_write},
|
{"Write", (PyCFunction)ctbcm_write},
|
||||||
{"Status", (method)ctbcm_status},
|
{"Status", (PyCFunction)ctbcm_status},
|
||||||
{"GetConfig", (method)ctbcm_getconfig},
|
{"GetConfig", (PyCFunction)ctbcm_getconfig},
|
||||||
{"SetConfig", (method)ctbcm_setconfig},
|
{"SetConfig", (PyCFunction)ctbcm_setconfig},
|
||||||
{"Choose", (method)ctbcm_choose},
|
{"Choose", (PyCFunction)ctbcm_choose},
|
||||||
{"Idle", (method)ctbcm_idle},
|
{"Idle", (PyCFunction)ctbcm_idle},
|
||||||
{"Listen", (method)ctbcm_listen},
|
{"Listen", (PyCFunction)ctbcm_listen},
|
||||||
{"Accept", (method)ctbcm_accept},
|
{"Accept", (PyCFunction)ctbcm_accept},
|
||||||
{"Abort", (method)ctbcm_abort},
|
{"Abort", (PyCFunction)ctbcm_abort},
|
||||||
{"Reset", (method)ctbcm_reset},
|
{"Reset", (PyCFunction)ctbcm_reset},
|
||||||
{"Break", (method)ctbcm_break},
|
{"Break", (PyCFunction)ctbcm_break},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctbcm_getattr(self, name)
|
ctbcm_getattr(self, name)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
if ( strcmp(name, "callback") == 0 ) {
|
if ( strcmp(name, "callback") == 0 ) {
|
||||||
INCREF(self->callback);
|
Py_INCREF(self->callback);
|
||||||
return self->callback;
|
return self->callback;
|
||||||
}
|
}
|
||||||
return findmethod(ctbcm_methods, (object *)self, name);
|
return Py_FindMethod(ctbcm_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ctbcm_setattr(self, name, v)
|
ctbcm_setattr(self, name, v)
|
||||||
ctbcmobject *self;
|
ctbcmobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
object *v;
|
PyObject *v;
|
||||||
{
|
{
|
||||||
if ( strcmp(name, "callback") != 0 ) {
|
if ( strcmp(name, "callback") != 0 ) {
|
||||||
err_setstr(AttributeError, "ctbcm objects have callback attr only");
|
PyErr_SetString(PyExc_AttributeError, "ctbcm objects have callback attr only");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( v == NULL ) {
|
if ( v == NULL ) {
|
||||||
v = None;
|
v = Py_None;
|
||||||
}
|
}
|
||||||
INCREF(v); /* XXXX Must I do this? */
|
Py_INCREF(v); /* XXXX Must I do this? */
|
||||||
self->callback = v;
|
self->callback = v;
|
||||||
self->has_callback = (v != None);
|
self->has_callback = (v != Py_None);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
statichere typeobject ctbcmtype = {
|
statichere PyTypeObject ctbcmtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"ctbcm", /*tp_name*/
|
"ctbcm", /*tp_name*/
|
||||||
sizeof(ctbcmobject), /*tp_basicsize*/
|
sizeof(ctbcmobject), /*tp_basicsize*/
|
||||||
|
@ -467,13 +467,13 @@ statichere typeobject ctbcmtype = {
|
||||||
|
|
||||||
/* Function of no arguments returning new ctbcm object */
|
/* Function of no arguments returning new ctbcm object */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctb_cmnew(self, args)
|
ctb_cmnew(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int strlen;
|
int strlen;
|
||||||
object *sizes_obj;
|
PyObject *sizes_obj;
|
||||||
char *c_str;
|
char *c_str;
|
||||||
unsigned char p_str[255];
|
unsigned char p_str[255];
|
||||||
CMBufferSizes sizes;
|
CMBufferSizes sizes;
|
||||||
|
@ -481,16 +481,16 @@ ctb_cmnew(self, args)
|
||||||
ConnHandle hdl;
|
ConnHandle hdl;
|
||||||
ctbcmobject *rv;
|
ctbcmobject *rv;
|
||||||
|
|
||||||
if (!getargs(args, "(s#O)", &c_str, &strlen, &sizes_obj))
|
if (!PyArg_Parse(args, "(s#O)", &c_str, &strlen, &sizes_obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
strncpy((char *)p_str+1, c_str, strlen);
|
strncpy((char *)p_str+1, c_str, strlen);
|
||||||
p_str[0] = strlen;
|
p_str[0] = strlen;
|
||||||
if (!initialize_ctb())
|
if (!initialize_ctb())
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( sizes_obj == None ) {
|
if ( sizes_obj == Py_None ) {
|
||||||
memset(sizes, '\0', sizeof sizes);
|
memset(sizes, '\0', sizeof sizes);
|
||||||
} else {
|
} else {
|
||||||
if ( !getargs(sizes_obj, "(llllll)", &sizes[0], &sizes[1], &sizes[2],
|
if ( !PyArg_Parse(sizes_obj, "(llllll)", &sizes[0], &sizes[1], &sizes[2],
|
||||||
&sizes[3], &sizes[4], &sizes[5]))
|
&sizes[3], &sizes[4], &sizes[5]))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +498,7 @@ ctb_cmnew(self, args)
|
||||||
return PyErr_Mac(ErrorObject, procid);
|
return PyErr_Mac(ErrorObject, procid);
|
||||||
hdl = CMNew(procid, cmNoMenus|cmQuiet, sizes, 0, 0);
|
hdl = CMNew(procid, cmNoMenus|cmQuiet, sizes, 0, 0);
|
||||||
if ( hdl == NULL ) {
|
if ( hdl == NULL ) {
|
||||||
err_setstr(ErrorObject, "CMNew failed");
|
PyErr_SetString(ErrorObject, "CMNew failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rv = newctbcmobject(args);
|
rv = newctbcmobject(args);
|
||||||
|
@ -506,26 +506,26 @@ ctb_cmnew(self, args)
|
||||||
return NULL; /* XXXX Should dispose of hdl */
|
return NULL; /* XXXX Should dispose of hdl */
|
||||||
rv->hdl = hdl;
|
rv->hdl = hdl;
|
||||||
CMSetUserData(hdl, (long)rv);
|
CMSetUserData(hdl, (long)rv);
|
||||||
return (object *)rv;
|
return (PyObject *)rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ctb_available(self, args)
|
ctb_available(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
ok = initialize_ctb();
|
ok = initialize_ctb();
|
||||||
err_clear();
|
PyErr_Clear();
|
||||||
return newintobject(ok);
|
return PyInt_FromLong(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List of functions defined in the module */
|
/* List of functions defined in the module */
|
||||||
|
|
||||||
static struct methodlist ctb_methods[] = {
|
static struct PyMethodDef ctb_methods[] = {
|
||||||
{"CMNew", ctb_cmnew},
|
{"CMNew", ctb_cmnew},
|
||||||
{"available", ctb_available},
|
{"available", ctb_available},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
|
@ -537,15 +537,15 @@ static struct methodlist ctb_methods[] = {
|
||||||
void
|
void
|
||||||
initctb()
|
initctb()
|
||||||
{
|
{
|
||||||
object *m, *d, *o;
|
PyObject *m, *d, *o;
|
||||||
|
|
||||||
/* Create the module and add the functions */
|
/* Create the module and add the functions */
|
||||||
m = initmodule("ctb", ctb_methods);
|
m = Py_InitModule("ctb", ctb_methods);
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = getmoduledict(m);
|
d = PyModule_GetDict(m);
|
||||||
|
|
||||||
#define CMCONST(name, value) o = newintobject(value); dictinsert(d, name, o)
|
#define CMCONST(name, value) o = PyInt_FromLong(value); PyDict_SetItemString(d, name, o)
|
||||||
|
|
||||||
CMCONST("cmData", 1);
|
CMCONST("cmData", 1);
|
||||||
CMCONST("cmCntl", 2);
|
CMCONST("cmCntl", 2);
|
||||||
|
@ -576,10 +576,10 @@ initctb()
|
||||||
CMCONST("cmStatusListenPend", 0x2000);
|
CMCONST("cmStatusListenPend", 0x2000);
|
||||||
CMCONST("cmStatusIncomingCallPresent", 0x4000);
|
CMCONST("cmStatusIncomingCallPresent", 0x4000);
|
||||||
|
|
||||||
ErrorObject = newstringobject("ctb.error");
|
ErrorObject = PyString_FromString("ctb.error");
|
||||||
dictinsert(d, "error", ErrorObject);
|
PyDict_SetItemString(d, "error", ErrorObject);
|
||||||
|
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
if (err_occurred())
|
if (PyErr_Occurred())
|
||||||
fatal("can't initialize module ctb");
|
Py_FatalError("can't initialize module ctb");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,26 +24,25 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* Macintosh Gestalt interface */
|
/* Macintosh Gestalt interface */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h"
|
|
||||||
|
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
#include <GestaltEqu.h>
|
#include <GestaltEqu.h>
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
gestalt_gestalt(self, args)
|
gestalt_gestalt(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr iErr;
|
OSErr iErr;
|
||||||
char *str;
|
char *str;
|
||||||
int size;
|
int size;
|
||||||
OSType selector;
|
OSType selector;
|
||||||
long response;
|
long response;
|
||||||
if (!getargs(args, "s#", &str, &size))
|
if (!PyArg_Parse(args, "s#", &str, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (size != 4) {
|
if (size != 4) {
|
||||||
err_setstr(TypeError, "gestalt arg must be 4-char string");
|
PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
selector = *(OSType*)str;
|
selector = *(OSType*)str;
|
||||||
|
@ -51,13 +50,13 @@ gestalt_gestalt(self, args)
|
||||||
if (iErr != 0) {
|
if (iErr != 0) {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
sprintf(buf, "Gestalt error code %d", iErr);
|
sprintf(buf, "Gestalt error code %d", iErr);
|
||||||
err_setstr(RuntimeError, buf);
|
PyErr_SetString(PyExc_RuntimeError, buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return newintobject(response);
|
return PyInt_FromLong(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist gestalt_methods[] = {
|
static struct PyMethodDef gestalt_methods[] = {
|
||||||
{"gestalt", gestalt_gestalt},
|
{"gestalt", gestalt_gestalt},
|
||||||
{NULL, NULL} /* Sentinel */
|
{NULL, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
@ -65,5 +64,5 @@ static struct methodlist gestalt_methods[] = {
|
||||||
void
|
void
|
||||||
initgestalt()
|
initgestalt()
|
||||||
{
|
{
|
||||||
initmodule("gestalt", gestalt_methods);
|
Py_InitModule("gestalt", gestalt_methods);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h" /* For getargs() etc. */
|
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
|
|
||||||
#include <Memory.h>
|
#include <Memory.h>
|
||||||
|
@ -39,17 +38,17 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#define FileFilterUPP FileFilterProcPtr
|
#define FileFilterUPP FileFilterProcPtr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static object *ErrorObject;
|
static PyObject *ErrorObject;
|
||||||
|
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
/* Declarations for objects of type Alias */
|
/* Declarations for objects of type Alias */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
AliasHandle alias;
|
AliasHandle alias;
|
||||||
} mfsaobject;
|
} mfsaobject;
|
||||||
|
|
||||||
staticforward typeobject Mfsatype;
|
staticforward PyTypeObject Mfsatype;
|
||||||
|
|
||||||
#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
|
#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
|
||||||
|
|
||||||
|
@ -57,11 +56,11 @@ staticforward typeobject Mfsatype;
|
||||||
/* Declarations for objects of type FSSpec */
|
/* Declarations for objects of type FSSpec */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
FSSpec fsspec;
|
FSSpec fsspec;
|
||||||
} mfssobject;
|
} mfssobject;
|
||||||
|
|
||||||
staticforward typeobject Mfsstype;
|
staticforward PyTypeObject Mfsstype;
|
||||||
|
|
||||||
#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
|
#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
|
||||||
|
|
||||||
|
@ -70,11 +69,11 @@ staticforward typeobject Mfsstype;
|
||||||
/* Declarations for objects of type FInfo */
|
/* Declarations for objects of type FInfo */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
FInfo finfo;
|
FInfo finfo;
|
||||||
} mfsiobject;
|
} mfsiobject;
|
||||||
|
|
||||||
staticforward typeobject Mfsitype;
|
staticforward PyTypeObject Mfsitype;
|
||||||
|
|
||||||
#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
|
#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
|
||||||
|
|
||||||
|
@ -83,17 +82,17 @@ mfssobject *newmfssobject(FSSpec *fss); /* Forward */
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfsa_Resolve(self, args)
|
mfsa_Resolve(self, args)
|
||||||
mfsaobject *self;
|
mfsaobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec from, *fromp, result;
|
FSSpec from, *fromp, result;
|
||||||
Boolean changed;
|
Boolean changed;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
from.name[0] = 0;
|
from.name[0] = 0;
|
||||||
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &from))
|
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (from.name[0] )
|
if (from.name[0] )
|
||||||
fromp = &from;
|
fromp = &from;
|
||||||
|
@ -104,39 +103,39 @@ mfsa_Resolve(self, args)
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkvalue("(Oi)", newmfssobject(&result), (int)changed);
|
return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfsa_GetInfo(self, args)
|
mfsa_GetInfo(self, args)
|
||||||
mfsaobject *self;
|
mfsaobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
Str63 value;
|
Str63 value;
|
||||||
int i;
|
int i;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!newgetargs(args, "i", &i))
|
if (!PyArg_ParseTuple(args, "i", &i))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
|
err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return newsizedstringobject((char *)&value[1], value[0]);
|
return PyString_FromStringAndSize((char *)&value[1], value[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfsa_Update(self, args)
|
mfsa_Update(self, args)
|
||||||
mfsaobject *self;
|
mfsaobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec target, fromfile, *fromfilep;
|
FSSpec target, fromfile, *fromfilep;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
Boolean changed;
|
Boolean changed;
|
||||||
|
|
||||||
fromfile.name[0] = 0;
|
fromfile.name[0] = 0;
|
||||||
if (!newgetargs(args, "O&|O&", PyMac_GetFSSpec, &target,
|
if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
|
||||||
PyMac_GetFSSpec, &fromfile))
|
PyMac_GetFSSpec, &fromfile))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( fromfile.name[0] )
|
if ( fromfile.name[0] )
|
||||||
|
@ -148,20 +147,20 @@ mfsa_Update(self, args)
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return mkvalue("i", (int)changed);
|
return Py_BuildValue("i", (int)changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist mfsa_methods[] = {
|
static struct PyMethodDef mfsa_methods[] = {
|
||||||
{"Resolve", (method)mfsa_Resolve, 1},
|
{"Resolve", (PyCFunction)mfsa_Resolve, 1},
|
||||||
{"GetInfo", (method)mfsa_GetInfo, 1},
|
{"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
|
||||||
{"Update", (method)mfsa_Update, 1},
|
{"Update", (PyCFunction)mfsa_Update, 1},
|
||||||
|
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfsa_getattr(self, name)
|
mfsa_getattr(self, name)
|
||||||
mfsaobject *self;
|
mfsaobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -176,7 +175,7 @@ mfsa_getattr(self, name)
|
||||||
HUnlock((Handle)self->alias);
|
HUnlock((Handle)self->alias);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
return findmethod(mfsa_methods, (object *)self, name);
|
return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
mfsaobject *
|
mfsaobject *
|
||||||
|
@ -185,7 +184,7 @@ newmfsaobject(alias)
|
||||||
{
|
{
|
||||||
mfsaobject *self;
|
mfsaobject *self;
|
||||||
|
|
||||||
self = NEWOBJ(mfsaobject, &Mfsatype);
|
self = PyObject_NEW(mfsaobject, &Mfsatype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->alias = alias;
|
self->alias = alias;
|
||||||
|
@ -203,11 +202,11 @@ mfsa_dealloc(self)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
statichere typeobject Mfsatype = {
|
statichere PyTypeObject Mfsatype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"Alias", /*tp_name*/
|
"Alias", /*tp_name*/
|
||||||
sizeof(mfsaobject), /*tp_basicsize*/
|
sizeof(mfsaobject), /*tp_basicsize*/
|
||||||
|
@ -230,7 +229,7 @@ statichere typeobject Mfsatype = {
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct methodlist mfsi_methods[] = {
|
static struct PyMethodDef mfsi_methods[] = {
|
||||||
|
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
@ -242,7 +241,7 @@ newmfsiobject()
|
||||||
{
|
{
|
||||||
mfsiobject *self;
|
mfsiobject *self;
|
||||||
|
|
||||||
self = NEWOBJ(mfsiobject, &Mfsitype);
|
self = PyObject_NEW(mfsiobject, &Mfsitype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset((char *)&self->finfo, '\0', sizeof(self->finfo));
|
memset((char *)&self->finfo, '\0', sizeof(self->finfo));
|
||||||
|
@ -253,10 +252,10 @@ static void
|
||||||
mfsi_dealloc(self)
|
mfsi_dealloc(self)
|
||||||
mfsiobject *self;
|
mfsiobject *self;
|
||||||
{
|
{
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfsi_getattr(self, name)
|
mfsi_getattr(self, name)
|
||||||
mfsiobject *self;
|
mfsiobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -272,7 +271,7 @@ mfsi_getattr(self, name)
|
||||||
else if ( strcmp(name, "Fldr") == 0 )
|
else if ( strcmp(name, "Fldr") == 0 )
|
||||||
return Py_BuildValue("i", (int)self->finfo.fdFldr);
|
return Py_BuildValue("i", (int)self->finfo.fdFldr);
|
||||||
else
|
else
|
||||||
return findmethod(mfsi_methods, (object *)self, name);
|
return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,13 +279,13 @@ static int
|
||||||
mfsi_setattr(self, name, v)
|
mfsi_setattr(self, name, v)
|
||||||
mfsiobject *self;
|
mfsiobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
object *v;
|
PyObject *v;
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ( v == NULL ) {
|
if ( v == NULL ) {
|
||||||
err_setstr(AttributeError, "Cannot delete attribute");
|
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( strcmp(name, "Type") == 0 )
|
if ( strcmp(name, "Type") == 0 )
|
||||||
|
@ -302,7 +301,7 @@ mfsi_setattr(self, name, v)
|
||||||
rv = PyArg_Parse(v, "i", &i);
|
rv = PyArg_Parse(v, "i", &i);
|
||||||
self->finfo.fdFldr = (short)i;
|
self->finfo.fdFldr = (short)i;
|
||||||
} else {
|
} else {
|
||||||
err_setstr(AttributeError, "No such attribute");
|
PyErr_SetString(PyExc_AttributeError, "No such attribute");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (rv)
|
if (rv)
|
||||||
|
@ -311,8 +310,8 @@ mfsi_setattr(self, name, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static typeobject Mfsitype = {
|
static PyTypeObject Mfsitype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"FInfo object", /*tp_name*/
|
"FInfo object", /*tp_name*/
|
||||||
sizeof(mfsiobject), /*tp_basicsize*/
|
sizeof(mfsiobject), /*tp_basicsize*/
|
||||||
|
@ -340,7 +339,7 @@ static typeobject Mfsitype = {
|
||||||
*/
|
*/
|
||||||
FSSpec *
|
FSSpec *
|
||||||
mfs_GetFSSpecFSSpec(self)
|
mfs_GetFSSpecFSSpec(self)
|
||||||
object *self;
|
PyObject *self;
|
||||||
{
|
{
|
||||||
if ( is_mfssobject(self) )
|
if ( is_mfssobject(self) )
|
||||||
return &((mfssobject *)self)->fsspec;
|
return &((mfssobject *)self)->fsspec;
|
||||||
|
@ -395,46 +394,46 @@ PyMac_SetFileDates(fss, crdat, mddat, bkdat)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_as_pathname(self, args)
|
mfss_as_pathname(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char strbuf[257];
|
char strbuf[257];
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = PyMac_GetFullPath(&self->fsspec, strbuf);
|
err = PyMac_GetFullPath(&self->fsspec, strbuf);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return newstringobject(strbuf);
|
return PyString_FromString(strbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_as_tuple(self, args)
|
mfss_as_tuple(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
|
return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
|
||||||
&self->fsspec.name[1], self->fsspec.name[0]);
|
&self->fsspec.name[1], self->fsspec.name[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_NewAlias(self, args)
|
mfss_NewAlias(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec src, *srcp;
|
FSSpec src, *srcp;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
AliasHandle alias;
|
AliasHandle alias;
|
||||||
|
|
||||||
src.name[0] = 0;
|
src.name[0] = 0;
|
||||||
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &src))
|
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( src.name[0] )
|
if ( src.name[0] )
|
||||||
srcp = &src;
|
srcp = &src;
|
||||||
|
@ -446,37 +445,37 @@ mfss_NewAlias(self, args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (object *)newmfsaobject(alias);
|
return (PyObject *)newmfsaobject(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_NewAliasMinimal(self, args)
|
mfss_NewAliasMinimal(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
AliasHandle alias;
|
AliasHandle alias;
|
||||||
|
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = NewAliasMinimal(&self->fsspec, &alias);
|
err = NewAliasMinimal(&self->fsspec, &alias);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)newmfsaobject(alias);
|
return (PyObject *)newmfsaobject(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
|
/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_GetCreatorType(self, args)
|
mfss_GetCreatorType(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
FInfo info;
|
FInfo info;
|
||||||
|
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FSpGetFInfo(&self->fsspec, &info);
|
err = FSpGetFInfo(&self->fsspec, &info);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
|
@ -487,16 +486,16 @@ mfss_GetCreatorType(self, args)
|
||||||
PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
|
PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_SetCreatorType(self, args)
|
mfss_SetCreatorType(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
OSType creator, type;
|
OSType creator, type;
|
||||||
FInfo info;
|
FInfo info;
|
||||||
|
|
||||||
if (!newgetargs(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
|
if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FSpGetFInfo(&self->fsspec, &info);
|
err = FSpGetFInfo(&self->fsspec, &info);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
|
@ -510,78 +509,78 @@ mfss_SetCreatorType(self, args)
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_GetFInfo(self, args)
|
mfss_GetFInfo(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
mfsiobject *fip;
|
mfsiobject *fip;
|
||||||
|
|
||||||
|
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (fip=newmfsiobject()) == NULL )
|
if ( (fip=newmfsiobject()) == NULL )
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FSpGetFInfo(&self->fsspec, &fip->finfo);
|
err = FSpGetFInfo(&self->fsspec, &fip->finfo);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
DECREF(fip);
|
Py_DECREF(fip);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)fip;
|
return (PyObject *)fip;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_SetFInfo(self, args)
|
mfss_SetFInfo(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
mfsiobject *fip;
|
mfsiobject *fip;
|
||||||
|
|
||||||
if (!newgetargs(args, "O!", &Mfsitype, &fip))
|
if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FSpSetFInfo(&self->fsspec, &fip->finfo);
|
err = FSpSetFInfo(&self->fsspec, &fip->finfo);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_GetDates(self, args)
|
mfss_GetDates(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
unsigned long crdat, mddat, bkdat;
|
unsigned long crdat, mddat, bkdat;
|
||||||
|
|
||||||
if (!newgetargs(args, ""))
|
if (!PyArg_ParseTuple(args, ""))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
|
err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkvalue("ddd", (double)crdat, (double)mddat, (double)bkdat);
|
return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_SetDates(self, args)
|
mfss_SetDates(self, args)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
double crdat, mddat, bkdat;
|
double crdat, mddat, bkdat;
|
||||||
|
|
||||||
if (!newgetargs(args, "ddd", &crdat, &mddat, &bkdat))
|
if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
|
err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
|
||||||
(unsigned long)mddat, (unsigned long)bkdat);
|
(unsigned long)mddat, (unsigned long)bkdat);
|
||||||
|
@ -589,35 +588,35 @@ mfss_SetDates(self, args)
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist mfss_methods[] = {
|
static struct PyMethodDef mfss_methods[] = {
|
||||||
{"as_pathname", (method)mfss_as_pathname, 1},
|
{"as_pathname", (PyCFunction)mfss_as_pathname, 1},
|
||||||
{"as_tuple", (method)mfss_as_tuple, 1},
|
{"as_tuple", (PyCFunction)mfss_as_tuple, 1},
|
||||||
{"NewAlias", (method)mfss_NewAlias, 1},
|
{"NewAlias", (PyCFunction)mfss_NewAlias, 1},
|
||||||
{"NewAliasMinimal", (method)mfss_NewAliasMinimal, 1},
|
{"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
|
||||||
{"GetCreatorType", (method)mfss_GetCreatorType, 1},
|
{"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
|
||||||
{"SetCreatorType", (method)mfss_SetCreatorType, 1},
|
{"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
|
||||||
{"GetFInfo", (method)mfss_GetFInfo, 1},
|
{"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
|
||||||
{"SetFInfo", (method)mfss_SetFInfo, 1},
|
{"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
|
||||||
{"GetDates", (method)mfss_GetDates, 1},
|
{"GetDates", (PyCFunction)mfss_GetDates, 1},
|
||||||
{"SetDates", (method)mfss_SetDates, 1},
|
{"SetDates", (PyCFunction)mfss_SetDates, 1},
|
||||||
|
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_getattr(self, name)
|
mfss_getattr(self, name)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
if ( strcmp(name, "data") == 0)
|
if ( strcmp(name, "data") == 0)
|
||||||
return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
|
return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
|
||||||
return findmethod(mfss_methods, (object *)self, name);
|
return Py_FindMethod(mfss_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
mfssobject *
|
mfssobject *
|
||||||
|
@ -626,7 +625,7 @@ newmfssobject(fss)
|
||||||
{
|
{
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
|
|
||||||
self = NEWOBJ(mfssobject, &Mfsstype);
|
self = PyObject_NEW(mfssobject, &Mfsstype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->fsspec = *fss;
|
self->fsspec = *fss;
|
||||||
|
@ -637,10 +636,10 @@ static void
|
||||||
mfss_dealloc(self)
|
mfss_dealloc(self)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
{
|
{
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfss_repr(self)
|
mfss_repr(self)
|
||||||
mfssobject *self;
|
mfssobject *self;
|
||||||
{
|
{
|
||||||
|
@ -650,7 +649,7 @@ mfss_repr(self)
|
||||||
self->fsspec.vRefNum,
|
self->fsspec.vRefNum,
|
||||||
self->fsspec.parID,
|
self->fsspec.parID,
|
||||||
self->fsspec.name[0], self->fsspec.name+1);
|
self->fsspec.name[0], self->fsspec.name+1);
|
||||||
return newstringobject(buf);
|
return PyString_FromString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -673,8 +672,8 @@ mfss_compare(v, w)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
statichere typeobject Mfsstype = {
|
statichere PyTypeObject Mfsstype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"FSSpec", /*tp_name*/
|
"FSSpec", /*tp_name*/
|
||||||
sizeof(mfssobject), /*tp_basicsize*/
|
sizeof(mfssobject), /*tp_basicsize*/
|
||||||
|
@ -695,29 +694,29 @@ statichere typeobject Mfsstype = {
|
||||||
/* End of code for FSSpec objects */
|
/* End of code for FSSpec objects */
|
||||||
/* -------------------------------------------------------- */
|
/* -------------------------------------------------------- */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_ResolveAliasFile(self, args)
|
mfs_ResolveAliasFile(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec fss;
|
FSSpec fss;
|
||||||
Boolean chain = 1, isfolder, wasaliased;
|
Boolean chain = 1, isfolder, wasaliased;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!newgetargs(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
|
if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
|
||||||
return NULL;
|
return NULL;
|
||||||
err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
|
err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkvalue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
|
return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_StandardGetFile(self, args)
|
mfs_StandardGetFile(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
SFTypeList list;
|
SFTypeList list;
|
||||||
short numtypes;
|
short numtypes;
|
||||||
|
@ -725,7 +724,7 @@ mfs_StandardGetFile(self, args)
|
||||||
|
|
||||||
list[0] = list[1] = list[2] = list[3] = 0;
|
list[0] = list[1] = list[2] = list[3] = 0;
|
||||||
numtypes = 0;
|
numtypes = 0;
|
||||||
if (!newgetargs(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
|
if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
|
||||||
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
|
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
|
||||||
PyMac_GetOSType, &list[3]) )
|
PyMac_GetOSType, &list[3]) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -735,13 +734,13 @@ mfs_StandardGetFile(self, args)
|
||||||
if ( numtypes == 0 )
|
if ( numtypes == 0 )
|
||||||
numtypes = -1;
|
numtypes = -1;
|
||||||
StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
|
StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
|
||||||
return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
|
return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_PromptGetFile(self, args)
|
mfs_PromptGetFile(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
SFTypeList list;
|
SFTypeList list;
|
||||||
short numtypes;
|
short numtypes;
|
||||||
|
@ -750,7 +749,7 @@ mfs_PromptGetFile(self, args)
|
||||||
|
|
||||||
list[0] = list[1] = list[2] = list[3] = 0;
|
list[0] = list[1] = list[2] = list[3] = 0;
|
||||||
numtypes = 0;
|
numtypes = 0;
|
||||||
if (!newgetargs(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
|
if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
|
||||||
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
|
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
|
||||||
PyMac_GetOSType, &list[3]) )
|
PyMac_GetOSType, &list[3]) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -760,30 +759,30 @@ mfs_PromptGetFile(self, args)
|
||||||
if ( numtypes == 0 )
|
if ( numtypes == 0 )
|
||||||
numtypes = -1;
|
numtypes = -1;
|
||||||
PyMac_PromptGetFile(numtypes, list, &reply, prompt);
|
PyMac_PromptGetFile(numtypes, list, &reply, prompt);
|
||||||
return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
|
return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_StandardPutFile(self, args)
|
mfs_StandardPutFile(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
Str255 prompt, dft;
|
Str255 prompt, dft;
|
||||||
StandardFileReply reply;
|
StandardFileReply reply;
|
||||||
|
|
||||||
dft[0] = 0;
|
dft[0] = 0;
|
||||||
if (!newgetargs(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
|
if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
|
||||||
return NULL;
|
return NULL;
|
||||||
StandardPutFile(prompt, dft, &reply);
|
StandardPutFile(prompt, dft, &reply);
|
||||||
return mkvalue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
|
return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Set initial directory for file dialogs */
|
** Set initial directory for file dialogs */
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_SetFolder(self, args)
|
mfs_SetFolder(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec spec;
|
FSSpec spec;
|
||||||
FSSpec ospec;
|
FSSpec ospec;
|
||||||
|
@ -797,53 +796,53 @@ mfs_SetFolder(self, args)
|
||||||
|
|
||||||
/* Go to working directory by default */
|
/* Go to working directory by default */
|
||||||
(void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
|
(void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
|
||||||
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &spec))
|
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
|
||||||
return NULL;
|
return NULL;
|
||||||
/* Set standard-file working directory */
|
/* Set standard-file working directory */
|
||||||
LMSetSFSaveDisk(-spec.vRefNum);
|
LMSetSFSaveDisk(-spec.vRefNum);
|
||||||
LMSetCurDirStore(spec.parID);
|
LMSetCurDirStore(spec.parID);
|
||||||
return (object *)newmfssobject(&ospec);
|
return (PyObject *)newmfssobject(&ospec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_FSSpec(self, args)
|
mfs_FSSpec(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec fss;
|
FSSpec fss;
|
||||||
|
|
||||||
if (!newgetargs(args, "O&", PyMac_GetFSSpec, &fss))
|
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
|
||||||
return NULL;
|
return NULL;
|
||||||
return (object *)newmfssobject(&fss);
|
return (PyObject *)newmfssobject(&fss);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_RawFSSpec(self, args)
|
mfs_RawFSSpec(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec *fssp;
|
FSSpec *fssp;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if (!newgetargs(args, "s#", &fssp, &size))
|
if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( size != sizeof(FSSpec) ) {
|
if ( size != sizeof(FSSpec) ) {
|
||||||
PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
|
PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)newmfssobject(fssp);
|
return (PyObject *)newmfssobject(fssp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_RawAlias(self, args)
|
mfs_RawAlias(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *dataptr;
|
char *dataptr;
|
||||||
Handle h;
|
Handle h;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
if (!newgetargs(args, "s#", &dataptr, &size))
|
if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
h = NewHandle(size);
|
h = NewHandle(size);
|
||||||
if ( h == NULL ) {
|
if ( h == NULL ) {
|
||||||
|
@ -853,29 +852,29 @@ mfs_RawAlias(self, args)
|
||||||
HLock(h);
|
HLock(h);
|
||||||
memcpy((char *)*h, dataptr, size);
|
memcpy((char *)*h, dataptr, size);
|
||||||
HUnlock(h);
|
HUnlock(h);
|
||||||
return (object *)newmfsaobject((AliasHandle)h);
|
return (PyObject *)newmfsaobject((AliasHandle)h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_GetDirectory(self, args)
|
mfs_GetDirectory(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
FSSpec fsdir;
|
FSSpec fsdir;
|
||||||
int ok;
|
int ok;
|
||||||
char *prompt = NULL;
|
char *prompt = NULL;
|
||||||
|
|
||||||
if (!newgetargs(args, "|s", &prompt) )
|
if (!PyArg_ParseTuple(args, "|s", &prompt) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ok = PyMac_GetDirectory(&fsdir, prompt);
|
ok = PyMac_GetDirectory(&fsdir, prompt);
|
||||||
return mkvalue("(Oi)", newmfssobject(&fsdir), ok);
|
return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_FindFolder(self, args)
|
mfs_FindFolder(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
short where;
|
short where;
|
||||||
|
@ -884,46 +883,46 @@ mfs_FindFolder(self, args)
|
||||||
short refnum;
|
short refnum;
|
||||||
long dirid;
|
long dirid;
|
||||||
|
|
||||||
if (!newgetargs(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
|
if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
|
err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return mkvalue("(ii)", refnum, dirid);
|
return Py_BuildValue("(ii)", refnum, dirid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_FindApplication(self, args)
|
mfs_FindApplication(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
OSType which;
|
OSType which;
|
||||||
FSSpec fss;
|
FSSpec fss;
|
||||||
|
|
||||||
if (!newgetargs(args, "O&", PyMac_GetOSType, &which) )
|
if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
|
||||||
return NULL;
|
return NULL;
|
||||||
err = FindApplicationFromCreator(which, &fss);
|
err = FindApplicationFromCreator(which, &fss);
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
PyErr_Mac(ErrorObject, err);
|
PyErr_Mac(ErrorObject, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)newmfssobject(&fss);
|
return (PyObject *)newmfssobject(&fss);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mfs_FInfo(self, args)
|
mfs_FInfo(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
return (object *)newmfsiobject();
|
return (PyObject *)newmfsiobject();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List of methods defined in the module */
|
/* List of methods defined in the module */
|
||||||
|
|
||||||
static struct methodlist mfs_methods[] = {
|
static struct PyMethodDef mfs_methods[] = {
|
||||||
{"ResolveAliasFile", mfs_ResolveAliasFile, 1},
|
{"ResolveAliasFile", mfs_ResolveAliasFile, 1},
|
||||||
{"StandardGetFile", mfs_StandardGetFile, 1},
|
{"StandardGetFile", mfs_StandardGetFile, 1},
|
||||||
{"PromptGetFile", mfs_PromptGetFile, 1},
|
{"PromptGetFile", mfs_PromptGetFile, 1},
|
||||||
|
@ -946,19 +945,19 @@ static struct methodlist mfs_methods[] = {
|
||||||
void
|
void
|
||||||
initmacfs()
|
initmacfs()
|
||||||
{
|
{
|
||||||
object *m, *d;
|
PyObject *m, *d;
|
||||||
|
|
||||||
/* Create the module and add the functions */
|
/* Create the module and add the functions */
|
||||||
m = initmodule("macfs", mfs_methods);
|
m = Py_InitModule("macfs", mfs_methods);
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = getmoduledict(m);
|
d = PyModule_GetDict(m);
|
||||||
ErrorObject = newstringobject("macfs.error");
|
ErrorObject = PyString_FromString("macfs.error");
|
||||||
dictinsert(d, "error", ErrorObject);
|
PyDict_SetItemString(d, "error", ErrorObject);
|
||||||
|
|
||||||
/* XXXX Add constants here */
|
/* XXXX Add constants here */
|
||||||
|
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
if (err_occurred())
|
if (PyErr_Occurred())
|
||||||
fatal("can't initialize module macfs");
|
Py_FatalError("can't initialize module macfs");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* Mac module implementation */
|
/* Mac module implementation */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h"
|
|
||||||
#include "ceval.h"
|
#include "ceval.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -89,100 +88,100 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#ifndef USE_GUSI
|
#ifndef USE_GUSI
|
||||||
|
|
||||||
int chdir PROTO((const char *path));
|
int chdir Py_PROTO((const char *path));
|
||||||
int mkdir PROTO((const char *path, int mode));
|
int mkdir Py_PROTO((const char *path, int mode));
|
||||||
DIR * opendir PROTO((char *));
|
DIR * opendir Py_PROTO((char *));
|
||||||
void closedir PROTO((DIR *));
|
void closedir Py_PROTO((DIR *));
|
||||||
struct dirent * readdir PROTO((DIR *));
|
struct dirent * readdir Py_PROTO((DIR *));
|
||||||
int rmdir PROTO((const char *path));
|
int rmdir Py_PROTO((const char *path));
|
||||||
int sync PROTO((void));
|
int sync Py_PROTO((void));
|
||||||
|
|
||||||
#if defined(THINK_C) || defined(__SC__)
|
#if defined(THINK_C) || defined(__SC__)
|
||||||
int unlink PROTO((char *));
|
int unlink Py_PROTO((char *));
|
||||||
#else
|
#else
|
||||||
int unlink PROTO((const char *));
|
int unlink Py_PROTO((const char *));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* USE_GUSI */
|
#endif /* USE_GUSI */
|
||||||
|
|
||||||
char *getwd PROTO((char *));
|
char *getwd Py_PROTO((char *));
|
||||||
char *getbootvol PROTO((void));
|
char *getbootvol Py_PROTO((void));
|
||||||
|
|
||||||
|
|
||||||
static object *MacError; /* Exception mac.error */
|
static PyObject *MacError; /* Exception mac.error */
|
||||||
|
|
||||||
/* Set a MAC-specific error from errno, and return NULL */
|
/* Set a MAC-specific error from errno, and return NULL */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_error()
|
mac_error()
|
||||||
{
|
{
|
||||||
return err_errno(MacError);
|
return PyErr_SetFromErrno(MacError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MAC generic methods */
|
/* MAC generic methods */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_1str(args, func)
|
mac_1str(args, func)
|
||||||
object *args;
|
PyObject *args;
|
||||||
int (*func) FPROTO((const char *));
|
int (*func) Py_FPROTO((const char *));
|
||||||
{
|
{
|
||||||
char *path1;
|
char *path1;
|
||||||
int res;
|
int res;
|
||||||
if (!getargs(args, "s", &path1))
|
if (!PyArg_Parse(args, "s", &path1))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = (*func)(path1);
|
res = (*func)(path1);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_2str(args, func)
|
mac_2str(args, func)
|
||||||
object *args;
|
PyObject *args;
|
||||||
int (*func) FPROTO((const char *, const char *));
|
int (*func) Py_FPROTO((const char *, const char *));
|
||||||
{
|
{
|
||||||
char *path1, *path2;
|
char *path1, *path2;
|
||||||
int res;
|
int res;
|
||||||
if (!getargs(args, "(ss)", &path1, &path2))
|
if (!PyArg_Parse(args, "(ss)", &path1, &path2))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = (*func)(path1, path2);
|
res = (*func)(path1, path2);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_strint(args, func)
|
mac_strint(args, func)
|
||||||
object *args;
|
PyObject *args;
|
||||||
int (*func) FPROTO((const char *, int));
|
int (*func) Py_FPROTO((const char *, int));
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int i;
|
||||||
int res;
|
int res;
|
||||||
if (!getargs(args, "(si)", &path, &i))
|
if (!PyArg_Parse(args, "(si)", &path, &i))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = (*func)(path, i);
|
res = (*func)(path, i);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_chdir(self, args)
|
mac_chdir(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
#ifdef USE_GUSI
|
#ifdef USE_GUSI
|
||||||
object *rv;
|
PyObject *rv;
|
||||||
|
|
||||||
/* Change MacOS's idea of wd too */
|
/* Change MacOS's idea of wd too */
|
||||||
rv = mac_1str(args, chdir);
|
rv = mac_1str(args, chdir);
|
||||||
|
@ -194,264 +193,264 @@ mac_chdir(self, args)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_close(self, args)
|
mac_close(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int fd, res;
|
int fd, res;
|
||||||
if (!getargs(args, "i", &fd))
|
if (!PyArg_Parse(args, "i", &fd))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = close(fd);
|
res = close(fd);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
#ifndef USE_GUSI
|
#ifndef USE_GUSI
|
||||||
/* GUSI gives surious errors here? */
|
/* GUSI gives surious errors here? */
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
#endif
|
#endif
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WEHAVE_DUP
|
#ifdef WEHAVE_DUP
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_dup(self, args)
|
mac_dup(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
if (!getargs(args, "i", &fd))
|
if (!PyArg_Parse(args, "i", &fd))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
fd = dup(fd);
|
fd = dup(fd);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newintobject((long)fd);
|
return PyInt_FromLong((long)fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WEHAVE_FDOPEN
|
#ifdef WEHAVE_FDOPEN
|
||||||
static object *
|
static PyObject *
|
||||||
mac_fdopen(self, args)
|
mac_fdopen(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
extern int fclose PROTO((FILE *));
|
extern int fclose Py_PROTO((FILE *));
|
||||||
int fd;
|
int fd;
|
||||||
char *mode;
|
char *mode;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
if (!getargs(args, "(is)", &fd, &mode))
|
if (!PyArg_Parse(args, "(is)", &fd, &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
fp = fdopen(fd, mode);
|
fp = fdopen(fd, mode);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newopenfileobject(fp, "(fdopen)", mode, fclose);
|
return PyFile_FromFile(fp, "(fdopen)", mode, fclose);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_getbootvol(self, args)
|
mac_getbootvol(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = getbootvol();
|
res = getbootvol();
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newstringobject(res);
|
return PyString_FromString(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_getcwd(self, args)
|
mac_getcwd(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char path[MAXPATHLEN];
|
char path[MAXPATHLEN];
|
||||||
char *res;
|
char *res;
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
#ifdef USE_GUSI
|
#ifdef USE_GUSI
|
||||||
res = getcwd(path, sizeof path);
|
res = getcwd(path, sizeof path);
|
||||||
#else
|
#else
|
||||||
res = getwd(path);
|
res = getwd(path);
|
||||||
#endif
|
#endif
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
err_setstr(MacError, path);
|
PyErr_SetString(MacError, path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return newstringobject(res);
|
return PyString_FromString(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_listdir(self, args)
|
mac_listdir(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
object *d, *v;
|
PyObject *d, *v;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *ep;
|
struct dirent *ep;
|
||||||
if (!getargs(args, "s", &name))
|
if (!PyArg_Parse(args, "s", &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
if ((dirp = opendir(name)) == NULL) {
|
if ((dirp = opendir(name)) == NULL) {
|
||||||
RET_SAVE
|
Py_BLOCK_THREADS
|
||||||
return mac_error();
|
return mac_error();
|
||||||
}
|
}
|
||||||
if ((d = newlistobject(0)) == NULL) {
|
if ((d = PyList_New(0)) == NULL) {
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
RET_SAVE
|
Py_BLOCK_THREADS
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
while ((ep = readdir(dirp)) != NULL) {
|
while ((ep = readdir(dirp)) != NULL) {
|
||||||
v = newstringobject(ep->d_name);
|
v = PyString_FromString(ep->d_name);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
DECREF(d);
|
Py_DECREF(d);
|
||||||
d = NULL;
|
d = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (addlistitem(d, v) != 0) {
|
if (PyList_Append(d, v) != 0) {
|
||||||
DECREF(v);
|
Py_DECREF(v);
|
||||||
DECREF(d);
|
Py_DECREF(d);
|
||||||
d = NULL;
|
d = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_lseek(self, args)
|
mac_lseek(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int where;
|
int where;
|
||||||
int how;
|
int how;
|
||||||
long res;
|
long res;
|
||||||
if (!getargs(args, "(iii)", &fd, &where, &how))
|
if (!PyArg_Parse(args, "(iii)", &fd, &where, &how))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = lseek(fd, (long)where, how);
|
res = lseek(fd, (long)where, how);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newintobject(res);
|
return PyInt_FromLong(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_mkdir(self, args)
|
mac_mkdir(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
char *path;
|
char *path;
|
||||||
int mode = 0777; /* Unused */
|
int mode = 0777; /* Unused */
|
||||||
if (!newgetargs(args, "s|i", &path, &mode))
|
if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
#ifdef USE_GUSI
|
#ifdef USE_GUSI
|
||||||
res = mkdir(path);
|
res = mkdir(path);
|
||||||
#else
|
#else
|
||||||
res = mkdir(path, mode);
|
res = mkdir(path, mode);
|
||||||
#endif
|
#endif
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_open(self, args)
|
mac_open(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
char *path;
|
char *path;
|
||||||
int mode;
|
int mode;
|
||||||
int fd;
|
int fd;
|
||||||
if (!getargs(args, "(si)", &path, &mode))
|
if (!PyArg_Parse(args, "(si)", &path, &mode))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
fd = open(path, mode);
|
fd = open(path, mode);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newintobject((long)fd);
|
return PyInt_FromLong((long)fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_read(self, args)
|
mac_read(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int fd, size;
|
int fd, size;
|
||||||
object *buffer;
|
PyObject *buffer;
|
||||||
if (!getargs(args, "(ii)", &fd, &size))
|
if (!PyArg_Parse(args, "(ii)", &fd, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
buffer = newsizedstringobject((char *)NULL, size);
|
buffer = PyString_FromStringAndSize((char *)NULL, size);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
size = read(fd, getstringvalue(buffer), size);
|
size = read(fd, PyString_AsString(buffer), size);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
DECREF(buffer);
|
Py_DECREF(buffer);
|
||||||
return mac_error();
|
return mac_error();
|
||||||
}
|
}
|
||||||
resizestring(&buffer, size);
|
_PyString_Resize(&buffer, size);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_rename(self, args)
|
mac_rename(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
return mac_2str(args, rename);
|
return mac_2str(args, rename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_rmdir(self, args)
|
mac_rmdir(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
return mac_1str(args, rmdir);
|
return mac_1str(args, rmdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_stat(self, args)
|
mac_stat(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *path;
|
char *path;
|
||||||
int res;
|
int res;
|
||||||
if (!getargs(args, "s", &path))
|
if (!PyArg_Parse(args, "s", &path))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = stat(path, &st);
|
res = stat(path, &st);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
#if 1
|
#if 1
|
||||||
return mkvalue("(lllllllddd)",
|
return Py_BuildValue("(lllllllddd)",
|
||||||
(long)st.st_mode,
|
(long)st.st_mode,
|
||||||
(long)st.st_ino,
|
(long)st.st_ino,
|
||||||
(long)st.st_dev,
|
(long)st.st_dev,
|
||||||
|
@ -463,7 +462,7 @@ mac_stat(self, args)
|
||||||
(double)st.st_mtime,
|
(double)st.st_mtime,
|
||||||
(double)st.st_ctime);
|
(double)st.st_ctime);
|
||||||
#else
|
#else
|
||||||
return mkvalue("(llllllllll)",
|
return Py_BuildValue("(llllllllll)",
|
||||||
(long)st.st_mode,
|
(long)st.st_mode,
|
||||||
(long)st.st_ino,
|
(long)st.st_ino,
|
||||||
(long)st.st_dev,
|
(long)st.st_dev,
|
||||||
|
@ -477,34 +476,34 @@ mac_stat(self, args)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_xstat(self, args)
|
mac_xstat(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
struct macstat mst;
|
struct macstat mst;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *path;
|
char *path;
|
||||||
int res;
|
int res;
|
||||||
if (!getargs(args, "s", &path))
|
if (!PyArg_Parse(args, "s", &path))
|
||||||
return NULL;
|
return NULL;
|
||||||
/*
|
/*
|
||||||
** Convoluted: we want stat() and xstat() to agree, so we call both
|
** Convoluted: we want stat() and xstat() to agree, so we call both
|
||||||
** stat and macstat, and use the latter only for values not provided by
|
** stat and macstat, and use the latter only for values not provided by
|
||||||
** the former.
|
** the former.
|
||||||
*/
|
*/
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = macstat(path, &mst);
|
res = macstat(path, &mst);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = stat(path, &st);
|
res = stat(path, &st);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
#if 1
|
#if 1
|
||||||
return mkvalue("(llllllldddls#s#)",
|
return Py_BuildValue("(llllllldddls#s#)",
|
||||||
(long)st.st_mode,
|
(long)st.st_mode,
|
||||||
(long)st.st_ino,
|
(long)st.st_ino,
|
||||||
(long)st.st_dev,
|
(long)st.st_dev,
|
||||||
|
@ -519,7 +518,7 @@ mac_xstat(self, args)
|
||||||
mst.st_creator, 4,
|
mst.st_creator, 4,
|
||||||
mst.st_type, 4);
|
mst.st_type, 4);
|
||||||
#else
|
#else
|
||||||
return mkvalue("(llllllllllls#s#)",
|
return Py_BuildValue("(llllllllllls#s#)",
|
||||||
(long)st.st_mode,
|
(long)st.st_mode,
|
||||||
(long)st.st_ino,
|
(long)st.st_ino,
|
||||||
(long)st.st_dev,
|
(long)st.st_dev,
|
||||||
|
@ -536,61 +535,61 @@ mac_xstat(self, args)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_sync(self, args)
|
mac_sync(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
res = sync();
|
res = sync();
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_unlink(self, args)
|
mac_unlink(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
return mac_1str(args, (int (*)(const char *))unlink);
|
return mac_1str(args, (int (*)(const char *))unlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mac_write(self, args)
|
mac_write(self, args)
|
||||||
object *self;
|
PyObject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
int fd, size;
|
int fd, size;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
if (!getargs(args, "(is#)", &fd, &buffer, &size))
|
if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
Py_BEGIN_ALLOW_THREADS
|
||||||
size = write(fd, buffer, size);
|
size = write(fd, buffer, size);
|
||||||
END_SAVE
|
Py_END_ALLOW_THREADS
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
return mac_error();
|
return mac_error();
|
||||||
return newintobject((long)size);
|
return PyInt_FromLong((long)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_MALLOC_DEBUG
|
#ifdef USE_MALLOC_DEBUG
|
||||||
static object *
|
static PyObject *
|
||||||
mac_mstats(self, args)
|
mac_mstats(self, args)
|
||||||
object*self;
|
PyObject*self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
mstats("python");
|
mstats("python");
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
#endif USE_MALLOC_DEBUG
|
#endif USE_MALLOC_DEBUG
|
||||||
|
|
||||||
static struct methodlist mac_methods[] = {
|
static struct PyMethodDef mac_methods[] = {
|
||||||
{"chdir", mac_chdir},
|
{"chdir", mac_chdir},
|
||||||
{"close", mac_close},
|
{"close", mac_close},
|
||||||
#ifdef WEHAVE_DUP
|
#ifdef WEHAVE_DUP
|
||||||
|
@ -625,13 +624,13 @@ static struct methodlist mac_methods[] = {
|
||||||
void
|
void
|
||||||
initmac()
|
initmac()
|
||||||
{
|
{
|
||||||
object *m, *d;
|
PyObject *m, *d;
|
||||||
|
|
||||||
m = initmodule("mac", mac_methods);
|
m = Py_InitModule("mac", mac_methods);
|
||||||
d = getmoduledict(m);
|
d = PyModule_GetDict(m);
|
||||||
|
|
||||||
/* Initialize mac.error exception */
|
/* Initialize mac.error exception */
|
||||||
MacError = newstringobject("mac.error");
|
MacError = PyString_FromString("mac.error");
|
||||||
if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
|
if (MacError == NULL || PyDict_SetItemString(d, "error", MacError) != 0)
|
||||||
fatal("can't define mac.error");
|
Py_FatalError("can't define mac.error");
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* xx module */
|
/* xx module */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "Python.h"
|
||||||
#include "modsupport.h"
|
|
||||||
|
|
||||||
#include <GestaltEqu.h>
|
#include <GestaltEqu.h>
|
||||||
#include "Speech.h"
|
#include "Speech.h"
|
||||||
|
@ -48,7 +47,7 @@ int lib_available;
|
||||||
#define double2fixed(x) ((Fixed)((x)*32768.0))
|
#define double2fixed(x) ((Fixed)((x)*32768.0))
|
||||||
|
|
||||||
char *CurrentSpeech;
|
char *CurrentSpeech;
|
||||||
object *ms_error_object;
|
PyObject *ms_error_object;
|
||||||
int speech_available;
|
int speech_available;
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -68,12 +67,12 @@ init_available() {
|
||||||
static
|
static
|
||||||
check_available() {
|
check_available() {
|
||||||
if ( !speech_available ) {
|
if ( !speech_available ) {
|
||||||
err_setstr(ms_error_object, "Speech Mgr not available");
|
PyErr_SetString(ms_error_object, "Speech Mgr not available");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef __powerc
|
#ifdef __powerc
|
||||||
if ( !lib_available ) {
|
if ( !lib_available ) {
|
||||||
err_setstr(ms_error_object, "Speech Mgr available, but shared lib missing");
|
PyErr_SetString(ms_error_object, "Speech Mgr available, but shared lib missing");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,12 +84,12 @@ check_available() {
|
||||||
** Part one - the speech channel object
|
** Part one - the speech channel object
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
SpeechChannel chan;
|
SpeechChannel chan;
|
||||||
object *curtext; /* If non-NULL current text being spoken */
|
PyObject *curtext; /* If non-NULL current text being spoken */
|
||||||
} scobject;
|
} scobject;
|
||||||
|
|
||||||
staticforward typeobject sctype;
|
staticforward PyTypeObject sctype;
|
||||||
|
|
||||||
#define is_scobject(v) ((v)->ob_type == &sctype)
|
#define is_scobject(v) ((v)->ob_type == &sctype)
|
||||||
|
|
||||||
|
@ -101,11 +100,11 @@ newscobject(arg)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
self = NEWOBJ(scobject, &sctype);
|
self = PyObject_NEW(scobject, &sctype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) {
|
if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) {
|
||||||
DECREF(self);
|
Py_DECREF(self);
|
||||||
return (scobject *)PyErr_Mac(ms_error_object, err);
|
return (scobject *)PyErr_Mac(ms_error_object, err);
|
||||||
}
|
}
|
||||||
self->curtext = NULL;
|
self->curtext = NULL;
|
||||||
|
@ -119,146 +118,146 @@ sc_dealloc(self)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
{
|
{
|
||||||
DisposeSpeechChannel(self->chan);
|
DisposeSpeechChannel(self->chan);
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_Stop(self, args)
|
sc_Stop(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=StopSpeech(self->chan)) != 0) {
|
if ((err=StopSpeech(self->chan)) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ( self->curtext ) {
|
if ( self->curtext ) {
|
||||||
DECREF(self->curtext);
|
Py_DECREF(self->curtext);
|
||||||
self->curtext = NULL;
|
self->curtext = NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_SpeakText(self, args)
|
sc_SpeakText(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
char *str;
|
char *str;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!getargs(args, "s#", &str, &len))
|
if (!PyArg_Parse(args, "s#", &str, &len))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( self->curtext ) {
|
if ( self->curtext ) {
|
||||||
StopSpeech(self->chan);
|
StopSpeech(self->chan);
|
||||||
DECREF(self->curtext);
|
Py_DECREF(self->curtext);
|
||||||
self->curtext = NULL;
|
self->curtext = NULL;
|
||||||
}
|
}
|
||||||
if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) {
|
if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(void)getargs(args, "O", &self->curtext); /* Or should I check this? */
|
(void)PyArg_Parse(args, "O", &self->curtext); /* Or should I check this? */
|
||||||
INCREF(self->curtext);
|
Py_INCREF(self->curtext);
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_GetRate(self, args)
|
sc_GetRate(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
Fixed farg;
|
Fixed farg;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=GetSpeechRate(self->chan, &farg)) != 0) {
|
if ((err=GetSpeechRate(self->chan, &farg)) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return newfloatobject(fixed2double(farg));
|
return PyFloat_FromDouble(fixed2double(farg));
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_GetPitch(self, args)
|
sc_GetPitch(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
Fixed farg;
|
Fixed farg;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=GetSpeechPitch(self->chan, &farg)) != 0) {
|
if ((err=GetSpeechPitch(self->chan, &farg)) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return newfloatobject(fixed2double(farg));
|
return PyFloat_FromDouble(fixed2double(farg));
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_SetRate(self, args)
|
sc_SetRate(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
double darg;
|
double darg;
|
||||||
|
|
||||||
if (!getargs(args, "d", &darg))
|
if (!PyArg_Parse(args, "d", &darg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) {
|
if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_SetPitch(self, args)
|
sc_SetPitch(self, args)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
double darg;
|
double darg;
|
||||||
|
|
||||||
if (!getargs(args, "d", &darg))
|
if (!PyArg_Parse(args, "d", &darg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) {
|
if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) {
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist sc_methods[] = {
|
static struct PyMethodDef sc_methods[] = {
|
||||||
{"Stop", (method)sc_Stop},
|
{"Stop", (PyCFunction)sc_Stop},
|
||||||
{"SetRate", (method)sc_SetRate},
|
{"SetRate", (PyCFunction)sc_SetRate},
|
||||||
{"GetRate", (method)sc_GetRate},
|
{"GetRate", (PyCFunction)sc_GetRate},
|
||||||
{"SetPitch", (method)sc_SetPitch},
|
{"SetPitch", (PyCFunction)sc_SetPitch},
|
||||||
{"GetPitch", (method)sc_GetPitch},
|
{"GetPitch", (PyCFunction)sc_GetPitch},
|
||||||
{"SpeakText", (method)sc_SpeakText},
|
{"SpeakText", (PyCFunction)sc_SpeakText},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
sc_getattr(self, name)
|
sc_getattr(self, name)
|
||||||
scobject *self;
|
scobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
return findmethod(sc_methods, (object *)self, name);
|
return Py_FindMethod(sc_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static typeobject sctype = {
|
static PyTypeObject sctype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"MacSpeechChannel", /*tp_name*/
|
"MacSpeechChannel", /*tp_name*/
|
||||||
sizeof(scobject), /*tp_basicsize*/
|
sizeof(scobject), /*tp_basicsize*/
|
||||||
|
@ -281,13 +280,13 @@ static typeobject sctype = {
|
||||||
** Part two - the voice object
|
** Part two - the voice object
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
PyObject_HEAD
|
||||||
int initialized;
|
int initialized;
|
||||||
VoiceSpec vs;
|
VoiceSpec vs;
|
||||||
VoiceDescription vd;
|
VoiceDescription vd;
|
||||||
} mvobject;
|
} mvobject;
|
||||||
|
|
||||||
staticforward typeobject mvtype;
|
staticforward PyTypeObject mvtype;
|
||||||
|
|
||||||
#define is_mvobject(v) ((v)->ob_type == &mvtype)
|
#define is_mvobject(v) ((v)->ob_type == &mvtype)
|
||||||
|
|
||||||
|
@ -295,7 +294,7 @@ static mvobject *
|
||||||
newmvobject()
|
newmvobject()
|
||||||
{
|
{
|
||||||
mvobject *self;
|
mvobject *self;
|
||||||
self = NEWOBJ(mvobject, &mvtype);
|
self = PyObject_NEW(mvobject, &mvtype);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->initialized = 0;
|
self->initialized = 0;
|
||||||
|
@ -326,56 +325,56 @@ static void
|
||||||
mv_dealloc(self)
|
mv_dealloc(self)
|
||||||
mvobject *self;
|
mvobject *self;
|
||||||
{
|
{
|
||||||
DEL(self);
|
PyMem_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mv_getgender(self, args)
|
mv_getgender(self, args)
|
||||||
mvobject *self;
|
mvobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
object *rv;
|
PyObject *rv;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!self->initialized) {
|
if (!self->initialized) {
|
||||||
err_setstr(ms_error_object, "Uninitialized voice");
|
PyErr_SetString(ms_error_object, "Uninitialized voice");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rv = newintobject(self->vd.gender);
|
rv = PyInt_FromLong(self->vd.gender);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mv_newchannel(self, args)
|
mv_newchannel(self, args)
|
||||||
mvobject *self;
|
mvobject *self;
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!self->initialized) {
|
if (!self->initialized) {
|
||||||
err_setstr(ms_error_object, "Uninitialized voice");
|
PyErr_SetString(ms_error_object, "Uninitialized voice");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)newscobject(&self->vs);
|
return (PyObject *)newscobject(&self->vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct methodlist mv_methods[] = {
|
static struct PyMethodDef mv_methods[] = {
|
||||||
{"GetGender", (method)mv_getgender},
|
{"GetGender", (PyCFunction)mv_getgender},
|
||||||
{"NewChannel", (method)mv_newchannel},
|
{"NewChannel", (PyCFunction)mv_newchannel},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
mv_getattr(self, name)
|
mv_getattr(self, name)
|
||||||
mvobject *self;
|
mvobject *self;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
return findmethod(mv_methods, (object *)self, name);
|
return Py_FindMethod(mv_methods, (PyObject *)self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static typeobject mvtype = {
|
static PyTypeObject mvtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
PyObject_HEAD_INIT(&PyType_Type)
|
||||||
0, /*ob_size*/
|
0, /*ob_size*/
|
||||||
"MacVoice", /*tp_name*/
|
"MacVoice", /*tp_name*/
|
||||||
sizeof(mvobject), /*tp_basicsize*/
|
sizeof(mvobject), /*tp_basicsize*/
|
||||||
|
@ -401,46 +400,46 @@ static typeobject mvtype = {
|
||||||
|
|
||||||
/* See if Speech manager available */
|
/* See if Speech manager available */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_Available(self, args)
|
ms_Available(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
return newintobject(speech_available);
|
return PyInt_FromLong(speech_available);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count number of busy speeches */
|
/* Count number of busy speeches */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_Busy(self, args)
|
ms_Busy(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
short result;
|
short result;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( !check_available() )
|
if ( !check_available() )
|
||||||
return NULL;
|
return NULL;
|
||||||
result = SpeechBusy();
|
result = SpeechBusy();
|
||||||
return newintobject(result);
|
return PyInt_FromLong(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Say something */
|
/* Say something */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_SpeakString(self, args)
|
ms_SpeakString(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
OSErr err;
|
OSErr err;
|
||||||
char *str;
|
char *str;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!getstrarg(args, &str))
|
if (!PyArg_Parse(args, "s", &str))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( !check_available())
|
if ( !check_available())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -459,68 +458,68 @@ ms_SpeakString(self, args)
|
||||||
PyErr_Mac(ms_error_object, err);
|
PyErr_Mac(ms_error_object, err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
INCREF(None);
|
Py_INCREF(Py_None);
|
||||||
return None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Count number of available voices */
|
/* Count number of available voices */
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_CountVoices(self, args)
|
ms_CountVoices(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
short result;
|
short result;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( !check_available())
|
if ( !check_available())
|
||||||
return NULL;
|
return NULL;
|
||||||
CountVoices(&result);
|
CountVoices(&result);
|
||||||
return newintobject(result);
|
return PyInt_FromLong(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_GetIndVoice(self, args)
|
ms_GetIndVoice(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
mvobject *rv;
|
mvobject *rv;
|
||||||
long ind;
|
long ind;
|
||||||
|
|
||||||
if( !getargs(args, "i", &ind))
|
if( !PyArg_Parse(args, "i", &ind))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( !check_available() )
|
if ( !check_available() )
|
||||||
return NULL;
|
return NULL;
|
||||||
rv = newmvobject();
|
rv = newmvobject();
|
||||||
if ( !initmvobject(rv, ind) ) {
|
if ( !initmvobject(rv, ind) ) {
|
||||||
DECREF(rv);
|
Py_DECREF(rv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return (object *)rv;
|
return (PyObject *)rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static object *
|
static PyObject *
|
||||||
ms_Version(self, args)
|
ms_Version(self, args)
|
||||||
object *self; /* Not used */
|
PyObject *self; /* Not used */
|
||||||
object *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
NumVersion v;
|
NumVersion v;
|
||||||
|
|
||||||
if (!getnoarg(args))
|
if (!PyArg_NoArgs(args))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ( !check_available())
|
if ( !check_available())
|
||||||
return NULL;
|
return NULL;
|
||||||
v = SpeechManagerVersion();
|
v = SpeechManagerVersion();
|
||||||
return newintobject(*(int *)&v);
|
return PyInt_FromLong(*(int *)&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* List of functions defined in the module */
|
/* List of functions defined in the module */
|
||||||
|
|
||||||
static struct methodlist ms_methods[] = {
|
static struct PyMethodDef ms_methods[] = {
|
||||||
{"Available", ms_Available},
|
{"Available", ms_Available},
|
||||||
{"CountVoices", ms_CountVoices},
|
{"CountVoices", ms_CountVoices},
|
||||||
{"Busy", ms_Busy},
|
{"Busy", ms_Busy},
|
||||||
|
@ -535,18 +534,18 @@ static struct methodlist ms_methods[] = {
|
||||||
void
|
void
|
||||||
initmacspeech()
|
initmacspeech()
|
||||||
{
|
{
|
||||||
object *m, *d;
|
PyObject *m, *d;
|
||||||
|
|
||||||
speech_available = init_available();
|
speech_available = init_available();
|
||||||
/* Create the module and add the functions */
|
/* Create the module and add the functions */
|
||||||
m = initmodule("macspeech", ms_methods);
|
m = Py_InitModule("macspeech", ms_methods);
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = getmoduledict(m);
|
d = PyModule_GetDict(m);
|
||||||
ms_error_object = newstringobject("macspeech.error");
|
ms_error_object = PyString_FromString("macspeech.error");
|
||||||
dictinsert(d, "error", ms_error_object);
|
PyDict_SetItemString(d, "error", ms_error_object);
|
||||||
|
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
if (err_occurred())
|
if (PyErr_Occurred())
|
||||||
fatal("can't initialize module macspeech");
|
Py_FatalError("can't initialize module macspeech");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue