/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* Python extensions by Paul Moore, David Leonard, Roland Puntaier.
*
* Common code for if_python.c and if_python3.c.
*/
/*
* obtain a lock on the Vim data structures
*/
static void
Python_Lock_Vim(void)
{
}
/*
* release a lock on the Vim data structures
*/
static void
Python_Release_Vim(void)
{
}
/* Output object definition
*/
static PyObject *OutputWrite(PyObject *, PyObject *);
static PyObject *OutputWritelines(PyObject *, PyObject *);
static PyObject *OutputFlush(PyObject *, PyObject *);
/* Function to write a line, points to either msg() or emsg(). */
typedef void (*writefn)(char_u *);
static void writer(writefn fn, char_u *str, PyInt n);
typedef struct
{
PyObject_HEAD
long softspace;
long error;
} OutputObject;
static struct PyMethodDef OutputMethods[] = {
/* name, function, calling, documentation */
{"write", OutputWrite, 1, ""},
{"writelines", OutputWritelines, 1, ""},
{"flush", OutputFlush, 1, ""},
{ NULL, NULL, 0, NULL}
};
#define PyErr_SetVim(str) PyErr_SetString(VimError, str)
/*************/
/* Output buffer management
*/
static PyObject *
OutputWrite(PyObject *self, PyObject *args)
{
int len;
char *str;
int error = ((OutputObject *)(self))->error;
if (!PyArg_ParseTuple(args, "s#", &str, &len))
return NULL;
Py_BEGIN_ALLOW_THREADS
Python_Lock_Vim();
writer((writefn)(error ? emsg : msg), (char_u *)str, len);
Python_Release_Vim();
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
OutputWritelines(PyObject *self, PyObject *args)
{
PyInt n;
PyInt i;
PyObject *list;
int error = ((OutputObject *)(self))