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