Update of /cvsroot/pure-data/externals/grill/py/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13144/source
Modified Files: clmeth.cpp main.cpp main.h Log Message: ""
Index: clmeth.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/clmeth.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** clmeth.cpp 22 Jan 2004 03:38:36 -0000 1.6 --- clmeth.cpp 26 Mar 2004 03:27:49 -0000 1.7 *************** *** 132,136 **** }
- //! Send message to outlet PyObject *pyext::pyext_outlet(PyObject *,PyObject *args) --- 132,135 ----
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** main.cpp 27 Jan 2004 03:37:59 -0000 1.11 --- main.cpp 26 Mar 2004 03:27:49 -0000 1.12 *************** *** 36,39 **** --- 36,46 ----
+ static PyMethodDef StdOut_Methods[] = + { + { "write", py::StdOut_Write, 1 }, + { NULL, NULL, } + }; + + py::py(): module(NULL), *************** *** 67,70 **** --- 74,81 ----
PyModule_AddStringConstant(module_obj,"__doc__",(C *)py_doc); + + // redirect stdout + PyObject* py_out = Py_InitModule("stdout", StdOut_Methods); + PySys_SetObject("stdout", py_out); } else { *************** *** 167,171 **** if(docf && PyString_Check(docf)) { post(""); ! post(PyString_AsString(docf)); }
--- 178,203 ---- if(docf && PyString_Check(docf)) { post(""); ! const char *s = PyString_AsString(docf); ! ! // FIX: Python doc strings can easily be larger than 1k characters ! // -> split into separate lines ! for(;;) { ! char buf[1024]; ! char *nl = strchr(s,'\n'); ! if(!nl) { ! // no more newline found ! post(s); ! break; ! } ! else { ! // copy string before newline to temp buffer and post ! int l = nl-s; ! if(l >= sizeof(buf)) l = sizeof buf-1; ! strncpy(buf,s,l); // copy all but newline ! buf[l] = 0; ! post(buf); ! s = nl+1; // set after newline ! } ! } }
*************** *** 264,268 **** for(i = 0; i < n; ++i) { PyObject *pt = PyList_GetItem(pobj,i); ! if(PyString_Check(pt) && !strcmp(dir,PyString_AsString(pt))) break; } if(i == n) { // string is not yet existent in path --- 296,300 ---- for(i = 0; i < n; ++i) { PyObject *pt = PyList_GetItem(pobj,i); ! if(PyString_Check(pt) && !strcmp(dir,PyString_AS_STRING(pt))) break; } if(i == n) { // string is not yet existent in path *************** *** 274,275 **** --- 306,346 ---- } } + + static PyObject *output = NULL; + + // post to the console + PyObject* py::StdOut_Write(PyObject* self, PyObject* args) + { + if(PySequence_Check(args)) { + int sz = PySequence_Size(args); + for(int i = 0; i < sz; ++i) { + PyObject *val = PySequence_GetItem(args,i); // borrowed + PyObject *str = PyObject_Str(val); + char *cstr = PyString_AS_STRING(str); + char *lf = strchr(cstr,'\n'); + + // line feed in string + if(!lf) { + // no -> just append + if(output) + PyString_ConcatAndDel(&output,str); + else + output = str; + } + else { + // yes -> append up to line feed, reset output buffer to string remainder + PyObject *part = PyString_FromStringAndSize(cstr,lf-cstr); + if(output) + PyString_ConcatAndDel(&output,part); + else + output = part; + post(PyString_AS_STRING(output)); + Py_DECREF(output); + output = PyString_FromString(lf+1); + } + } + } + + Py_INCREF(Py_None); + return Py_None; + }
Index: main.h =================================================================== RCS file: /cvsroot/pure-data/externals/grill/py/source/main.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** main.h 22 Jan 2004 03:38:37 -0000 1.17 --- main.h 26 Mar 2004 03:27:49 -0000 1.18 *************** *** 26,31 **** #endif
! #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 405) ! #error You need at least flext version 0.4.5 #endif
--- 26,31 ---- #endif
! #if !defined(FLEXT_VERSION) || (FLEXT_VERSION < 406) ! #error You need at least flext version 0.4.6 #endif
*************** *** 137,140 **** --- 137,142 ---- #endif
+ static PyObject* StdOut_Write(PyObject* Self, PyObject* Args); + protected: // callbacks