blob: cedcb0ff35636438d8a417c12dd16423c81e0b4e [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 Drakeb638aaf2001-05-07 17:55:35 +000019static char termios__doc__[] = "\
20This module provides an interface to the Posix calls for tty I/O control.\n\
21For a complete description of these calls, see the Posix or Unix manual\n\
22pages. It is only available for those Unix versions that support Posix\n\
23termios style tty I/O control.\n\
24\n\
25All functions in this module take a file descriptor fd as their first\n\
26argument. This can be an integer file descriptor, such as returned by\n\
27sys.stdin.fileno(), or a file object, such as sys.stdin itself.";
Guido van Rossum9adae8e1994-09-12 10:41:22 +000028
29static PyObject *TermiosError;
30
Fred Drakeb638aaf2001-05-07 17:55:35 +000031static char* fname;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000032
Fred Drakeb638aaf2001-05-07 17:55:35 +000033static 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 Rossum9adae8e1994-09-12 10:41:22 +000063
Guido van Rossum1aca4d81998-03-03 22:10:18 +000064static char termios_tcgetattr__doc__[] = "\
65tcgetattr(fd) -> list_of_attrs\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +000066\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +000067Get the tty attributes for file descriptor fd, as follows:\n\
68[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
69of the tty special characters (each a string of length 1, except the items\n\
70with indices VMIN and VTIME, which are integers when these fields are\n\
71defined). The interpretation of the flags and the speeds as well as the\n\
72indexing in the cc array must be done using the symbolic constants defined\n\
Fred Drake29fd0312001-04-09 19:32:52 +000073in this module.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +000074
Guido van Rossum9adae8e1994-09-12 10:41:22 +000075static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000076termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000077{
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 Drakeb638aaf2001-05-07 17:55:35 +000086 fname = "tcgetattr";
87
88 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
89 fdconv, (void*)&fd))
Guido van Rossum9adae8e1994-09-12 10:41:22 +000090 return NULL;
91
92 if (tcgetattr(fd, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +000093 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000094
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 Warsaw5709dcf1997-01-10 18:42:18 +0000105 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000106 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 Rossum36dd0d21996-12-10 15:23:00 +0000112 if ((mode.c_lflag & ICANON) == 0) {
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000113 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
114 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000115 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000116 PyList_SetItem(cc, VMIN, v);
117 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
118 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000119 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000120 PyList_SetItem(cc, VTIME, v);
121 }
122
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000123 if (!(v = PyList_New(7)))
124 goto err;
125
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000126 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 Warsaw5709dcf1997-01-10 18:42:18 +0000133 if (PyErr_Occurred()){
134 Py_DECREF(v);
135 goto err;
136 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000137 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000138 err:
139 Py_DECREF(cc);
140 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000141}
142
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000143static char termios_tcsetattr__doc__[] = "\
144tcsetattr(fd, when, attributes) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000145\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000146Set the tty attributes for file descriptor fd.\n\
147The attributes to be set are taken from the attributes argument, which\n\
148is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000149determines when the attributes are changed: termios.TCSANOW to\n\
150change immediately, termios.TCSADRAIN to change after transmitting all\n\
151queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000152queued output and discarding all queued input. ";
153
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000154static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000155termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000156{
157 int fd, when;
158 struct termios mode;
159 speed_t ispeed, ospeed;
160 PyObject *term, *cc, *v;
161 int i;
162
Fred Drakeb638aaf2001-05-07 17:55:35 +0000163 fname = "tcsetattr";
164
165 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
166 fdconv, &fd, &when, &term))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000167 return NULL;
168 if (!PyList_Check(term) || PyList_Size(term) != 7) {
Fred Drakeb638aaf2001-05-07 17:55:35 +0000169 PyErr_SetString(PyExc_TypeError,
170 "tcsetattr, arg 3: must be 7 element list");
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000171 return NULL;
172 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000173
Guido van Rossume7c41931998-06-12 14:26:18 +0000174 /* Get the old mode, in case there are any hidden fields... */
175 if (tcgetattr(fd, &mode) == -1)
176 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000177 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 Warsaw5709dcf1997-01-10 18:42:18 +0000184 if (PyErr_Occurred())
185 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000186
187 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
Fred Drakeb638aaf2001-05-07 17:55:35 +0000188 PyErr_Format(PyExc_TypeError,
189 "tcsetattr: attributes[6] must be %d element list",
190 NCCS);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000191 return NULL;
192 }
193
194 for (i = 0; i < NCCS; i++) {
195 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000196
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000197 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 Drakeb638aaf2001-05-07 17:55:35 +0000202 PyErr_SetString(PyExc_TypeError,
203 "tcsetattr: elements of attributes must be characters or integers");
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000204 return NULL;
205 }
206 }
207
208 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000209 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000210 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000211 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000212 if (tcsetattr(fd, when, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000213 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000214
215 Py_INCREF(Py_None);
216 return Py_None;
217}
218
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000219static char termios_tcsendbreak__doc__[] = "\
220tcsendbreak(fd, duration) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000221\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000222Send a break on file descriptor fd.\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000223A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
224has a system dependent meaning.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000225
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000226static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000227termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000228{
229 int fd, duration;
230
Fred Drakeb638aaf2001-05-07 17:55:35 +0000231 fname = "tcsendbreak";
232
233 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
234 fdconv, &fd, &duration))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000235 return NULL;
236 if (tcsendbreak(fd, duration) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000237 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000238
239 Py_INCREF(Py_None);
240 return Py_None;
241}
242
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000243static char termios_tcdrain__doc__[] = "\
244tcdrain(fd) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000245\n\
246Wait until all output written to file descriptor fd has been transmitted.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000247
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000248static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000249termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000250{
251 int fd;
252
Fred Drakeb638aaf2001-05-07 17:55:35 +0000253 fname = "tcdrain";
254
255 if (!PyArg_ParseTuple(args, "O&:tcdrain",
256 fdconv, &fd))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000257 return NULL;
258 if (tcdrain(fd) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000259 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000260
261 Py_INCREF(Py_None);
262 return Py_None;
263}
264
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000265static char termios_tcflush__doc__[] = "\
266tcflush(fd, queue) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000267\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000268Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000269The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
270queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000271both queues. ";
272
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000273static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000274termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000275{
276 int fd, queue;
277
Fred Drakeb638aaf2001-05-07 17:55:35 +0000278 fname = "tcflush";
279
280 if (!PyArg_ParseTuple(args, "O&i:tcflush",
281 fdconv, &fd, &queue))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000282 return NULL;
283 if (tcflush(fd, queue) == -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
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000290static char termios_tcflow__doc__[] = "\
291tcflow(fd, action) -> None\n\
Fred Drakeb638aaf2001-05-07 17:55:35 +0000292\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000293Suspend or resume input or output on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000294The action argument can be termios.TCOOFF to suspend output,\n\
295termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
296or termios.TCION to restart input.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000297
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000298static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000299termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000300{
301 int fd, action;
302
Fred Drakeb638aaf2001-05-07 17:55:35 +0000303 fname = "tcflow";
304
305 if (!PyArg_ParseTuple(args, "O&i:tcflow",
306 fdconv, &fd, &action))
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000307 return NULL;
308 if (tcflow(fd, action) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000309 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000310
311 Py_INCREF(Py_None);
312 return Py_None;
313}
314
315static PyMethodDef termios_methods[] =
316{
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000317 {"tcgetattr", termios_tcgetattr,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000318 METH_VARARGS, termios_tcgetattr__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000319 {"tcsetattr", termios_tcsetattr,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000320 METH_VARARGS, termios_tcsetattr__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000321 {"tcsendbreak", termios_tcsendbreak,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000322 METH_VARARGS, termios_tcsendbreak__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000323 {"tcdrain", termios_tcdrain,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000324 METH_VARARGS, termios_tcdrain__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000325 {"tcflush", termios_tcflush,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000326 METH_VARARGS, termios_tcflush__doc__},
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000327 {"tcflow", termios_tcflow,
Fred Drakeb638aaf2001-05-07 17:55:35 +0000328 METH_VARARGS, termios_tcflow__doc__},
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000329 {NULL, NULL}
330};
331
Fred Drakedf48d142001-02-27 21:22:39 +0000332
Fred Drake9ef7fa82001-03-01 21:54:49 +0000333#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 Drakedf48d142001-02-27 21:22:39 +0000341static 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 Rossum2242f2f2001-04-11 20:58:20 +0000362#ifdef B57600
Fred Drakedf48d142001-02-27 21:22:39 +0000363 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000364#endif
365#ifdef B115200
Fred Drakedf48d142001-02-27 21:22:39 +0000366 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000367#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000368#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000369 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000370#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000371#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000372 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000373#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000374
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 Draked85556c2001-03-03 18:08:52 +0000401#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000402 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000403#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000404 {"IXON", IXON},
405 {"IXANY", IXANY},
406 {"IXOFF", IXOFF},
407 {"IMAXBEL", IMAXBEL},
408
409 /* struct termios.c_oflag constants */
410 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000411#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000412 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000413#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000414 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000415#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000416 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000417#endif
418#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000419 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000420#endif
421#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000422 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000423#endif
424#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000425 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000426#endif
427#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000428 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000429#endif
430#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000431 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000432#endif
433#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000434 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000435#endif
436#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000437 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000438#endif
439#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000440 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000441#endif
442#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000443 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000444#endif
445#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000446 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000447#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000448
449 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000450#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000451 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000452#endif
453#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000454 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000455#endif
456#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000457 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000458#endif
459#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000460 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000461#endif
462#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000463 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000464#endif
465#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000466 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000467#endif
468#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000469 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000470#endif
471#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000472 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000473#endif
474#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000475 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000476#endif
477#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000478 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000479#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000480#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000481 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000482#endif
Fred Draked85556c2001-03-03 18:08:52 +0000483#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000484 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000485#endif
486#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000487 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000488#endif
489#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000490 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000491#endif
492#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000493 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000494#endif
495#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000496 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000497#endif
498#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000499 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000500#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000501
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 Drakeabb379e2001-03-01 03:28:08 +0000510#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000511 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000512#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000513#ifdef CRTSCTS
514 {"CRTSCTS", (long)CRTSCTS},
515#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000516
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 Drakeabb379e2001-03-01 03:28:08 +0000526#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000527 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000528#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000529 {"ECHO", ECHO},
530 {"ECHOE", ECHOE},
531 {"ECHOK", ECHOK},
532 {"ECHONL", ECHONL},
533 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000534#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000535 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000536#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000537 {"ECHOKE", ECHOKE},
538 {"FLUSHO", FLUSHO},
539 {"NOFLSH", NOFLSH},
540 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000541#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000542 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000543#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000544 {"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 Drakededbebf2001-03-02 06:50:58 +0000554#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 Drakedf48d142001-02-27 21:22:39 +0000557 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000558 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000559#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000560 {"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 Drake55a00342001-03-26 17:14:02 +0000570
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 Drakedf48d142001-02-27 21:22:39 +0000899 /* sentinel */
900 {NULL, 0}
901};
902
903
Guido van Rossum3886bb61998-12-04 18:50:17 +0000904DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000905PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000906{
907 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000908 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000909
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000910 m = Py_InitModule4("termios", termios_methods, termios__doc__,
911 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000912
913 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000914 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000915 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000916
917 while (constant->name != NULL) {
918 PyModule_AddIntConstant(m, constant->name, constant->value);
919 ++constant;
920 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000921}