Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 1 | /* termiosmodule.c -- POSIX terminal I/O module implementation. */ |
| 2 | |
Guido van Rossum | ca6954a | 1999-01-14 19:31:42 +0000 | [diff] [blame] | 3 | #include "Python.h" |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 4 | |
| 5 | #define PyInit_termios inittermios |
| 6 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 7 | #include <termios.h> |
Fred Drake | b2877dd | 2001-05-09 17:53:06 +0000 | [diff] [blame] | 8 | #ifdef __osf__ |
| 9 | /* On OSF, sys/ioctl.h requires that struct termio already be defined, |
| 10 | * so this needs to be included first on that platform. */ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 11 | #include <termio.h> |
Fred Drake | b2877dd | 2001-05-09 17:53:06 +0000 | [diff] [blame] | 12 | #endif |
Fred Drake | 9b3bc49 | 2001-04-04 21:19:26 +0000 | [diff] [blame] | 13 | #include <sys/ioctl.h> |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 14 | |
Fred Drake | 87068f1 | 2001-05-11 16:14:17 +0000 | [diff] [blame] | 15 | /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR, |
| 16 | * MDTR, MRI, and MRTS (appearantly used internally by some things |
| 17 | * defined as macros; these are not used here directly). |
| 18 | */ |
| 19 | #ifdef HAVE_SYS_MODEM_H |
| 20 | #include <sys/modem.h> |
| 21 | #endif |
| 22 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 23 | PyDoc_STRVAR(termios__doc__, |
| 24 | "This module provides an interface to the Posix calls for tty I/O control.\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 25 | For a complete description of these calls, see the Posix or Unix manual\n\ |
| 26 | pages. It is only available for those Unix versions that support Posix\n\ |
| 27 | termios style tty I/O control.\n\ |
| 28 | \n\ |
| 29 | All functions in this module take a file descriptor fd as their first\n\ |
| 30 | argument. This can be an integer file descriptor, such as returned by\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 31 | sys.stdin.fileno(), or a file object, such as sys.stdin itself."); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 32 | |
| 33 | static PyObject *TermiosError; |
| 34 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 35 | static int fdconv(PyObject* obj, void* p) |
| 36 | { |
| 37 | int fd; |
| 38 | |
| 39 | fd = PyObject_AsFileDescriptor(obj); |
Fred Drake | c99ff60 | 2001-05-09 20:14:09 +0000 | [diff] [blame] | 40 | if (fd >= 0) { |
| 41 | *(int*)p = fd; |
| 42 | return 1; |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 43 | } |
Fred Drake | c99ff60 | 2001-05-09 20:14:09 +0000 | [diff] [blame] | 44 | return 0; |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 45 | } |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 46 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 47 | PyDoc_STRVAR(termios_tcgetattr__doc__, |
| 48 | "tcgetattr(fd) -> list_of_attrs\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 49 | \n\ |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 50 | Get the tty attributes for file descriptor fd, as follows:\n\ |
| 51 | [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\ |
| 52 | of the tty special characters (each a string of length 1, except the items\n\ |
| 53 | with indices VMIN and VTIME, which are integers when these fields are\n\ |
| 54 | defined). The interpretation of the flags and the speeds as well as the\n\ |
| 55 | indexing in the cc array must be done using the symbolic constants defined\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 56 | in this module."); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 57 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 58 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 59 | termios_tcgetattr(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 60 | { |
| 61 | int fd; |
| 62 | struct termios mode; |
| 63 | PyObject *cc; |
| 64 | speed_t ispeed, ospeed; |
| 65 | PyObject *v; |
| 66 | int i; |
| 67 | char ch; |
| 68 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 69 | if (!PyArg_ParseTuple(args, "O&:tcgetattr", |
| 70 | fdconv, (void*)&fd)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 71 | return NULL; |
| 72 | |
| 73 | if (tcgetattr(fd, &mode) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 74 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 75 | |
| 76 | ispeed = cfgetispeed(&mode); |
| 77 | ospeed = cfgetospeed(&mode); |
| 78 | |
| 79 | cc = PyList_New(NCCS); |
| 80 | if (cc == NULL) |
| 81 | return NULL; |
| 82 | for (i = 0; i < NCCS; i++) { |
| 83 | ch = (char)mode.c_cc[i]; |
| 84 | v = PyString_FromStringAndSize(&ch, 1); |
| 85 | if (v == NULL) |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 86 | goto err; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 87 | PyList_SetItem(cc, i, v); |
| 88 | } |
| 89 | |
| 90 | /* Convert the MIN and TIME slots to integer. On some systems, the |
| 91 | MIN and TIME slots are the same as the EOF and EOL slots. So we |
| 92 | only do this in noncanonical input mode. */ |
Guido van Rossum | 36dd0d2 | 1996-12-10 15:23:00 +0000 | [diff] [blame] | 93 | if ((mode.c_lflag & ICANON) == 0) { |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 94 | v = PyInt_FromLong((long)mode.c_cc[VMIN]); |
| 95 | if (v == NULL) |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 96 | goto err; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 97 | PyList_SetItem(cc, VMIN, v); |
| 98 | v = PyInt_FromLong((long)mode.c_cc[VTIME]); |
| 99 | if (v == NULL) |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 100 | goto err; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 101 | PyList_SetItem(cc, VTIME, v); |
| 102 | } |
| 103 | |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 104 | if (!(v = PyList_New(7))) |
| 105 | goto err; |
| 106 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 107 | PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag)); |
| 108 | PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag)); |
| 109 | PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag)); |
| 110 | PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag)); |
| 111 | PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed)); |
| 112 | PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed)); |
| 113 | PyList_SetItem(v, 6, cc); |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 114 | if (PyErr_Occurred()){ |
| 115 | Py_DECREF(v); |
| 116 | goto err; |
| 117 | } |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 118 | return v; |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 119 | err: |
| 120 | Py_DECREF(cc); |
| 121 | return NULL; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 124 | PyDoc_STRVAR(termios_tcsetattr__doc__, |
| 125 | "tcsetattr(fd, when, attributes) -> None\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 126 | \n\ |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 127 | Set the tty attributes for file descriptor fd.\n\ |
| 128 | The attributes to be set are taken from the attributes argument, which\n\ |
| 129 | is a list like the one returned by tcgetattr(). The when argument\n\ |
Fred Drake | 29fd031 | 2001-04-09 19:32:52 +0000 | [diff] [blame] | 130 | determines when the attributes are changed: termios.TCSANOW to\n\ |
| 131 | change immediately, termios.TCSADRAIN to change after transmitting all\n\ |
| 132 | queued output, or termios.TCSAFLUSH to change after transmitting all\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 133 | queued output and discarding all queued input. "); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 134 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 135 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 136 | termios_tcsetattr(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 137 | { |
| 138 | int fd, when; |
| 139 | struct termios mode; |
| 140 | speed_t ispeed, ospeed; |
| 141 | PyObject *term, *cc, *v; |
| 142 | int i; |
| 143 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 144 | if (!PyArg_ParseTuple(args, "O&iO:tcsetattr", |
| 145 | fdconv, &fd, &when, &term)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 146 | return NULL; |
| 147 | if (!PyList_Check(term) || PyList_Size(term) != 7) { |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 148 | PyErr_SetString(PyExc_TypeError, |
| 149 | "tcsetattr, arg 3: must be 7 element list"); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 150 | return NULL; |
| 151 | } |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 152 | |
Guido van Rossum | e7c4193 | 1998-06-12 14:26:18 +0000 | [diff] [blame] | 153 | /* Get the old mode, in case there are any hidden fields... */ |
| 154 | if (tcgetattr(fd, &mode) == -1) |
| 155 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 156 | mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0)); |
| 157 | mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1)); |
| 158 | mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2)); |
| 159 | mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3)); |
| 160 | ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4)); |
| 161 | ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5)); |
| 162 | cc = PyList_GetItem(term, 6); |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 163 | if (PyErr_Occurred()) |
| 164 | return NULL; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 165 | |
| 166 | if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) { |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 167 | PyErr_Format(PyExc_TypeError, |
| 168 | "tcsetattr: attributes[6] must be %d element list", |
| 169 | NCCS); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 170 | return NULL; |
| 171 | } |
| 172 | |
| 173 | for (i = 0; i < NCCS; i++) { |
| 174 | v = PyList_GetItem(cc, i); |
Barry Warsaw | 5709dcf | 1997-01-10 18:42:18 +0000 | [diff] [blame] | 175 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 176 | if (PyString_Check(v) && PyString_Size(v) == 1) |
| 177 | mode.c_cc[i] = (cc_t) * PyString_AsString(v); |
| 178 | else if (PyInt_Check(v)) |
| 179 | mode.c_cc[i] = (cc_t) PyInt_AsLong(v); |
| 180 | else { |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 181 | PyErr_SetString(PyExc_TypeError, |
| 182 | "tcsetattr: elements of attributes must be characters or integers"); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 183 | return NULL; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (cfsetispeed(&mode, (speed_t) ispeed) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 188 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 189 | if (cfsetospeed(&mode, (speed_t) ospeed) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 190 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 191 | if (tcsetattr(fd, when, &mode) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 192 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 193 | |
| 194 | Py_INCREF(Py_None); |
| 195 | return Py_None; |
| 196 | } |
| 197 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 198 | PyDoc_STRVAR(termios_tcsendbreak__doc__, |
| 199 | "tcsendbreak(fd, duration) -> None\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 200 | \n\ |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 201 | Send a break on file descriptor fd.\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 202 | A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 203 | has a system dependent meaning."); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 204 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 205 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 206 | termios_tcsendbreak(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 207 | { |
| 208 | int fd, duration; |
| 209 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 210 | if (!PyArg_ParseTuple(args, "O&i:tcsendbreak", |
| 211 | fdconv, &fd, &duration)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 212 | return NULL; |
| 213 | if (tcsendbreak(fd, duration) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 214 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 215 | |
| 216 | Py_INCREF(Py_None); |
| 217 | return Py_None; |
| 218 | } |
| 219 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 220 | PyDoc_STRVAR(termios_tcdrain__doc__, |
| 221 | "tcdrain(fd) -> None\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 222 | \n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 223 | Wait until all output written to file descriptor fd has been transmitted."); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 224 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 225 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 226 | termios_tcdrain(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 227 | { |
| 228 | int fd; |
| 229 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 230 | if (!PyArg_ParseTuple(args, "O&:tcdrain", |
| 231 | fdconv, &fd)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 232 | return NULL; |
| 233 | if (tcdrain(fd) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 234 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 235 | |
| 236 | Py_INCREF(Py_None); |
| 237 | return Py_None; |
| 238 | } |
| 239 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 240 | PyDoc_STRVAR(termios_tcflush__doc__, |
| 241 | "tcflush(fd, queue) -> None\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 242 | \n\ |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 243 | Discard queued data on file descriptor fd.\n\ |
Fred Drake | 29fd031 | 2001-04-09 19:32:52 +0000 | [diff] [blame] | 244 | The queue selector specifies which queue: termios.TCIFLUSH for the input\n\ |
| 245 | queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 246 | both queues. "); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 247 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 248 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 249 | termios_tcflush(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 250 | { |
| 251 | int fd, queue; |
| 252 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 253 | if (!PyArg_ParseTuple(args, "O&i:tcflush", |
| 254 | fdconv, &fd, &queue)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 255 | return NULL; |
| 256 | if (tcflush(fd, queue) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 257 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 258 | |
| 259 | Py_INCREF(Py_None); |
| 260 | return Py_None; |
| 261 | } |
| 262 | |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 263 | PyDoc_STRVAR(termios_tcflow__doc__, |
| 264 | "tcflow(fd, action) -> None\n\ |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 265 | \n\ |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 266 | Suspend or resume input or output on file descriptor fd.\n\ |
Fred Drake | 29fd031 | 2001-04-09 19:32:52 +0000 | [diff] [blame] | 267 | The action argument can be termios.TCOOFF to suspend output,\n\ |
| 268 | termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 269 | or termios.TCION to restart input."); |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 270 | |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 271 | static PyObject * |
Peter Schneider-Kamp | 416d413 | 2000-07-10 12:15:54 +0000 | [diff] [blame] | 272 | termios_tcflow(PyObject *self, PyObject *args) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 273 | { |
| 274 | int fd, action; |
| 275 | |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 276 | if (!PyArg_ParseTuple(args, "O&i:tcflow", |
| 277 | fdconv, &fd, &action)) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 278 | return NULL; |
| 279 | if (tcflow(fd, action) == -1) |
Guido van Rossum | b8ad024 | 1997-07-17 22:55:06 +0000 | [diff] [blame] | 280 | return PyErr_SetFromErrno(TermiosError); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 281 | |
| 282 | Py_INCREF(Py_None); |
| 283 | return Py_None; |
| 284 | } |
| 285 | |
| 286 | static PyMethodDef termios_methods[] = |
| 287 | { |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 288 | {"tcgetattr", termios_tcgetattr, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 289 | METH_VARARGS, termios_tcgetattr__doc__}, |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 290 | {"tcsetattr", termios_tcsetattr, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 291 | METH_VARARGS, termios_tcsetattr__doc__}, |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 292 | {"tcsendbreak", termios_tcsendbreak, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 293 | METH_VARARGS, termios_tcsendbreak__doc__}, |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 294 | {"tcdrain", termios_tcdrain, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 295 | METH_VARARGS, termios_tcdrain__doc__}, |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 296 | {"tcflush", termios_tcflush, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 297 | METH_VARARGS, termios_tcflush__doc__}, |
Andrew M. Kuchling | a1abb72 | 2000-08-03 02:34:44 +0000 | [diff] [blame] | 298 | {"tcflow", termios_tcflow, |
Fred Drake | b638aaf | 2001-05-07 17:55:35 +0000 | [diff] [blame] | 299 | METH_VARARGS, termios_tcflow__doc__}, |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 300 | {NULL, NULL} |
| 301 | }; |
| 302 | |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 303 | |
Fred Drake | 9ef7fa8 | 2001-03-01 21:54:49 +0000 | [diff] [blame] | 304 | #if defined(VSWTCH) && !defined(VSWTC) |
| 305 | #define VSWTC VSWTCH |
| 306 | #endif |
| 307 | |
| 308 | #if defined(VSWTC) && !defined(VSWTCH) |
| 309 | #define VSWTCH VSWTC |
| 310 | #endif |
| 311 | |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 312 | static struct constant { |
| 313 | char *name; |
| 314 | long value; |
| 315 | } termios_constants[] = { |
| 316 | /* cfgetospeed(), cfsetospeed() constants */ |
| 317 | {"B0", B0}, |
| 318 | {"B50", B50}, |
| 319 | {"B75", B75}, |
| 320 | {"B110", B110}, |
| 321 | {"B134", B134}, |
| 322 | {"B150", B150}, |
| 323 | {"B200", B200}, |
| 324 | {"B300", B300}, |
| 325 | {"B600", B600}, |
| 326 | {"B1200", B1200}, |
| 327 | {"B1800", B1800}, |
| 328 | {"B2400", B2400}, |
| 329 | {"B4800", B4800}, |
| 330 | {"B9600", B9600}, |
| 331 | {"B19200", B19200}, |
| 332 | {"B38400", B38400}, |
Guido van Rossum | 2242f2f | 2001-04-11 20:58:20 +0000 | [diff] [blame] | 333 | #ifdef B57600 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 334 | {"B57600", B57600}, |
Guido van Rossum | 2242f2f | 2001-04-11 20:58:20 +0000 | [diff] [blame] | 335 | #endif |
| 336 | #ifdef B115200 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 337 | {"B115200", B115200}, |
Guido van Rossum | 2242f2f | 2001-04-11 20:58:20 +0000 | [diff] [blame] | 338 | #endif |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 339 | #ifdef B230400 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 340 | {"B230400", B230400}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 341 | #endif |
Fred Drake | 9ef7fa8 | 2001-03-01 21:54:49 +0000 | [diff] [blame] | 342 | #ifdef CBAUDEX |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 343 | {"CBAUDEX", CBAUDEX}, |
Fred Drake | 9ef7fa8 | 2001-03-01 21:54:49 +0000 | [diff] [blame] | 344 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 345 | |
| 346 | /* tcsetattr() constants */ |
| 347 | {"TCSANOW", TCSANOW}, |
| 348 | {"TCSADRAIN", TCSADRAIN}, |
| 349 | {"TCSAFLUSH", TCSAFLUSH}, |
| 350 | |
| 351 | /* tcflush() constants */ |
| 352 | {"TCIFLUSH", TCIFLUSH}, |
| 353 | {"TCOFLUSH", TCOFLUSH}, |
| 354 | {"TCIOFLUSH", TCIOFLUSH}, |
| 355 | |
| 356 | /* tcflow() constants */ |
| 357 | {"TCOOFF", TCOOFF}, |
| 358 | {"TCOON", TCOON}, |
| 359 | {"TCIOFF", TCIOFF}, |
| 360 | {"TCION", TCION}, |
| 361 | |
| 362 | /* struct termios.c_iflag constants */ |
| 363 | {"IGNBRK", IGNBRK}, |
| 364 | {"BRKINT", BRKINT}, |
| 365 | {"IGNPAR", IGNPAR}, |
| 366 | {"PARMRK", PARMRK}, |
| 367 | {"INPCK", INPCK}, |
| 368 | {"ISTRIP", ISTRIP}, |
| 369 | {"INLCR", INLCR}, |
| 370 | {"IGNCR", IGNCR}, |
| 371 | {"ICRNL", ICRNL}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 372 | #ifdef IUCLC |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 373 | {"IUCLC", IUCLC}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 374 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 375 | {"IXON", IXON}, |
| 376 | {"IXANY", IXANY}, |
| 377 | {"IXOFF", IXOFF}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 378 | #ifdef IMAXBEL |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 379 | {"IMAXBEL", IMAXBEL}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 380 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 381 | |
| 382 | /* struct termios.c_oflag constants */ |
| 383 | {"OPOST", OPOST}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 384 | #ifdef OLCUC |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 385 | {"OLCUC", OLCUC}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 386 | #endif |
Andrew MacIntyre | 7bf6833 | 2002-03-03 02:59:16 +0000 | [diff] [blame] | 387 | #ifdef ONLCR |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 388 | {"ONLCR", ONLCR}, |
Andrew MacIntyre | 7bf6833 | 2002-03-03 02:59:16 +0000 | [diff] [blame] | 389 | #endif |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 390 | #ifdef OCRNL |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 391 | {"OCRNL", OCRNL}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 392 | #endif |
| 393 | #ifdef ONOCR |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 394 | {"ONOCR", ONOCR}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 395 | #endif |
| 396 | #ifdef ONLRET |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 397 | {"ONLRET", ONLRET}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 398 | #endif |
| 399 | #ifdef OFILL |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 400 | {"OFILL", OFILL}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 401 | #endif |
| 402 | #ifdef OFDEL |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 403 | {"OFDEL", OFDEL}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 404 | #endif |
| 405 | #ifdef NLDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 406 | {"NLDLY", NLDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 407 | #endif |
| 408 | #ifdef CRDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 409 | {"CRDLY", CRDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 410 | #endif |
| 411 | #ifdef TABDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 412 | {"TABDLY", TABDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 413 | #endif |
| 414 | #ifdef BSDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 415 | {"BSDLY", BSDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 416 | #endif |
| 417 | #ifdef VTDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 418 | {"VTDLY", VTDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 419 | #endif |
| 420 | #ifdef FFDLY |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 421 | {"FFDLY", FFDLY}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 422 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 423 | |
| 424 | /* struct termios.c_oflag-related values (delay mask) */ |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 425 | #ifdef NL0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 426 | {"NL0", NL0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 427 | #endif |
| 428 | #ifdef NL1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 429 | {"NL1", NL1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 430 | #endif |
| 431 | #ifdef CR0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 432 | {"CR0", CR0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 433 | #endif |
| 434 | #ifdef CR1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 435 | {"CR1", CR1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 436 | #endif |
| 437 | #ifdef CR2 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 438 | {"CR2", CR2}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 439 | #endif |
| 440 | #ifdef CR3 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 441 | {"CR3", CR3}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 442 | #endif |
| 443 | #ifdef TAB0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 444 | {"TAB0", TAB0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 445 | #endif |
| 446 | #ifdef TAB1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 447 | {"TAB1", TAB1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 448 | #endif |
| 449 | #ifdef TAB2 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 450 | {"TAB2", TAB2}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 451 | #endif |
| 452 | #ifdef TAB3 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 453 | {"TAB3", TAB3}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 454 | #endif |
Fred Drake | dedbebf | 2001-03-02 06:50:58 +0000 | [diff] [blame] | 455 | #ifdef XTABS |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 456 | {"XTABS", XTABS}, |
Fred Drake | dedbebf | 2001-03-02 06:50:58 +0000 | [diff] [blame] | 457 | #endif |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 458 | #ifdef BS0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 459 | {"BS0", BS0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 460 | #endif |
| 461 | #ifdef BS1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 462 | {"BS1", BS1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 463 | #endif |
| 464 | #ifdef VT0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 465 | {"VT0", VT0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 466 | #endif |
| 467 | #ifdef VT1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 468 | {"VT1", VT1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 469 | #endif |
| 470 | #ifdef FF0 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 471 | {"FF0", FF0}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 472 | #endif |
| 473 | #ifdef FF1 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 474 | {"FF1", FF1}, |
Fred Drake | d85556c | 2001-03-03 18:08:52 +0000 | [diff] [blame] | 475 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 476 | |
| 477 | /* struct termios.c_cflag constants */ |
| 478 | {"CSIZE", CSIZE}, |
| 479 | {"CSTOPB", CSTOPB}, |
| 480 | {"CREAD", CREAD}, |
| 481 | {"PARENB", PARENB}, |
| 482 | {"PARODD", PARODD}, |
| 483 | {"HUPCL", HUPCL}, |
| 484 | {"CLOCAL", CLOCAL}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 485 | #ifdef CIBAUD |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 486 | {"CIBAUD", CIBAUD}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 487 | #endif |
Fred Drake | dedbebf | 2001-03-02 06:50:58 +0000 | [diff] [blame] | 488 | #ifdef CRTSCTS |
| 489 | {"CRTSCTS", (long)CRTSCTS}, |
| 490 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 491 | |
| 492 | /* struct termios.c_cflag-related values (character size) */ |
| 493 | {"CS5", CS5}, |
| 494 | {"CS6", CS6}, |
| 495 | {"CS7", CS7}, |
| 496 | {"CS8", CS8}, |
| 497 | |
| 498 | /* struct termios.c_lflag constants */ |
| 499 | {"ISIG", ISIG}, |
| 500 | {"ICANON", ICANON}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 501 | #ifdef XCASE |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 502 | {"XCASE", XCASE}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 503 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 504 | {"ECHO", ECHO}, |
| 505 | {"ECHOE", ECHOE}, |
| 506 | {"ECHOK", ECHOK}, |
| 507 | {"ECHONL", ECHONL}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 508 | #ifdef ECHOCTL |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 509 | {"ECHOCTL", ECHOCTL}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 510 | #endif |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 511 | #ifdef ECHOPRT |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 512 | {"ECHOPRT", ECHOPRT}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 513 | #endif |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 514 | #ifdef ECHOKE |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 515 | {"ECHOKE", ECHOKE}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 516 | #endif |
| 517 | #ifdef FLUSHO |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 518 | {"FLUSHO", FLUSHO}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 519 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 520 | {"NOFLSH", NOFLSH}, |
| 521 | {"TOSTOP", TOSTOP}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 522 | #ifdef PENDIN |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 523 | {"PENDIN", PENDIN}, |
Fred Drake | abb379e | 2001-03-01 03:28:08 +0000 | [diff] [blame] | 524 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 525 | {"IEXTEN", IEXTEN}, |
| 526 | |
| 527 | /* indexes into the control chars array returned by tcgetattr() */ |
| 528 | {"VINTR", VINTR}, |
| 529 | {"VQUIT", VQUIT}, |
| 530 | {"VERASE", VERASE}, |
| 531 | {"VKILL", VKILL}, |
| 532 | {"VEOF", VEOF}, |
| 533 | {"VTIME", VTIME}, |
| 534 | {"VMIN", VMIN}, |
Fred Drake | dedbebf | 2001-03-02 06:50:58 +0000 | [diff] [blame] | 535 | #ifdef VSWTC |
| 536 | /* The #defines above ensure that if either is defined, both are, |
| 537 | * but both may be omitted by the system headers. ;-( */ |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 538 | {"VSWTC", VSWTC}, |
Fred Drake | 9ef7fa8 | 2001-03-01 21:54:49 +0000 | [diff] [blame] | 539 | {"VSWTCH", VSWTCH}, |
Fred Drake | dedbebf | 2001-03-02 06:50:58 +0000 | [diff] [blame] | 540 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 541 | {"VSTART", VSTART}, |
| 542 | {"VSTOP", VSTOP}, |
| 543 | {"VSUSP", VSUSP}, |
| 544 | {"VEOL", VEOL}, |
Fred Drake | d0b625d | 2001-05-22 15:44:15 +0000 | [diff] [blame] | 545 | #ifdef VREPRINT |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 546 | {"VREPRINT", VREPRINT}, |
Fred Drake | 87068f1 | 2001-05-11 16:14:17 +0000 | [diff] [blame] | 547 | #endif |
Fred Drake | d0b625d | 2001-05-22 15:44:15 +0000 | [diff] [blame] | 548 | #ifdef VDISCARD |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 549 | {"VDISCARD", VDISCARD}, |
Fred Drake | 87068f1 | 2001-05-11 16:14:17 +0000 | [diff] [blame] | 550 | #endif |
Thomas Wouters | 819bb2c | 2001-06-11 15:25:16 +0000 | [diff] [blame] | 551 | #ifdef VWERASE |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 552 | {"VWERASE", VWERASE}, |
Thomas Wouters | 819bb2c | 2001-06-11 15:25:16 +0000 | [diff] [blame] | 553 | #endif |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 554 | #ifdef VLNEXT |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 555 | {"VLNEXT", VLNEXT}, |
Thomas Wouters | 2b30524 | 2001-06-15 12:05:44 +0000 | [diff] [blame] | 556 | #endif |
Andrew MacIntyre | 7bf6833 | 2002-03-03 02:59:16 +0000 | [diff] [blame] | 557 | #ifdef VEOL2 |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 558 | {"VEOL2", VEOL2}, |
Andrew MacIntyre | 7bf6833 | 2002-03-03 02:59:16 +0000 | [diff] [blame] | 559 | #endif |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 560 | |
Fred Drake | 55a0034 | 2001-03-26 17:14:02 +0000 | [diff] [blame] | 561 | |
| 562 | #ifdef B460800 |
| 563 | {"B460800", B460800}, |
| 564 | #endif |
| 565 | #ifdef CBAUD |
| 566 | {"CBAUD", CBAUD}, |
| 567 | #endif |
| 568 | #ifdef CDEL |
| 569 | {"CDEL", CDEL}, |
| 570 | #endif |
| 571 | #ifdef CDSUSP |
| 572 | {"CDSUSP", CDSUSP}, |
| 573 | #endif |
| 574 | #ifdef CEOF |
| 575 | {"CEOF", CEOF}, |
| 576 | #endif |
| 577 | #ifdef CEOL |
| 578 | {"CEOL", CEOL}, |
| 579 | #endif |
| 580 | #ifdef CEOL2 |
| 581 | {"CEOL2", CEOL2}, |
| 582 | #endif |
| 583 | #ifdef CEOT |
| 584 | {"CEOT", CEOT}, |
| 585 | #endif |
| 586 | #ifdef CERASE |
| 587 | {"CERASE", CERASE}, |
| 588 | #endif |
| 589 | #ifdef CESC |
| 590 | {"CESC", CESC}, |
| 591 | #endif |
| 592 | #ifdef CFLUSH |
| 593 | {"CFLUSH", CFLUSH}, |
| 594 | #endif |
| 595 | #ifdef CINTR |
| 596 | {"CINTR", CINTR}, |
| 597 | #endif |
| 598 | #ifdef CKILL |
| 599 | {"CKILL", CKILL}, |
| 600 | #endif |
| 601 | #ifdef CLNEXT |
| 602 | {"CLNEXT", CLNEXT}, |
| 603 | #endif |
| 604 | #ifdef CNUL |
| 605 | {"CNUL", CNUL}, |
| 606 | #endif |
| 607 | #ifdef COMMON |
| 608 | {"COMMON", COMMON}, |
| 609 | #endif |
| 610 | #ifdef CQUIT |
| 611 | {"CQUIT", CQUIT}, |
| 612 | #endif |
| 613 | #ifdef CRPRNT |
| 614 | {"CRPRNT", CRPRNT}, |
| 615 | #endif |
| 616 | #ifdef CSTART |
| 617 | {"CSTART", CSTART}, |
| 618 | #endif |
| 619 | #ifdef CSTOP |
| 620 | {"CSTOP", CSTOP}, |
| 621 | #endif |
| 622 | #ifdef CSUSP |
| 623 | {"CSUSP", CSUSP}, |
| 624 | #endif |
| 625 | #ifdef CSWTCH |
| 626 | {"CSWTCH", CSWTCH}, |
| 627 | #endif |
| 628 | #ifdef CWERASE |
| 629 | {"CWERASE", CWERASE}, |
| 630 | #endif |
| 631 | #ifdef EXTA |
| 632 | {"EXTA", EXTA}, |
| 633 | #endif |
| 634 | #ifdef EXTB |
| 635 | {"EXTB", EXTB}, |
| 636 | #endif |
| 637 | #ifdef FIOASYNC |
| 638 | {"FIOASYNC", FIOASYNC}, |
| 639 | #endif |
| 640 | #ifdef FIOCLEX |
| 641 | {"FIOCLEX", FIOCLEX}, |
| 642 | #endif |
| 643 | #ifdef FIONBIO |
| 644 | {"FIONBIO", FIONBIO}, |
| 645 | #endif |
| 646 | #ifdef FIONCLEX |
| 647 | {"FIONCLEX", FIONCLEX}, |
| 648 | #endif |
| 649 | #ifdef FIONREAD |
| 650 | {"FIONREAD", FIONREAD}, |
| 651 | #endif |
| 652 | #ifdef IBSHIFT |
| 653 | {"IBSHIFT", IBSHIFT}, |
| 654 | #endif |
| 655 | #ifdef INIT_C_CC |
| 656 | {"INIT_C_CC", INIT_C_CC}, |
| 657 | #endif |
| 658 | #ifdef IOCSIZE_MASK |
| 659 | {"IOCSIZE_MASK", IOCSIZE_MASK}, |
| 660 | #endif |
| 661 | #ifdef IOCSIZE_SHIFT |
| 662 | {"IOCSIZE_SHIFT", IOCSIZE_SHIFT}, |
| 663 | #endif |
| 664 | #ifdef NCC |
| 665 | {"NCC", NCC}, |
| 666 | #endif |
| 667 | #ifdef NCCS |
| 668 | {"NCCS", NCCS}, |
| 669 | #endif |
| 670 | #ifdef NSWTCH |
| 671 | {"NSWTCH", NSWTCH}, |
| 672 | #endif |
| 673 | #ifdef N_MOUSE |
| 674 | {"N_MOUSE", N_MOUSE}, |
| 675 | #endif |
| 676 | #ifdef N_PPP |
| 677 | {"N_PPP", N_PPP}, |
| 678 | #endif |
| 679 | #ifdef N_SLIP |
| 680 | {"N_SLIP", N_SLIP}, |
| 681 | #endif |
| 682 | #ifdef N_STRIP |
| 683 | {"N_STRIP", N_STRIP}, |
| 684 | #endif |
| 685 | #ifdef N_TTY |
| 686 | {"N_TTY", N_TTY}, |
| 687 | #endif |
| 688 | #ifdef TCFLSH |
| 689 | {"TCFLSH", TCFLSH}, |
| 690 | #endif |
| 691 | #ifdef TCGETA |
| 692 | {"TCGETA", TCGETA}, |
| 693 | #endif |
| 694 | #ifdef TCGETS |
| 695 | {"TCGETS", TCGETS}, |
| 696 | #endif |
| 697 | #ifdef TCSBRK |
| 698 | {"TCSBRK", TCSBRK}, |
| 699 | #endif |
| 700 | #ifdef TCSBRKP |
| 701 | {"TCSBRKP", TCSBRKP}, |
| 702 | #endif |
| 703 | #ifdef TCSETA |
| 704 | {"TCSETA", TCSETA}, |
| 705 | #endif |
| 706 | #ifdef TCSETAF |
| 707 | {"TCSETAF", TCSETAF}, |
| 708 | #endif |
| 709 | #ifdef TCSETAW |
| 710 | {"TCSETAW", TCSETAW}, |
| 711 | #endif |
| 712 | #ifdef TCSETS |
| 713 | {"TCSETS", TCSETS}, |
| 714 | #endif |
| 715 | #ifdef TCSETSF |
| 716 | {"TCSETSF", TCSETSF}, |
| 717 | #endif |
| 718 | #ifdef TCSETSW |
| 719 | {"TCSETSW", TCSETSW}, |
| 720 | #endif |
| 721 | #ifdef TCXONC |
| 722 | {"TCXONC", TCXONC}, |
| 723 | #endif |
| 724 | #ifdef TIOCCONS |
| 725 | {"TIOCCONS", TIOCCONS}, |
| 726 | #endif |
| 727 | #ifdef TIOCEXCL |
| 728 | {"TIOCEXCL", TIOCEXCL}, |
| 729 | #endif |
| 730 | #ifdef TIOCGETD |
| 731 | {"TIOCGETD", TIOCGETD}, |
| 732 | #endif |
| 733 | #ifdef TIOCGICOUNT |
| 734 | {"TIOCGICOUNT", TIOCGICOUNT}, |
| 735 | #endif |
| 736 | #ifdef TIOCGLCKTRMIOS |
| 737 | {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS}, |
| 738 | #endif |
| 739 | #ifdef TIOCGPGRP |
| 740 | {"TIOCGPGRP", TIOCGPGRP}, |
| 741 | #endif |
| 742 | #ifdef TIOCGSERIAL |
| 743 | {"TIOCGSERIAL", TIOCGSERIAL}, |
| 744 | #endif |
| 745 | #ifdef TIOCGSOFTCAR |
| 746 | {"TIOCGSOFTCAR", TIOCGSOFTCAR}, |
| 747 | #endif |
| 748 | #ifdef TIOCGWINSZ |
| 749 | {"TIOCGWINSZ", TIOCGWINSZ}, |
| 750 | #endif |
| 751 | #ifdef TIOCINQ |
| 752 | {"TIOCINQ", TIOCINQ}, |
| 753 | #endif |
| 754 | #ifdef TIOCLINUX |
| 755 | {"TIOCLINUX", TIOCLINUX}, |
| 756 | #endif |
| 757 | #ifdef TIOCMBIC |
| 758 | {"TIOCMBIC", TIOCMBIC}, |
| 759 | #endif |
| 760 | #ifdef TIOCMBIS |
| 761 | {"TIOCMBIS", TIOCMBIS}, |
| 762 | #endif |
| 763 | #ifdef TIOCMGET |
| 764 | {"TIOCMGET", TIOCMGET}, |
| 765 | #endif |
| 766 | #ifdef TIOCMIWAIT |
| 767 | {"TIOCMIWAIT", TIOCMIWAIT}, |
| 768 | #endif |
| 769 | #ifdef TIOCMSET |
| 770 | {"TIOCMSET", TIOCMSET}, |
| 771 | #endif |
| 772 | #ifdef TIOCM_CAR |
| 773 | {"TIOCM_CAR", TIOCM_CAR}, |
| 774 | #endif |
| 775 | #ifdef TIOCM_CD |
| 776 | {"TIOCM_CD", TIOCM_CD}, |
| 777 | #endif |
| 778 | #ifdef TIOCM_CTS |
| 779 | {"TIOCM_CTS", TIOCM_CTS}, |
| 780 | #endif |
| 781 | #ifdef TIOCM_DSR |
| 782 | {"TIOCM_DSR", TIOCM_DSR}, |
| 783 | #endif |
| 784 | #ifdef TIOCM_DTR |
| 785 | {"TIOCM_DTR", TIOCM_DTR}, |
| 786 | #endif |
| 787 | #ifdef TIOCM_LE |
| 788 | {"TIOCM_LE", TIOCM_LE}, |
| 789 | #endif |
| 790 | #ifdef TIOCM_RI |
| 791 | {"TIOCM_RI", TIOCM_RI}, |
| 792 | #endif |
| 793 | #ifdef TIOCM_RNG |
| 794 | {"TIOCM_RNG", TIOCM_RNG}, |
| 795 | #endif |
| 796 | #ifdef TIOCM_RTS |
| 797 | {"TIOCM_RTS", TIOCM_RTS}, |
| 798 | #endif |
| 799 | #ifdef TIOCM_SR |
| 800 | {"TIOCM_SR", TIOCM_SR}, |
| 801 | #endif |
| 802 | #ifdef TIOCM_ST |
| 803 | {"TIOCM_ST", TIOCM_ST}, |
| 804 | #endif |
| 805 | #ifdef TIOCNOTTY |
| 806 | {"TIOCNOTTY", TIOCNOTTY}, |
| 807 | #endif |
| 808 | #ifdef TIOCNXCL |
| 809 | {"TIOCNXCL", TIOCNXCL}, |
| 810 | #endif |
| 811 | #ifdef TIOCOUTQ |
| 812 | {"TIOCOUTQ", TIOCOUTQ}, |
| 813 | #endif |
| 814 | #ifdef TIOCPKT |
| 815 | {"TIOCPKT", TIOCPKT}, |
| 816 | #endif |
| 817 | #ifdef TIOCPKT_DATA |
| 818 | {"TIOCPKT_DATA", TIOCPKT_DATA}, |
| 819 | #endif |
| 820 | #ifdef TIOCPKT_DOSTOP |
| 821 | {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP}, |
| 822 | #endif |
| 823 | #ifdef TIOCPKT_FLUSHREAD |
| 824 | {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD}, |
| 825 | #endif |
| 826 | #ifdef TIOCPKT_FLUSHWRITE |
| 827 | {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE}, |
| 828 | #endif |
| 829 | #ifdef TIOCPKT_NOSTOP |
| 830 | {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP}, |
| 831 | #endif |
| 832 | #ifdef TIOCPKT_START |
| 833 | {"TIOCPKT_START", TIOCPKT_START}, |
| 834 | #endif |
| 835 | #ifdef TIOCPKT_STOP |
| 836 | {"TIOCPKT_STOP", TIOCPKT_STOP}, |
| 837 | #endif |
| 838 | #ifdef TIOCSCTTY |
| 839 | {"TIOCSCTTY", TIOCSCTTY}, |
| 840 | #endif |
| 841 | #ifdef TIOCSERCONFIG |
| 842 | {"TIOCSERCONFIG", TIOCSERCONFIG}, |
| 843 | #endif |
| 844 | #ifdef TIOCSERGETLSR |
| 845 | {"TIOCSERGETLSR", TIOCSERGETLSR}, |
| 846 | #endif |
| 847 | #ifdef TIOCSERGETMULTI |
| 848 | {"TIOCSERGETMULTI", TIOCSERGETMULTI}, |
| 849 | #endif |
| 850 | #ifdef TIOCSERGSTRUCT |
| 851 | {"TIOCSERGSTRUCT", TIOCSERGSTRUCT}, |
| 852 | #endif |
| 853 | #ifdef TIOCSERGWILD |
| 854 | {"TIOCSERGWILD", TIOCSERGWILD}, |
| 855 | #endif |
| 856 | #ifdef TIOCSERSETMULTI |
| 857 | {"TIOCSERSETMULTI", TIOCSERSETMULTI}, |
| 858 | #endif |
| 859 | #ifdef TIOCSERSWILD |
| 860 | {"TIOCSERSWILD", TIOCSERSWILD}, |
| 861 | #endif |
| 862 | #ifdef TIOCSER_TEMT |
| 863 | {"TIOCSER_TEMT", TIOCSER_TEMT}, |
| 864 | #endif |
| 865 | #ifdef TIOCSETD |
| 866 | {"TIOCSETD", TIOCSETD}, |
| 867 | #endif |
| 868 | #ifdef TIOCSLCKTRMIOS |
| 869 | {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS}, |
| 870 | #endif |
| 871 | #ifdef TIOCSPGRP |
| 872 | {"TIOCSPGRP", TIOCSPGRP}, |
| 873 | #endif |
| 874 | #ifdef TIOCSSERIAL |
| 875 | {"TIOCSSERIAL", TIOCSSERIAL}, |
| 876 | #endif |
| 877 | #ifdef TIOCSSOFTCAR |
| 878 | {"TIOCSSOFTCAR", TIOCSSOFTCAR}, |
| 879 | #endif |
| 880 | #ifdef TIOCSTI |
| 881 | {"TIOCSTI", TIOCSTI}, |
| 882 | #endif |
| 883 | #ifdef TIOCSWINSZ |
| 884 | {"TIOCSWINSZ", TIOCSWINSZ}, |
| 885 | #endif |
| 886 | #ifdef TIOCTTYGSTRUCT |
| 887 | {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT}, |
| 888 | #endif |
| 889 | |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 890 | /* sentinel */ |
| 891 | {NULL, 0} |
| 892 | }; |
| 893 | |
| 894 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 895 | DL_EXPORT(void) |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 896 | PyInit_termios(void) |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 897 | { |
Fred Drake | 78f6c86 | 2002-02-14 07:11:23 +0000 | [diff] [blame] | 898 | PyObject *m; |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 899 | struct constant *constant = termios_constants; |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 900 | |
Guido van Rossum | 1aca4d8 | 1998-03-03 22:10:18 +0000 | [diff] [blame] | 901 | m = Py_InitModule4("termios", termios_methods, termios__doc__, |
| 902 | (PyObject *)NULL, PYTHON_API_VERSION); |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 903 | |
Fred Drake | 78f6c86 | 2002-02-14 07:11:23 +0000 | [diff] [blame] | 904 | if (TermiosError == NULL) { |
| 905 | TermiosError = PyErr_NewException("termios.error", NULL, NULL); |
| 906 | } |
| 907 | Py_INCREF(TermiosError); |
| 908 | PyModule_AddObject(m, "error", TermiosError); |
Fred Drake | df48d14 | 2001-02-27 21:22:39 +0000 | [diff] [blame] | 909 | |
| 910 | while (constant->name != NULL) { |
| 911 | PyModule_AddIntConstant(m, constant->name, constant->value); |
| 912 | ++constant; |
| 913 | } |
Guido van Rossum | 9adae8e | 1994-09-12 10:41:22 +0000 | [diff] [blame] | 914 | } |