blob: 1d5e20b3bd997a8871df15bde6b9699f361252da [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 Draked3908e22001-04-05 18:26:31 +00008/* XXX Some systems need this to get all the symbols, while
9 this breaks for others.
Fred Drake9b3bc492001-04-04 21:19:26 +000010#include <sys/ioctl.h>
Fred Draked3908e22001-04-05 18:26:31 +000011*/
Guido van Rossum9adae8e1994-09-12 10:41:22 +000012
Guido van Rossum1aca4d81998-03-03 22:10:18 +000013static char termios__doc__[] = "\
14This module provides an interface to the Posix calls for tty I/O control.\n\
15For a complete description of these calls, see the Posix or Unix manual\n\
16pages. It is only available for those Unix versions that support Posix\n\
17termios style tty I/O control (and then only if configured at installation\n\
18time).\n\
19\n\
20All functions in this module take a file descriptor fd as their first\n\
21argument. This must be an integer file descriptor, such as returned by\n\
Fred Drake29fd0312001-04-09 19:32:52 +000022sys.stdin.fileno().";
Guido van Rossum1aca4d81998-03-03 22:10:18 +000023
24
Guido van Rossumbcc20741998-08-04 22:53:56 +000025#ifdef __BEOS__
26#include <unistd.h>
27#endif
28
Guido van Rossum9adae8e1994-09-12 10:41:22 +000029#define BAD "bad termios argument"
30
31static PyObject *TermiosError;
32
33/* termios = tcgetattr(fd)
34 termios is
35 [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]]
36
37 Return the attributes of the terminal device. */
38
Guido van Rossum1aca4d81998-03-03 22:10:18 +000039static char termios_tcgetattr__doc__[] = "\
40tcgetattr(fd) -> list_of_attrs\n\
41Get the tty attributes for file descriptor fd, as follows:\n\
42[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
43of the tty special characters (each a string of length 1, except the items\n\
44with indices VMIN and VTIME, which are integers when these fields are\n\
45defined). The interpretation of the flags and the speeds as well as the\n\
46indexing in the cc array must be done using the symbolic constants defined\n\
Fred Drake29fd0312001-04-09 19:32:52 +000047in this module.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +000048
Guido van Rossum9adae8e1994-09-12 10:41:22 +000049static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000050termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000051{
52 int fd;
53 struct termios mode;
54 PyObject *cc;
55 speed_t ispeed, ospeed;
56 PyObject *v;
57 int i;
58 char ch;
59
60 if (!PyArg_Parse(args, "i", &fd))
61 return NULL;
62
63 if (tcgetattr(fd, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +000064 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000065
66 ispeed = cfgetispeed(&mode);
67 ospeed = cfgetospeed(&mode);
68
69 cc = PyList_New(NCCS);
70 if (cc == NULL)
71 return NULL;
72 for (i = 0; i < NCCS; i++) {
73 ch = (char)mode.c_cc[i];
74 v = PyString_FromStringAndSize(&ch, 1);
75 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000076 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000077 PyList_SetItem(cc, i, v);
78 }
79
80 /* Convert the MIN and TIME slots to integer. On some systems, the
81 MIN and TIME slots are the same as the EOF and EOL slots. So we
82 only do this in noncanonical input mode. */
Guido van Rossum36dd0d21996-12-10 15:23:00 +000083 if ((mode.c_lflag & ICANON) == 0) {
Guido van Rossum9adae8e1994-09-12 10:41:22 +000084 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
85 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000086 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000087 PyList_SetItem(cc, VMIN, v);
88 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
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, VTIME, v);
92 }
93
Barry Warsaw5709dcf1997-01-10 18:42:18 +000094 if (!(v = PyList_New(7)))
95 goto err;
96
Guido van Rossum9adae8e1994-09-12 10:41:22 +000097 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
98 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
99 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
100 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
101 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
102 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
103 PyList_SetItem(v, 6, cc);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000104 if (PyErr_Occurred()){
105 Py_DECREF(v);
106 goto err;
107 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000108 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000109 err:
110 Py_DECREF(cc);
111 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000112}
113
114/* tcsetattr(fd, when, termios)
115 Set the attributes of the terminal device. */
116
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000117static char termios_tcsetattr__doc__[] = "\
118tcsetattr(fd, when, attributes) -> None\n\
119Set the tty attributes for file descriptor fd.\n\
120The attributes to be set are taken from the attributes argument, which\n\
121is a list like the one returned by tcgetattr(). The when argument\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000122determines when the attributes are changed: termios.TCSANOW to\n\
123change immediately, termios.TCSADRAIN to change after transmitting all\n\
124queued output, or termios.TCSAFLUSH to change after transmitting all\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000125queued output and discarding all queued input. ";
126
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000127static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000128termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000129{
130 int fd, when;
131 struct termios mode;
132 speed_t ispeed, ospeed;
133 PyObject *term, *cc, *v;
134 int i;
135
136 if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
137 return NULL;
138 if (!PyList_Check(term) || PyList_Size(term) != 7) {
139 PyErr_SetString(PyExc_TypeError, BAD);
140 return NULL;
141 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000142
Guido van Rossume7c41931998-06-12 14:26:18 +0000143 /* Get the old mode, in case there are any hidden fields... */
144 if (tcgetattr(fd, &mode) == -1)
145 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000146 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
147 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
148 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
149 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
150 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
151 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
152 cc = PyList_GetItem(term, 6);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000153 if (PyErr_Occurred())
154 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000155
156 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
157 PyErr_SetString(PyExc_TypeError, BAD);
158 return NULL;
159 }
160
161 for (i = 0; i < NCCS; i++) {
162 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000163
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000164 if (PyString_Check(v) && PyString_Size(v) == 1)
165 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
166 else if (PyInt_Check(v))
167 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
168 else {
169 PyErr_SetString(PyExc_TypeError, BAD);
170 return NULL;
171 }
172 }
173
174 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000175 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000176 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000177 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000178 if (tcsetattr(fd, when, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000179 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000180
181 Py_INCREF(Py_None);
182 return Py_None;
183}
184
185/* tcsendbreak(fd, duration)
186 Generate a break condition. */
187
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000188static char termios_tcsendbreak__doc__[] = "\
189tcsendbreak(fd, duration) -> None\n\
190Send a break on file descriptor fd.\n\
191A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
192has a system dependent meaning. ";
193
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000194static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000195termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000196{
197 int fd, duration;
198
199 if (!PyArg_Parse(args, "(ii)", &fd, &duration))
200 return NULL;
201 if (tcsendbreak(fd, duration) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000202 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000203
204 Py_INCREF(Py_None);
205 return Py_None;
206}
207
208/* tcdrain(fd)
209 Wait until all queued output to the terminal has been
210 transmitted. */
211
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000212static char termios_tcdrain__doc__[] = "\
213tcdrain(fd) -> None\n\
214Wait until all output written to file descriptor fd has been transmitted. ";
215
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000216static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000217termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000218{
219 int fd;
220
221 if (!PyArg_Parse(args, "i", &fd))
222 return NULL;
223 if (tcdrain(fd) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000224 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000225
226 Py_INCREF(Py_None);
227 return Py_None;
228}
229
230/* tcflush(fd, queue)
231 Clear the input and/or output queues associated with
232 the terminal. */
233
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000234static char termios_tcflush__doc__[] = "\
235tcflush(fd, queue) -> None\n\
236Discard queued data on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000237The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
238queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000239both queues. ";
240
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000241static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000242termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000243{
244 int fd, queue;
245
246 if (!PyArg_Parse(args, "(ii)", &fd, &queue))
247 return NULL;
248 if (tcflush(fd, queue) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000249 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000250
251 Py_INCREF(Py_None);
252 return Py_None;
253}
254
255/* tcflow(fd, action)
256 Perform operations relating to XON/XOFF flow control on
257 the terminal. */
258
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000259static char termios_tcflow__doc__[] = "\
260tcflow(fd, action) -> None\n\
261Suspend or resume input or output on file descriptor fd.\n\
Fred Drake29fd0312001-04-09 19:32:52 +0000262The action argument can be termios.TCOOFF to suspend output,\n\
263termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
264or termios.TCION to restart input.";
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000265
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000266static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000267termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000268{
269 int fd, action;
270
271 if (!PyArg_Parse(args, "(ii)", &fd, &action))
272 return NULL;
273 if (tcflow(fd, action) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000274 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000275
276 Py_INCREF(Py_None);
277 return Py_None;
278}
279
280static PyMethodDef termios_methods[] =
281{
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000282 {"tcgetattr", termios_tcgetattr,
283 METH_OLDARGS, termios_tcgetattr__doc__},
284 {"tcsetattr", termios_tcsetattr,
285 METH_OLDARGS, termios_tcsetattr__doc__},
286 {"tcsendbreak", termios_tcsendbreak,
287 METH_OLDARGS, termios_tcsendbreak__doc__},
288 {"tcdrain", termios_tcdrain,
289 METH_OLDARGS, termios_tcdrain__doc__},
290 {"tcflush", termios_tcflush,
291 METH_OLDARGS, termios_tcflush__doc__},
292 {"tcflow", termios_tcflow,
293 METH_OLDARGS, termios_tcflow__doc__},
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000294 {NULL, NULL}
295};
296
Fred Drakedf48d142001-02-27 21:22:39 +0000297
Fred Drake9ef7fa82001-03-01 21:54:49 +0000298#if defined(VSWTCH) && !defined(VSWTC)
299#define VSWTC VSWTCH
300#endif
301
302#if defined(VSWTC) && !defined(VSWTCH)
303#define VSWTCH VSWTC
304#endif
305
Fred Drakedf48d142001-02-27 21:22:39 +0000306static struct constant {
307 char *name;
308 long value;
309} termios_constants[] = {
310 /* cfgetospeed(), cfsetospeed() constants */
311 {"B0", B0},
312 {"B50", B50},
313 {"B75", B75},
314 {"B110", B110},
315 {"B134", B134},
316 {"B150", B150},
317 {"B200", B200},
318 {"B300", B300},
319 {"B600", B600},
320 {"B1200", B1200},
321 {"B1800", B1800},
322 {"B2400", B2400},
323 {"B4800", B4800},
324 {"B9600", B9600},
325 {"B19200", B19200},
326 {"B38400", B38400},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000327#ifdef B57600
Fred Drakedf48d142001-02-27 21:22:39 +0000328 {"B57600", B57600},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000329#endif
330#ifdef B115200
Fred Drakedf48d142001-02-27 21:22:39 +0000331 {"B115200", B115200},
Guido van Rossum2242f2f2001-04-11 20:58:20 +0000332#endif
Fred Drakeabb379e2001-03-01 03:28:08 +0000333#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000334 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000335#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000336#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000337 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000338#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000339
340 /* tcsetattr() constants */
341 {"TCSANOW", TCSANOW},
342 {"TCSADRAIN", TCSADRAIN},
343 {"TCSAFLUSH", TCSAFLUSH},
344
345 /* tcflush() constants */
346 {"TCIFLUSH", TCIFLUSH},
347 {"TCOFLUSH", TCOFLUSH},
348 {"TCIOFLUSH", TCIOFLUSH},
349
350 /* tcflow() constants */
351 {"TCOOFF", TCOOFF},
352 {"TCOON", TCOON},
353 {"TCIOFF", TCIOFF},
354 {"TCION", TCION},
355
356 /* struct termios.c_iflag constants */
357 {"IGNBRK", IGNBRK},
358 {"BRKINT", BRKINT},
359 {"IGNPAR", IGNPAR},
360 {"PARMRK", PARMRK},
361 {"INPCK", INPCK},
362 {"ISTRIP", ISTRIP},
363 {"INLCR", INLCR},
364 {"IGNCR", IGNCR},
365 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000366#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000367 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000368#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000369 {"IXON", IXON},
370 {"IXANY", IXANY},
371 {"IXOFF", IXOFF},
372 {"IMAXBEL", IMAXBEL},
373
374 /* struct termios.c_oflag constants */
375 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000376#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000377 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000378#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000379 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000380#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000381 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000382#endif
383#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000384 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000385#endif
386#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000387 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000388#endif
389#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000390 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000391#endif
392#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000393 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000394#endif
395#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000396 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000397#endif
398#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000399 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000400#endif
401#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000402 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000403#endif
404#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000405 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000406#endif
407#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000408 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000409#endif
410#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000411 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000412#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000413
414 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000415#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000416 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000417#endif
418#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000419 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000420#endif
421#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000422 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000423#endif
424#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000425 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000426#endif
427#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000428 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000429#endif
430#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000431 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000432#endif
433#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000434 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000435#endif
436#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000437 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000438#endif
439#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000440 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000441#endif
442#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000443 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000444#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000445#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000446 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000447#endif
Fred Draked85556c2001-03-03 18:08:52 +0000448#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000449 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000450#endif
451#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000452 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000453#endif
454#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000455 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000456#endif
457#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000458 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000459#endif
460#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000461 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000462#endif
463#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000464 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000465#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000466
467 /* struct termios.c_cflag constants */
468 {"CSIZE", CSIZE},
469 {"CSTOPB", CSTOPB},
470 {"CREAD", CREAD},
471 {"PARENB", PARENB},
472 {"PARODD", PARODD},
473 {"HUPCL", HUPCL},
474 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000475#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000476 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000477#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000478#ifdef CRTSCTS
479 {"CRTSCTS", (long)CRTSCTS},
480#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000481
482 /* struct termios.c_cflag-related values (character size) */
483 {"CS5", CS5},
484 {"CS6", CS6},
485 {"CS7", CS7},
486 {"CS8", CS8},
487
488 /* struct termios.c_lflag constants */
489 {"ISIG", ISIG},
490 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000491#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000492 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000493#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000494 {"ECHO", ECHO},
495 {"ECHOE", ECHOE},
496 {"ECHOK", ECHOK},
497 {"ECHONL", ECHONL},
498 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000499#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000500 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000501#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000502 {"ECHOKE", ECHOKE},
503 {"FLUSHO", FLUSHO},
504 {"NOFLSH", NOFLSH},
505 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000506#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000507 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000508#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000509 {"IEXTEN", IEXTEN},
510
511 /* indexes into the control chars array returned by tcgetattr() */
512 {"VINTR", VINTR},
513 {"VQUIT", VQUIT},
514 {"VERASE", VERASE},
515 {"VKILL", VKILL},
516 {"VEOF", VEOF},
517 {"VTIME", VTIME},
518 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000519#ifdef VSWTC
520 /* The #defines above ensure that if either is defined, both are,
521 * but both may be omitted by the system headers. ;-( */
Fred Drakedf48d142001-02-27 21:22:39 +0000522 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000523 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000524#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000525 {"VSTART", VSTART},
526 {"VSTOP", VSTOP},
527 {"VSUSP", VSUSP},
528 {"VEOL", VEOL},
529 {"VREPRINT", VREPRINT},
530 {"VDISCARD", VDISCARD},
531 {"VWERASE", VWERASE},
532 {"VLNEXT", VLNEXT},
533 {"VEOL2", VEOL2},
534
Fred Drake55a00342001-03-26 17:14:02 +0000535
536#ifdef B460800
537 {"B460800", B460800},
538#endif
539#ifdef CBAUD
540 {"CBAUD", CBAUD},
541#endif
542#ifdef CDEL
543 {"CDEL", CDEL},
544#endif
545#ifdef CDSUSP
546 {"CDSUSP", CDSUSP},
547#endif
548#ifdef CEOF
549 {"CEOF", CEOF},
550#endif
551#ifdef CEOL
552 {"CEOL", CEOL},
553#endif
554#ifdef CEOL2
555 {"CEOL2", CEOL2},
556#endif
557#ifdef CEOT
558 {"CEOT", CEOT},
559#endif
560#ifdef CERASE
561 {"CERASE", CERASE},
562#endif
563#ifdef CESC
564 {"CESC", CESC},
565#endif
566#ifdef CFLUSH
567 {"CFLUSH", CFLUSH},
568#endif
569#ifdef CINTR
570 {"CINTR", CINTR},
571#endif
572#ifdef CKILL
573 {"CKILL", CKILL},
574#endif
575#ifdef CLNEXT
576 {"CLNEXT", CLNEXT},
577#endif
578#ifdef CNUL
579 {"CNUL", CNUL},
580#endif
581#ifdef COMMON
582 {"COMMON", COMMON},
583#endif
584#ifdef CQUIT
585 {"CQUIT", CQUIT},
586#endif
587#ifdef CRPRNT
588 {"CRPRNT", CRPRNT},
589#endif
590#ifdef CSTART
591 {"CSTART", CSTART},
592#endif
593#ifdef CSTOP
594 {"CSTOP", CSTOP},
595#endif
596#ifdef CSUSP
597 {"CSUSP", CSUSP},
598#endif
599#ifdef CSWTCH
600 {"CSWTCH", CSWTCH},
601#endif
602#ifdef CWERASE
603 {"CWERASE", CWERASE},
604#endif
605#ifdef EXTA
606 {"EXTA", EXTA},
607#endif
608#ifdef EXTB
609 {"EXTB", EXTB},
610#endif
611#ifdef FIOASYNC
612 {"FIOASYNC", FIOASYNC},
613#endif
614#ifdef FIOCLEX
615 {"FIOCLEX", FIOCLEX},
616#endif
617#ifdef FIONBIO
618 {"FIONBIO", FIONBIO},
619#endif
620#ifdef FIONCLEX
621 {"FIONCLEX", FIONCLEX},
622#endif
623#ifdef FIONREAD
624 {"FIONREAD", FIONREAD},
625#endif
626#ifdef IBSHIFT
627 {"IBSHIFT", IBSHIFT},
628#endif
629#ifdef INIT_C_CC
630 {"INIT_C_CC", INIT_C_CC},
631#endif
632#ifdef IOCSIZE_MASK
633 {"IOCSIZE_MASK", IOCSIZE_MASK},
634#endif
635#ifdef IOCSIZE_SHIFT
636 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
637#endif
638#ifdef NCC
639 {"NCC", NCC},
640#endif
641#ifdef NCCS
642 {"NCCS", NCCS},
643#endif
644#ifdef NSWTCH
645 {"NSWTCH", NSWTCH},
646#endif
647#ifdef N_MOUSE
648 {"N_MOUSE", N_MOUSE},
649#endif
650#ifdef N_PPP
651 {"N_PPP", N_PPP},
652#endif
653#ifdef N_SLIP
654 {"N_SLIP", N_SLIP},
655#endif
656#ifdef N_STRIP
657 {"N_STRIP", N_STRIP},
658#endif
659#ifdef N_TTY
660 {"N_TTY", N_TTY},
661#endif
662#ifdef TCFLSH
663 {"TCFLSH", TCFLSH},
664#endif
665#ifdef TCGETA
666 {"TCGETA", TCGETA},
667#endif
668#ifdef TCGETS
669 {"TCGETS", TCGETS},
670#endif
671#ifdef TCSBRK
672 {"TCSBRK", TCSBRK},
673#endif
674#ifdef TCSBRKP
675 {"TCSBRKP", TCSBRKP},
676#endif
677#ifdef TCSETA
678 {"TCSETA", TCSETA},
679#endif
680#ifdef TCSETAF
681 {"TCSETAF", TCSETAF},
682#endif
683#ifdef TCSETAW
684 {"TCSETAW", TCSETAW},
685#endif
686#ifdef TCSETS
687 {"TCSETS", TCSETS},
688#endif
689#ifdef TCSETSF
690 {"TCSETSF", TCSETSF},
691#endif
692#ifdef TCSETSW
693 {"TCSETSW", TCSETSW},
694#endif
695#ifdef TCXONC
696 {"TCXONC", TCXONC},
697#endif
698#ifdef TIOCCONS
699 {"TIOCCONS", TIOCCONS},
700#endif
701#ifdef TIOCEXCL
702 {"TIOCEXCL", TIOCEXCL},
703#endif
704#ifdef TIOCGETD
705 {"TIOCGETD", TIOCGETD},
706#endif
707#ifdef TIOCGICOUNT
708 {"TIOCGICOUNT", TIOCGICOUNT},
709#endif
710#ifdef TIOCGLCKTRMIOS
711 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
712#endif
713#ifdef TIOCGPGRP
714 {"TIOCGPGRP", TIOCGPGRP},
715#endif
716#ifdef TIOCGSERIAL
717 {"TIOCGSERIAL", TIOCGSERIAL},
718#endif
719#ifdef TIOCGSOFTCAR
720 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
721#endif
722#ifdef TIOCGWINSZ
723 {"TIOCGWINSZ", TIOCGWINSZ},
724#endif
725#ifdef TIOCINQ
726 {"TIOCINQ", TIOCINQ},
727#endif
728#ifdef TIOCLINUX
729 {"TIOCLINUX", TIOCLINUX},
730#endif
731#ifdef TIOCMBIC
732 {"TIOCMBIC", TIOCMBIC},
733#endif
734#ifdef TIOCMBIS
735 {"TIOCMBIS", TIOCMBIS},
736#endif
737#ifdef TIOCMGET
738 {"TIOCMGET", TIOCMGET},
739#endif
740#ifdef TIOCMIWAIT
741 {"TIOCMIWAIT", TIOCMIWAIT},
742#endif
743#ifdef TIOCMSET
744 {"TIOCMSET", TIOCMSET},
745#endif
746#ifdef TIOCM_CAR
747 {"TIOCM_CAR", TIOCM_CAR},
748#endif
749#ifdef TIOCM_CD
750 {"TIOCM_CD", TIOCM_CD},
751#endif
752#ifdef TIOCM_CTS
753 {"TIOCM_CTS", TIOCM_CTS},
754#endif
755#ifdef TIOCM_DSR
756 {"TIOCM_DSR", TIOCM_DSR},
757#endif
758#ifdef TIOCM_DTR
759 {"TIOCM_DTR", TIOCM_DTR},
760#endif
761#ifdef TIOCM_LE
762 {"TIOCM_LE", TIOCM_LE},
763#endif
764#ifdef TIOCM_RI
765 {"TIOCM_RI", TIOCM_RI},
766#endif
767#ifdef TIOCM_RNG
768 {"TIOCM_RNG", TIOCM_RNG},
769#endif
770#ifdef TIOCM_RTS
771 {"TIOCM_RTS", TIOCM_RTS},
772#endif
773#ifdef TIOCM_SR
774 {"TIOCM_SR", TIOCM_SR},
775#endif
776#ifdef TIOCM_ST
777 {"TIOCM_ST", TIOCM_ST},
778#endif
779#ifdef TIOCNOTTY
780 {"TIOCNOTTY", TIOCNOTTY},
781#endif
782#ifdef TIOCNXCL
783 {"TIOCNXCL", TIOCNXCL},
784#endif
785#ifdef TIOCOUTQ
786 {"TIOCOUTQ", TIOCOUTQ},
787#endif
788#ifdef TIOCPKT
789 {"TIOCPKT", TIOCPKT},
790#endif
791#ifdef TIOCPKT_DATA
792 {"TIOCPKT_DATA", TIOCPKT_DATA},
793#endif
794#ifdef TIOCPKT_DOSTOP
795 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
796#endif
797#ifdef TIOCPKT_FLUSHREAD
798 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
799#endif
800#ifdef TIOCPKT_FLUSHWRITE
801 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
802#endif
803#ifdef TIOCPKT_NOSTOP
804 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
805#endif
806#ifdef TIOCPKT_START
807 {"TIOCPKT_START", TIOCPKT_START},
808#endif
809#ifdef TIOCPKT_STOP
810 {"TIOCPKT_STOP", TIOCPKT_STOP},
811#endif
812#ifdef TIOCSCTTY
813 {"TIOCSCTTY", TIOCSCTTY},
814#endif
815#ifdef TIOCSERCONFIG
816 {"TIOCSERCONFIG", TIOCSERCONFIG},
817#endif
818#ifdef TIOCSERGETLSR
819 {"TIOCSERGETLSR", TIOCSERGETLSR},
820#endif
821#ifdef TIOCSERGETMULTI
822 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
823#endif
824#ifdef TIOCSERGSTRUCT
825 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
826#endif
827#ifdef TIOCSERGWILD
828 {"TIOCSERGWILD", TIOCSERGWILD},
829#endif
830#ifdef TIOCSERSETMULTI
831 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
832#endif
833#ifdef TIOCSERSWILD
834 {"TIOCSERSWILD", TIOCSERSWILD},
835#endif
836#ifdef TIOCSER_TEMT
837 {"TIOCSER_TEMT", TIOCSER_TEMT},
838#endif
839#ifdef TIOCSETD
840 {"TIOCSETD", TIOCSETD},
841#endif
842#ifdef TIOCSLCKTRMIOS
843 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
844#endif
845#ifdef TIOCSPGRP
846 {"TIOCSPGRP", TIOCSPGRP},
847#endif
848#ifdef TIOCSSERIAL
849 {"TIOCSSERIAL", TIOCSSERIAL},
850#endif
851#ifdef TIOCSSOFTCAR
852 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
853#endif
854#ifdef TIOCSTI
855 {"TIOCSTI", TIOCSTI},
856#endif
857#ifdef TIOCSWINSZ
858 {"TIOCSWINSZ", TIOCSWINSZ},
859#endif
860#ifdef TIOCTTYGSTRUCT
861 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
862#endif
863
Fred Drakedf48d142001-02-27 21:22:39 +0000864 /* sentinel */
865 {NULL, 0}
866};
867
868
Guido van Rossum3886bb61998-12-04 18:50:17 +0000869DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000870PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000871{
872 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000873 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000874
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000875 m = Py_InitModule4("termios", termios_methods, termios__doc__,
876 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000877
878 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000879 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000880 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000881
882 while (constant->name != NULL) {
883 PyModule_AddIntConstant(m, constant->name, constant->value);
884 ++constant;
885 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000886}