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