This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Modules / termios.c
blob3362e8158c2abaea17b141562b8fae38c9f5065b
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 static char 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 static char 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 static char 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 static char 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 static char 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 static char 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 static char 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 {"ONLCR", ONLCR},
388 #ifdef OCRNL
389 {"OCRNL", OCRNL},
390 #endif
391 #ifdef ONOCR
392 {"ONOCR", ONOCR},
393 #endif
394 #ifdef ONLRET
395 {"ONLRET", ONLRET},
396 #endif
397 #ifdef OFILL
398 {"OFILL", OFILL},
399 #endif
400 #ifdef OFDEL
401 {"OFDEL", OFDEL},
402 #endif
403 #ifdef NLDLY
404 {"NLDLY", NLDLY},
405 #endif
406 #ifdef CRDLY
407 {"CRDLY", CRDLY},
408 #endif
409 #ifdef TABDLY
410 {"TABDLY", TABDLY},
411 #endif
412 #ifdef BSDLY
413 {"BSDLY", BSDLY},
414 #endif
415 #ifdef VTDLY
416 {"VTDLY", VTDLY},
417 #endif
418 #ifdef FFDLY
419 {"FFDLY", FFDLY},
420 #endif
422 /* struct termios.c_oflag-related values (delay mask) */
423 #ifdef NL0
424 {"NL0", NL0},
425 #endif
426 #ifdef NL1
427 {"NL1", NL1},
428 #endif
429 #ifdef CR0
430 {"CR0", CR0},
431 #endif
432 #ifdef CR1
433 {"CR1", CR1},
434 #endif
435 #ifdef CR2
436 {"CR2", CR2},
437 #endif
438 #ifdef CR3
439 {"CR3", CR3},
440 #endif
441 #ifdef TAB0
442 {"TAB0", TAB0},
443 #endif
444 #ifdef TAB1
445 {"TAB1", TAB1},
446 #endif
447 #ifdef TAB2
448 {"TAB2", TAB2},
449 #endif
450 #ifdef TAB3
451 {"TAB3", TAB3},
452 #endif
453 #ifdef XTABS
454 {"XTABS", XTABS},
455 #endif
456 #ifdef BS0
457 {"BS0", BS0},
458 #endif
459 #ifdef BS1
460 {"BS1", BS1},
461 #endif
462 #ifdef VT0
463 {"VT0", VT0},
464 #endif
465 #ifdef VT1
466 {"VT1", VT1},
467 #endif
468 #ifdef FF0
469 {"FF0", FF0},
470 #endif
471 #ifdef FF1
472 {"FF1", FF1},
473 #endif
475 /* struct termios.c_cflag constants */
476 {"CSIZE", CSIZE},
477 {"CSTOPB", CSTOPB},
478 {"CREAD", CREAD},
479 {"PARENB", PARENB},
480 {"PARODD", PARODD},
481 {"HUPCL", HUPCL},
482 {"CLOCAL", CLOCAL},
483 #ifdef CIBAUD
484 {"CIBAUD", CIBAUD},
485 #endif
486 #ifdef CRTSCTS
487 {"CRTSCTS", (long)CRTSCTS},
488 #endif
490 /* struct termios.c_cflag-related values (character size) */
491 {"CS5", CS5},
492 {"CS6", CS6},
493 {"CS7", CS7},
494 {"CS8", CS8},
496 /* struct termios.c_lflag constants */
497 {"ISIG", ISIG},
498 {"ICANON", ICANON},
499 #ifdef XCASE
500 {"XCASE", XCASE},
501 #endif
502 {"ECHO", ECHO},
503 {"ECHOE", ECHOE},
504 {"ECHOK", ECHOK},
505 {"ECHONL", ECHONL},
506 #ifdef ECHOCTL
507 {"ECHOCTL", ECHOCTL},
508 #endif
509 #ifdef ECHOPRT
510 {"ECHOPRT", ECHOPRT},
511 #endif
512 #ifdef ECHOKE
513 {"ECHOKE", ECHOKE},
514 #endif
515 #ifdef FLUSHO
516 {"FLUSHO", FLUSHO},
517 #endif
518 {"NOFLSH", NOFLSH},
519 {"TOSTOP", TOSTOP},
520 #ifdef PENDIN
521 {"PENDIN", PENDIN},
522 #endif
523 {"IEXTEN", IEXTEN},
525 /* indexes into the control chars array returned by tcgetattr() */
526 {"VINTR", VINTR},
527 {"VQUIT", VQUIT},
528 {"VERASE", VERASE},
529 {"VKILL", VKILL},
530 {"VEOF", VEOF},
531 {"VTIME", VTIME},
532 {"VMIN", VMIN},
533 #ifdef VSWTC
534 /* The #defines above ensure that if either is defined, both are,
535 * but both may be omitted by the system headers. ;-( */
536 {"VSWTC", VSWTC},
537 {"VSWTCH", VSWTCH},
538 #endif
539 {"VSTART", VSTART},
540 {"VSTOP", VSTOP},
541 {"VSUSP", VSUSP},
542 {"VEOL", VEOL},
543 #ifdef VREPRINT
544 {"VREPRINT", VREPRINT},
545 #endif
546 #ifdef VDISCARD
547 {"VDISCARD", VDISCARD},
548 #endif
549 #ifdef VWERASE
550 {"VWERASE", VWERASE},
551 #endif
552 #ifdef VLNEXT
553 {"VLNEXT", VLNEXT},
554 #endif
555 {"VEOL2", VEOL2},
558 #ifdef B460800
559 {"B460800", B460800},
560 #endif
561 #ifdef CBAUD
562 {"CBAUD", CBAUD},
563 #endif
564 #ifdef CDEL
565 {"CDEL", CDEL},
566 #endif
567 #ifdef CDSUSP
568 {"CDSUSP", CDSUSP},
569 #endif
570 #ifdef CEOF
571 {"CEOF", CEOF},
572 #endif
573 #ifdef CEOL
574 {"CEOL", CEOL},
575 #endif
576 #ifdef CEOL2
577 {"CEOL2", CEOL2},
578 #endif
579 #ifdef CEOT
580 {"CEOT", CEOT},
581 #endif
582 #ifdef CERASE
583 {"CERASE", CERASE},
584 #endif
585 #ifdef CESC
586 {"CESC", CESC},
587 #endif
588 #ifdef CFLUSH
589 {"CFLUSH", CFLUSH},
590 #endif
591 #ifdef CINTR
592 {"CINTR", CINTR},
593 #endif
594 #ifdef CKILL
595 {"CKILL", CKILL},
596 #endif
597 #ifdef CLNEXT
598 {"CLNEXT", CLNEXT},
599 #endif
600 #ifdef CNUL
601 {"CNUL", CNUL},
602 #endif
603 #ifdef COMMON
604 {"COMMON", COMMON},
605 #endif
606 #ifdef CQUIT
607 {"CQUIT", CQUIT},
608 #endif
609 #ifdef CRPRNT
610 {"CRPRNT", CRPRNT},
611 #endif
612 #ifdef CSTART
613 {"CSTART", CSTART},
614 #endif
615 #ifdef CSTOP
616 {"CSTOP", CSTOP},
617 #endif
618 #ifdef CSUSP
619 {"CSUSP", CSUSP},
620 #endif
621 #ifdef CSWTCH
622 {"CSWTCH", CSWTCH},
623 #endif
624 #ifdef CWERASE
625 {"CWERASE", CWERASE},
626 #endif
627 #ifdef EXTA
628 {"EXTA", EXTA},
629 #endif
630 #ifdef EXTB
631 {"EXTB", EXTB},
632 #endif
633 #ifdef FIOASYNC
634 {"FIOASYNC", FIOASYNC},
635 #endif
636 #ifdef FIOCLEX
637 {"FIOCLEX", FIOCLEX},
638 #endif
639 #ifdef FIONBIO
640 {"FIONBIO", FIONBIO},
641 #endif
642 #ifdef FIONCLEX
643 {"FIONCLEX", FIONCLEX},
644 #endif
645 #ifdef FIONREAD
646 {"FIONREAD", FIONREAD},
647 #endif
648 #ifdef IBSHIFT
649 {"IBSHIFT", IBSHIFT},
650 #endif
651 #ifdef INIT_C_CC
652 {"INIT_C_CC", INIT_C_CC},
653 #endif
654 #ifdef IOCSIZE_MASK
655 {"IOCSIZE_MASK", IOCSIZE_MASK},
656 #endif
657 #ifdef IOCSIZE_SHIFT
658 {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
659 #endif
660 #ifdef NCC
661 {"NCC", NCC},
662 #endif
663 #ifdef NCCS
664 {"NCCS", NCCS},
665 #endif
666 #ifdef NSWTCH
667 {"NSWTCH", NSWTCH},
668 #endif
669 #ifdef N_MOUSE
670 {"N_MOUSE", N_MOUSE},
671 #endif
672 #ifdef N_PPP
673 {"N_PPP", N_PPP},
674 #endif
675 #ifdef N_SLIP
676 {"N_SLIP", N_SLIP},
677 #endif
678 #ifdef N_STRIP
679 {"N_STRIP", N_STRIP},
680 #endif
681 #ifdef N_TTY
682 {"N_TTY", N_TTY},
683 #endif
684 #ifdef TCFLSH
685 {"TCFLSH", TCFLSH},
686 #endif
687 #ifdef TCGETA
688 {"TCGETA", TCGETA},
689 #endif
690 #ifdef TCGETS
691 {"TCGETS", TCGETS},
692 #endif
693 #ifdef TCSBRK
694 {"TCSBRK", TCSBRK},
695 #endif
696 #ifdef TCSBRKP
697 {"TCSBRKP", TCSBRKP},
698 #endif
699 #ifdef TCSETA
700 {"TCSETA", TCSETA},
701 #endif
702 #ifdef TCSETAF
703 {"TCSETAF", TCSETAF},
704 #endif
705 #ifdef TCSETAW
706 {"TCSETAW", TCSETAW},
707 #endif
708 #ifdef TCSETS
709 {"TCSETS", TCSETS},
710 #endif
711 #ifdef TCSETSF
712 {"TCSETSF", TCSETSF},
713 #endif
714 #ifdef TCSETSW
715 {"TCSETSW", TCSETSW},
716 #endif
717 #ifdef TCXONC
718 {"TCXONC", TCXONC},
719 #endif
720 #ifdef TIOCCONS
721 {"TIOCCONS", TIOCCONS},
722 #endif
723 #ifdef TIOCEXCL
724 {"TIOCEXCL", TIOCEXCL},
725 #endif
726 #ifdef TIOCGETD
727 {"TIOCGETD", TIOCGETD},
728 #endif
729 #ifdef TIOCGICOUNT
730 {"TIOCGICOUNT", TIOCGICOUNT},
731 #endif
732 #ifdef TIOCGLCKTRMIOS
733 {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
734 #endif
735 #ifdef TIOCGPGRP
736 {"TIOCGPGRP", TIOCGPGRP},
737 #endif
738 #ifdef TIOCGSERIAL
739 {"TIOCGSERIAL", TIOCGSERIAL},
740 #endif
741 #ifdef TIOCGSOFTCAR
742 {"TIOCGSOFTCAR", TIOCGSOFTCAR},
743 #endif
744 #ifdef TIOCGWINSZ
745 {"TIOCGWINSZ", TIOCGWINSZ},
746 #endif
747 #ifdef TIOCINQ
748 {"TIOCINQ", TIOCINQ},
749 #endif
750 #ifdef TIOCLINUX
751 {"TIOCLINUX", TIOCLINUX},
752 #endif
753 #ifdef TIOCMBIC
754 {"TIOCMBIC", TIOCMBIC},
755 #endif
756 #ifdef TIOCMBIS
757 {"TIOCMBIS", TIOCMBIS},
758 #endif
759 #ifdef TIOCMGET
760 {"TIOCMGET", TIOCMGET},
761 #endif
762 #ifdef TIOCMIWAIT
763 {"TIOCMIWAIT", TIOCMIWAIT},
764 #endif
765 #ifdef TIOCMSET
766 {"TIOCMSET", TIOCMSET},
767 #endif
768 #ifdef TIOCM_CAR
769 {"TIOCM_CAR", TIOCM_CAR},
770 #endif
771 #ifdef TIOCM_CD
772 {"TIOCM_CD", TIOCM_CD},
773 #endif
774 #ifdef TIOCM_CTS
775 {"TIOCM_CTS", TIOCM_CTS},
776 #endif
777 #ifdef TIOCM_DSR
778 {"TIOCM_DSR", TIOCM_DSR},
779 #endif
780 #ifdef TIOCM_DTR
781 {"TIOCM_DTR", TIOCM_DTR},
782 #endif
783 #ifdef TIOCM_LE
784 {"TIOCM_LE", TIOCM_LE},
785 #endif
786 #ifdef TIOCM_RI
787 {"TIOCM_RI", TIOCM_RI},
788 #endif
789 #ifdef TIOCM_RNG
790 {"TIOCM_RNG", TIOCM_RNG},
791 #endif
792 #ifdef TIOCM_RTS
793 {"TIOCM_RTS", TIOCM_RTS},
794 #endif
795 #ifdef TIOCM_SR
796 {"TIOCM_SR", TIOCM_SR},
797 #endif
798 #ifdef TIOCM_ST
799 {"TIOCM_ST", TIOCM_ST},
800 #endif
801 #ifdef TIOCNOTTY
802 {"TIOCNOTTY", TIOCNOTTY},
803 #endif
804 #ifdef TIOCNXCL
805 {"TIOCNXCL", TIOCNXCL},
806 #endif
807 #ifdef TIOCOUTQ
808 {"TIOCOUTQ", TIOCOUTQ},
809 #endif
810 #ifdef TIOCPKT
811 {"TIOCPKT", TIOCPKT},
812 #endif
813 #ifdef TIOCPKT_DATA
814 {"TIOCPKT_DATA", TIOCPKT_DATA},
815 #endif
816 #ifdef TIOCPKT_DOSTOP
817 {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
818 #endif
819 #ifdef TIOCPKT_FLUSHREAD
820 {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
821 #endif
822 #ifdef TIOCPKT_FLUSHWRITE
823 {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
824 #endif
825 #ifdef TIOCPKT_NOSTOP
826 {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
827 #endif
828 #ifdef TIOCPKT_START
829 {"TIOCPKT_START", TIOCPKT_START},
830 #endif
831 #ifdef TIOCPKT_STOP
832 {"TIOCPKT_STOP", TIOCPKT_STOP},
833 #endif
834 #ifdef TIOCSCTTY
835 {"TIOCSCTTY", TIOCSCTTY},
836 #endif
837 #ifdef TIOCSERCONFIG
838 {"TIOCSERCONFIG", TIOCSERCONFIG},
839 #endif
840 #ifdef TIOCSERGETLSR
841 {"TIOCSERGETLSR", TIOCSERGETLSR},
842 #endif
843 #ifdef TIOCSERGETMULTI
844 {"TIOCSERGETMULTI", TIOCSERGETMULTI},
845 #endif
846 #ifdef TIOCSERGSTRUCT
847 {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
848 #endif
849 #ifdef TIOCSERGWILD
850 {"TIOCSERGWILD", TIOCSERGWILD},
851 #endif
852 #ifdef TIOCSERSETMULTI
853 {"TIOCSERSETMULTI", TIOCSERSETMULTI},
854 #endif
855 #ifdef TIOCSERSWILD
856 {"TIOCSERSWILD", TIOCSERSWILD},
857 #endif
858 #ifdef TIOCSER_TEMT
859 {"TIOCSER_TEMT", TIOCSER_TEMT},
860 #endif
861 #ifdef TIOCSETD
862 {"TIOCSETD", TIOCSETD},
863 #endif
864 #ifdef TIOCSLCKTRMIOS
865 {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
866 #endif
867 #ifdef TIOCSPGRP
868 {"TIOCSPGRP", TIOCSPGRP},
869 #endif
870 #ifdef TIOCSSERIAL
871 {"TIOCSSERIAL", TIOCSSERIAL},
872 #endif
873 #ifdef TIOCSSOFTCAR
874 {"TIOCSSOFTCAR", TIOCSSOFTCAR},
875 #endif
876 #ifdef TIOCSTI
877 {"TIOCSTI", TIOCSTI},
878 #endif
879 #ifdef TIOCSWINSZ
880 {"TIOCSWINSZ", TIOCSWINSZ},
881 #endif
882 #ifdef TIOCTTYGSTRUCT
883 {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
884 #endif
886 /* sentinel */
887 {NULL, 0}
891 DL_EXPORT(void)
892 PyInit_termios(void)
894 PyObject *m, *d;
895 struct constant *constant = termios_constants;
897 m = Py_InitModule4("termios", termios_methods, termios__doc__,
898 (PyObject *)NULL, PYTHON_API_VERSION);
900 d = PyModule_GetDict(m);
901 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
902 PyDict_SetItemString(d, "error", TermiosError);
904 while (constant->name != NULL) {
905 PyModule_AddIntConstant(m, constant->name, constant->value);
906 ++constant;