diff options
Diffstat (limited to 'RISCOS/Modules')
-rw-r--r-- | RISCOS/Modules/riscosmodule.c | 188 | ||||
-rw-r--r-- | RISCOS/Modules/swimodule.c | 153 |
2 files changed, 335 insertions, 6 deletions
diff --git a/RISCOS/Modules/riscosmodule.c b/RISCOS/Modules/riscosmodule.c index adcc128..55f189d 100644 --- a/RISCOS/Modules/riscosmodule.c +++ b/RISCOS/Modules/riscosmodule.c @@ -6,6 +6,8 @@ #include "oslib/osfile.h" #include "unixstuff.h" +#include <sys/fcntl.h> + #include "Python.h" #include "structseq.h" @@ -368,6 +370,184 @@ static PyMethodDef riscos_methods[] = { {NULL, NULL} /* Sentinel */ }; +static int +ins(PyObject *module, char *symbol, long value) +{ + return PyModule_AddIntConstant(module, symbol, value); +} + + +static int +all_ins(PyObject *d) +{ +#ifdef F_OK + if (ins(d, "F_OK", (long)F_OK)) return -1; +#endif +#ifdef R_OK + if (ins(d, "R_OK", (long)R_OK)) return -1; +#endif +#ifdef W_OK + if (ins(d, "W_OK", (long)W_OK)) return -1; +#endif +#ifdef X_OK + if (ins(d, "X_OK", (long)X_OK)) return -1; +#endif +#ifdef NGROUPS_MAX + if (ins(d, "NGROUPS_MAX", (long)NGROUPS_MAX)) return -1; +#endif +#ifdef TMP_MAX + if (ins(d, "TMP_MAX", (long)TMP_MAX)) return -1; +#endif +#ifdef WCONTINUED + if (ins(d, "WCONTINUED", (long)WCONTINUED)) return -1; +#endif +#ifdef WNOHANG + if (ins(d, "WNOHANG", (long)WNOHANG)) return -1; +#endif +#ifdef WUNTRACED + if (ins(d, "WUNTRACED", (long)WUNTRACED)) return -1; +#endif +#ifdef O_RDONLY + if (ins(d, "O_RDONLY", (long)O_RDONLY)) return -1; +#endif +#ifdef O_WRONLY + if (ins(d, "O_WRONLY", (long)O_WRONLY)) return -1; +#endif +#ifdef O_RDWR + if (ins(d, "O_RDWR", (long)O_RDWR)) return -1; +#endif +#ifdef O_NDELAY + if (ins(d, "O_NDELAY", (long)O_NDELAY)) return -1; +#endif +#ifdef O_NONBLOCK + if (ins(d, "O_NONBLOCK", (long)O_NONBLOCK)) return -1; +#endif +#ifdef O_APPEND + if (ins(d, "O_APPEND", (long)O_APPEND)) return -1; +#endif +#ifdef O_DSYNC + if (ins(d, "O_DSYNC", (long)O_DSYNC)) return -1; +#endif +#ifdef O_RSYNC + if (ins(d, "O_RSYNC", (long)O_RSYNC)) return -1; +#endif +#ifdef O_SYNC + if (ins(d, "O_SYNC", (long)O_SYNC)) return -1; +#endif +#ifdef O_NOCTTY + if (ins(d, "O_NOCTTY", (long)O_NOCTTY)) return -1; +#endif +#ifdef O_CREAT + if (ins(d, "O_CREAT", (long)O_CREAT)) return -1; +#endif +#ifdef O_EXCL + if (ins(d, "O_EXCL", (long)O_EXCL)) return -1; +#endif +#ifdef O_TRUNC + if (ins(d, "O_TRUNC", (long)O_TRUNC)) return -1; +#endif +#ifdef O_BINARY + if (ins(d, "O_BINARY", (long)O_BINARY)) return -1; +#endif +#ifdef O_TEXT + if (ins(d, "O_TEXT", (long)O_TEXT)) return -1; +#endif +#ifdef O_LARGEFILE + if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1; +#endif + +/* MS Windows */ +#ifdef O_NOINHERIT + /* Don't inherit in child processes. */ + if (ins(d, "O_NOINHERIT", (long)O_NOINHERIT)) return -1; +#endif +#ifdef _O_SHORT_LIVED + /* Optimize for short life (keep in memory). */ + /* MS forgot to define this one with a non-underscore form too. */ + if (ins(d, "O_SHORT_LIVED", (long)_O_SHORT_LIVED)) return -1; +#endif +#ifdef O_TEMPORARY + /* Automatically delete when last handle is closed. */ + if (ins(d, "O_TEMPORARY", (long)O_TEMPORARY)) return -1; +#endif +#ifdef O_RANDOM + /* Optimize for random access. */ + if (ins(d, "O_RANDOM", (long)O_RANDOM)) return -1; +#endif +#ifdef O_SEQUENTIAL + /* Optimize for sequential access. */ + if (ins(d, "O_SEQUENTIAL", (long)O_SEQUENTIAL)) return -1; +#endif + +/* GNU extensions. */ +#ifdef O_DIRECT + /* Direct disk access. */ + if (ins(d, "O_DIRECT", (long)O_DIRECT)) return -1; +#endif +#ifdef O_DIRECTORY + /* Must be a directory. */ + if (ins(d, "O_DIRECTORY", (long)O_DIRECTORY)) return -1; +#endif +#ifdef O_NOFOLLOW + /* Do not follow links. */ + if (ins(d, "O_NOFOLLOW", (long)O_NOFOLLOW)) return -1; +#endif + + /* These come from sysexits.h */ +#ifdef EX_OK + if (ins(d, "EX_OK", (long)EX_OK)) return -1; +#endif /* EX_OK */ +#ifdef EX_USAGE + if (ins(d, "EX_USAGE", (long)EX_USAGE)) return -1; +#endif /* EX_USAGE */ +#ifdef EX_DATAERR + if (ins(d, "EX_DATAERR", (long)EX_DATAERR)) return -1; +#endif /* EX_DATAERR */ +#ifdef EX_NOINPUT + if (ins(d, "EX_NOINPUT", (long)EX_NOINPUT)) return -1; +#endif /* EX_NOINPUT */ +#ifdef EX_NOUSER + if (ins(d, "EX_NOUSER", (long)EX_NOUSER)) return -1; +#endif /* EX_NOUSER */ +#ifdef EX_NOHOST + if (ins(d, "EX_NOHOST", (long)EX_NOHOST)) return -1; +#endif /* EX_NOHOST */ +#ifdef EX_UNAVAILABLE + if (ins(d, "EX_UNAVAILABLE", (long)EX_UNAVAILABLE)) return -1; +#endif /* EX_UNAVAILABLE */ +#ifdef EX_SOFTWARE + if (ins(d, "EX_SOFTWARE", (long)EX_SOFTWARE)) return -1; +#endif /* EX_SOFTWARE */ +#ifdef EX_OSERR + if (ins(d, "EX_OSERR", (long)EX_OSERR)) return -1; +#endif /* EX_OSERR */ +#ifdef EX_OSFILE + if (ins(d, "EX_OSFILE", (long)EX_OSFILE)) return -1; +#endif /* EX_OSFILE */ +#ifdef EX_CANTCREAT + if (ins(d, "EX_CANTCREAT", (long)EX_CANTCREAT)) return -1; +#endif /* EX_CANTCREAT */ +#ifdef EX_IOERR + if (ins(d, "EX_IOERR", (long)EX_IOERR)) return -1; +#endif /* EX_IOERR */ +#ifdef EX_TEMPFAIL + if (ins(d, "EX_TEMPFAIL", (long)EX_TEMPFAIL)) return -1; +#endif /* EX_TEMPFAIL */ +#ifdef EX_PROTOCOL + if (ins(d, "EX_PROTOCOL", (long)EX_PROTOCOL)) return -1; +#endif /* EX_PROTOCOL */ +#ifdef EX_NOPERM + if (ins(d, "EX_NOPERM", (long)EX_NOPERM)) return -1; +#endif /* EX_NOPERM */ +#ifdef EX_CONFIG + if (ins(d, "EX_CONFIG", (long)EX_CONFIG)) return -1; +#endif /* EX_CONFIG */ +#ifdef EX_NOTFOUND + if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1; +#endif /* EX_NOTFOUND */ + + return 0; +} void @@ -376,10 +556,14 @@ initriscos() PyObject *m, *d, *stat_m; m = Py_InitModule("riscos", riscos_methods); + + if (all_ins(m)) + return; + d = PyModule_GetDict(m); - /* Initialize riscos.error exception */ - PyDict_SetItemString(d, "error", PyExc_OSError); + Py_INCREF(PyExc_OSError); + PyModule_AddObject(m, "error", PyExc_OSError); PyStructSequence_InitType(&StatResultType, &stat_result_desc); PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); diff --git a/RISCOS/Modules/swimodule.c b/RISCOS/Modules/swimodule.c index ec02ae7..583fc57 100644 --- a/RISCOS/Modules/swimodule.c +++ b/RISCOS/Modules/swimodule.c @@ -11,6 +11,9 @@ * Added swi.ArgError which is generated for errors when the user passes invalid arguments to functions etc * Added "errnum" attribute to swi.error, so one can now check to see what the error number was + + 1.02 03 March 2002 Dietmar Schwertberger + * Added string, integer, integers, tuple and tuples */ #include "oslib/os.h" @@ -412,13 +415,155 @@ static PyObject *swi_swi(PyObject *self,PyObject *args) fail:Py_DECREF(result);return 0; } +static PyObject *swi_string(PyObject *self, PyObject *arg) +{ char *s; + int l=-1; + if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&s, &l)) return NULL; + if (l==-1) + l = strlen(s); + return PyString_FromStringAndSize((char*)s, l); +} + +static char swi_string__doc__[] = +"string(address[, length]) -> string\n\ +Read a null terminated string from the given address."; + + +static PyObject *swi_integer(PyObject *self, PyObject *arg) +{ int *i; + + if(!PyArg_ParseTuple(arg,"i",(unsigned int *)&i)) + return NULL; + return PyInt_FromLong(*i); +} + +static char swi_integer__doc__[] = +"integer(address) -> string\n\ +Read an integer from the given address."; + + +static PyObject *swi_integers(PyObject *self, PyObject *arg) +{ int *i; + int c=-1; + PyObject *result, *result1; + + if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&i, &c)) return NULL; + result=PyList_New(0); + if (result) { + while ( c>0 || (c==-1 && *i) ) { + result1 = PyInt_FromLong((long)*i); + if (!result1) { + Py_DECREF(result); + return NULL; + } + if (PyList_Append(result, result1)!=0) { + Py_DECREF(result); + Py_DECREF(result1); + return NULL; + }; + i++; + if (c!=-1) + c--; + } + } + return result; +} + +static char swi_integers__doc__[] = +"integers(address[, count]) -> string\n\ +Either read a null terminated list of integers or\n\ +a list of given length from the given address."; + + +static PyObject *swi_tuples(PyObject *self, PyObject *arg) +{ + unsigned char *i; /* points to current */ + int c=-1, l=4, j, zero; /* count, length, index */ + PyObject *result, *result1, *result11; + + if(!PyArg_ParseTuple(arg,"i|ii",(unsigned int *)&i, &l, &c)) return NULL; + result=PyList_New(0); + if (result) { + while (c) { + result1 = PyTuple_New(l); + if (!result1) { + Py_DECREF(result); + return NULL; + } + zero = (c==-1); /* check for zeros? */ + for(j=0;j<l;j++) { + if (zero && *i) + zero = 0; /* non-zero found */ + result11 = PyInt_FromLong((long)(*i)); + if (!result11) { + Py_DECREF(result); + return NULL; + } + PyTuple_SetItem(result1, j, result11); + i++; + } + if (c==-1 && zero) { + Py_DECREF(result1); + c = 0; + break; + } + if (PyList_Append(result, result1)!=0) { + Py_DECREF(result1); + Py_DECREF(result); + return NULL; + } + if (c!=-1) + c--; + } + } + return result; +} + +static char swi_tuples__doc__[] = +"tuples(address[, length=4[, count]]) -> string\n\ +Either read a null terminated list of byte tuples or\n\ +a list of given length from the given address."; + + +static PyObject *swi_tuple(PyObject *self, PyObject *arg) +{ + unsigned char *i; /* points to current */ + int c=1, j; + PyObject *result, *result1; + + if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&i, &c)) return NULL; + result = PyTuple_New(c); + if (!result) + return NULL; + for(j=0;j<c;j++) { + result1 = PyInt_FromLong((long)(i[j])); + if (!result1) { + Py_DECREF(result); + return NULL; + } + PyTuple_SetItem(result, j, result1); + } + return result; +} + +static char swi_tuple__doc__[] = +"tuple(address[, count=1]]) -> tuple\n\ +Read count bytes from given address."; + + static PyMethodDef SwiMethods[]= -{ { "swi",swi_swi,1}, - { "block",PyBlock_New,1}, - { "register",PyRegister,1}, - { NULL,NULL} /* Sentinel */ +{ { "swi", swi_swi,1}, + { "block", PyBlock_New,1}, + { "register", PyRegister,1}, + { "string", swi_string,METH_VARARGS, swi_string__doc__}, + { "integer", swi_integer,METH_VARARGS, swi_integer__doc__}, + { "integers", swi_integers,METH_VARARGS, swi_integers__doc__}, + { "tuples", swi_tuples,METH_VARARGS, swi_tuples__doc__}, + { "tuple", swi_tuple,METH_VARARGS, swi_tuple__doc__}, + { NULL,NULL,0,NULL} /* Sentinel */ }; + void initswi() { PyObject *m, *d; m = Py_InitModule("swi", SwiMethods); |