blob: 146a16fe2f99c1a94a585eb189f786e9cf9d1162 [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\
22sys.stdin.fileno().\n\
23\n\
24This module should be used in conjunction with the TERMIOS module,\n\
25which defines the relevant symbolic constants.";
26
27
Guido van Rossumbcc20741998-08-04 22:53:56 +000028#ifdef __BEOS__
29#include <unistd.h>
30#endif
31
Guido van Rossum9adae8e1994-09-12 10:41:22 +000032#define BAD "bad termios argument"
33
34static PyObject *TermiosError;
35
36/* termios = tcgetattr(fd)
37 termios is
38 [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]]
39
40 Return the attributes of the terminal device. */
41
Guido van Rossum1aca4d81998-03-03 22:10:18 +000042static char termios_tcgetattr__doc__[] = "\
43tcgetattr(fd) -> list_of_attrs\n\
44Get the tty attributes for file descriptor fd, as follows:\n\
45[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
46of the tty special characters (each a string of length 1, except the items\n\
47with indices VMIN and VTIME, which are integers when these fields are\n\
48defined). The interpretation of the flags and the speeds as well as the\n\
49indexing in the cc array must be done using the symbolic constants defined\n\
50in the TERMIOS module.";
51
Guido van Rossum9adae8e1994-09-12 10:41:22 +000052static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +000053termios_tcgetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +000054{
55 int fd;
56 struct termios mode;
57 PyObject *cc;
58 speed_t ispeed, ospeed;
59 PyObject *v;
60 int i;
61 char ch;
62
63 if (!PyArg_Parse(args, "i", &fd))
64 return NULL;
65
66 if (tcgetattr(fd, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +000067 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +000068
69 ispeed = cfgetispeed(&mode);
70 ospeed = cfgetospeed(&mode);
71
72 cc = PyList_New(NCCS);
73 if (cc == NULL)
74 return NULL;
75 for (i = 0; i < NCCS; i++) {
76 ch = (char)mode.c_cc[i];
77 v = PyString_FromStringAndSize(&ch, 1);
78 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000079 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000080 PyList_SetItem(cc, i, v);
81 }
82
83 /* Convert the MIN and TIME slots to integer. On some systems, the
84 MIN and TIME slots are the same as the EOF and EOL slots. So we
85 only do this in noncanonical input mode. */
Guido van Rossum36dd0d21996-12-10 15:23:00 +000086 if ((mode.c_lflag & ICANON) == 0) {
Guido van Rossum9adae8e1994-09-12 10:41:22 +000087 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
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, VMIN, v);
91 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
92 if (v == NULL)
Barry Warsaw5709dcf1997-01-10 18:42:18 +000093 goto err;
Guido van Rossum9adae8e1994-09-12 10:41:22 +000094 PyList_SetItem(cc, VTIME, v);
95 }
96
Barry Warsaw5709dcf1997-01-10 18:42:18 +000097 if (!(v = PyList_New(7)))
98 goto err;
99
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000100 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
101 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
102 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
103 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
104 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
105 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
106 PyList_SetItem(v, 6, cc);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000107 if (PyErr_Occurred()){
108 Py_DECREF(v);
109 goto err;
110 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000111 return v;
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000112 err:
113 Py_DECREF(cc);
114 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000115}
116
117/* tcsetattr(fd, when, termios)
118 Set the attributes of the terminal device. */
119
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000120static char termios_tcsetattr__doc__[] = "\
121tcsetattr(fd, when, attributes) -> None\n\
122Set the tty attributes for file descriptor fd.\n\
123The attributes to be set are taken from the attributes argument, which\n\
124is a list like the one returned by tcgetattr(). The when argument\n\
125determines when the attributes are changed: TERMIOS.TCSANOW to\n\
126change immediately, TERMIOS.TCSADRAIN to change after transmitting all\n\
127queued output, or TERMIOS.TCSAFLUSH to change after transmitting all\n\
128queued output and discarding all queued input. ";
129
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000130static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000131termios_tcsetattr(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000132{
133 int fd, when;
134 struct termios mode;
135 speed_t ispeed, ospeed;
136 PyObject *term, *cc, *v;
137 int i;
138
139 if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
140 return NULL;
141 if (!PyList_Check(term) || PyList_Size(term) != 7) {
142 PyErr_SetString(PyExc_TypeError, BAD);
143 return NULL;
144 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000145
Guido van Rossume7c41931998-06-12 14:26:18 +0000146 /* Get the old mode, in case there are any hidden fields... */
147 if (tcgetattr(fd, &mode) == -1)
148 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000149 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
150 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
151 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
152 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
153 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
154 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
155 cc = PyList_GetItem(term, 6);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000156 if (PyErr_Occurred())
157 return NULL;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000158
159 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
160 PyErr_SetString(PyExc_TypeError, BAD);
161 return NULL;
162 }
163
164 for (i = 0; i < NCCS; i++) {
165 v = PyList_GetItem(cc, i);
Barry Warsaw5709dcf1997-01-10 18:42:18 +0000166
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000167 if (PyString_Check(v) && PyString_Size(v) == 1)
168 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
169 else if (PyInt_Check(v))
170 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
171 else {
172 PyErr_SetString(PyExc_TypeError, BAD);
173 return NULL;
174 }
175 }
176
177 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000178 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000179 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000180 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000181 if (tcsetattr(fd, when, &mode) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000182 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000183
184 Py_INCREF(Py_None);
185 return Py_None;
186}
187
188/* tcsendbreak(fd, duration)
189 Generate a break condition. */
190
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000191static char termios_tcsendbreak__doc__[] = "\
192tcsendbreak(fd, duration) -> None\n\
193Send a break on file descriptor fd.\n\
194A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
195has a system dependent meaning. ";
196
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000197static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000198termios_tcsendbreak(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000199{
200 int fd, duration;
201
202 if (!PyArg_Parse(args, "(ii)", &fd, &duration))
203 return NULL;
204 if (tcsendbreak(fd, duration) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000205 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000206
207 Py_INCREF(Py_None);
208 return Py_None;
209}
210
211/* tcdrain(fd)
212 Wait until all queued output to the terminal has been
213 transmitted. */
214
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000215static char termios_tcdrain__doc__[] = "\
216tcdrain(fd) -> None\n\
217Wait until all output written to file descriptor fd has been transmitted. ";
218
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000219static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000220termios_tcdrain(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000221{
222 int fd;
223
224 if (!PyArg_Parse(args, "i", &fd))
225 return NULL;
226 if (tcdrain(fd) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000227 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000228
229 Py_INCREF(Py_None);
230 return Py_None;
231}
232
233/* tcflush(fd, queue)
234 Clear the input and/or output queues associated with
235 the terminal. */
236
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000237static char termios_tcflush__doc__[] = "\
238tcflush(fd, queue) -> None\n\
239Discard queued data on file descriptor fd.\n\
240The queue selector specifies which queue: TERMIOS.TCIFLUSH for the input\n\
241queue, TERMIOS.TCOFLUSH for the output queue, or TERMIOS.TCIOFLUSH for\n\
242both queues. ";
243
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000244static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000245termios_tcflush(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000246{
247 int fd, queue;
248
249 if (!PyArg_Parse(args, "(ii)", &fd, &queue))
250 return NULL;
251 if (tcflush(fd, queue) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000252 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000253
254 Py_INCREF(Py_None);
255 return Py_None;
256}
257
258/* tcflow(fd, action)
259 Perform operations relating to XON/XOFF flow control on
260 the terminal. */
261
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000262static char termios_tcflow__doc__[] = "\
263tcflow(fd, action) -> None\n\
264Suspend or resume input or output on file descriptor fd.\n\
265The action argument can be TERMIOS.TCOOFF to suspend output,\n\
266TERMIOS.TCOON to restart output, TERMIOS.TCIOFF to suspend input,\n\
267or TERMIOS.TCION to restart input. ";
268
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000269static PyObject *
Peter Schneider-Kamp416d4132000-07-10 12:15:54 +0000270termios_tcflow(PyObject *self, PyObject *args)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000271{
272 int fd, action;
273
274 if (!PyArg_Parse(args, "(ii)", &fd, &action))
275 return NULL;
276 if (tcflow(fd, action) == -1)
Guido van Rossumb8ad0241997-07-17 22:55:06 +0000277 return PyErr_SetFromErrno(TermiosError);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000278
279 Py_INCREF(Py_None);
280 return Py_None;
281}
282
283static PyMethodDef termios_methods[] =
284{
Andrew M. Kuchlinga1abb722000-08-03 02:34:44 +0000285 {"tcgetattr", termios_tcgetattr,
286 METH_OLDARGS, termios_tcgetattr__doc__},
287 {"tcsetattr", termios_tcsetattr,
288 METH_OLDARGS, termios_tcsetattr__doc__},
289 {"tcsendbreak", termios_tcsendbreak,
290 METH_OLDARGS, termios_tcsendbreak__doc__},
291 {"tcdrain", termios_tcdrain,
292 METH_OLDARGS, termios_tcdrain__doc__},
293 {"tcflush", termios_tcflush,
294 METH_OLDARGS, termios_tcflush__doc__},
295 {"tcflow", termios_tcflow,
296 METH_OLDARGS, termios_tcflow__doc__},
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000297 {NULL, NULL}
298};
299
Fred Drakedf48d142001-02-27 21:22:39 +0000300
Fred Drake9ef7fa82001-03-01 21:54:49 +0000301#if defined(VSWTCH) && !defined(VSWTC)
302#define VSWTC VSWTCH
303#endif
304
305#if defined(VSWTC) && !defined(VSWTCH)
306#define VSWTCH VSWTC
307#endif
308
Fred Drakedf48d142001-02-27 21:22:39 +0000309static struct constant {
310 char *name;
311 long value;
312} termios_constants[] = {
313 /* cfgetospeed(), cfsetospeed() constants */
314 {"B0", B0},
315 {"B50", B50},
316 {"B75", B75},
317 {"B110", B110},
318 {"B134", B134},
319 {"B150", B150},
320 {"B200", B200},
321 {"B300", B300},
322 {"B600", B600},
323 {"B1200", B1200},
324 {"B1800", B1800},
325 {"B2400", B2400},
326 {"B4800", B4800},
327 {"B9600", B9600},
328 {"B19200", B19200},
329 {"B38400", B38400},
330 {"B57600", B57600},
331 {"B115200", B115200},
Fred Drakeabb379e2001-03-01 03:28:08 +0000332#ifdef B230400
Fred Drakedf48d142001-02-27 21:22:39 +0000333 {"B230400", B230400},
Fred Drakeabb379e2001-03-01 03:28:08 +0000334#endif
Fred Drake9ef7fa82001-03-01 21:54:49 +0000335#ifdef CBAUDEX
Fred Drakedf48d142001-02-27 21:22:39 +0000336 {"CBAUDEX", CBAUDEX},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000337#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000338
339 /* tcsetattr() constants */
340 {"TCSANOW", TCSANOW},
341 {"TCSADRAIN", TCSADRAIN},
342 {"TCSAFLUSH", TCSAFLUSH},
343
344 /* tcflush() constants */
345 {"TCIFLUSH", TCIFLUSH},
346 {"TCOFLUSH", TCOFLUSH},
347 {"TCIOFLUSH", TCIOFLUSH},
348
349 /* tcflow() constants */
350 {"TCOOFF", TCOOFF},
351 {"TCOON", TCOON},
352 {"TCIOFF", TCIOFF},
353 {"TCION", TCION},
354
355 /* struct termios.c_iflag constants */
356 {"IGNBRK", IGNBRK},
357 {"BRKINT", BRKINT},
358 {"IGNPAR", IGNPAR},
359 {"PARMRK", PARMRK},
360 {"INPCK", INPCK},
361 {"ISTRIP", ISTRIP},
362 {"INLCR", INLCR},
363 {"IGNCR", IGNCR},
364 {"ICRNL", ICRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000365#ifdef IUCLC
Fred Drakedf48d142001-02-27 21:22:39 +0000366 {"IUCLC", IUCLC},
Fred Draked85556c2001-03-03 18:08:52 +0000367#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000368 {"IXON", IXON},
369 {"IXANY", IXANY},
370 {"IXOFF", IXOFF},
371 {"IMAXBEL", IMAXBEL},
372
373 /* struct termios.c_oflag constants */
374 {"OPOST", OPOST},
Fred Draked85556c2001-03-03 18:08:52 +0000375#ifdef OLCUC
Fred Drakedf48d142001-02-27 21:22:39 +0000376 {"OLCUC", OLCUC},
Fred Draked85556c2001-03-03 18:08:52 +0000377#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000378 {"ONLCR", ONLCR},
Fred Draked85556c2001-03-03 18:08:52 +0000379#ifdef OCRNL
Fred Drakedf48d142001-02-27 21:22:39 +0000380 {"OCRNL", OCRNL},
Fred Draked85556c2001-03-03 18:08:52 +0000381#endif
382#ifdef ONOCR
Fred Drakedf48d142001-02-27 21:22:39 +0000383 {"ONOCR", ONOCR},
Fred Draked85556c2001-03-03 18:08:52 +0000384#endif
385#ifdef ONLRET
Fred Drakedf48d142001-02-27 21:22:39 +0000386 {"ONLRET", ONLRET},
Fred Draked85556c2001-03-03 18:08:52 +0000387#endif
388#ifdef OFILL
Fred Drakedf48d142001-02-27 21:22:39 +0000389 {"OFILL", OFILL},
Fred Draked85556c2001-03-03 18:08:52 +0000390#endif
391#ifdef OFDEL
Fred Drakedf48d142001-02-27 21:22:39 +0000392 {"OFDEL", OFDEL},
Fred Draked85556c2001-03-03 18:08:52 +0000393#endif
394#ifdef NLDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000395 {"NLDLY", NLDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000396#endif
397#ifdef CRDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000398 {"CRDLY", CRDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000399#endif
400#ifdef TABDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000401 {"TABDLY", TABDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000402#endif
403#ifdef BSDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000404 {"BSDLY", BSDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000405#endif
406#ifdef VTDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000407 {"VTDLY", VTDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000408#endif
409#ifdef FFDLY
Fred Drakedf48d142001-02-27 21:22:39 +0000410 {"FFDLY", FFDLY},
Fred Draked85556c2001-03-03 18:08:52 +0000411#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000412
413 /* struct termios.c_oflag-related values (delay mask) */
Fred Draked85556c2001-03-03 18:08:52 +0000414#ifdef NL0
Fred Drakedf48d142001-02-27 21:22:39 +0000415 {"NL0", NL0},
Fred Draked85556c2001-03-03 18:08:52 +0000416#endif
417#ifdef NL1
Fred Drakedf48d142001-02-27 21:22:39 +0000418 {"NL1", NL1},
Fred Draked85556c2001-03-03 18:08:52 +0000419#endif
420#ifdef CR0
Fred Drakedf48d142001-02-27 21:22:39 +0000421 {"CR0", CR0},
Fred Draked85556c2001-03-03 18:08:52 +0000422#endif
423#ifdef CR1
Fred Drakedf48d142001-02-27 21:22:39 +0000424 {"CR1", CR1},
Fred Draked85556c2001-03-03 18:08:52 +0000425#endif
426#ifdef CR2
Fred Drakedf48d142001-02-27 21:22:39 +0000427 {"CR2", CR2},
Fred Draked85556c2001-03-03 18:08:52 +0000428#endif
429#ifdef CR3
Fred Drakedf48d142001-02-27 21:22:39 +0000430 {"CR3", CR3},
Fred Draked85556c2001-03-03 18:08:52 +0000431#endif
432#ifdef TAB0
Fred Drakedf48d142001-02-27 21:22:39 +0000433 {"TAB0", TAB0},
Fred Draked85556c2001-03-03 18:08:52 +0000434#endif
435#ifdef TAB1
Fred Drakedf48d142001-02-27 21:22:39 +0000436 {"TAB1", TAB1},
Fred Draked85556c2001-03-03 18:08:52 +0000437#endif
438#ifdef TAB2
Fred Drakedf48d142001-02-27 21:22:39 +0000439 {"TAB2", TAB2},
Fred Draked85556c2001-03-03 18:08:52 +0000440#endif
441#ifdef TAB3
Fred Drakedf48d142001-02-27 21:22:39 +0000442 {"TAB3", TAB3},
Fred Draked85556c2001-03-03 18:08:52 +0000443#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000444#ifdef XTABS
Fred Drakedf48d142001-02-27 21:22:39 +0000445 {"XTABS", XTABS},
Fred Drakededbebf2001-03-02 06:50:58 +0000446#endif
Fred Draked85556c2001-03-03 18:08:52 +0000447#ifdef BS0
Fred Drakedf48d142001-02-27 21:22:39 +0000448 {"BS0", BS0},
Fred Draked85556c2001-03-03 18:08:52 +0000449#endif
450#ifdef BS1
Fred Drakedf48d142001-02-27 21:22:39 +0000451 {"BS1", BS1},
Fred Draked85556c2001-03-03 18:08:52 +0000452#endif
453#ifdef VT0
Fred Drakedf48d142001-02-27 21:22:39 +0000454 {"VT0", VT0},
Fred Draked85556c2001-03-03 18:08:52 +0000455#endif
456#ifdef VT1
Fred Drakedf48d142001-02-27 21:22:39 +0000457 {"VT1", VT1},
Fred Draked85556c2001-03-03 18:08:52 +0000458#endif
459#ifdef FF0
Fred Drakedf48d142001-02-27 21:22:39 +0000460 {"FF0", FF0},
Fred Draked85556c2001-03-03 18:08:52 +0000461#endif
462#ifdef FF1
Fred Drakedf48d142001-02-27 21:22:39 +0000463 {"FF1", FF1},
Fred Draked85556c2001-03-03 18:08:52 +0000464#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000465
466 /* struct termios.c_cflag constants */
467 {"CSIZE", CSIZE},
468 {"CSTOPB", CSTOPB},
469 {"CREAD", CREAD},
470 {"PARENB", PARENB},
471 {"PARODD", PARODD},
472 {"HUPCL", HUPCL},
473 {"CLOCAL", CLOCAL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000474#ifdef CIBAUD
Fred Drakedf48d142001-02-27 21:22:39 +0000475 {"CIBAUD", CIBAUD},
Fred Drakeabb379e2001-03-01 03:28:08 +0000476#endif
Fred Drakededbebf2001-03-02 06:50:58 +0000477#ifdef CRTSCTS
478 {"CRTSCTS", (long)CRTSCTS},
479#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000480
481 /* struct termios.c_cflag-related values (character size) */
482 {"CS5", CS5},
483 {"CS6", CS6},
484 {"CS7", CS7},
485 {"CS8", CS8},
486
487 /* struct termios.c_lflag constants */
488 {"ISIG", ISIG},
489 {"ICANON", ICANON},
Fred Drakeabb379e2001-03-01 03:28:08 +0000490#ifdef XCASE
Fred Drakedf48d142001-02-27 21:22:39 +0000491 {"XCASE", XCASE},
Fred Drakeabb379e2001-03-01 03:28:08 +0000492#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000493 {"ECHO", ECHO},
494 {"ECHOE", ECHOE},
495 {"ECHOK", ECHOK},
496 {"ECHONL", ECHONL},
497 {"ECHOCTL", ECHOCTL},
Fred Drakeabb379e2001-03-01 03:28:08 +0000498#ifdef ECHOPRT
Fred Drakedf48d142001-02-27 21:22:39 +0000499 {"ECHOPRT", ECHOPRT},
Fred Drakeabb379e2001-03-01 03:28:08 +0000500#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000501 {"ECHOKE", ECHOKE},
502 {"FLUSHO", FLUSHO},
503 {"NOFLSH", NOFLSH},
504 {"TOSTOP", TOSTOP},
Fred Drakeabb379e2001-03-01 03:28:08 +0000505#ifdef PENDIN
Fred Drakedf48d142001-02-27 21:22:39 +0000506 {"PENDIN", PENDIN},
Fred Drakeabb379e2001-03-01 03:28:08 +0000507#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000508 {"IEXTEN", IEXTEN},
509
510 /* indexes into the control chars array returned by tcgetattr() */
511 {"VINTR", VINTR},
512 {"VQUIT", VQUIT},
513 {"VERASE", VERASE},
514 {"VKILL", VKILL},
515 {"VEOF", VEOF},
516 {"VTIME", VTIME},
517 {"VMIN", VMIN},
Fred Drakededbebf2001-03-02 06:50:58 +0000518#ifdef VSWTC
519 /* The #defines above ensure that if either is defined, both are,
520 * but both may be omitted by the system headers. ;-( */
Fred Drakedf48d142001-02-27 21:22:39 +0000521 {"VSWTC", VSWTC},
Fred Drake9ef7fa82001-03-01 21:54:49 +0000522 {"VSWTCH", VSWTCH},
Fred Drakededbebf2001-03-02 06:50:58 +0000523#endif
Fred Drakedf48d142001-02-27 21:22:39 +0000524 {"VSTART", VSTART},
525 {"VSTOP", VSTOP},
526 {"VSUSP", VSUSP},
527 {"VEOL", VEOL},
528 {"VREPRINT", VREPRINT},
529 {"VDISCARD", VDISCARD},
530 {"VWERASE", VWERASE},
531 {"VLNEXT", VLNEXT},
532 {"VEOL2", VEOL2},
533
Fred Drake55a00342001-03-26 17:14:02 +0000534
535#ifdef B460800
536 {"B460800", B460800},
537#endif
538#ifdef CBAUD
539 {"CBAUD", CBAUD},
540#endif
541#ifdef CDEL
542 {"CDEL", CDEL},
543#endif
544#ifdef CDSUSP
545 {"CDSUSP", CDSUSP},
546#endif
547#ifdef CEOF
548 {"CEOF", CEOF},
549#endif
550#ifdef CEOL
551 {"CEOL", CEOL},
552#endif
553#ifdef CEOL2
554 {"CEOL2", CEOL2},
555#endif
556#ifdef CEOT
557 {"CEOT", CEOT},
558#endif
559#ifdef CERASE
560 {"CERASE", CERASE},
561#endif
562#ifdef CESC
563 {"CESC", CESC},
564#endif
565#ifdef CFLUSH
566 {"CFLUSH", CFLUSH},
567#endif
568#ifdef CINTR
569 {"CINTR", CINTR},
570#endif
571#ifdef CKILL
572 {"CKILL", CKILL},
573#endif
574#ifdef CLNEXT
575 {"CLNEXT", CLNEXT},
576#endif
577#ifdef CNUL
578 {"CNUL", CNUL},
579#endif
580#ifdef COMMON
581 {"COMMON", COMMON},
582#endif
583#ifdef CQUIT
584 {"CQUIT", CQUIT},
585#endif
586#ifdef CRPRNT
587 {"CRPRNT", CRPRNT},
588#endif
589#ifdef CSTART
590 {"CSTART", CSTART},
591#endif
592#ifdef CSTOP
593 {"CSTOP", CSTOP},
594#endif
595#ifdef CSUSP
596 {"CSUSP", CSUSP},
597#endif
598#ifdef CSWTCH
599 {"CSWTCH", CSWTCH},
600#endif
601#ifdef CWERASE
602 {"CWERASE", CWERASE},
603#endif
604#ifdef EXTA
605 {"EXTA", EXTA},
606#endif
607#ifdef EXTB
608 {"EXTB", EXTB},
609#endif
610#ifdef FIOASYNC
611 {"FIOASYNC", FIOASYNC},
612#endif
613#ifdef FIOCLEX
614 {"FIOCLEX", FIOCLEX},
615#endif
616#ifdef FIONBIO
617 {"FIONBIO", FIONBIO},
618#endif
619#ifdef FIONCLEX
620 {"FIONCLEX", FIONCLEX},
621#endif
622#ifdef FIONREAD
623 {"FIONREAD", FIONREAD},
624#endif
625#ifdef IBSHIFT
626 {"IBSHIFT", IBSHIFT},
627#endif
628#ifdef INIT_C_CC
629 {"INIT_C_CC", INIT_C_CC},
630#endif
631#ifdef IOCSIZE_MASK
632 {"IOCSIZE_MASK", IOCSIZE_MASK},
633#endif
634#ifdef IOCSIZE_SHIFT
635 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
636#endif
637#ifdef NCC
638 {"NCC", NCC},
639#endif
640#ifdef NCCS
641 {"NCCS", NCCS},
642#endif
643#ifdef NSWTCH
644 {"NSWTCH", NSWTCH},
645#endif
646#ifdef N_MOUSE
647 {"N_MOUSE", N_MOUSE},
648#endif
649#ifdef N_PPP
650 {"N_PPP", N_PPP},
651#endif
652#ifdef N_SLIP
653 {"N_SLIP", N_SLIP},
654#endif
655#ifdef N_STRIP
656 {"N_STRIP", N_STRIP},
657#endif
658#ifdef N_TTY
659 {"N_TTY", N_TTY},
660#endif
661#ifdef TCFLSH
662 {"TCFLSH", TCFLSH},
663#endif
664#ifdef TCGETA
665 {"TCGETA", TCGETA},
666#endif
667#ifdef TCGETS
668 {"TCGETS", TCGETS},
669#endif
670#ifdef TCSBRK
671 {"TCSBRK", TCSBRK},
672#endif
673#ifdef TCSBRKP
674 {"TCSBRKP", TCSBRKP},
675#endif
676#ifdef TCSETA
677 {"TCSETA", TCSETA},
678#endif
679#ifdef TCSETAF
680 {"TCSETAF", TCSETAF},
681#endif
682#ifdef TCSETAW
683 {"TCSETAW", TCSETAW},
684#endif
685#ifdef TCSETS
686 {"TCSETS", TCSETS},
687#endif
688#ifdef TCSETSF
689 {"TCSETSF", TCSETSF},
690#endif
691#ifdef TCSETSW
692 {"TCSETSW", TCSETSW},
693#endif
694#ifdef TCXONC
695 {"TCXONC", TCXONC},
696#endif
697#ifdef TIOCCONS
698 {"TIOCCONS", TIOCCONS},
699#endif
700#ifdef TIOCEXCL
701 {"TIOCEXCL", TIOCEXCL},
702#endif
703#ifdef TIOCGETD
704 {"TIOCGETD", TIOCGETD},
705#endif
706#ifdef TIOCGICOUNT
707 {"TIOCGICOUNT", TIOCGICOUNT},
708#endif
709#ifdef TIOCGLCKTRMIOS
710 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
711#endif
712#ifdef TIOCGPGRP
713 {"TIOCGPGRP", TIOCGPGRP},
714#endif
715#ifdef TIOCGSERIAL
716 {"TIOCGSERIAL", TIOCGSERIAL},
717#endif
718#ifdef TIOCGSOFTCAR
719 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
720#endif
721#ifdef TIOCGWINSZ
722 {"TIOCGWINSZ", TIOCGWINSZ},
723#endif
724#ifdef TIOCINQ
725 {"TIOCINQ", TIOCINQ},
726#endif
727#ifdef TIOCLINUX
728 {"TIOCLINUX", TIOCLINUX},
729#endif
730#ifdef TIOCMBIC
731 {"TIOCMBIC", TIOCMBIC},
732#endif
733#ifdef TIOCMBIS
734 {"TIOCMBIS", TIOCMBIS},
735#endif
736#ifdef TIOCMGET
737 {"TIOCMGET", TIOCMGET},
738#endif
739#ifdef TIOCMIWAIT
740 {"TIOCMIWAIT", TIOCMIWAIT},
741#endif
742#ifdef TIOCMSET
743 {"TIOCMSET", TIOCMSET},
744#endif
745#ifdef TIOCM_CAR
746 {"TIOCM_CAR", TIOCM_CAR},
747#endif
748#ifdef TIOCM_CD
749 {"TIOCM_CD", TIOCM_CD},
750#endif
751#ifdef TIOCM_CTS
752 {"TIOCM_CTS", TIOCM_CTS},
753#endif
754#ifdef TIOCM_DSR
755 {"TIOCM_DSR", TIOCM_DSR},
756#endif
757#ifdef TIOCM_DTR
758 {"TIOCM_DTR", TIOCM_DTR},
759#endif
760#ifdef TIOCM_LE
761 {"TIOCM_LE", TIOCM_LE},
762#endif
763#ifdef TIOCM_RI
764 {"TIOCM_RI", TIOCM_RI},
765#endif
766#ifdef TIOCM_RNG
767 {"TIOCM_RNG", TIOCM_RNG},
768#endif
769#ifdef TIOCM_RTS
770 {"TIOCM_RTS", TIOCM_RTS},
771#endif
772#ifdef TIOCM_SR
773 {"TIOCM_SR", TIOCM_SR},
774#endif
775#ifdef TIOCM_ST
776 {"TIOCM_ST", TIOCM_ST},
777#endif
778#ifdef TIOCNOTTY
779 {"TIOCNOTTY", TIOCNOTTY},
780#endif
781#ifdef TIOCNXCL
782 {"TIOCNXCL", TIOCNXCL},
783#endif
784#ifdef TIOCOUTQ
785 {"TIOCOUTQ", TIOCOUTQ},
786#endif
787#ifdef TIOCPKT
788 {"TIOCPKT", TIOCPKT},
789#endif
790#ifdef TIOCPKT_DATA
791 {"TIOCPKT_DATA", TIOCPKT_DATA},
792#endif
793#ifdef TIOCPKT_DOSTOP
794 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
795#endif
796#ifdef TIOCPKT_FLUSHREAD
797 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
798#endif
799#ifdef TIOCPKT_FLUSHWRITE
800 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
801#endif
802#ifdef TIOCPKT_NOSTOP
803 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
804#endif
805#ifdef TIOCPKT_START
806 {"TIOCPKT_START", TIOCPKT_START},
807#endif
808#ifdef TIOCPKT_STOP
809 {"TIOCPKT_STOP", TIOCPKT_STOP},
810#endif
811#ifdef TIOCSCTTY
812 {"TIOCSCTTY", TIOCSCTTY},
813#endif
814#ifdef TIOCSERCONFIG
815 {"TIOCSERCONFIG", TIOCSERCONFIG},
816#endif
817#ifdef TIOCSERGETLSR
818 {"TIOCSERGETLSR", TIOCSERGETLSR},
819#endif
820#ifdef TIOCSERGETMULTI
821 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
822#endif
823#ifdef TIOCSERGSTRUCT
824 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
825#endif
826#ifdef TIOCSERGWILD
827 {"TIOCSERGWILD", TIOCSERGWILD},
828#endif
829#ifdef TIOCSERSETMULTI
830 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
831#endif
832#ifdef TIOCSERSWILD
833 {"TIOCSERSWILD", TIOCSERSWILD},
834#endif
835#ifdef TIOCSER_TEMT
836 {"TIOCSER_TEMT", TIOCSER_TEMT},
837#endif
838#ifdef TIOCSETD
839 {"TIOCSETD", TIOCSETD},
840#endif
841#ifdef TIOCSLCKTRMIOS
842 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
843#endif
844#ifdef TIOCSPGRP
845 {"TIOCSPGRP", TIOCSPGRP},
846#endif
847#ifdef TIOCSSERIAL
848 {"TIOCSSERIAL", TIOCSSERIAL},
849#endif
850#ifdef TIOCSSOFTCAR
851 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
852#endif
853#ifdef TIOCSTI
854 {"TIOCSTI", TIOCSTI},
855#endif
856#ifdef TIOCSWINSZ
857 {"TIOCSWINSZ", TIOCSWINSZ},
858#endif
859#ifdef TIOCTTYGSTRUCT
860 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
861#endif
862
Fred Drakedf48d142001-02-27 21:22:39 +0000863 /* sentinel */
864 {NULL, 0}
865};
866
867
Guido van Rossum3886bb61998-12-04 18:50:17 +0000868DL_EXPORT(void)
Thomas Woutersf3f33dc2000-07-21 06:00:07 +0000869PyInit_termios(void)
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000870{
871 PyObject *m, *d;
Fred Drakedf48d142001-02-27 21:22:39 +0000872 struct constant *constant = termios_constants;
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000873
Guido van Rossum1aca4d81998-03-03 22:10:18 +0000874 m = Py_InitModule4("termios", termios_methods, termios__doc__,
875 (PyObject *)NULL, PYTHON_API_VERSION);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000876
877 d = PyModule_GetDict(m);
Guido van Rossum0cb96de1997-10-01 04:29:29 +0000878 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000879 PyDict_SetItemString(d, "error", TermiosError);
Fred Drakedf48d142001-02-27 21:22:39 +0000880
881 while (constant->name != NULL) {
882 PyModule_AddIntConstant(m, constant->name, constant->value);
883 ++constant;
884 }
Guido van Rossum9adae8e1994-09-12 10:41:22 +0000885}