blob: 9079351c66d4a2a2bcda0de001be080e61a1f214 [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
Fred Drakedf48d142001-02-27 21:22:39 +0000545 {"VWERASE", VWERASE},
546 {"VLNEXT", VLNEXT},
547 {"VEOL2", VEOL2},
548
Fred Drake55a00342001-03-26 17:14:02 +0000549
550#ifdef B460800
551 {"B460800", B460800},
552#endif
553#ifdef CBAUD
554 {"CBAUD", CBAUD},
555#endif
556#ifdef CDEL
557 {"CDEL", CDEL},
558#endif
559#ifdef CDSUSP
560 {"CDSUSP", CDSUSP},
561#endif
562#ifdef CEOF
563 {"CEOF", CEOF},
564#endif
565#ifdef CEOL
566 {"CEOL", CEOL},
567#endif
568#ifdef CEOL2
569 {"CEOL2", CEOL2},
570#endif
571#ifdef CEOT
572 {"CEOT", CEOT},
573#endif
574#ifdef CERASE
575 {"CERASE", CERASE},
576#endif
577#ifdef CESC
578 {"CESC", CESC},
579#endif
580#ifdef CFLUSH
581 {"CFLUSH", CFLUSH},
582#endif
583#ifdef CINTR
584 {"CINTR", CINTR},
585#endif
586#ifdef CKILL
587 {"CKILL", CKILL},
588#endif
589#ifdef CLNEXT
590 {"CLNEXT", CLNEXT},
591#endif
592#ifdef CNUL
593 {"CNUL", CNUL},
594#endif
595#ifdef COMMON
596 {"COMMON", COMMON},
597#endif
598#ifdef CQUIT
599 {"CQUIT", CQUIT},
600#endif
601#ifdef CRPRNT
602 {"CRPRNT", CRPRNT},
603#endif
604#ifdef CSTART
605 {"CSTART", CSTART},
606#endif
607#ifdef CSTOP
608 {"CSTOP", CSTOP},
609#endif
610#ifdef CSUSP
611 {"CSUSP", CSUSP},
612#endif
613#ifdef CSWTCH
614 {"CSWTCH", CSWTCH},
615#endif
616#ifdef CWERASE
617 {"CWERASE", CWERASE},
618#endif
619#ifdef EXTA
620 {"EXTA", EXTA},
621#endif
622#ifdef EXTB
623 {"EXTB", EXTB},
624#endif
625#ifdef FIOASYNC
626 {"FIOASYNC", FIOASYNC},
627#endif
628#ifdef FIOCLEX
629 {"FIOCLEX", FIOCLEX},
630#endif
631#ifdef FIONBIO
632 {"FIONBIO", FIONBIO},
633#endif
634#ifdef FIONCLEX
635 {"FIONCLEX", FIONCLEX},
636#endif
637#ifdef FIONREAD
638 {"FIONREAD", FIONREAD},
639#endif
640#ifdef IBSHIFT
641 {"IBSHIFT", IBSHIFT},
642#endif
643#ifdef INIT_C_CC
644 {"INIT_C_CC", INIT_C_CC},
645#endif
646#ifdef IOCSIZE_MASK
647 {"IOCSIZE_MASK", IOCSIZE_MASK},
648#endif
649#ifdef IOCSIZE_SHIFT
650 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
651#endif
652#ifdef NCC
653 {"NCC", NCC},
654#endif
655#ifdef NCCS
656 {"NCCS", NCCS},
657#endif
658#ifdef NSWTCH
659 {"NSWTCH", NSWTCH},
660#endif
661#ifdef N_MOUSE
662 {"N_MOUSE", N_MOUSE},
663#endif
664#ifdef N_PPP
665 {"N_PPP", N_PPP},
666#endif
667#ifdef N_SLIP
668 {"N_SLIP", N_SLIP},
669#endif
670#ifdef N_STRIP
671 {"N_STRIP", N_STRIP},
672#endif
673#ifdef N_TTY
674 {"N_TTY", N_TTY},
675#endif
676#ifdef TCFLSH
677 {"TCFLSH", TCFLSH},
678#endif
679#ifdef TCGETA
680 {"TCGETA", TCGETA},
681#endif
682#ifdef TCGETS
683 {"TCGETS", TCGETS},
684#endif
685#ifdef TCSBRK
686 {"TCSBRK", TCSBRK},
687#endif
688#ifdef TCSBRKP
689 {"TCSBRKP", TCSBRKP},
690#endif
691#ifdef TCSETA
692 {"TCSETA", TCSETA},
693#endif
694#ifdef TCSETAF
695 {"TCSETAF", TCSETAF},
696#endif
697#ifdef TCSETAW
698 {"TCSETAW", TCSETAW},
699#endif
700#ifdef TCSETS
701 {"TCSETS", TCSETS},
702#endif
703#ifdef TCSETSF
704 {"TCSETSF", TCSETSF},
705#endif
706#ifdef TCSETSW
707 {"TCSETSW", TCSETSW},
708#endif
709#ifdef TCXONC
710 {"TCXONC", TCXONC},
711#endif
712#ifdef TIOCCONS
713 {"TIOCCONS", TIOCCONS},
714#endif
715#ifdef TIOCEXCL
716 {"TIOCEXCL", TIOCEXCL},
717#endif
718#ifdef TIOCGETD
719 {"TIOCGETD", TIOCGETD},
720#endif
721#ifdef TIOCGICOUNT
722 {"TIOCGICOUNT", TIOCGICOUNT},
723#endif
724#ifdef TIOCGLCKTRMIOS
725 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
726#endif
727#ifdef TIOCGPGRP
728 {"TIOCGPGRP", TIOCGPGRP},
729#endif
730#ifdef TIOCGSERIAL
731 {"TIOCGSERIAL", TIOCGSERIAL},
732#endif
733#ifdef TIOCGSOFTCAR
734 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
735#endif
736#ifdef TIOCGWINSZ
737 {"TIOCGWINSZ", TIOCGWINSZ},
738#endif
739#ifdef TIOCINQ
740 {"TIOCINQ", TIOCINQ},
741#endif
742#ifdef TIOCLINUX
743 {"TIOCLINUX", TIOCLINUX},
744#endif
745#ifdef TIOCMBIC
746 {"TIOCMBIC", TIOCMBIC},
747#endif
748#ifdef TIOCMBIS
749 {"TIOCMBIS", TIOCMBIS},
750#endif
751#ifdef TIOCMGET
752 {"TIOCMGET", TIOCMGET},
753#endif
754#ifdef TIOCMIWAIT
755 {"TIOCMIWAIT", TIOCMIWAIT},
756#endif
757#ifdef TIOCMSET
758 {"TIOCMSET", TIOCMSET},
759#endif
760#ifdef TIOCM_CAR
761 {"TIOCM_CAR", TIOCM_CAR},
762#endif
763#ifdef TIOCM_CD
764 {"TIOCM_CD", TIOCM_CD},
765#endif
766#ifdef TIOCM_CTS
767 {"TIOCM_CTS", TIOCM_CTS},
768#endif
769#ifdef TIOCM_DSR
770 {"TIOCM_DSR", TIOCM_DSR},
771#endif
772#ifdef TIOCM_DTR
773 {"TIOCM_DTR", TIOCM_DTR},
774#endif
775#ifdef TIOCM_LE
776 {"TIOCM_LE", TIOCM_LE},
777#endif
778#ifdef TIOCM_RI
779 {"TIOCM_RI", TIOCM_RI},
780#endif
781#ifdef TIOCM_RNG
782 {"TIOCM_RNG", TIOCM_RNG},
783#endif
784#ifdef TIOCM_RTS
785 {"TIOCM_RTS", TIOCM_RTS},
786#endif
787#ifdef TIOCM_SR
788 {"TIOCM_SR", TIOCM_SR},
789#endif
790#ifdef TIOCM_ST
791 {"TIOCM_ST", TIOCM_ST},
792#endif
793#ifdef TIOCNOTTY
794 {"TIOCNOTTY", TIOCNOTTY},
795#endif
796#ifdef TIOCNXCL
797 {"TIOCNXCL", TIOCNXCL},
798#endif
799#ifdef TIOCOUTQ
800 {"TIOCOUTQ", TIOCOUTQ},
801#endif
802#ifdef TIOCPKT
803 {"TIOCPKT", TIOCPKT},
804#endif
805#ifdef TIOCPKT_DATA
806 {"TIOCPKT_DATA", TIOCPKT_DATA},
807#endif
808#ifdef TIOCPKT_DOSTOP
809 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
810#endif
811#ifdef TIOCPKT_FLUSHREAD
812 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
813#endif
814#ifdef TIOCPKT_FLUSHWRITE
815 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
816#endif
817#ifdef TIOCPKT_NOSTOP
818 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
819#endif
820#ifdef TIOCPKT_START
821 {"TIOCPKT_START", TIOCPKT_START},
822#endif
823#ifdef TIOCPKT_STOP
824 {"TIOCPKT_STOP", TIOCPKT_STOP},
825#endif
826#ifdef TIOCSCTTY
827 {"TIOCSCTTY", TIOCSCTTY},
828#endif
829#ifdef TIOCSERCONFIG
830 {"TIOCSERCONFIG", TIOCSERCONFIG},
831#endif
832#ifdef TIOCSERGETLSR
833 {"TIOCSERGETLSR", TIOCSERGETLSR},
834#endif
835#ifdef TIOCSERGETMULTI
836 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
837#endif
838#ifdef TIOCSERGSTRUCT
839 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
840#endif
841#ifdef TIOCSERGWILD
842 {"TIOCSERGWILD", TIOCSERGWILD},
843#endif
844#ifdef TIOCSERSETMULTI
845 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
846#endif
847#ifdef TIOCSERSWILD
848 {"TIOCSERSWILD", TIOCSERSWILD},
849#endif
850#ifdef TIOCSER_TEMT
851 {"TIOCSER_TEMT", TIOCSER_TEMT},
852#endif
853#ifdef TIOCSETD
854 {"TIOCSETD", TIOCSETD},
855#endif
856#ifdef TIOCSLCKTRMIOS
857 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
858#endif
859#ifdef TIOCSPGRP
860 {"TIOCSPGRP", TIOCSPGRP},
861#endif
862#ifdef TIOCSSERIAL
863 {"TIOCSSERIAL", TIOCSSERIAL},
864#endif
865#ifdef TIOCSSOFTCAR
866 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
867#endif
868#ifdef TIOCSTI
869 {"TIOCSTI", TIOCSTI},
870#endif
871#ifdef TIOCSWINSZ
872 {"TIOCSWINSZ", TIOCSWINSZ},
873#endif
874#ifdef TIOCTTYGSTRUCT
875 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
876#endif
877
Fred Drakedf48d142001-02-27 21:22:39 +0000878 /* sentinel */
879 {NULL, 0}
880};
881
882
Guido van Rossum3886bb61998-12-04 18:50:17 +0000883DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000884PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000885{
886 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000887 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000888
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000889 m = Py_InitModule4("termios", termios_methods, termios__doc__,
890 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000891
892 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000893 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000894 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000895
896 while (constant->name != NULL) {
897 PyModule_AddIntConstant(m, constant->name, constant->value);
898 ++constant;
899 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000900}