blob: 054d25993708fc702530e98eb585518f03fb2d53 [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>
8
Guido van Rossum1aca4d81998-03-03 22:10:18 +00009static char termios__doc__[] = "\
10This module provides an interface to the Posix calls for tty I/O control.\n\
11For a complete description of these calls, see the Posix or Unix manual\n\
12pages. It is only available for those Unix versions that support Posix\n\
13termios style tty I/O control (and then only if configured at installation\n\
14time).\n\
15\n\
16All functions in this module take a file descriptor fd as their first\n\
17argument. This must be an integer file descriptor, such as returned by\n\
18sys.stdin.fileno().\n\
19\n\
20This module should be used in conjunction with the TERMIOS module,\n\
21which defines the relevant symbolic constants.";
22
23
Guido van Rossumbcc20741998-08-04 22:53:56 +000024#ifdef __BEOS__
25#include <unistd.h>
26#endif
27
Guido van Rossum9adae8e1994-09-12 10:41:22 +000028#define BAD "bad termios argument"
29
30static PyObject *TermiosError;
31
32/* termios = tcgetattr(fd)
33 termios is
34 [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]]
35
36 Return the attributes of the terminal device. */
37
Guido van Rossum1aca4d81998-03-03 22:10:18 +000038static char termios_tcgetattr__doc__[] = "\
39tcgetattr(fd) -> list_of_attrs\n\
40Get the tty attributes for file descriptor fd, as follows:\n\
41[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
42of the tty special characters (each a string of length 1, except the items\n\
43with indices VMIN and VTIME, which are integers when these fields are\n\
44defined). The interpretation of the flags and the speeds as well as the\n\
45indexing in the cc array must be done using the symbolic constants defined\n\
46in the TERMIOS module.";
47
Guido van Rossum9adae8e1994-09-12 10:41:22 +000048static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000049termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000050{
51 int fd;
52 struct termios mode;
53 PyObject *cc;
54 speed_t ispeed, ospeed;
55 PyObject *v;
56 int i;
57 char ch;
58
59 if (!PyArg_Parse(args, "i", &fd))
60 return NULL;
61
62 if (tcgetattr(fd, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +000063 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000064
65 ispeed = cfgetispeed(&mode);
66 ospeed = cfgetospeed(&mode);
67
68 cc = PyList_New(NCCS);
69 if (cc == NULL)
70 return NULL;
71 for (i = 0; i < NCCS; i++) {
72 ch = (char)mode.c_cc[i];
73 v = PyString_FromStringAndSize(&ch, 1);
74 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000075 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000076 PyList_SetItem(cc, i, v);
77 }
78
79 /* Convert the MIN and TIME slots to integer. On some systems, the
80 MIN and TIME slots are the same as the EOF and EOL slots. So we
81 only do this in noncanonical input mode. */
Guido van Rossum36dd0d21996-12-10 15:23:00 +000082 if ((mode.c_lflag & ICANON) == 0) {
Guido van Rossum9adae8e1994-09-12 10:41:22 +000083 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
84 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000085 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000086 PyList_SetItem(cc, VMIN, v);
87 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
88 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000089 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000090 PyList_SetItem(cc, VTIME, v);
91 }
92
Barry Warsaw5709dcf1997-01-10 18:42:18 +000093 if (!(v = PyList_New(7)))
94 goto err;
95
Guido van Rossum9adae8e1994-09-12 10:41:22 +000096 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
97 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
98 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
99 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
100 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
101 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
102 PyList_SetItem(v, 6, cc);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000103 if (PyErr_Occurred()){
104 Py_DECREF(v);
105 goto err;
106 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000107 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000108 err:
109 Py_DECREF(cc);
110 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000111}
112
113/* tcsetattr(fd, when, termios)
114 Set the attributes of the terminal device. */
115
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000116static char termios_tcsetattr__doc__[] = "\
117tcsetattr(fd, when, attributes) -> None\n\
118Set the tty attributes for file descriptor fd.\n\
119The attributes to be set are taken from the attributes argument, which\n\
120is a list like the one returned by tcgetattr(). The when argument\n\
121determines when the attributes are changed: TERMIOS.TCSANOW to\n\
122change immediately, TERMIOS.TCSADRAIN to change after transmitting all\n\
123queued output, or TERMIOS.TCSAFLUSH to change after transmitting all\n\
124queued output and discarding all queued input. ";
125
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000126static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000127termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000128{
129 int fd, when;
130 struct termios mode;
131 speed_t ispeed, ospeed;
132 PyObject *term, *cc, *v;
133 int i;
134
135 if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
136 return NULL;
137 if (!PyList_Check(term) || PyList_Size(term) != 7) {
138 PyErr_SetString(PyExc_TypeError, BAD);
139 return NULL;
140 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000141
Guido van Rossume7c41931998-06-12 14:26:18 +0000142 /* Get the old mode, in case there are any hidden fields... */
143 if (tcgetattr(fd, &mode) == -1)
144 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000145 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
146 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
147 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
148 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
149 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
150 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
151 cc = PyList_GetItem(term, 6);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000152 if (PyErr_Occurred())
153 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000154
155 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
156 PyErr_SetString(PyExc_TypeError, BAD);
157 return NULL;
158 }
159
160 for (i = 0; i < NCCS; i++) {
161 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000162
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000163 if (PyString_Check(v) && PyString_Size(v) == 1)
164 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
165 else if (PyInt_Check(v))
166 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
167 else {
168 PyErr_SetString(PyExc_TypeError, BAD);
169 return NULL;
170 }
171 }
172
173 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000174 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000175 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000176 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000177 if (tcsetattr(fd, when, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000178 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000179
180 Py_INCREF(Py_None);
181 return Py_None;
182}
183
184/* tcsendbreak(fd, duration)
185 Generate a break condition. */
186
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000187static char termios_tcsendbreak__doc__[] = "\
188tcsendbreak(fd, duration) -> None\n\
189Send a break on file descriptor fd.\n\
190A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
191has a system dependent meaning. ";
192
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000193static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000194termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000195{
196 int fd, duration;
197
198 if (!PyArg_Parse(args, "(ii)", &fd, &duration))
199 return NULL;
200 if (tcsendbreak(fd, duration) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000201 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000202
203 Py_INCREF(Py_None);
204 return Py_None;
205}
206
207/* tcdrain(fd)
208 Wait until all queued output to the terminal has been
209 transmitted. */
210
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000211static char termios_tcdrain__doc__[] = "\
212tcdrain(fd) -> None\n\
213Wait until all output written to file descriptor fd has been transmitted. ";
214
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000215static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000216termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000217{
218 int fd;
219
220 if (!PyArg_Parse(args, "i", &fd))
221 return NULL;
222 if (tcdrain(fd) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000223 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000224
225 Py_INCREF(Py_None);
226 return Py_None;
227}
228
229/* tcflush(fd, queue)
230 Clear the input and/or output queues associated with
231 the terminal. */
232
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000233static char termios_tcflush__doc__[] = "\
234tcflush(fd, queue) -> None\n\
235Discard queued data on file descriptor fd.\n\
236The queue selector specifies which queue: TERMIOS.TCIFLUSH for the input\n\
237queue, TERMIOS.TCOFLUSH for the output queue, or TERMIOS.TCIOFLUSH for\n\
238both queues. ";
239
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000240static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000241termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000242{
243 int fd, queue;
244
245 if (!PyArg_Parse(args, "(ii)", &fd, &queue))
246 return NULL;
247 if (tcflush(fd, queue) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000248 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000249
250 Py_INCREF(Py_None);
251 return Py_None;
252}
253
254/* tcflow(fd, action)
255 Perform operations relating to XON/XOFF flow control on
256 the terminal. */
257
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000258static char termios_tcflow__doc__[] = "\
259tcflow(fd, action) -> None\n\
260Suspend or resume input or output on file descriptor fd.\n\
261The action argument can be TERMIOS.TCOOFF to suspend output,\n\
262TERMIOS.TCOON to restart output, TERMIOS.TCIOFF to suspend input,\n\
263or TERMIOS.TCION to restart input. ";
264
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000265static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000266termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000267{
268 int fd, action;
269
270 if (!PyArg_Parse(args, "(ii)", &fd, &action))
271 return NULL;
272 if (tcflow(fd, action) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000273 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000274
275 Py_INCREF(Py_None);
276 return Py_None;
277}
278
279static PyMethodDef termios_methods[] =
280{
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000281 {"tcgetattr", termios_tcgetattr,
282 METH_OLDARGS, termios_tcgetattr__doc__},
283 {"tcsetattr", termios_tcsetattr,
284 METH_OLDARGS, termios_tcsetattr__doc__},
285 {"tcsendbreak", termios_tcsendbreak,
286 METH_OLDARGS, termios_tcsendbreak__doc__},
287 {"tcdrain", termios_tcdrain,
288 METH_OLDARGS, termios_tcdrain__doc__},
289 {"tcflush", termios_tcflush,
290 METH_OLDARGS, termios_tcflush__doc__},
291 {"tcflow", termios_tcflow,
292 METH_OLDARGS, termios_tcflow__doc__},
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000293 {NULL, NULL}
294};
295
Fred Drakedf48d142001-02-27 21:22:39 +0000296
Fred Drake9ef7fa82001-03-01 21:54:49 +0000297#if defined(VSWTCH) && !defined(VSWTC)
298#define VSWTC VSWTCH
299#endif
300
301#if defined(VSWTC) && !defined(VSWTCH)
302#define VSWTCH VSWTC
303#endif
304
Fred Drakedf48d142001-02-27 21:22:39 +0000305static struct constant {
306 char *name;
307 long value;
308} termios_constants[] = {
309 /* cfgetospeed(), cfsetospeed() constants */
310 {"B0", B0},
311 {"B50", B50},
312 {"B75", B75},
313 {"B110", B110},
314 {"B134", B134},
315 {"B150", B150},
316 {"B200", B200},
317 {"B300", B300},
318 {"B600", B600},
319 {"B1200", B1200},
320 {"B1800", B1800},
321 {"B2400", B2400},
322 {"B4800", B4800},
323 {"B9600", B9600},
324 {"B19200", B19200},
325 {"B38400", B38400},
326 {"B57600", B57600},
327 {"B115200", B115200},
Fred Drakeabb379e2001-03-01 03:28:08 +0000328#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000329 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000330#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000331#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000332 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000333#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000334
335 /* tcsetattr() constants */
336 {"TCSANOW", TCSANOW},
337 {"TCSADRAIN", TCSADRAIN},
338 {"TCSAFLUSH", TCSAFLUSH},
339
340 /* tcflush() constants */
341 {"TCIFLUSH", TCIFLUSH},
342 {"TCOFLUSH", TCOFLUSH},
343 {"TCIOFLUSH", TCIOFLUSH},
344
345 /* tcflow() constants */
346 {"TCOOFF", TCOOFF},
347 {"TCOON", TCOON},
348 {"TCIOFF", TCIOFF},
349 {"TCION", TCION},
350
351 /* struct termios.c_iflag constants */
352 {"IGNBRK", IGNBRK},
353 {"BRKINT", BRKINT},
354 {"IGNPAR", IGNPAR},
355 {"PARMRK", PARMRK},
356 {"INPCK", INPCK},
357 {"ISTRIP", ISTRIP},
358 {"INLCR", INLCR},
359 {"IGNCR", IGNCR},
360 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000361#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000362 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000363#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000364 {"IXON", IXON},
365 {"IXANY", IXANY},
366 {"IXOFF", IXOFF},
367 {"IMAXBEL", IMAXBEL},
368
369 /* struct termios.c_oflag constants */
370 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000371#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000372 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000373#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000374 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000375#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000376 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000377#endif
378#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000379 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000380#endif
381#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000382 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000383#endif
384#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000385 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000386#endif
387#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000388 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000389#endif
390#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000391 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000392#endif
393#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000394 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000395#endif
396#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000397 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000398#endif
399#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000400 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000401#endif
402#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000403 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000404#endif
405#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000406 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000407#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000408
409 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000410#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000411 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000412#endif
413#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000414 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000415#endif
416#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000417 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000418#endif
419#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000420 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000421#endif
422#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000423 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000424#endif
425#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000426 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000427#endif
428#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000429 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000430#endif
431#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000432 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000433#endif
434#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000435 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000436#endif
437#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000438 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000439#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000440#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000441 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000442#endif
Fred Draked85556c2001-03-03 18:08:52 +0000443#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000444 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000445#endif
446#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000447 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000448#endif
449#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000450 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000451#endif
452#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000453 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000454#endif
455#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000456 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000457#endif
458#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000459 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000460#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000461
462 /* struct termios.c_cflag constants */
463 {"CSIZE", CSIZE},
464 {"CSTOPB", CSTOPB},
465 {"CREAD", CREAD},
466 {"PARENB", PARENB},
467 {"PARODD", PARODD},
468 {"HUPCL", HUPCL},
469 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000470#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000471 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000472#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000473#ifdef CRTSCTS
474 {"CRTSCTS", (long)CRTSCTS},
475#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000476
477 /* struct termios.c_cflag-related values (character size) */
478 {"CS5", CS5},
479 {"CS6", CS6},
480 {"CS7", CS7},
481 {"CS8", CS8},
482
483 /* struct termios.c_lflag constants */
484 {"ISIG", ISIG},
485 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000486#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000487 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000488#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000489 {"ECHO", ECHO},
490 {"ECHOE", ECHOE},
491 {"ECHOK", ECHOK},
492 {"ECHONL", ECHONL},
493 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000494#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000495 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000496#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000497 {"ECHOKE", ECHOKE},
498 {"FLUSHO", FLUSHO},
499 {"NOFLSH", NOFLSH},
500 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000501#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000502 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000503#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000504 {"IEXTEN", IEXTEN},
505
506 /* indexes into the control chars array returned by tcgetattr() */
507 {"VINTR", VINTR},
508 {"VQUIT", VQUIT},
509 {"VERASE", VERASE},
510 {"VKILL", VKILL},
511 {"VEOF", VEOF},
512 {"VTIME", VTIME},
513 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000514#ifdef VSWTC
515 /* The #defines above ensure that if either is defined, both are,
516 * but both may be omitted by the system headers. ;-( */
Fred Drakedf48d142001-02-27 21:22:39 +0000517 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000518 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000519#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000520 {"VSTART", VSTART},
521 {"VSTOP", VSTOP},
522 {"VSUSP", VSUSP},
523 {"VEOL", VEOL},
524 {"VREPRINT", VREPRINT},
525 {"VDISCARD", VDISCARD},
526 {"VWERASE", VWERASE},
527 {"VLNEXT", VLNEXT},
528 {"VEOL2", VEOL2},
529
Fred Drake55a00342001-03-26 17:14:02 +0000530
531#ifdef B460800
532 {"B460800", B460800},
533#endif
534#ifdef CBAUD
535 {"CBAUD", CBAUD},
536#endif
537#ifdef CDEL
538 {"CDEL", CDEL},
539#endif
540#ifdef CDSUSP
541 {"CDSUSP", CDSUSP},
542#endif
543#ifdef CEOF
544 {"CEOF", CEOF},
545#endif
546#ifdef CEOL
547 {"CEOL", CEOL},
548#endif
549#ifdef CEOL2
550 {"CEOL2", CEOL2},
551#endif
552#ifdef CEOT
553 {"CEOT", CEOT},
554#endif
555#ifdef CERASE
556 {"CERASE", CERASE},
557#endif
558#ifdef CESC
559 {"CESC", CESC},
560#endif
561#ifdef CFLUSH
562 {"CFLUSH", CFLUSH},
563#endif
564#ifdef CINTR
565 {"CINTR", CINTR},
566#endif
567#ifdef CKILL
568 {"CKILL", CKILL},
569#endif
570#ifdef CLNEXT
571 {"CLNEXT", CLNEXT},
572#endif
573#ifdef CNUL
574 {"CNUL", CNUL},
575#endif
576#ifdef COMMON
577 {"COMMON", COMMON},
578#endif
579#ifdef CQUIT
580 {"CQUIT", CQUIT},
581#endif
582#ifdef CRPRNT
583 {"CRPRNT", CRPRNT},
584#endif
585#ifdef CSTART
586 {"CSTART", CSTART},
587#endif
588#ifdef CSTOP
589 {"CSTOP", CSTOP},
590#endif
591#ifdef CSUSP
592 {"CSUSP", CSUSP},
593#endif
594#ifdef CSWTCH
595 {"CSWTCH", CSWTCH},
596#endif
597#ifdef CWERASE
598 {"CWERASE", CWERASE},
599#endif
600#ifdef EXTA
601 {"EXTA", EXTA},
602#endif
603#ifdef EXTB
604 {"EXTB", EXTB},
605#endif
606#ifdef FIOASYNC
607 {"FIOASYNC", FIOASYNC},
608#endif
609#ifdef FIOCLEX
610 {"FIOCLEX", FIOCLEX},
611#endif
612#ifdef FIONBIO
613 {"FIONBIO", FIONBIO},
614#endif
615#ifdef FIONCLEX
616 {"FIONCLEX", FIONCLEX},
617#endif
618#ifdef FIONREAD
619 {"FIONREAD", FIONREAD},
620#endif
621#ifdef IBSHIFT
622 {"IBSHIFT", IBSHIFT},
623#endif
624#ifdef INIT_C_CC
625 {"INIT_C_CC", INIT_C_CC},
626#endif
627#ifdef IOCSIZE_MASK
628 {"IOCSIZE_MASK", IOCSIZE_MASK},
629#endif
630#ifdef IOCSIZE_SHIFT
631 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
632#endif
633#ifdef NCC
634 {"NCC", NCC},
635#endif
636#ifdef NCCS
637 {"NCCS", NCCS},
638#endif
639#ifdef NSWTCH
640 {"NSWTCH", NSWTCH},
641#endif
642#ifdef N_MOUSE
643 {"N_MOUSE", N_MOUSE},
644#endif
645#ifdef N_PPP
646 {"N_PPP", N_PPP},
647#endif
648#ifdef N_SLIP
649 {"N_SLIP", N_SLIP},
650#endif
651#ifdef N_STRIP
652 {"N_STRIP", N_STRIP},
653#endif
654#ifdef N_TTY
655 {"N_TTY", N_TTY},
656#endif
657#ifdef TCFLSH
658 {"TCFLSH", TCFLSH},
659#endif
660#ifdef TCGETA
661 {"TCGETA", TCGETA},
662#endif
663#ifdef TCGETS
664 {"TCGETS", TCGETS},
665#endif
666#ifdef TCSBRK
667 {"TCSBRK", TCSBRK},
668#endif
669#ifdef TCSBRKP
670 {"TCSBRKP", TCSBRKP},
671#endif
672#ifdef TCSETA
673 {"TCSETA", TCSETA},
674#endif
675#ifdef TCSETAF
676 {"TCSETAF", TCSETAF},
677#endif
678#ifdef TCSETAW
679 {"TCSETAW", TCSETAW},
680#endif
681#ifdef TCSETS
682 {"TCSETS", TCSETS},
683#endif
684#ifdef TCSETSF
685 {"TCSETSF", TCSETSF},
686#endif
687#ifdef TCSETSW
688 {"TCSETSW", TCSETSW},
689#endif
690#ifdef TCXONC
691 {"TCXONC", TCXONC},
692#endif
693#ifdef TIOCCONS
694 {"TIOCCONS", TIOCCONS},
695#endif
696#ifdef TIOCEXCL
697 {"TIOCEXCL", TIOCEXCL},
698#endif
699#ifdef TIOCGETD
700 {"TIOCGETD", TIOCGETD},
701#endif
702#ifdef TIOCGICOUNT
703 {"TIOCGICOUNT", TIOCGICOUNT},
704#endif
705#ifdef TIOCGLCKTRMIOS
706 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
707#endif
708#ifdef TIOCGPGRP
709 {"TIOCGPGRP", TIOCGPGRP},
710#endif
711#ifdef TIOCGSERIAL
712 {"TIOCGSERIAL", TIOCGSERIAL},
713#endif
714#ifdef TIOCGSOFTCAR
715 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
716#endif
717#ifdef TIOCGWINSZ
718 {"TIOCGWINSZ", TIOCGWINSZ},
719#endif
720#ifdef TIOCINQ
721 {"TIOCINQ", TIOCINQ},
722#endif
723#ifdef TIOCLINUX
724 {"TIOCLINUX", TIOCLINUX},
725#endif
726#ifdef TIOCMBIC
727 {"TIOCMBIC", TIOCMBIC},
728#endif
729#ifdef TIOCMBIS
730 {"TIOCMBIS", TIOCMBIS},
731#endif
732#ifdef TIOCMGET
733 {"TIOCMGET", TIOCMGET},
734#endif
735#ifdef TIOCMIWAIT
736 {"TIOCMIWAIT", TIOCMIWAIT},
737#endif
738#ifdef TIOCMSET
739 {"TIOCMSET", TIOCMSET},
740#endif
741#ifdef TIOCM_CAR
742 {"TIOCM_CAR", TIOCM_CAR},
743#endif
744#ifdef TIOCM_CD
745 {"TIOCM_CD", TIOCM_CD},
746#endif
747#ifdef TIOCM_CTS
748 {"TIOCM_CTS", TIOCM_CTS},
749#endif
750#ifdef TIOCM_DSR
751 {"TIOCM_DSR", TIOCM_DSR},
752#endif
753#ifdef TIOCM_DTR
754 {"TIOCM_DTR", TIOCM_DTR},
755#endif
756#ifdef TIOCM_LE
757 {"TIOCM_LE", TIOCM_LE},
758#endif
759#ifdef TIOCM_RI
760 {"TIOCM_RI", TIOCM_RI},
761#endif
762#ifdef TIOCM_RNG
763 {"TIOCM_RNG", TIOCM_RNG},
764#endif
765#ifdef TIOCM_RTS
766 {"TIOCM_RTS", TIOCM_RTS},
767#endif
768#ifdef TIOCM_SR
769 {"TIOCM_SR", TIOCM_SR},
770#endif
771#ifdef TIOCM_ST
772 {"TIOCM_ST", TIOCM_ST},
773#endif
774#ifdef TIOCNOTTY
775 {"TIOCNOTTY", TIOCNOTTY},
776#endif
777#ifdef TIOCNXCL
778 {"TIOCNXCL", TIOCNXCL},
779#endif
780#ifdef TIOCOUTQ
781 {"TIOCOUTQ", TIOCOUTQ},
782#endif
783#ifdef TIOCPKT
784 {"TIOCPKT", TIOCPKT},
785#endif
786#ifdef TIOCPKT_DATA
787 {"TIOCPKT_DATA", TIOCPKT_DATA},
788#endif
789#ifdef TIOCPKT_DOSTOP
790 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
791#endif
792#ifdef TIOCPKT_FLUSHREAD
793 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
794#endif
795#ifdef TIOCPKT_FLUSHWRITE
796 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
797#endif
798#ifdef TIOCPKT_NOSTOP
799 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
800#endif
801#ifdef TIOCPKT_START
802 {"TIOCPKT_START", TIOCPKT_START},
803#endif
804#ifdef TIOCPKT_STOP
805 {"TIOCPKT_STOP", TIOCPKT_STOP},
806#endif
807#ifdef TIOCSCTTY
808 {"TIOCSCTTY", TIOCSCTTY},
809#endif
810#ifdef TIOCSERCONFIG
811 {"TIOCSERCONFIG", TIOCSERCONFIG},
812#endif
813#ifdef TIOCSERGETLSR
814 {"TIOCSERGETLSR", TIOCSERGETLSR},
815#endif
816#ifdef TIOCSERGETMULTI
817 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
818#endif
819#ifdef TIOCSERGSTRUCT
820 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
821#endif
822#ifdef TIOCSERGWILD
823 {"TIOCSERGWILD", TIOCSERGWILD},
824#endif
825#ifdef TIOCSERSETMULTI
826 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
827#endif
828#ifdef TIOCSERSWILD
829 {"TIOCSERSWILD", TIOCSERSWILD},
830#endif
831#ifdef TIOCSER_TEMT
832 {"TIOCSER_TEMT", TIOCSER_TEMT},
833#endif
834#ifdef TIOCSETD
835 {"TIOCSETD", TIOCSETD},
836#endif
837#ifdef TIOCSLCKTRMIOS
838 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
839#endif
840#ifdef TIOCSPGRP
841 {"TIOCSPGRP", TIOCSPGRP},
842#endif
843#ifdef TIOCSSERIAL
844 {"TIOCSSERIAL", TIOCSSERIAL},
845#endif
846#ifdef TIOCSSOFTCAR
847 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
848#endif
849#ifdef TIOCSTI
850 {"TIOCSTI", TIOCSTI},
851#endif
852#ifdef TIOCSWINSZ
853 {"TIOCSWINSZ", TIOCSWINSZ},
854#endif
855#ifdef TIOCTTYGSTRUCT
856 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
857#endif
858
Fred Drakedf48d142001-02-27 21:22:39 +0000859 /* sentinel */
860 {NULL, 0}
861};
862
863
Guido van Rossum3886bb61998-12-04 18:50:17 +0000864DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000865PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000866{
867 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000868 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000869
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000870 m = Py_InitModule4("termios", termios_methods, termios__doc__,
871 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000872
873 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000874 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000875 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000876
877 while (constant->name != NULL) {
878 PyModule_AddIntConstant(m, constant->name, constant->value);
879 ++constant;
880 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000881}