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