Line data Source code
1 : /* termiosmodule.c -- POSIX terminal I/O module implementation. */
2 :
3 : #include "Python.h"
4 :
5 : /* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
6 : is defined, so we define it here. */
7 : #if defined(__sgi)
8 : #define CTRL(c) ((c)&037)
9 : #endif
10 :
11 : #include <termios.h>
12 : #include <sys/ioctl.h>
13 :
14 : /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
15 : * MDTR, MRI, and MRTS (appearantly used internally by some things
16 : * defined as macros; these are not used here directly).
17 : */
18 : #ifdef HAVE_SYS_MODEM_H
19 : #include <sys/modem.h>
20 : #endif
21 : /* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
22 : #ifdef HAVE_SYS_BSDTTY_H
23 : #include <sys/bsdtty.h>
24 : #endif
25 :
26 : PyDoc_STRVAR(termios__doc__,
27 : "This module provides an interface to the Posix calls for tty I/O control.\n\
28 : For a complete description of these calls, see the Posix or Unix manual\n\
29 : pages. It is only available for those Unix versions that support Posix\n\
30 : termios style tty I/O control.\n\
31 : \n\
32 : All functions in this module take a file descriptor fd as their first\n\
33 : argument. This can be an integer file descriptor, such as returned by\n\
34 : sys.stdin.fileno(), or a file object, such as sys.stdin itself.");
35 :
36 : static PyObject *TermiosError;
37 :
38 0 : static int fdconv(PyObject* obj, void* p)
39 : {
40 : int fd;
41 :
42 0 : fd = PyObject_AsFileDescriptor(obj);
43 0 : if (fd >= 0) {
44 0 : *(int*)p = fd;
45 0 : return 1;
46 : }
47 0 : return 0;
48 : }
49 :
50 : PyDoc_STRVAR(termios_tcgetattr__doc__,
51 : "tcgetattr(fd) -> list_of_attrs\n\
52 : \n\
53 : Get the tty attributes for file descriptor fd, as follows:\n\
54 : [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
55 : of the tty special characters (each a string of length 1, except the items\n\
56 : with indices VMIN and VTIME, which are integers when these fields are\n\
57 : defined). The interpretation of the flags and the speeds as well as the\n\
58 : indexing in the cc array must be done using the symbolic constants defined\n\
59 : in this module.");
60 :
61 : static PyObject *
62 0 : termios_tcgetattr(PyObject *self, PyObject *args)
63 : {
64 : int fd;
65 : struct termios mode;
66 : PyObject *cc;
67 : speed_t ispeed, ospeed;
68 : PyObject *v;
69 : int i;
70 : char ch;
71 :
72 0 : if (!PyArg_ParseTuple(args, "O&:tcgetattr",
73 : fdconv, (void*)&fd))
74 0 : return NULL;
75 :
76 0 : if (tcgetattr(fd, &mode) == -1)
77 0 : return PyErr_SetFromErrno(TermiosError);
78 :
79 0 : ispeed = cfgetispeed(&mode);
80 0 : ospeed = cfgetospeed(&mode);
81 :
82 0 : cc = PyList_New(NCCS);
83 0 : if (cc == NULL)
84 0 : return NULL;
85 0 : for (i = 0; i < NCCS; i++) {
86 0 : ch = (char)mode.c_cc[i];
87 0 : v = PyBytes_FromStringAndSize(&ch, 1);
88 0 : if (v == NULL)
89 0 : goto err;
90 0 : PyList_SetItem(cc, i, v);
91 : }
92 :
93 : /* Convert the MIN and TIME slots to integer. On some systems, the
94 : MIN and TIME slots are the same as the EOF and EOL slots. So we
95 : only do this in noncanonical input mode. */
96 0 : if ((mode.c_lflag & ICANON) == 0) {
97 0 : v = PyLong_FromLong((long)mode.c_cc[VMIN]);
98 0 : if (v == NULL)
99 0 : goto err;
100 0 : PyList_SetItem(cc, VMIN, v);
101 0 : v = PyLong_FromLong((long)mode.c_cc[VTIME]);
102 0 : if (v == NULL)
103 0 : goto err;
104 0 : PyList_SetItem(cc, VTIME, v);
105 : }
106 :
107 0 : if (!(v = PyList_New(7)))
108 0 : goto err;
109 :
110 0 : PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
111 0 : PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
112 0 : PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
113 0 : PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
114 0 : PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
115 0 : PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
116 0 : PyList_SetItem(v, 6, cc);
117 0 : if (PyErr_Occurred()){
118 0 : Py_DECREF(v);
119 0 : goto err;
120 : }
121 0 : return v;
122 : err:
123 0 : Py_DECREF(cc);
124 0 : return NULL;
125 : }
126 :
127 : PyDoc_STRVAR(termios_tcsetattr__doc__,
128 : "tcsetattr(fd, when, attributes) -> None\n\
129 : \n\
130 : Set the tty attributes for file descriptor fd.\n\
131 : The attributes to be set are taken from the attributes argument, which\n\
132 : is a list like the one returned by tcgetattr(). The when argument\n\
133 : determines when the attributes are changed: termios.TCSANOW to\n\
134 : change immediately, termios.TCSADRAIN to change after transmitting all\n\
135 : queued output, or termios.TCSAFLUSH to change after transmitting all\n\
136 : queued output and discarding all queued input. ");
137 :
138 : static PyObject *
139 0 : termios_tcsetattr(PyObject *self, PyObject *args)
140 : {
141 : int fd, when;
142 : struct termios mode;
143 : speed_t ispeed, ospeed;
144 : PyObject *term, *cc, *v;
145 : int i;
146 :
147 0 : if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
148 : fdconv, &fd, &when, &term))
149 0 : return NULL;
150 0 : if (!PyList_Check(term) || PyList_Size(term) != 7) {
151 0 : PyErr_SetString(PyExc_TypeError,
152 : "tcsetattr, arg 3: must be 7 element list");
153 0 : return NULL;
154 : }
155 :
156 : /* Get the old mode, in case there are any hidden fields... */
157 0 : if (tcgetattr(fd, &mode) == -1)
158 0 : return PyErr_SetFromErrno(TermiosError);
159 0 : mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
160 0 : mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
161 0 : mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
162 0 : mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
163 0 : ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
164 0 : ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
165 0 : cc = PyList_GetItem(term, 6);
166 0 : if (PyErr_Occurred())
167 0 : return NULL;
168 :
169 0 : if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
170 0 : PyErr_Format(PyExc_TypeError,
171 : "tcsetattr: attributes[6] must be %d element list",
172 : NCCS);
173 0 : return NULL;
174 : }
175 :
176 0 : for (i = 0; i < NCCS; i++) {
177 0 : v = PyList_GetItem(cc, i);
178 :
179 0 : if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
180 0 : mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
181 0 : else if (PyLong_Check(v))
182 0 : mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
183 : else {
184 0 : PyErr_SetString(PyExc_TypeError,
185 : "tcsetattr: elements of attributes must be characters or integers");
186 0 : return NULL;
187 : }
188 : }
189 :
190 0 : if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
191 0 : return PyErr_SetFromErrno(TermiosError);
192 0 : if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
193 0 : return PyErr_SetFromErrno(TermiosError);
194 0 : if (tcsetattr(fd, when, &mode) == -1)
195 0 : return PyErr_SetFromErrno(TermiosError);
196 :
197 0 : Py_INCREF(Py_None);
198 0 : return Py_None;
199 : }
200 :
201 : PyDoc_STRVAR(termios_tcsendbreak__doc__,
202 : "tcsendbreak(fd, duration) -> None\n\
203 : \n\
204 : Send a break on file descriptor fd.\n\
205 : A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
206 : has a system dependent meaning.");
207 :
208 : static PyObject *
209 0 : termios_tcsendbreak(PyObject *self, PyObject *args)
210 : {
211 : int fd, duration;
212 :
213 0 : if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
214 : fdconv, &fd, &duration))
215 0 : return NULL;
216 0 : if (tcsendbreak(fd, duration) == -1)
217 0 : return PyErr_SetFromErrno(TermiosError);
218 :
219 0 : Py_INCREF(Py_None);
220 0 : return Py_None;
221 : }
222 :
223 : PyDoc_STRVAR(termios_tcdrain__doc__,
224 : "tcdrain(fd) -> None\n\
225 : \n\
226 : Wait until all output written to file descriptor fd has been transmitted.");
227 :
228 : static PyObject *
229 0 : termios_tcdrain(PyObject *self, PyObject *args)
230 : {
231 : int fd;
232 :
233 0 : if (!PyArg_ParseTuple(args, "O&:tcdrain",
234 : fdconv, &fd))
235 0 : return NULL;
236 0 : if (tcdrain(fd) == -1)
237 0 : return PyErr_SetFromErrno(TermiosError);
238 :
239 0 : Py_INCREF(Py_None);
240 0 : return Py_None;
241 : }
242 :
243 : PyDoc_STRVAR(termios_tcflush__doc__,
244 : "tcflush(fd, queue) -> None\n\
245 : \n\
246 : Discard queued data on file descriptor fd.\n\
247 : The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
248 : queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
249 : both queues. ");
250 :
251 : static PyObject *
252 0 : termios_tcflush(PyObject *self, PyObject *args)
253 : {
254 : int fd, queue;
255 :
256 0 : if (!PyArg_ParseTuple(args, "O&i:tcflush",
257 : fdconv, &fd, &queue))
258 0 : return NULL;
259 0 : if (tcflush(fd, queue) == -1)
260 0 : return PyErr_SetFromErrno(TermiosError);
261 :
262 0 : Py_INCREF(Py_None);
263 0 : return Py_None;
264 : }
265 :
266 : PyDoc_STRVAR(termios_tcflow__doc__,
267 : "tcflow(fd, action) -> None\n\
268 : \n\
269 : Suspend or resume input or output on file descriptor fd.\n\
270 : The action argument can be termios.TCOOFF to suspend output,\n\
271 : termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
272 : or termios.TCION to restart input.");
273 :
274 : static PyObject *
275 0 : termios_tcflow(PyObject *self, PyObject *args)
276 : {
277 : int fd, action;
278 :
279 0 : if (!PyArg_ParseTuple(args, "O&i:tcflow",
280 : fdconv, &fd, &action))
281 0 : return NULL;
282 0 : if (tcflow(fd, action) == -1)
283 0 : return PyErr_SetFromErrno(TermiosError);
284 :
285 0 : Py_INCREF(Py_None);
286 0 : return Py_None;
287 : }
288 :
289 : static PyMethodDef termios_methods[] =
290 : {
291 : {"tcgetattr", termios_tcgetattr,
292 : METH_VARARGS, termios_tcgetattr__doc__},
293 : {"tcsetattr", termios_tcsetattr,
294 : METH_VARARGS, termios_tcsetattr__doc__},
295 : {"tcsendbreak", termios_tcsendbreak,
296 : METH_VARARGS, termios_tcsendbreak__doc__},
297 : {"tcdrain", termios_tcdrain,
298 : METH_VARARGS, termios_tcdrain__doc__},
299 : {"tcflush", termios_tcflush,
300 : METH_VARARGS, termios_tcflush__doc__},
301 : {"tcflow", termios_tcflow,
302 : METH_VARARGS, termios_tcflow__doc__},
303 : {NULL, NULL}
304 : };
305 :
306 :
307 : #if defined(VSWTCH) && !defined(VSWTC)
308 : #define VSWTC VSWTCH
309 : #endif
310 :
311 : #if defined(VSWTC) && !defined(VSWTCH)
312 : #define VSWTCH VSWTC
313 : #endif
314 :
315 : static struct constant {
316 : char *name;
317 : long value;
318 : } termios_constants[] = {
319 : /* cfgetospeed(), cfsetospeed() constants */
320 : {"B0", B0},
321 : {"B50", B50},
322 : {"B75", B75},
323 : {"B110", B110},
324 : {"B134", B134},
325 : {"B150", B150},
326 : {"B200", B200},
327 : {"B300", B300},
328 : {"B600", B600},
329 : {"B1200", B1200},
330 : {"B1800", B1800},
331 : {"B2400", B2400},
332 : {"B4800", B4800},
333 : {"B9600", B9600},
334 : {"B19200", B19200},
335 : {"B38400", B38400},
336 : #ifdef B57600
337 : {"B57600", B57600},
338 : #endif
339 : #ifdef B115200
340 : {"B115200", B115200},
341 : #endif
342 : #ifdef B230400
343 : {"B230400", B230400},
344 : #endif
345 : #ifdef B460800
346 : {"B460800", B460800},
347 : #endif
348 : #ifdef B500000
349 : {"B500000", B500000},
350 : #endif
351 : #ifdef B576000
352 : {"B576000", B576000},
353 : #endif
354 : #ifdef B921600
355 : {"B921600", B921600},
356 : #endif
357 : #ifdef B1000000
358 : {"B1000000", B1000000},
359 : #endif
360 : #ifdef B1152000
361 : {"B1152000", B1152000},
362 : #endif
363 : #ifdef B1500000
364 : {"B1500000", B1500000},
365 : #endif
366 : #ifdef B2000000
367 : {"B2000000", B2000000},
368 : #endif
369 : #ifdef B2500000
370 : {"B2500000", B2500000},
371 : #endif
372 : #ifdef B3000000
373 : {"B3000000", B3000000},
374 : #endif
375 : #ifdef B3500000
376 : {"B3500000", B3500000},
377 : #endif
378 : #ifdef B4000000
379 : {"B4000000", B4000000},
380 : #endif
381 :
382 : #ifdef CBAUDEX
383 : {"CBAUDEX", CBAUDEX},
384 : #endif
385 :
386 : /* tcsetattr() constants */
387 : {"TCSANOW", TCSANOW},
388 : {"TCSADRAIN", TCSADRAIN},
389 : {"TCSAFLUSH", TCSAFLUSH},
390 : #ifdef TCSASOFT
391 : {"TCSASOFT", TCSASOFT},
392 : #endif
393 :
394 : /* tcflush() constants */
395 : {"TCIFLUSH", TCIFLUSH},
396 : {"TCOFLUSH", TCOFLUSH},
397 : {"TCIOFLUSH", TCIOFLUSH},
398 :
399 : /* tcflow() constants */
400 : {"TCOOFF", TCOOFF},
401 : {"TCOON", TCOON},
402 : {"TCIOFF", TCIOFF},
403 : {"TCION", TCION},
404 :
405 : /* struct termios.c_iflag constants */
406 : {"IGNBRK", IGNBRK},
407 : {"BRKINT", BRKINT},
408 : {"IGNPAR", IGNPAR},
409 : {"PARMRK", PARMRK},
410 : {"INPCK", INPCK},
411 : {"ISTRIP", ISTRIP},
412 : {"INLCR", INLCR},
413 : {"IGNCR", IGNCR},
414 : {"ICRNL", ICRNL},
415 : #ifdef IUCLC
416 : {"IUCLC", IUCLC},
417 : #endif
418 : {"IXON", IXON},
419 : {"IXANY", IXANY},
420 : {"IXOFF", IXOFF},
421 : #ifdef IMAXBEL
422 : {"IMAXBEL", IMAXBEL},
423 : #endif
424 :
425 : /* struct termios.c_oflag constants */
426 : {"OPOST", OPOST},
427 : #ifdef OLCUC
428 : {"OLCUC", OLCUC},
429 : #endif
430 : #ifdef ONLCR
431 : {"ONLCR", ONLCR},
432 : #endif
433 : #ifdef OCRNL
434 : {"OCRNL", OCRNL},
435 : #endif
436 : #ifdef ONOCR
437 : {"ONOCR", ONOCR},
438 : #endif
439 : #ifdef ONLRET
440 : {"ONLRET", ONLRET},
441 : #endif
442 : #ifdef OFILL
443 : {"OFILL", OFILL},
444 : #endif
445 : #ifdef OFDEL
446 : {"OFDEL", OFDEL},
447 : #endif
448 : #ifdef NLDLY
449 : {"NLDLY", NLDLY},
450 : #endif
451 : #ifdef CRDLY
452 : {"CRDLY", CRDLY},
453 : #endif
454 : #ifdef TABDLY
455 : {"TABDLY", TABDLY},
456 : #endif
457 : #ifdef BSDLY
458 : {"BSDLY", BSDLY},
459 : #endif
460 : #ifdef VTDLY
461 : {"VTDLY", VTDLY},
462 : #endif
463 : #ifdef FFDLY
464 : {"FFDLY", FFDLY},
465 : #endif
466 :
467 : /* struct termios.c_oflag-related values (delay mask) */
468 : #ifdef NL0
469 : {"NL0", NL0},
470 : #endif
471 : #ifdef NL1
472 : {"NL1", NL1},
473 : #endif
474 : #ifdef CR0
475 : {"CR0", CR0},
476 : #endif
477 : #ifdef CR1
478 : {"CR1", CR1},
479 : #endif
480 : #ifdef CR2
481 : {"CR2", CR2},
482 : #endif
483 : #ifdef CR3
484 : {"CR3", CR3},
485 : #endif
486 : #ifdef TAB0
487 : {"TAB0", TAB0},
488 : #endif
489 : #ifdef TAB1
490 : {"TAB1", TAB1},
491 : #endif
492 : #ifdef TAB2
493 : {"TAB2", TAB2},
494 : #endif
495 : #ifdef TAB3
496 : {"TAB3", TAB3},
497 : #endif
498 : #ifdef XTABS
499 : {"XTABS", XTABS},
500 : #endif
501 : #ifdef BS0
502 : {"BS0", BS0},
503 : #endif
504 : #ifdef BS1
505 : {"BS1", BS1},
506 : #endif
507 : #ifdef VT0
508 : {"VT0", VT0},
509 : #endif
510 : #ifdef VT1
511 : {"VT1", VT1},
512 : #endif
513 : #ifdef FF0
514 : {"FF0", FF0},
515 : #endif
516 : #ifdef FF1
517 : {"FF1", FF1},
518 : #endif
519 :
520 : /* struct termios.c_cflag constants */
521 : {"CSIZE", CSIZE},
522 : {"CSTOPB", CSTOPB},
523 : {"CREAD", CREAD},
524 : {"PARENB", PARENB},
525 : {"PARODD", PARODD},
526 : {"HUPCL", HUPCL},
527 : {"CLOCAL", CLOCAL},
528 : #ifdef CIBAUD
529 : {"CIBAUD", CIBAUD},
530 : #endif
531 : #ifdef CRTSCTS
532 : {"CRTSCTS", (long)CRTSCTS},
533 : #endif
534 :
535 : /* struct termios.c_cflag-related values (character size) */
536 : {"CS5", CS5},
537 : {"CS6", CS6},
538 : {"CS7", CS7},
539 : {"CS8", CS8},
540 :
541 : /* struct termios.c_lflag constants */
542 : {"ISIG", ISIG},
543 : {"ICANON", ICANON},
544 : #ifdef XCASE
545 : {"XCASE", XCASE},
546 : #endif
547 : {"ECHO", ECHO},
548 : {"ECHOE", ECHOE},
549 : {"ECHOK", ECHOK},
550 : {"ECHONL", ECHONL},
551 : #ifdef ECHOCTL
552 : {"ECHOCTL", ECHOCTL},
553 : #endif
554 : #ifdef ECHOPRT
555 : {"ECHOPRT", ECHOPRT},
556 : #endif
557 : #ifdef ECHOKE
558 : {"ECHOKE", ECHOKE},
559 : #endif
560 : #ifdef FLUSHO
561 : {"FLUSHO", FLUSHO},
562 : #endif
563 : {"NOFLSH", NOFLSH},
564 : {"TOSTOP", TOSTOP},
565 : #ifdef PENDIN
566 : {"PENDIN", PENDIN},
567 : #endif
568 : {"IEXTEN", IEXTEN},
569 :
570 : /* indexes into the control chars array returned by tcgetattr() */
571 : {"VINTR", VINTR},
572 : {"VQUIT", VQUIT},
573 : {"VERASE", VERASE},
574 : {"VKILL", VKILL},
575 : {"VEOF", VEOF},
576 : {"VTIME", VTIME},
577 : {"VMIN", VMIN},
578 : #ifdef VSWTC
579 : /* The #defines above ensure that if either is defined, both are,
580 : * but both may be omitted by the system headers. ;-( */
581 : {"VSWTC", VSWTC},
582 : {"VSWTCH", VSWTCH},
583 : #endif
584 : {"VSTART", VSTART},
585 : {"VSTOP", VSTOP},
586 : {"VSUSP", VSUSP},
587 : {"VEOL", VEOL},
588 : #ifdef VREPRINT
589 : {"VREPRINT", VREPRINT},
590 : #endif
591 : #ifdef VDISCARD
592 : {"VDISCARD", VDISCARD},
593 : #endif
594 : #ifdef VWERASE
595 : {"VWERASE", VWERASE},
596 : #endif
597 : #ifdef VLNEXT
598 : {"VLNEXT", VLNEXT},
599 : #endif
600 : #ifdef VEOL2
601 : {"VEOL2", VEOL2},
602 : #endif
603 :
604 :
605 : #ifdef B460800
606 : {"B460800", B460800},
607 : #endif
608 : #ifdef CBAUD
609 : {"CBAUD", CBAUD},
610 : #endif
611 : #ifdef CDEL
612 : {"CDEL", CDEL},
613 : #endif
614 : #ifdef CDSUSP
615 : {"CDSUSP", CDSUSP},
616 : #endif
617 : #ifdef CEOF
618 : {"CEOF", CEOF},
619 : #endif
620 : #ifdef CEOL
621 : {"CEOL", CEOL},
622 : #endif
623 : #ifdef CEOL2
624 : {"CEOL2", CEOL2},
625 : #endif
626 : #ifdef CEOT
627 : {"CEOT", CEOT},
628 : #endif
629 : #ifdef CERASE
630 : {"CERASE", CERASE},
631 : #endif
632 : #ifdef CESC
633 : {"CESC", CESC},
634 : #endif
635 : #ifdef CFLUSH
636 : {"CFLUSH", CFLUSH},
637 : #endif
638 : #ifdef CINTR
639 : {"CINTR", CINTR},
640 : #endif
641 : #ifdef CKILL
642 : {"CKILL", CKILL},
643 : #endif
644 : #ifdef CLNEXT
645 : {"CLNEXT", CLNEXT},
646 : #endif
647 : #ifdef CNUL
648 : {"CNUL", CNUL},
649 : #endif
650 : #ifdef COMMON
651 : {"COMMON", COMMON},
652 : #endif
653 : #ifdef CQUIT
654 : {"CQUIT", CQUIT},
655 : #endif
656 : #ifdef CRPRNT
657 : {"CRPRNT", CRPRNT},
658 : #endif
659 : #ifdef CSTART
660 : {"CSTART", CSTART},
661 : #endif
662 : #ifdef CSTOP
663 : {"CSTOP", CSTOP},
664 : #endif
665 : #ifdef CSUSP
666 : {"CSUSP", CSUSP},
667 : #endif
668 : #ifdef CSWTCH
669 : {"CSWTCH", CSWTCH},
670 : #endif
671 : #ifdef CWERASE
672 : {"CWERASE", CWERASE},
673 : #endif
674 : #ifdef EXTA
675 : {"EXTA", EXTA},
676 : #endif
677 : #ifdef EXTB
678 : {"EXTB", EXTB},
679 : #endif
680 : #ifdef FIOASYNC
681 : {"FIOASYNC", FIOASYNC},
682 : #endif
683 : #ifdef FIOCLEX
684 : {"FIOCLEX", FIOCLEX},
685 : #endif
686 : #ifdef FIONBIO
687 : {"FIONBIO", FIONBIO},
688 : #endif
689 : #ifdef FIONCLEX
690 : {"FIONCLEX", FIONCLEX},
691 : #endif
692 : #ifdef FIONREAD
693 : {"FIONREAD", FIONREAD},
694 : #endif
695 : #ifdef IBSHIFT
696 : {"IBSHIFT", IBSHIFT},
697 : #endif
698 : #ifdef INIT_C_CC
699 : {"INIT_C_CC", INIT_C_CC},
700 : #endif
701 : #ifdef IOCSIZE_MASK
702 : {"IOCSIZE_MASK", IOCSIZE_MASK},
703 : #endif
704 : #ifdef IOCSIZE_SHIFT
705 : {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
706 : #endif
707 : #ifdef NCC
708 : {"NCC", NCC},
709 : #endif
710 : #ifdef NCCS
711 : {"NCCS", NCCS},
712 : #endif
713 : #ifdef NSWTCH
714 : {"NSWTCH", NSWTCH},
715 : #endif
716 : #ifdef N_MOUSE
717 : {"N_MOUSE", N_MOUSE},
718 : #endif
719 : #ifdef N_PPP
720 : {"N_PPP", N_PPP},
721 : #endif
722 : #ifdef N_SLIP
723 : {"N_SLIP", N_SLIP},
724 : #endif
725 : #ifdef N_STRIP
726 : {"N_STRIP", N_STRIP},
727 : #endif
728 : #ifdef N_TTY
729 : {"N_TTY", N_TTY},
730 : #endif
731 : #ifdef TCFLSH
732 : {"TCFLSH", TCFLSH},
733 : #endif
734 : #ifdef TCGETA
735 : {"TCGETA", TCGETA},
736 : #endif
737 : #ifdef TCGETS
738 : {"TCGETS", TCGETS},
739 : #endif
740 : #ifdef TCSBRK
741 : {"TCSBRK", TCSBRK},
742 : #endif
743 : #ifdef TCSBRKP
744 : {"TCSBRKP", TCSBRKP},
745 : #endif
746 : #ifdef TCSETA
747 : {"TCSETA", TCSETA},
748 : #endif
749 : #ifdef TCSETAF
750 : {"TCSETAF", TCSETAF},
751 : #endif
752 : #ifdef TCSETAW
753 : {"TCSETAW", TCSETAW},
754 : #endif
755 : #ifdef TCSETS
756 : {"TCSETS", TCSETS},
757 : #endif
758 : #ifdef TCSETSF
759 : {"TCSETSF", TCSETSF},
760 : #endif
761 : #ifdef TCSETSW
762 : {"TCSETSW", TCSETSW},
763 : #endif
764 : #ifdef TCXONC
765 : {"TCXONC", TCXONC},
766 : #endif
767 : #ifdef TIOCCONS
768 : {"TIOCCONS", TIOCCONS},
769 : #endif
770 : #ifdef TIOCEXCL
771 : {"TIOCEXCL", TIOCEXCL},
772 : #endif
773 : #ifdef TIOCGETD
774 : {"TIOCGETD", TIOCGETD},
775 : #endif
776 : #ifdef TIOCGICOUNT
777 : {"TIOCGICOUNT", TIOCGICOUNT},
778 : #endif
779 : #ifdef TIOCGLCKTRMIOS
780 : {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
781 : #endif
782 : #ifdef TIOCGPGRP
783 : {"TIOCGPGRP", TIOCGPGRP},
784 : #endif
785 : #ifdef TIOCGSERIAL
786 : {"TIOCGSERIAL", TIOCGSERIAL},
787 : #endif
788 : #ifdef TIOCGSOFTCAR
789 : {"TIOCGSOFTCAR", TIOCGSOFTCAR},
790 : #endif
791 : #ifdef TIOCGWINSZ
792 : {"TIOCGWINSZ", TIOCGWINSZ},
793 : #endif
794 : #ifdef TIOCINQ
795 : {"TIOCINQ", TIOCINQ},
796 : #endif
797 : #ifdef TIOCLINUX
798 : {"TIOCLINUX", TIOCLINUX},
799 : #endif
800 : #ifdef TIOCMBIC
801 : {"TIOCMBIC", TIOCMBIC},
802 : #endif
803 : #ifdef TIOCMBIS
804 : {"TIOCMBIS", TIOCMBIS},
805 : #endif
806 : #ifdef TIOCMGET
807 : {"TIOCMGET", TIOCMGET},
808 : #endif
809 : #ifdef TIOCMIWAIT
810 : {"TIOCMIWAIT", TIOCMIWAIT},
811 : #endif
812 : #ifdef TIOCMSET
813 : {"TIOCMSET", TIOCMSET},
814 : #endif
815 : #ifdef TIOCM_CAR
816 : {"TIOCM_CAR", TIOCM_CAR},
817 : #endif
818 : #ifdef TIOCM_CD
819 : {"TIOCM_CD", TIOCM_CD},
820 : #endif
821 : #ifdef TIOCM_CTS
822 : {"TIOCM_CTS", TIOCM_CTS},
823 : #endif
824 : #ifdef TIOCM_DSR
825 : {"TIOCM_DSR", TIOCM_DSR},
826 : #endif
827 : #ifdef TIOCM_DTR
828 : {"TIOCM_DTR", TIOCM_DTR},
829 : #endif
830 : #ifdef TIOCM_LE
831 : {"TIOCM_LE", TIOCM_LE},
832 : #endif
833 : #ifdef TIOCM_RI
834 : {"TIOCM_RI", TIOCM_RI},
835 : #endif
836 : #ifdef TIOCM_RNG
837 : {"TIOCM_RNG", TIOCM_RNG},
838 : #endif
839 : #ifdef TIOCM_RTS
840 : {"TIOCM_RTS", TIOCM_RTS},
841 : #endif
842 : #ifdef TIOCM_SR
843 : {"TIOCM_SR", TIOCM_SR},
844 : #endif
845 : #ifdef TIOCM_ST
846 : {"TIOCM_ST", TIOCM_ST},
847 : #endif
848 : #ifdef TIOCNOTTY
849 : {"TIOCNOTTY", TIOCNOTTY},
850 : #endif
851 : #ifdef TIOCNXCL
852 : {"TIOCNXCL", TIOCNXCL},
853 : #endif
854 : #ifdef TIOCOUTQ
855 : {"TIOCOUTQ", TIOCOUTQ},
856 : #endif
857 : #ifdef TIOCPKT
858 : {"TIOCPKT", TIOCPKT},
859 : #endif
860 : #ifdef TIOCPKT_DATA
861 : {"TIOCPKT_DATA", TIOCPKT_DATA},
862 : #endif
863 : #ifdef TIOCPKT_DOSTOP
864 : {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
865 : #endif
866 : #ifdef TIOCPKT_FLUSHREAD
867 : {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
868 : #endif
869 : #ifdef TIOCPKT_FLUSHWRITE
870 : {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
871 : #endif
872 : #ifdef TIOCPKT_NOSTOP
873 : {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
874 : #endif
875 : #ifdef TIOCPKT_START
876 : {"TIOCPKT_START", TIOCPKT_START},
877 : #endif
878 : #ifdef TIOCPKT_STOP
879 : {"TIOCPKT_STOP", TIOCPKT_STOP},
880 : #endif
881 : #ifdef TIOCSCTTY
882 : {"TIOCSCTTY", TIOCSCTTY},
883 : #endif
884 : #ifdef TIOCSERCONFIG
885 : {"TIOCSERCONFIG", TIOCSERCONFIG},
886 : #endif
887 : #ifdef TIOCSERGETLSR
888 : {"TIOCSERGETLSR", TIOCSERGETLSR},
889 : #endif
890 : #ifdef TIOCSERGETMULTI
891 : {"TIOCSERGETMULTI", TIOCSERGETMULTI},
892 : #endif
893 : #ifdef TIOCSERGSTRUCT
894 : {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
895 : #endif
896 : #ifdef TIOCSERGWILD
897 : {"TIOCSERGWILD", TIOCSERGWILD},
898 : #endif
899 : #ifdef TIOCSERSETMULTI
900 : {"TIOCSERSETMULTI", TIOCSERSETMULTI},
901 : #endif
902 : #ifdef TIOCSERSWILD
903 : {"TIOCSERSWILD", TIOCSERSWILD},
904 : #endif
905 : #ifdef TIOCSER_TEMT
906 : {"TIOCSER_TEMT", TIOCSER_TEMT},
907 : #endif
908 : #ifdef TIOCSETD
909 : {"TIOCSETD", TIOCSETD},
910 : #endif
911 : #ifdef TIOCSLCKTRMIOS
912 : {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
913 : #endif
914 : #ifdef TIOCSPGRP
915 : {"TIOCSPGRP", TIOCSPGRP},
916 : #endif
917 : #ifdef TIOCSSERIAL
918 : {"TIOCSSERIAL", TIOCSSERIAL},
919 : #endif
920 : #ifdef TIOCSSOFTCAR
921 : {"TIOCSSOFTCAR", TIOCSSOFTCAR},
922 : #endif
923 : #ifdef TIOCSTI
924 : {"TIOCSTI", TIOCSTI},
925 : #endif
926 : #ifdef TIOCSWINSZ
927 : {"TIOCSWINSZ", TIOCSWINSZ},
928 : #endif
929 : #ifdef TIOCTTYGSTRUCT
930 : {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
931 : #endif
932 :
933 : /* sentinel */
934 : {NULL, 0}
935 : };
936 :
937 :
938 : static struct PyModuleDef termiosmodule = {
939 : PyModuleDef_HEAD_INIT,
940 : "termios",
941 : termios__doc__,
942 : -1,
943 : termios_methods,
944 : NULL,
945 : NULL,
946 : NULL,
947 : NULL
948 : };
949 :
950 : PyMODINIT_FUNC
951 0 : PyInit_termios(void)
952 : {
953 : PyObject *m;
954 0 : struct constant *constant = termios_constants;
955 :
956 0 : m = PyModule_Create(&termiosmodule);
957 0 : if (m == NULL)
958 0 : return NULL;
959 :
960 0 : if (TermiosError == NULL) {
961 0 : TermiosError = PyErr_NewException("termios.error", NULL, NULL);
962 : }
963 0 : Py_INCREF(TermiosError);
964 0 : PyModule_AddObject(m, "error", TermiosError);
965 :
966 0 : while (constant->name != NULL) {
967 0 : PyModule_AddIntConstant(m, constant->name, constant->value);
968 0 : ++constant;
969 : }
970 0 : return m;
971 : }
|