blob: 3aa8423977c165f7b47e7fe162ba2ffd4f5454aa [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},
327 {"B57600", B57600},
328 {"B115200", B115200},
Fred Drakeabb379e2001-03-01 03:28:08 +0000329#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000330 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000331#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000332#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000333 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000334#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000335
336 /* tcsetattr() constants */
337 {"TCSANOW", TCSANOW},
338 {"TCSADRAIN", TCSADRAIN},
339 {"TCSAFLUSH", TCSAFLUSH},
340
341 /* tcflush() constants */
342 {"TCIFLUSH", TCIFLUSH},
343 {"TCOFLUSH", TCOFLUSH},
344 {"TCIOFLUSH", TCIOFLUSH},
345
346 /* tcflow() constants */
347 {"TCOOFF", TCOOFF},
348 {"TCOON", TCOON},
349 {"TCIOFF", TCIOFF},
350 {"TCION", TCION},
351
352 /* struct termios.c_iflag constants */
353 {"IGNBRK", IGNBRK},
354 {"BRKINT", BRKINT},
355 {"IGNPAR", IGNPAR},
356 {"PARMRK", PARMRK},
357 {"INPCK", INPCK},
358 {"ISTRIP", ISTRIP},
359 {"INLCR", INLCR},
360 {"IGNCR", IGNCR},
361 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000362#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000363 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000364#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000365 {"IXON", IXON},
366 {"IXANY", IXANY},
367 {"IXOFF", IXOFF},
368 {"IMAXBEL", IMAXBEL},
369
370 /* struct termios.c_oflag constants */
371 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000372#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000373 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000374#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000375 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000376#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000377 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000378#endif
379#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000380 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000381#endif
382#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000383 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000384#endif
385#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000386 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000387#endif
388#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000389 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000390#endif
391#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000392 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000393#endif
394#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000395 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000396#endif
397#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000398 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000399#endif
400#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000401 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000402#endif
403#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000404 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000405#endif
406#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000407 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000408#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000409
410 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000411#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000412 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000413#endif
414#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000415 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000416#endif
417#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000418 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000419#endif
420#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000421 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000422#endif
423#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000424 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000425#endif
426#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000427 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000428#endif
429#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000430 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000431#endif
432#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000433 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000434#endif
435#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000436 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000437#endif
438#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000439 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000440#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000441#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000442 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000443#endif
Fred Draked85556c2001-03-03 18:08:52 +0000444#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000445 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000446#endif
447#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000448 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000449#endif
450#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000451 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000452#endif
453#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000454 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000455#endif
456#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000457 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000458#endif
459#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000460 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000461#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000462
463 /* struct termios.c_cflag constants */
464 {"CSIZE", CSIZE},
465 {"CSTOPB", CSTOPB},
466 {"CREAD", CREAD},
467 {"PARENB", PARENB},
468 {"PARODD", PARODD},
469 {"HUPCL", HUPCL},
470 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000471#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000472 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000473#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000474#ifdef CRTSCTS
475 {"CRTSCTS", (long)CRTSCTS},
476#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000477
478 /* struct termios.c_cflag-related values (character size) */
479 {"CS5", CS5},
480 {"CS6", CS6},
481 {"CS7", CS7},
482 {"CS8", CS8},
483
484 /* struct termios.c_lflag constants */
485 {"ISIG", ISIG},
486 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000487#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000488 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000489#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000490 {"ECHO", ECHO},
491 {"ECHOE", ECHOE},
492 {"ECHOK", ECHOK},
493 {"ECHONL", ECHONL},
494 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000495#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000496 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000497#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000498 {"ECHOKE", ECHOKE},
499 {"FLUSHO", FLUSHO},
500 {"NOFLSH", NOFLSH},
501 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000502#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000503 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000504#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000505 {"IEXTEN", IEXTEN},
506
507 /* indexes into the control chars array returned by tcgetattr() */
508 {"VINTR", VINTR},
509 {"VQUIT", VQUIT},
510 {"VERASE", VERASE},
511 {"VKILL", VKILL},
512 {"VEOF", VEOF},
513 {"VTIME", VTIME},
514 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000515#ifdef VSWTC
516 /* The #defines above ensure that if either is defined, both are,
517 * but both may be omitted by the system headers. ;-( */
Fred Drakedf48d142001-02-27 21:22:39 +0000518 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000519 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000520#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000521 {"VSTART", VSTART},
522 {"VSTOP", VSTOP},
523 {"VSUSP", VSUSP},
524 {"VEOL", VEOL},
525 {"VREPRINT", VREPRINT},
526 {"VDISCARD", VDISCARD},
527 {"VWERASE", VWERASE},
528 {"VLNEXT", VLNEXT},
529 {"VEOL2", VEOL2},
530
Fred Drake55a00342001-03-26 17:14:02 +0000531
532#ifdef B460800
533 {"B460800", B460800},
534#endif
535#ifdef CBAUD
536 {"CBAUD", CBAUD},
537#endif
538#ifdef CDEL
539 {"CDEL", CDEL},
540#endif
541#ifdef CDSUSP
542 {"CDSUSP", CDSUSP},
543#endif
544#ifdef CEOF
545 {"CEOF", CEOF},
546#endif
547#ifdef CEOL
548 {"CEOL", CEOL},
549#endif
550#ifdef CEOL2
551 {"CEOL2", CEOL2},
552#endif
553#ifdef CEOT
554 {"CEOT", CEOT},
555#endif
556#ifdef CERASE
557 {"CERASE", CERASE},
558#endif
559#ifdef CESC
560 {"CESC", CESC},
561#endif
562#ifdef CFLUSH
563 {"CFLUSH", CFLUSH},
564#endif
565#ifdef CINTR
566 {"CINTR", CINTR},
567#endif
568#ifdef CKILL
569 {"CKILL", CKILL},
570#endif
571#ifdef CLNEXT
572 {"CLNEXT", CLNEXT},
573#endif
574#ifdef CNUL
575 {"CNUL", CNUL},
576#endif
577#ifdef COMMON
578 {"COMMON", COMMON},
579#endif
580#ifdef CQUIT
581 {"CQUIT", CQUIT},
582#endif
583#ifdef CRPRNT
584 {"CRPRNT", CRPRNT},
585#endif
586#ifdef CSTART
587 {"CSTART", CSTART},
588#endif
589#ifdef CSTOP
590 {"CSTOP", CSTOP},
591#endif
592#ifdef CSUSP
593 {"CSUSP", CSUSP},
594#endif
595#ifdef CSWTCH
596 {"CSWTCH", CSWTCH},
597#endif
598#ifdef CWERASE
599 {"CWERASE", CWERASE},
600#endif
601#ifdef EXTA
602 {"EXTA", EXTA},
603#endif
604#ifdef EXTB
605 {"EXTB", EXTB},
606#endif
607#ifdef FIOASYNC
608 {"FIOASYNC", FIOASYNC},
609#endif
610#ifdef FIOCLEX
611 {"FIOCLEX", FIOCLEX},
612#endif
613#ifdef FIONBIO
614 {"FIONBIO", FIONBIO},
615#endif
616#ifdef FIONCLEX
617 {"FIONCLEX", FIONCLEX},
618#endif
619#ifdef FIONREAD
620 {"FIONREAD", FIONREAD},
621#endif
622#ifdef IBSHIFT
623 {"IBSHIFT", IBSHIFT},
624#endif
625#ifdef INIT_C_CC
626 {"INIT_C_CC", INIT_C_CC},
627#endif
628#ifdef IOCSIZE_MASK
629 {"IOCSIZE_MASK", IOCSIZE_MASK},
630#endif
631#ifdef IOCSIZE_SHIFT
632 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
633#endif
634#ifdef NCC
635 {"NCC", NCC},
636#endif
637#ifdef NCCS
638 {"NCCS", NCCS},
639#endif
640#ifdef NSWTCH
641 {"NSWTCH", NSWTCH},
642#endif
643#ifdef N_MOUSE
644 {"N_MOUSE", N_MOUSE},
645#endif
646#ifdef N_PPP
647 {"N_PPP", N_PPP},
648#endif
649#ifdef N_SLIP
650 {"N_SLIP", N_SLIP},
651#endif
652#ifdef N_STRIP
653 {"N_STRIP", N_STRIP},
654#endif
655#ifdef N_TTY
656 {"N_TTY", N_TTY},
657#endif
658#ifdef TCFLSH
659 {"TCFLSH", TCFLSH},
660#endif
661#ifdef TCGETA
662 {"TCGETA", TCGETA},
663#endif
664#ifdef TCGETS
665 {"TCGETS", TCGETS},
666#endif
667#ifdef TCSBRK
668 {"TCSBRK", TCSBRK},
669#endif
670#ifdef TCSBRKP
671 {"TCSBRKP", TCSBRKP},
672#endif
673#ifdef TCSETA
674 {"TCSETA", TCSETA},
675#endif
676#ifdef TCSETAF
677 {"TCSETAF", TCSETAF},
678#endif
679#ifdef TCSETAW
680 {"TCSETAW", TCSETAW},
681#endif
682#ifdef TCSETS
683 {"TCSETS", TCSETS},
684#endif
685#ifdef TCSETSF
686 {"TCSETSF", TCSETSF},
687#endif
688#ifdef TCSETSW
689 {"TCSETSW", TCSETSW},
690#endif
691#ifdef TCXONC
692 {"TCXONC", TCXONC},
693#endif
694#ifdef TIOCCONS
695 {"TIOCCONS", TIOCCONS},
696#endif
697#ifdef TIOCEXCL
698 {"TIOCEXCL", TIOCEXCL},
699#endif
700#ifdef TIOCGETD
701 {"TIOCGETD", TIOCGETD},
702#endif
703#ifdef TIOCGICOUNT
704 {"TIOCGICOUNT", TIOCGICOUNT},
705#endif
706#ifdef TIOCGLCKTRMIOS
707 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
708#endif
709#ifdef TIOCGPGRP
710 {"TIOCGPGRP", TIOCGPGRP},
711#endif
712#ifdef TIOCGSERIAL
713 {"TIOCGSERIAL", TIOCGSERIAL},
714#endif
715#ifdef TIOCGSOFTCAR
716 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
717#endif
718#ifdef TIOCGWINSZ
719 {"TIOCGWINSZ", TIOCGWINSZ},
720#endif
721#ifdef TIOCINQ
722 {"TIOCINQ", TIOCINQ},
723#endif
724#ifdef TIOCLINUX
725 {"TIOCLINUX", TIOCLINUX},
726#endif
727#ifdef TIOCMBIC
728 {"TIOCMBIC", TIOCMBIC},
729#endif
730#ifdef TIOCMBIS
731 {"TIOCMBIS", TIOCMBIS},
732#endif
733#ifdef TIOCMGET
734 {"TIOCMGET", TIOCMGET},
735#endif
736#ifdef TIOCMIWAIT
737 {"TIOCMIWAIT", TIOCMIWAIT},
738#endif
739#ifdef TIOCMSET
740 {"TIOCMSET", TIOCMSET},
741#endif
742#ifdef TIOCM_CAR
743 {"TIOCM_CAR", TIOCM_CAR},
744#endif
745#ifdef TIOCM_CD
746 {"TIOCM_CD", TIOCM_CD},
747#endif
748#ifdef TIOCM_CTS
749 {"TIOCM_CTS", TIOCM_CTS},
750#endif
751#ifdef TIOCM_DSR
752 {"TIOCM_DSR", TIOCM_DSR},
753#endif
754#ifdef TIOCM_DTR
755 {"TIOCM_DTR", TIOCM_DTR},
756#endif
757#ifdef TIOCM_LE
758 {"TIOCM_LE", TIOCM_LE},
759#endif
760#ifdef TIOCM_RI
761 {"TIOCM_RI", TIOCM_RI},
762#endif
763#ifdef TIOCM_RNG
764 {"TIOCM_RNG", TIOCM_RNG},
765#endif
766#ifdef TIOCM_RTS
767 {"TIOCM_RTS", TIOCM_RTS},
768#endif
769#ifdef TIOCM_SR
770 {"TIOCM_SR", TIOCM_SR},
771#endif
772#ifdef TIOCM_ST
773 {"TIOCM_ST", TIOCM_ST},
774#endif
775#ifdef TIOCNOTTY
776 {"TIOCNOTTY", TIOCNOTTY},
777#endif
778#ifdef TIOCNXCL
779 {"TIOCNXCL", TIOCNXCL},
780#endif
781#ifdef TIOCOUTQ
782 {"TIOCOUTQ", TIOCOUTQ},
783#endif
784#ifdef TIOCPKT
785 {"TIOCPKT", TIOCPKT},
786#endif
787#ifdef TIOCPKT_DATA
788 {"TIOCPKT_DATA", TIOCPKT_DATA},
789#endif
790#ifdef TIOCPKT_DOSTOP
791 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
792#endif
793#ifdef TIOCPKT_FLUSHREAD
794 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
795#endif
796#ifdef TIOCPKT_FLUSHWRITE
797 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
798#endif
799#ifdef TIOCPKT_NOSTOP
800 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
801#endif
802#ifdef TIOCPKT_START
803 {"TIOCPKT_START", TIOCPKT_START},
804#endif
805#ifdef TIOCPKT_STOP
806 {"TIOCPKT_STOP", TIOCPKT_STOP},
807#endif
808#ifdef TIOCSCTTY
809 {"TIOCSCTTY", TIOCSCTTY},
810#endif
811#ifdef TIOCSERCONFIG
812 {"TIOCSERCONFIG", TIOCSERCONFIG},
813#endif
814#ifdef TIOCSERGETLSR
815 {"TIOCSERGETLSR", TIOCSERGETLSR},
816#endif
817#ifdef TIOCSERGETMULTI
818 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
819#endif
820#ifdef TIOCSERGSTRUCT
821 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
822#endif
823#ifdef TIOCSERGWILD
824 {"TIOCSERGWILD", TIOCSERGWILD},
825#endif
826#ifdef TIOCSERSETMULTI
827 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
828#endif
829#ifdef TIOCSERSWILD
830 {"TIOCSERSWILD", TIOCSERSWILD},
831#endif
832#ifdef TIOCSER_TEMT
833 {"TIOCSER_TEMT", TIOCSER_TEMT},
834#endif
835#ifdef TIOCSETD
836 {"TIOCSETD", TIOCSETD},
837#endif
838#ifdef TIOCSLCKTRMIOS
839 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
840#endif
841#ifdef TIOCSPGRP
842 {"TIOCSPGRP", TIOCSPGRP},
843#endif
844#ifdef TIOCSSERIAL
845 {"TIOCSSERIAL", TIOCSSERIAL},
846#endif
847#ifdef TIOCSSOFTCAR
848 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
849#endif
850#ifdef TIOCSTI
851 {"TIOCSTI", TIOCSTI},
852#endif
853#ifdef TIOCSWINSZ
854 {"TIOCSWINSZ", TIOCSWINSZ},
855#endif
856#ifdef TIOCTTYGSTRUCT
857 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
858#endif
859
Fred Drakedf48d142001-02-27 21:22:39 +0000860 /* sentinel */
861 {NULL, 0}
862};
863
864
Guido van Rossum3886bb61998-12-04 18:50:17 +0000865DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000866PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000867{
868 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000869 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000870
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000871 m = Py_InitModule4("termios", termios_methods, termios__doc__,
872 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000873
874 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000875 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000876 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000877
878 while (constant->name != NULL) {
879 PyModule_AddIntConstant(m, constant->name, constant->value);
880 ++constant;
881 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000882}