blob: 54d72b2fb62a36f56368242acbe8b32aab432166 [file] [log] [blame]
Guido van Rossum9adae8e1994-09-12 10:41:22 +00001/* termiosmodule.c -- POSIX terminal I/O module implementation. */
2
Guido van Rossumca6954a1999-01-14 19:31:42 +00003#include "Python.h"
Guido van Rossum9adae8e1994-09-12 10:41:22 +00004
5#define PyInit_termios inittermios
6
Guido van Rossum9adae8e1994-09-12 10:41:22 +00007#include <termios.h>
Fred Drakeb2877dd2001-05-09 17:53:06 +00008#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 Drakeb638aaf2001-05-07 17:55:35 +000011#include <termio.h>
Fred Drakeb2877dd2001-05-09 17:53:06 +000012#endif
Fred Drake9b3bc492001-04-04 21:19:26 +000013#include <sys/ioctl.h>
Guido van Rossum1aca4d81998-03-03 22:10:18 +000014
Guido van Rossumbcc20741998-08-04 22:53:56 +000015#ifdef __BEOS__
16#include <unistd.h>
17#endif
18
Fred Drake87068f12001-05-11 16:14:17 +000019/* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
20 * MDTR, MRI, and MRTS (appearantly used internally by some things
21 * defined as macros; these are not used here directly).
22 */
23#ifdef HAVE_SYS_MODEM_H
24#include <sys/modem.h>
25#endif
26
Fred Drakeb638aaf2001-05-07 17:55:35 +000027static char termios__doc__[] = "\
28This module provides an interface to the Posix calls for tty I/O control.\n\
29For a complete description of these calls, see the Posix or Unix manual\n\
30pages. It is only available for those Unix versions that support Posix\n\
31termios style tty I/O control.\n\
32\n\
33All functions in this module take a file descriptor fd as their first\n\
34argument. This can be an integer file descriptor, such as returned by\n\
35sys.stdin.fileno(), or a file object, such as sys.stdin itself.";
Guido van Rossum9adae8e1994-09-12 10:41:22 +000036
37static PyObject *TermiosError;
38
Fred Drakeb638aaf2001-05-07 17:55:35 +000039static int fdconv(PyObject* obj, void* p)
40{
41 int fd;
42
43 fd = PyObject_AsFileDescriptor(obj);
Fred Drakec99ff602001-05-09 20:14:09 +000044 if (fd >= 0) {
45 *(int*)p = fd;
46 return 1;
Fred Drakeb638aaf2001-05-07 17:55:35 +000047 }
Fred Drakec99ff602001-05-09 20:14:09 +000048 return 0;
Fred Drakeb638aaf2001-05-07 17:55:35 +000049}
Guido van Rossum9adae8e1994-09-12 10:41:22 +000050
Guido van Rossum1aca4d81998-03-03 22:10:18 +000051static char termios_tcgetattr__doc__[] = "\
52tcgetattr(fd) -> list_of_attrs\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000053\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +000054Get the tty attributes for file descriptor fd, as follows:\n\
55[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
56of the tty special characters (each a string of length 1, except the items\n\
57with indices VMIN and VTIME, which are integers when these fields are\n\
58defined). The interpretation of the flags and the speeds as well as the\n\
59indexing in the cc array must be done using the symbolic constants defined\n\
Fred Drake29fd0312001-04-09 19:32:52 +000060in this module.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +000061
Guido van Rossum9adae8e1994-09-12 10:41:22 +000062static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000063termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000064{
65 int fd;
66 struct termios mode;
67 PyObject *cc;
68 speed_t ispeed, ospeed;
69 PyObject *v;
70 int i;
71 char ch;
72
Fred Drakeb638aaf2001-05-07 17:55:35 +000073 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
74 fdconv, (void*)&fd))
Guido van Rossum9adae8e1994-09-12 10:41:22 +000075 return NULL;
76
77 if (tcgetattr(fd, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +000078 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000079
80 ispeed = cfgetispeed(&mode);
81 ospeed = cfgetospeed(&mode);
82
83 cc = PyList_New(NCCS);
84 if (cc == NULL)
85 return NULL;
86 for (i = 0; i < NCCS; i++) {
87 ch = (char)mode.c_cc[i];
88 v = PyString_FromStringAndSize(&ch, 1);
89 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000090 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000091 PyList_SetItem(cc, i, v);
92 }
93
94 /* Convert the MIN and TIME slots to integer. On some systems, the
95 MIN and TIME slots are the same as the EOF and EOL slots. So we
96 only do this in noncanonical input mode. */
Guido van Rossum36dd0d21996-12-10 15:23:00 +000097 if ((mode.c_lflag & ICANON) == 0) {
Guido van Rossum9adae8e1994-09-12 10:41:22 +000098 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
99 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000100 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000101 PyList_SetItem(cc, VMIN, v);
102 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
103 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000104 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000105 PyList_SetItem(cc, VTIME, v);
106 }
107
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000108 if (!(v = PyList_New(7)))
109 goto err;
110
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000111 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
112 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
113 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
114 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
115 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
116 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
117 PyList_SetItem(v, 6, cc);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000118 if (PyErr_Occurred()){
119 Py_DECREF(v);
120 goto err;
121 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000122 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000123 err:
124 Py_DECREF(cc);
125 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000126}
127
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000128static char termios_tcsetattr__doc__[] = "\
129tcsetattr(fd, when, attributes) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000130\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000131Set the tty attributes for file descriptor fd.\n\
132The attributes to be set are taken from the attributes argument, which\n\
133is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000134determines when the attributes are changed: termios.TCSANOW to\n\
135change immediately, termios.TCSADRAIN to change after transmitting all\n\
136queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000137queued output and discarding all queued input. ";
138
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000139static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000140termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000141{
142 int fd, when;
143 struct termios mode;
144 speed_t ispeed, ospeed;
145 PyObject *term, *cc, *v;
146 int i;
147
Fred Drakeb638aaf2001-05-07 17:55:35 +0000148 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
149 fdconv, &fd, &when, &term))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000150 return NULL;
151 if (!PyList_Check(term) || PyList_Size(term) != 7) {
Fred Drakeb638aaf2001-05-07 17:55:35 +0000152 PyErr_SetString(PyExc_TypeError,
153 "tcsetattr, arg 3: must be 7 element list");
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000154 return NULL;
155 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000156
Guido van Rossume7c41931998-06-12 14:26:18 +0000157 /* Get the old mode, in case there are any hidden fields... */
158 if (tcgetattr(fd, &mode) == -1)
159 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000160 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
161 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
162 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
163 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
164 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
165 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
166 cc = PyList_GetItem(term, 6);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000167 if (PyErr_Occurred())
168 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000169
170 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
Fred Drakeb638aaf2001-05-07 17:55:35 +0000171 PyErr_Format(PyExc_TypeError,
172 "tcsetattr: attributes[6] must be %d element list",
173 NCCS);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000174 return NULL;
175 }
176
177 for (i = 0; i < NCCS; i++) {
178 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000179
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000180 if (PyString_Check(v) && PyString_Size(v) == 1)
181 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
182 else if (PyInt_Check(v))
183 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
184 else {
Fred Drakeb638aaf2001-05-07 17:55:35 +0000185 PyErr_SetString(PyExc_TypeError,
186 "tcsetattr: elements of attributes must be characters or integers");
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000187 return NULL;
188 }
189 }
190
191 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000192 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000193 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000194 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000195 if (tcsetattr(fd, when, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000196 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000197
198 Py_INCREF(Py_None);
199 return Py_None;
200}
201
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000202static char termios_tcsendbreak__doc__[] = "\
203tcsendbreak(fd, duration) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000204\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000205Send a break on file descriptor fd.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000206A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
207has a system dependent meaning.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000208
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000209static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000210termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000211{
212 int fd, duration;
213
Fred Drakeb638aaf2001-05-07 17:55:35 +0000214 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
215 fdconv, &fd, &duration))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000216 return NULL;
217 if (tcsendbreak(fd, duration) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000218 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000219
220 Py_INCREF(Py_None);
221 return Py_None;
222}
223
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000224static char termios_tcdrain__doc__[] = "\
225tcdrain(fd) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000226\n\
227Wait until all output written to file descriptor fd has been transmitted.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000228
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000229static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000230termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000231{
232 int fd;
233
Fred Drakeb638aaf2001-05-07 17:55:35 +0000234 if (!PyArg_ParseTuple(args, "O&:tcdrain",
235 fdconv, &fd))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000236 return NULL;
237 if (tcdrain(fd) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000238 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000239
240 Py_INCREF(Py_None);
241 return Py_None;
242}
243
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000244static char termios_tcflush__doc__[] = "\
245tcflush(fd, queue) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000246\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000247Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000248The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
249queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000250both queues. ";
251
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000252static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000253termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000254{
255 int fd, queue;
256
Fred Drakeb638aaf2001-05-07 17:55:35 +0000257 if (!PyArg_ParseTuple(args, "O&i:tcflush",
258 fdconv, &fd, &queue))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000259 return NULL;
260 if (tcflush(fd, queue) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000261 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000262
263 Py_INCREF(Py_None);
264 return Py_None;
265}
266
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000267static char termios_tcflow__doc__[] = "\
268tcflow(fd, action) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000269\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000270Suspend or resume input or output on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000271The action argument can be termios.TCOOFF to suspend output,\n\
272termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
273or termios.TCION to restart input.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000274
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000275static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000276termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000277{
278 int fd, action;
279
Fred Drakeb638aaf2001-05-07 17:55:35 +0000280 if (!PyArg_ParseTuple(args, "O&i:tcflow",
281 fdconv, &fd, &action))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000282 return NULL;
283 if (tcflow(fd, action) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000284 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000285
286 Py_INCREF(Py_None);
287 return Py_None;
288}
289
290static PyMethodDef termios_methods[] =
291{
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000292 {"tcgetattr", termios_tcgetattr,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000293 METH_VARARGS, termios_tcgetattr__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000294 {"tcsetattr", termios_tcsetattr,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000295 METH_VARARGS, termios_tcsetattr__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000296 {"tcsendbreak", termios_tcsendbreak,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000297 METH_VARARGS, termios_tcsendbreak__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000298 {"tcdrain", termios_tcdrain,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000299 METH_VARARGS, termios_tcdrain__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000300 {"tcflush", termios_tcflush,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000301 METH_VARARGS, termios_tcflush__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000302 {"tcflow", termios_tcflow,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000303 METH_VARARGS, termios_tcflow__doc__},
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000304 {NULL, NULL}
305};
306
Fred Drakedf48d142001-02-27 21:22:39 +0000307
Fred Drake9ef7fa82001-03-01 21:54:49 +0000308#if defined(VSWTCH) && !defined(VSWTC)
309#define VSWTC VSWTCH
310#endif
311
312#if defined(VSWTC) && !defined(VSWTCH)
313#define VSWTCH VSWTC
314#endif
315
Fred Drakedf48d142001-02-27 21:22:39 +0000316static struct constant {
317 char *name;
318 long value;
319} termios_constants[] = {
320 /* cfgetospeed(), cfsetospeed() constants */
321 {"B0", B0},
322 {"B50", B50},
323 {"B75", B75},
324 {"B110", B110},
325 {"B134", B134},
326 {"B150", B150},
327 {"B200", B200},
328 {"B300", B300},
329 {"B600", B600},
330 {"B1200", B1200},
331 {"B1800", B1800},
332 {"B2400", B2400},
333 {"B4800", B4800},
334 {"B9600", B9600},
335 {"B19200", B19200},
336 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000337#ifdef B57600
Fred Drakedf48d142001-02-27 21:22:39 +0000338 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000339#endif
340#ifdef B115200
Fred Drakedf48d142001-02-27 21:22:39 +0000341 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000342#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000343#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000344 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000345#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000346#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000347 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000348#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000349
350 /* tcsetattr() constants */
351 {"TCSANOW", TCSANOW},
352 {"TCSADRAIN", TCSADRAIN},
353 {"TCSAFLUSH", TCSAFLUSH},
354
355 /* tcflush() constants */
356 {"TCIFLUSH", TCIFLUSH},
357 {"TCOFLUSH", TCOFLUSH},
358 {"TCIOFLUSH", TCIOFLUSH},
359
360 /* tcflow() constants */
361 {"TCOOFF", TCOOFF},
362 {"TCOON", TCOON},
363 {"TCIOFF", TCIOFF},
364 {"TCION", TCION},
365
366 /* struct termios.c_iflag constants */
367 {"IGNBRK", IGNBRK},
368 {"BRKINT", BRKINT},
369 {"IGNPAR", IGNPAR},
370 {"PARMRK", PARMRK},
371 {"INPCK", INPCK},
372 {"ISTRIP", ISTRIP},
373 {"INLCR", INLCR},
374 {"IGNCR", IGNCR},
375 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000376#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000377 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000378#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000379 {"IXON", IXON},
380 {"IXANY", IXANY},
381 {"IXOFF", IXOFF},
382 {"IMAXBEL", IMAXBEL},
383
384 /* struct termios.c_oflag constants */
385 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000386#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000387 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000388#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000389 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000390#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000391 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000392#endif
393#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000394 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000395#endif
396#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000397 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000398#endif
399#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000400 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000401#endif
402#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000403 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000404#endif
405#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000406 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000407#endif
408#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000409 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000410#endif
411#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000412 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000413#endif
414#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000415 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000416#endif
417#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000418 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000419#endif
420#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000421 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000422#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000423
424 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000425#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000426 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000427#endif
428#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000429 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000430#endif
431#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000432 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000433#endif
434#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000435 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000436#endif
437#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000438 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000439#endif
440#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000441 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000442#endif
443#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000444 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000445#endif
446#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000447 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000448#endif
449#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000450 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000451#endif
452#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000453 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000454#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000455#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000456 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000457#endif
Fred Draked85556c2001-03-03 18:08:52 +0000458#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000459 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000460#endif
461#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000462 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000463#endif
464#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000465 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000466#endif
467#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000468 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000469#endif
470#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000471 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000472#endif
473#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000474 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000475#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000476
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 Drakeabb379e2001-03-01 03:28:08 +0000485#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000486 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000487#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000488#ifdef CRTSCTS
489 {"CRTSCTS", (long)CRTSCTS},
490#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000491
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 Drakeabb379e2001-03-01 03:28:08 +0000501#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000502 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000503#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000504 {"ECHO", ECHO},
505 {"ECHOE", ECHOE},
506 {"ECHOK", ECHOK},
507 {"ECHONL", ECHONL},
508 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000509#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000510 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000511#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000512 {"ECHOKE", ECHOKE},
513 {"FLUSHO", FLUSHO},
514 {"NOFLSH", NOFLSH},
515 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000516#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000517 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000518#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000519 {"IEXTEN", IEXTEN},
520
521 /* indexes into the control chars array returned by tcgetattr() */
522 {"VINTR", VINTR},
523 {"VQUIT", VQUIT},
524 {"VERASE", VERASE},
525 {"VKILL", VKILL},
526 {"VEOF", VEOF},
527 {"VTIME", VTIME},
528 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000529#ifdef VSWTC
530 /* The #defines above ensure that if either is defined, both are,
531 * but both may be omitted by the system headers. ;-( */
Fred Drakedf48d142001-02-27 21:22:39 +0000532 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000533 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000534#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000535 {"VSTART", VSTART},
536 {"VSTOP", VSTOP},
537 {"VSUSP", VSUSP},
538 {"VEOL", VEOL},
Fred Draked0b625d2001-05-22 15:44:15 +0000539#ifdef VREPRINT
Fred Drakedf48d142001-02-27 21:22:39 +0000540 {"VREPRINT", VREPRINT},
Fred Drake87068f12001-05-11 16:14:17 +0000541#endif
Fred Draked0b625d2001-05-22 15:44:15 +0000542#ifdef VDISCARD
Fred Drakedf48d142001-02-27 21:22:39 +0000543 {"VDISCARD", VDISCARD},
Fred Drake87068f12001-05-11 16:14:17 +0000544#endif
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000545#ifdef VWERASE
Fred Drakedf48d142001-02-27 21:22:39 +0000546 {"VWERASE", VWERASE},
Thomas Wouters819bb2c2001-06-11 15:25:16 +0000547#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000548 {"VLNEXT", VLNEXT},
549 {"VEOL2", VEOL2},
550
Fred Drake55a00342001-03-26 17:14:02 +0000551
552#ifdef B460800
553 {"B460800", B460800},
554#endif
555#ifdef CBAUD
556 {"CBAUD", CBAUD},
557#endif
558#ifdef CDEL
559 {"CDEL", CDEL},
560#endif
561#ifdef CDSUSP
562 {"CDSUSP", CDSUSP},
563#endif
564#ifdef CEOF
565 {"CEOF", CEOF},
566#endif
567#ifdef CEOL
568 {"CEOL", CEOL},
569#endif
570#ifdef CEOL2
571 {"CEOL2", CEOL2},
572#endif
573#ifdef CEOT
574 {"CEOT", CEOT},
575#endif
576#ifdef CERASE
577 {"CERASE", CERASE},
578#endif
579#ifdef CESC
580 {"CESC", CESC},
581#endif
582#ifdef CFLUSH
583 {"CFLUSH", CFLUSH},
584#endif
585#ifdef CINTR
586 {"CINTR", CINTR},
587#endif
588#ifdef CKILL
589 {"CKILL", CKILL},
590#endif
591#ifdef CLNEXT
592 {"CLNEXT", CLNEXT},
593#endif
594#ifdef CNUL
595 {"CNUL", CNUL},
596#endif
597#ifdef COMMON
598 {"COMMON", COMMON},
599#endif
600#ifdef CQUIT
601 {"CQUIT", CQUIT},
602#endif
603#ifdef CRPRNT
604 {"CRPRNT", CRPRNT},
605#endif
606#ifdef CSTART
607 {"CSTART", CSTART},
608#endif
609#ifdef CSTOP
610 {"CSTOP", CSTOP},
611#endif
612#ifdef CSUSP
613 {"CSUSP", CSUSP},
614#endif
615#ifdef CSWTCH
616 {"CSWTCH", CSWTCH},
617#endif
618#ifdef CWERASE
619 {"CWERASE", CWERASE},
620#endif
621#ifdef EXTA
622 {"EXTA", EXTA},
623#endif
624#ifdef EXTB
625 {"EXTB", EXTB},
626#endif
627#ifdef FIOASYNC
628 {"FIOASYNC", FIOASYNC},
629#endif
630#ifdef FIOCLEX
631 {"FIOCLEX", FIOCLEX},
632#endif
633#ifdef FIONBIO
634 {"FIONBIO", FIONBIO},
635#endif
636#ifdef FIONCLEX
637 {"FIONCLEX", FIONCLEX},
638#endif
639#ifdef FIONREAD
640 {"FIONREAD", FIONREAD},
641#endif
642#ifdef IBSHIFT
643 {"IBSHIFT", IBSHIFT},
644#endif
645#ifdef INIT_C_CC
646 {"INIT_C_CC", INIT_C_CC},
647#endif
648#ifdef IOCSIZE_MASK
649 {"IOCSIZE_MASK", IOCSIZE_MASK},
650#endif
651#ifdef IOCSIZE_SHIFT
652 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
653#endif
654#ifdef NCC
655 {"NCC", NCC},
656#endif
657#ifdef NCCS
658 {"NCCS", NCCS},
659#endif
660#ifdef NSWTCH
661 {"NSWTCH", NSWTCH},
662#endif
663#ifdef N_MOUSE
664 {"N_MOUSE", N_MOUSE},
665#endif
666#ifdef N_PPP
667 {"N_PPP", N_PPP},
668#endif
669#ifdef N_SLIP
670 {"N_SLIP", N_SLIP},
671#endif
672#ifdef N_STRIP
673 {"N_STRIP", N_STRIP},
674#endif
675#ifdef N_TTY
676 {"N_TTY", N_TTY},
677#endif
678#ifdef TCFLSH
679 {"TCFLSH", TCFLSH},
680#endif
681#ifdef TCGETA
682 {"TCGETA", TCGETA},
683#endif
684#ifdef TCGETS
685 {"TCGETS", TCGETS},
686#endif
687#ifdef TCSBRK
688 {"TCSBRK", TCSBRK},
689#endif
690#ifdef TCSBRKP
691 {"TCSBRKP", TCSBRKP},
692#endif
693#ifdef TCSETA
694 {"TCSETA", TCSETA},
695#endif
696#ifdef TCSETAF
697 {"TCSETAF", TCSETAF},
698#endif
699#ifdef TCSETAW
700 {"TCSETAW", TCSETAW},
701#endif
702#ifdef TCSETS
703 {"TCSETS", TCSETS},
704#endif
705#ifdef TCSETSF
706 {"TCSETSF", TCSETSF},
707#endif
708#ifdef TCSETSW
709 {"TCSETSW", TCSETSW},
710#endif
711#ifdef TCXONC
712 {"TCXONC", TCXONC},
713#endif
714#ifdef TIOCCONS
715 {"TIOCCONS", TIOCCONS},
716#endif
717#ifdef TIOCEXCL
718 {"TIOCEXCL", TIOCEXCL},
719#endif
720#ifdef TIOCGETD
721 {"TIOCGETD", TIOCGETD},
722#endif
723#ifdef TIOCGICOUNT
724 {"TIOCGICOUNT", TIOCGICOUNT},
725#endif
726#ifdef TIOCGLCKTRMIOS
727 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
728#endif
729#ifdef TIOCGPGRP
730 {"TIOCGPGRP", TIOCGPGRP},
731#endif
732#ifdef TIOCGSERIAL
733 {"TIOCGSERIAL", TIOCGSERIAL},
734#endif
735#ifdef TIOCGSOFTCAR
736 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
737#endif
738#ifdef TIOCGWINSZ
739 {"TIOCGWINSZ", TIOCGWINSZ},
740#endif
741#ifdef TIOCINQ
742 {"TIOCINQ", TIOCINQ},
743#endif
744#ifdef TIOCLINUX
745 {"TIOCLINUX", TIOCLINUX},
746#endif
747#ifdef TIOCMBIC
748 {"TIOCMBIC", TIOCMBIC},
749#endif
750#ifdef TIOCMBIS
751 {"TIOCMBIS", TIOCMBIS},
752#endif
753#ifdef TIOCMGET
754 {"TIOCMGET", TIOCMGET},
755#endif
756#ifdef TIOCMIWAIT
757 {"TIOCMIWAIT", TIOCMIWAIT},
758#endif
759#ifdef TIOCMSET
760 {"TIOCMSET", TIOCMSET},
761#endif
762#ifdef TIOCM_CAR
763 {"TIOCM_CAR", TIOCM_CAR},
764#endif
765#ifdef TIOCM_CD
766 {"TIOCM_CD", TIOCM_CD},
767#endif
768#ifdef TIOCM_CTS
769 {"TIOCM_CTS", TIOCM_CTS},
770#endif
771#ifdef TIOCM_DSR
772 {"TIOCM_DSR", TIOCM_DSR},
773#endif
774#ifdef TIOCM_DTR
775 {"TIOCM_DTR", TIOCM_DTR},
776#endif
777#ifdef TIOCM_LE
778 {"TIOCM_LE", TIOCM_LE},
779#endif
780#ifdef TIOCM_RI
781 {"TIOCM_RI", TIOCM_RI},
782#endif
783#ifdef TIOCM_RNG
784 {"TIOCM_RNG", TIOCM_RNG},
785#endif
786#ifdef TIOCM_RTS
787 {"TIOCM_RTS", TIOCM_RTS},
788#endif
789#ifdef TIOCM_SR
790 {"TIOCM_SR", TIOCM_SR},
791#endif
792#ifdef TIOCM_ST
793 {"TIOCM_ST", TIOCM_ST},
794#endif
795#ifdef TIOCNOTTY
796 {"TIOCNOTTY", TIOCNOTTY},
797#endif
798#ifdef TIOCNXCL
799 {"TIOCNXCL", TIOCNXCL},
800#endif
801#ifdef TIOCOUTQ
802 {"TIOCOUTQ", TIOCOUTQ},
803#endif
804#ifdef TIOCPKT
805 {"TIOCPKT", TIOCPKT},
806#endif
807#ifdef TIOCPKT_DATA
808 {"TIOCPKT_DATA", TIOCPKT_DATA},
809#endif
810#ifdef TIOCPKT_DOSTOP
811 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
812#endif
813#ifdef TIOCPKT_FLUSHREAD
814 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
815#endif
816#ifdef TIOCPKT_FLUSHWRITE
817 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
818#endif
819#ifdef TIOCPKT_NOSTOP
820 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
821#endif
822#ifdef TIOCPKT_START
823 {"TIOCPKT_START", TIOCPKT_START},
824#endif
825#ifdef TIOCPKT_STOP
826 {"TIOCPKT_STOP", TIOCPKT_STOP},
827#endif
828#ifdef TIOCSCTTY
829 {"TIOCSCTTY", TIOCSCTTY},
830#endif
831#ifdef TIOCSERCONFIG
832 {"TIOCSERCONFIG", TIOCSERCONFIG},
833#endif
834#ifdef TIOCSERGETLSR
835 {"TIOCSERGETLSR", TIOCSERGETLSR},
836#endif
837#ifdef TIOCSERGETMULTI
838 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
839#endif
840#ifdef TIOCSERGSTRUCT
841 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
842#endif
843#ifdef TIOCSERGWILD
844 {"TIOCSERGWILD", TIOCSERGWILD},
845#endif
846#ifdef TIOCSERSETMULTI
847 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
848#endif
849#ifdef TIOCSERSWILD
850 {"TIOCSERSWILD", TIOCSERSWILD},
851#endif
852#ifdef TIOCSER_TEMT
853 {"TIOCSER_TEMT", TIOCSER_TEMT},
854#endif
855#ifdef TIOCSETD
856 {"TIOCSETD", TIOCSETD},
857#endif
858#ifdef TIOCSLCKTRMIOS
859 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
860#endif
861#ifdef TIOCSPGRP
862 {"TIOCSPGRP", TIOCSPGRP},
863#endif
864#ifdef TIOCSSERIAL
865 {"TIOCSSERIAL", TIOCSSERIAL},
866#endif
867#ifdef TIOCSSOFTCAR
868 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
869#endif
870#ifdef TIOCSTI
871 {"TIOCSTI", TIOCSTI},
872#endif
873#ifdef TIOCSWINSZ
874 {"TIOCSWINSZ", TIOCSWINSZ},
875#endif
876#ifdef TIOCTTYGSTRUCT
877 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
878#endif
879
Fred Drakedf48d142001-02-27 21:22:39 +0000880 /* sentinel */
881 {NULL, 0}
882};
883
884
Guido van Rossum3886bb61998-12-04 18:50:17 +0000885DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000886PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000887{
888 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000889 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000890
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000891 m = Py_InitModule4("termios", termios_methods, termios__doc__,
892 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000893
894 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000895 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000896 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000897
898 while (constant->name != NULL) {
899 PyModule_AddIntConstant(m, constant->name, constant->value);
900 ++constant;
901 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000902}