#include <Python.h>
#include <structmember.h>
#include <eggdrop/eggdrop.h>
#include "pythonscript.h"
Go to the source code of this file.
Data Structures | |
| struct | StdioObject |
| struct | tLineBuf |
Defines | |
| #define | Stdio_Check(op) PyObject_TypeCheck(op, &Stdio_Type) |
Functions | |
| static PyObject * | Stdio_New (PyTypeObject *Type, PyObject *args, PyObject *kwds) |
| static void | Log (int Target, const char *Text) |
| static size_t | WriteLine (unsigned Target, char *Text, size_t len) |
| static void | Write (int Target, const char *Text, int len) |
| void | Flush (unsigned Target) |
| static PyObject * | Stdio_Write (PyObject *self, PyObject *args) |
| static PyObject * | Stdio_Flush (PyObject *self, PyObject *args) |
Variables | |
| static const char | rcsid [] = "$Id: mystdio.c,v 1.2 2007-01-13 12:23:40 sven Exp $" |
| static tLineBuf | LineBuf [2] |
| partymember_t * | LogTarget |
| static PyMemberDef | Stdio_Members [] |
| static PyMethodDef | Stdio_Methods [] |
| PyTypeObject | Stdio_Type |
| #define Stdio_Check | ( | op | ) | PyObject_TypeCheck(op, &Stdio_Type) |
| void Flush | ( | unsigned | Target | ) |
| static void Log | ( | int | Target, | |
| const char * | Text | |||
| ) | [static] |
Definition at line 69 of file mystdio.c.
References LOG_MISC, partymember_printf(), and putlog().
Referenced by WriteLine().
00069 { 00070 char *Prefix; 00071 00072 if (!Target) Prefix = "Python: %s"; 00073 else Prefix = "Python Error: %s"; 00074 00075 if (LogTarget) { 00076 partymember_printf(LogTarget, Prefix, Text); 00077 return; 00078 } 00079 putlog(LOG_MISC, "*", Prefix, Text); 00080 }
| static PyObject* Stdio_Flush | ( | PyObject * | self, | |
| PyObject * | args | |||
| ) | [static] |
Definition at line 133 of file mystdio.c.
References Flush().
00133 { 00134 StdioObject *this = (StdioObject *) self; 00135 00136 if (this->Type < 2) Flush(this->Type); 00137 Py_INCREF(Py_None); 00138 return Py_None; 00139 }
| static PyObject* Stdio_New | ( | PyTypeObject * | Type, | |
| PyObject * | args, | |||
| PyObject * | kwds | |||
| ) | [static] |
Definition at line 48 of file mystdio.c.
References StdioObject::softspace, Stdio_Check, and StdioObject::Type.
00048 { 00049 unsigned IOtype; 00050 PyObject *Para; 00051 StdioObject *Stdio; 00052 00053 if (!PyArg_ParseTuple(args, "O", &Para)) return 0; 00054 if (Stdio_Check(Para)) { 00055 Stdio = (StdioObject *) Para; 00056 IOtype = Stdio->Type; 00057 } else if (PyInt_Check(Para)) { 00058 IOtype = PyInt_AsLong(Para) - 1; 00059 } else { 00060 PyErr_Format(PyExc_TypeError, "Expected eggdrop.stdio got %s", Para->ob_type->tp_name); 00061 return 0; 00062 } 00063 if (!(Stdio = (StdioObject *) Type->tp_alloc(Type, 0))) return 0; 00064 Stdio->softspace = 0; 00065 Stdio->Type = IOtype; 00066 return (PyObject *) Stdio; 00067 }
| static PyObject* Stdio_Write | ( | PyObject * | self, | |
| PyObject * | args | |||
| ) | [static] |
Definition at line 122 of file mystdio.c.
References Write().
00122 { 00123 int len; 00124 const char *Text; 00125 StdioObject *this = (StdioObject *) self; 00126 00127 if (!PyArg_ParseTuple(args, "s#", &Text, &len)) return 0; 00128 if (this->Type < 2) Write(this->Type, Text, len); 00129 Py_INCREF(Py_None); 00130 return Py_None; 00131 }
| static void Write | ( | int | Target, | |
| const char * | Text, | |||
| int | len | |||
| ) | [static] |
Definition at line 95 of file mystdio.c.
References tLineBuf::buf, tLineBuf::bufsize, tLineBuf::strlen, and WriteLine().
Referenced by Flush(), Help(), and Stdio_Write().
00095 { 00096 int written; 00097 char *TextPtr; 00098 tLineBuf *Line = &LineBuf[Target]; 00099 00100 if (Line->strlen + len > Line->bufsize) { 00101 Line->bufsize = ((Line->strlen + len) & ~0x3FF) + 1024; // make it up to 1 KB larger than necessary 00102 Line->buf = realloc(Line->buf, Line->bufsize); 00103 } 00104 memcpy(Line->buf + Line->strlen, Text, len); 00105 Line->strlen += len; 00106 TextPtr = Line->buf; 00107 while ((written = WriteLine(Target, TextPtr, Line->strlen))) { 00108 TextPtr += written; 00109 Line->strlen -= written; 00110 } 00111 if (Line->strlen) memmove(Line->buf, TextPtr, Line->strlen); 00112 if (Line->bufsize > 0x100000 && Line->strlen < 1024) { 00113 Line->bufsize = 1024; 00114 Line->buf = realloc(Line->buf, 1024); 00115 } 00116 }
| static size_t WriteLine | ( | unsigned | Target, | |
| char * | Text, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 82 of file mystdio.c.
References Log().
Referenced by Write().
00082 { 00083 size_t written; 00084 char *newline; 00085 00086 newline = memchr(Text, '\n', len); 00087 if (!newline) return 0; 00088 written = newline - Text + 1; 00089 *newline = 0; 00090 if (written > 1 && newline[-1] == '\r') newline[-1] = 0; 00091 Log(Target, Text); 00092 return written; 00093 }
const char rcsid[] = "$Id: mystdio.c,v 1.2 2007-01-13 12:23:40 sven Exp $" [static] |
PyMemberDef Stdio_Members[] [static] |
Initial value:
{
{"softspace", T_INT, offsetof(StdioObject, softspace), 0, "Has a documented use for print and an undocumented use for the interactive interpreter."},
{0}
}
PyMethodDef Stdio_Methods[] [static] |
Initial value:
{
{"write", Stdio_Write, METH_VARARGS, "Write some text"},
{"flush", Stdio_Flush, METH_NOARGS, "Display the buffered content *now*"},
{0}
}
| PyTypeObject Stdio_Type |
1.5.6