Index: termios.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/termios.c,v retrieving revision 2.24 diff -c -r2.24 termios.c *** termios.c 2001/04/11 20:57:57 2.24 --- termios.c 2001/04/18 15:23:07 *************** *** 5,43 **** #define PyInit_termios inittermios #include ! /* XXX Some systems need this to get all the symbols, while ! this breaks for others. #include - */ static char termios__doc__[] = "\ This module provides an interface to the Posix calls for tty I/O control.\n\ For a complete description of these calls, see the Posix or Unix manual\n\ pages. It is only available for those Unix versions that support Posix\n\ ! termios style tty I/O control (and then only if configured at installation\n\ ! time).\n\ \n\ All functions in this module take a file descriptor fd as their first\n\ ! argument. This must be an integer file descriptor, such as returned by\n\ ! sys.stdin.fileno()."; ! #ifdef __BEOS__ ! #include ! #endif ! #define BAD "bad termios argument" ! static PyObject *TermiosError; ! /* termios = tcgetattr(fd) ! termios is ! [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]] ! Return the attributes of the terminal device. */ static char termios_tcgetattr__doc__[] = "\ tcgetattr(fd) -> list_of_attrs\n\ Get the tty attributes for file descriptor fd, as follows:\n\ [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\ of the tty special characters (each a string of length 1, except the items\n\ --- 5,65 ---- #define PyInit_termios inittermios #include ! #include #include + #ifdef __BEOS__ + #include + #endif + static char termios__doc__[] = "\ This module provides an interface to the Posix calls for tty I/O control.\n\ For a complete description of these calls, see the Posix or Unix manual\n\ pages. It is only available for those Unix versions that support Posix\n\ ! termios style tty I/O control.\n\ \n\ All functions in this module take a file descriptor fd as their first\n\ ! argument. This can be an integer file descriptor, such as returned by\n\ ! sys.stdin.fileno(), or a file object, such as sys.stdin itself."; + static PyObject *TermiosError; ! static char* fname; ! static int fdconv(PyObject* obj, void* p) ! { ! int fd; ! fd = PyObject_AsFileDescriptor(obj); ! if (fd == -1) { ! if (PyInt_Check(obj)) { ! fd = PyInt_AS_LONG(obj); ! } ! else { ! char* tname; ! if (PyInstance_Check(obj)) { ! tname = PyString_AS_STRING( ! ((PyInstanceObject*)obj)->in_class->cl_name); ! } ! else { ! tname = obj->ob_type->tp_name; ! } ! ! PyErr_Format(PyExc_TypeError, ! "%s, arg 1: can't extract file descriptor from \"%.500s\"", ! fname, tname); ! return 0; ! } ! } ! *(int*)p = fd; ! return 1; ! } static char termios_tcgetattr__doc__[] = "\ tcgetattr(fd) -> list_of_attrs\n\ + \n\ Get the tty attributes for file descriptor fd, as follows:\n\ [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\ of the tty special characters (each a string of length 1, except the items\n\ *************** *** 57,63 **** int i; char ch; ! if (!PyArg_Parse(args, "i", &fd)) return NULL; if (tcgetattr(fd, &mode) == -1) --- 79,88 ---- int i; char ch; ! fname = "tcgetattr"; ! ! if (!PyArg_ParseTuple(args, "O&:tcgetattr", ! fdconv, (void*)&fd)) return NULL; if (tcgetattr(fd, &mode) == -1) *************** *** 111,121 **** return NULL; } - /* tcsetattr(fd, when, termios) - Set the attributes of the terminal device. */ - static char termios_tcsetattr__doc__[] = "\ tcsetattr(fd, when, attributes) -> None\n\ Set the tty attributes for file descriptor fd.\n\ The attributes to be set are taken from the attributes argument, which\n\ is a list like the one returned by tcgetattr(). The when argument\n\ --- 136,144 ---- return NULL; } static char termios_tcsetattr__doc__[] = "\ tcsetattr(fd, when, attributes) -> None\n\ + \n\ Set the tty attributes for file descriptor fd.\n\ The attributes to be set are taken from the attributes argument, which\n\ is a list like the one returned by tcgetattr(). The when argument\n\ *************** *** 132,142 **** speed_t ispeed, ospeed; PyObject *term, *cc, *v; int i; ! if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term)) return NULL; if (!PyList_Check(term) || PyList_Size(term) != 7) { ! PyErr_SetString(PyExc_TypeError, BAD); return NULL; } --- 155,169 ---- speed_t ispeed, ospeed; PyObject *term, *cc, *v; int i; + + fname = "tcsetattr"; ! if (!PyArg_ParseTuple(args, "O&iO:tcsetattr", ! fdconv, &fd, &when, &term)) return NULL; if (!PyList_Check(term) || PyList_Size(term) != 7) { ! PyErr_SetString(PyExc_TypeError, ! "tcsetattr, arg 3: must be 7 element list"); return NULL; } *************** *** 154,160 **** return NULL; if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) { ! PyErr_SetString(PyExc_TypeError, BAD); return NULL; } --- 181,189 ---- return NULL; if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) { ! PyErr_Format(PyExc_TypeError, ! "tcsetattr: attributes[6] must be %d element list", ! NCCS); return NULL; } *************** *** 166,172 **** else if (PyInt_Check(v)) mode.c_cc[i] = (cc_t) PyInt_AsLong(v); else { ! PyErr_SetString(PyExc_TypeError, BAD); return NULL; } } --- 195,202 ---- else if (PyInt_Check(v)) mode.c_cc[i] = (cc_t) PyInt_AsLong(v); else { ! PyErr_SetString(PyExc_TypeError, ! "tcsetattr: elements of attributes must be characters or integers"); return NULL; } } *************** *** 182,202 **** return Py_None; } - /* tcsendbreak(fd, duration) - Generate a break condition. */ - static char termios_tcsendbreak__doc__[] = "\ tcsendbreak(fd, duration) -> None\n\ Send a break on file descriptor fd.\n\ ! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\ ! has a system dependent meaning. "; static PyObject * termios_tcsendbreak(PyObject *self, PyObject *args) { int fd, duration; ! if (!PyArg_Parse(args, "(ii)", &fd, &duration)) return NULL; if (tcsendbreak(fd, duration) == -1) return PyErr_SetFromErrno(TermiosError); --- 212,233 ---- return Py_None; } static char termios_tcsendbreak__doc__[] = "\ tcsendbreak(fd, duration) -> None\n\ + \n\ Send a break on file descriptor fd.\n\ ! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\ ! has a system dependent meaning."; static PyObject * termios_tcsendbreak(PyObject *self, PyObject *args) { int fd, duration; ! fname = "tcsendbreak"; ! ! if (!PyArg_ParseTuple(args, "O&i:tcsendbreak", ! fdconv, &fd, &duration)) return NULL; if (tcsendbreak(fd, duration) == -1) return PyErr_SetFromErrno(TermiosError); *************** *** 205,224 **** return Py_None; } - /* tcdrain(fd) - Wait until all queued output to the terminal has been - transmitted. */ - static char termios_tcdrain__doc__[] = "\ tcdrain(fd) -> None\n\ ! Wait until all output written to file descriptor fd has been transmitted. "; static PyObject * termios_tcdrain(PyObject *self, PyObject *args) { int fd; ! if (!PyArg_Parse(args, "i", &fd)) return NULL; if (tcdrain(fd) == -1) return PyErr_SetFromErrno(TermiosError); --- 236,255 ---- return Py_None; } static char termios_tcdrain__doc__[] = "\ tcdrain(fd) -> None\n\ ! \n\ ! Wait until all output written to file descriptor fd has been transmitted."; static PyObject * termios_tcdrain(PyObject *self, PyObject *args) { int fd; + + fname = "tcdrain"; ! if (!PyArg_ParseTuple(args, "O&:tcdrain", ! fdconv, &fd)) return NULL; if (tcdrain(fd) == -1) return PyErr_SetFromErrno(TermiosError); *************** *** 227,238 **** return Py_None; } - /* tcflush(fd, queue) - Clear the input and/or output queues associated with - the terminal. */ - static char termios_tcflush__doc__[] = "\ tcflush(fd, queue) -> None\n\ Discard queued data on file descriptor fd.\n\ The queue selector specifies which queue: termios.TCIFLUSH for the input\n\ queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\ --- 258,266 ---- return Py_None; } static char termios_tcflush__doc__[] = "\ tcflush(fd, queue) -> None\n\ + \n\ Discard queued data on file descriptor fd.\n\ The queue selector specifies which queue: termios.TCIFLUSH for the input\n\ queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\ *************** *** 243,249 **** { int fd, queue; ! if (!PyArg_Parse(args, "(ii)", &fd, &queue)) return NULL; if (tcflush(fd, queue) == -1) return PyErr_SetFromErrno(TermiosError); --- 271,280 ---- { int fd, queue; ! fname = "tcflush"; ! ! if (!PyArg_ParseTuple(args, "O&i:tcflush", ! fdconv, &fd, &queue)) return NULL; if (tcflush(fd, queue) == -1) return PyErr_SetFromErrno(TermiosError); *************** *** 252,263 **** return Py_None; } - /* tcflow(fd, action) - Perform operations relating to XON/XOFF flow control on - the terminal. */ - static char termios_tcflow__doc__[] = "\ tcflow(fd, action) -> None\n\ Suspend or resume input or output on file descriptor fd.\n\ The action argument can be termios.TCOOFF to suspend output,\n\ termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\ --- 283,291 ---- return Py_None; } static char termios_tcflow__doc__[] = "\ tcflow(fd, action) -> None\n\ + \n\ Suspend or resume input or output on file descriptor fd.\n\ The action argument can be termios.TCOOFF to suspend output,\n\ termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\ *************** *** 267,274 **** termios_tcflow(PyObject *self, PyObject *args) { int fd, action; ! if (!PyArg_Parse(args, "(ii)", &fd, &action)) return NULL; if (tcflow(fd, action) == -1) return PyErr_SetFromErrno(TermiosError); --- 295,305 ---- termios_tcflow(PyObject *self, PyObject *args) { int fd, action; + + fname = "tcflow"; ! if (!PyArg_ParseTuple(args, "O&i:tcflow", ! fdconv, &fd, &action)) return NULL; if (tcflow(fd, action) == -1) return PyErr_SetFromErrno(TermiosError); *************** *** 280,296 **** static PyMethodDef termios_methods[] = { {"tcgetattr", termios_tcgetattr, ! METH_OLDARGS, termios_tcgetattr__doc__}, {"tcsetattr", termios_tcsetattr, ! METH_OLDARGS, termios_tcsetattr__doc__}, {"tcsendbreak", termios_tcsendbreak, ! METH_OLDARGS, termios_tcsendbreak__doc__}, {"tcdrain", termios_tcdrain, ! METH_OLDARGS, termios_tcdrain__doc__}, {"tcflush", termios_tcflush, ! METH_OLDARGS, termios_tcflush__doc__}, {"tcflow", termios_tcflow, ! METH_OLDARGS, termios_tcflow__doc__}, {NULL, NULL} }; --- 311,327 ---- static PyMethodDef termios_methods[] = { {"tcgetattr", termios_tcgetattr, ! METH_VARARGS, termios_tcgetattr__doc__}, {"tcsetattr", termios_tcsetattr, ! METH_VARARGS, termios_tcsetattr__doc__}, {"tcsendbreak", termios_tcsendbreak, ! METH_VARARGS, termios_tcsendbreak__doc__}, {"tcdrain", termios_tcdrain, ! METH_VARARGS, termios_tcdrain__doc__}, {"tcflush", termios_tcflush, ! METH_VARARGS, termios_tcflush__doc__}, {"tcflow", termios_tcflow, ! METH_VARARGS, termios_tcflow__doc__}, {NULL, NULL} };