This commit was manufactured by cvs2svn to create tag 'r212'.
[python/dscho.git] / Modules / termios.c
blobc77dff36ad79e715380922ab3ce7177bec50815a
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 #ifdef __BEOS__
16 #include <unistd.h>
17 #endif
19 /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
20 * MDTR, MRI, and MRTS (appearantly used internally by some things
21 * defined as macros; these are not used here directly).
23 #ifdef HAVE_SYS_MODEM_H
24 #include <sys/modem.h>
25 #endif
27 static char termios__doc__[] = "\
28 This module provides an interface to the Posix calls for tty I/O control.\n\
29 For a complete description of these calls, see the Posix or Unix manual\n\
30 pages. It is only available for those Unix versions that support Posix\n\
31 termios style tty I/O control.\n\
32 \n\
33 All functions in this module take a file descriptor fd as their first\n\
34 argument. This can be an integer file descriptor, such as returned by\n\
35 sys.stdin.fileno(), or a file object, such as sys.stdin itself.";
37 static PyObject *TermiosError;
39 static int fdconv(PyObject* obj, void* p)
41 int fd;
43 fd = PyObject_AsFileDescriptor(obj);
44 if (fd >= 0) {
45 *(int*)p = fd;
46 return 1;
48 return 0;
51 static char termios_tcgetattr__doc__[] = "\
52 tcgetattr(fd) -> list_of_attrs\n\
53 \n\
54 Get the tty attributes for file descriptor fd, as follows:\n\
55 [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
56 of the tty special characters (each a string of length 1, except the items\n\
57 with indices VMIN and VTIME, which are integers when these fields are\n\
58 defined). The interpretation of the flags and the speeds as well as the\n\
59 indexing in the cc array must be done using the symbolic constants defined\n\
60 in this module.";
62 static PyObject *
63 termios_tcgetattr(PyObject *self, PyObject *args)
65 int fd;
66 struct termios mode;
67 PyObject *cc;
68 speed_t ispeed, ospeed;
69 PyObject *v;
70 int i;
71 char ch;
73 if (!PyArg_ParseTuple(args, "O&:tcgetattr",
74 fdconv, (void*)&fd))
75 return NULL;
77 if (tcgetattr(fd, &mode) == -1)
78 return PyErr_SetFromErrno(TermiosError);
80 ispeed = cfgetispeed(&mode);
81 ospeed = cfgetospeed(&mode);
83 cc = PyList_New(NCCS);
84 if (cc == NULL)
85 return NULL;
86 for (i = 0; i < NCCS; i++) {
87 ch = (char)mode.c_cc[i];
88 v = PyString_FromStringAndSize(&ch, 1);
89 if (v == NULL)
90 goto err;
91 PyList_SetItem(cc, i, v);
94 /* Convert the MIN and TIME slots to integer. On some systems, the
95 MIN and TIME slots are the same as the EOF and EOL slots. So we
96 only do this in noncanonical input mode. */
97 if ((mode.c_lflag & ICANON) == 0) {
98 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
99 if (v == NULL)
100 goto err;
101 PyList_SetItem(cc, VMIN, v);
102 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
103 if (v == NULL)
104 goto err;
105 PyList_SetItem(cc, VTIME, v);
108 if (!(v = PyList_New(7)))
109 goto err;
111 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
112 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
113 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
114 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
115 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
116 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
117 PyList_SetItem(v, 6, cc);
118 if (PyErr_Occurred()){
119 Py_DECREF(v);
120 goto err;
122 return v;
123 err:
124 Py_DECREF(cc);
125 return NULL;
128 static char termios_tcsetattr__doc__[] = "\
129 tcsetattr(fd, when, attributes) -> None\n\
131 Set the tty attributes for file descriptor fd.\n\
132 The attributes to be set are taken from the attributes argument, which\n\
133 is a list like the one returned by tcgetattr(). The when argument\n\
134 determines when the attributes are changed: termios.TCSANOW to\n\
135 change immediately, termios.TCSADRAIN to change after transmitting all\n\
136 queued output, or termios.TCSAFLUSH to change after transmitting all\n\
137 queued output and discarding all queued input. ";
139 static PyObject *
140 termios_tcsetattr(PyObject *self, PyObject *args)
142 int fd, when;
143 struct termios mode;
144 speed_t ispeed, ospeed;
145 PyObject *term, *cc, *v;
146 int i;
148 if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
149 fdconv, &fd, &when, &term))
150 return NULL;
151 if (!PyList_Check(term) || PyList_Size(term) != 7) {
152 PyErr_SetString(PyExc_TypeError,
153 "tcsetattr, arg 3: must be 7 element list");
154 return NULL;
157 /* Get the old mode, in case there are any hidden fields... */
158 if (tcgetattr(fd, &mode) == -1)
159 return PyErr_SetFromErrno(TermiosError);
160 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
161 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
162 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
163 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
164 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
165 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
166 cc = PyList_GetItem(term, 6);
167 if (PyErr_Occurred())
168 return NULL;
170 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
171 PyErr_Format(PyExc_TypeError,
172 "tcsetattr: attributes[6] must be %d element list",
173 NCCS);
174 return NULL;
177 for (i = 0; i < NCCS; i++) {
178 v = PyList_GetItem(cc, i);
180 if (PyString_Check(v) && PyString_Size(v) == 1)
181 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
182 else if (PyInt_Check(v))
183 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
184 else {
185 PyErr_SetString(PyExc_TypeError,
186 "tcsetattr: elements of attributes must be characters or integers");
187 return NULL;
191 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
192 return PyErr_SetFromErrno(TermiosError);
193 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
194 return PyErr_SetFromErrno(TermiosError);
195 if (tcsetattr(fd, when, &mode) == -1)
196 return PyErr_SetFromErrno(TermiosError);
198 Py_INCREF(Py_None);
199 return Py_None;
202 static char termios_tcsendbreak__doc__[] = "\
203 tcsendbreak(fd, duration) -> None\n\
205 Send a break on file descriptor fd.\n\
206 A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
207 has a system dependent meaning.";
209 static PyObject *
210 termios_tcsendbreak(PyObject *self, PyObject *args)
212 int fd, duration;
214 if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
215 fdconv, &fd, &duration))
216 return NULL;
217 if (tcsendbreak(fd, duration) == -1)
218 return PyErr_SetFromErrno(TermiosError);
220 Py_INCREF(Py_None);
221 return Py_None;
224 static char termios_tcdrain__doc__[] = "\
225 tcdrain(fd) -> None\n\
227 Wait until all output written to file descriptor fd has been transmitted.";
229 static PyObject *
230 termios_tcdrain(PyObject *self, PyObject *args)
232 int fd;
234 if (!PyArg_ParseTuple(args, "O&:tcdrain",
235 fdconv, &fd))
236 return NULL;
237 if (tcdrain(fd) == -1)
238 return PyErr_SetFromErrno(TermiosError);
240 Py_INCREF(Py_None);
241 return Py_None;
244 static char termios_tcflush__doc__[] = "\
245 tcflush(fd, queue) -> None\n\
247 Discard queued data on file descriptor fd.\n\
248 The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
249 queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
250 both queues. ";
252 static PyObject *
253 termios_tcflush(PyObject *self, PyObject *args)
255 int fd, queue;
257 if (!PyArg_ParseTuple(args, "O&i:tcflush",
258 fdconv, &fd, &queue))
259 return NULL;
260 if (tcflush(fd, queue) == -1)
261 return PyErr_SetFromErrno(TermiosError);
263 Py_INCREF(Py_None);
264 return Py_None;
267 static char termios_tcflow__doc__[] = "\
268 tcflow(fd, action) -> None\n\
270 Suspend or resume input or output on file descriptor fd.\n\
271 The action argument can be termios.TCOOFF to suspend output,\n\
272 termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
273 or termios.TCION to restart input.";
275 static PyObject *
276 termios_tcflow(PyObject *self, PyObject *args)
278 int fd, action;
280 if (!PyArg_ParseTuple(args, "O&i:tcflow",
281 fdconv, &fd, &action))
282 return NULL;
283 if (tcflow(fd, action) == -1)
284 return PyErr_SetFromErrno(TermiosError);
286 Py_INCREF(Py_None);
287 return Py_None;
290 static PyMethodDef termios_methods[] =
292 {"tcgetattr", termios_tcgetattr,
293 METH_VARARGS, termios_tcgetattr__doc__},
294 {"tcsetattr", termios_tcsetattr,
295 METH_VARARGS, termios_tcsetattr__doc__},
296 {"tcsendbreak", termios_tcsendbreak,
297 METH_VARARGS, termios_tcsendbreak__doc__},
298 {"tcdrain", termios_tcdrain,
299 METH_VARARGS, termios_tcdrain__doc__},
300 {"tcflush", termios_tcflush,
301 METH_VARARGS, termios_tcflush__doc__},
302 {"tcflow", termios_tcflow,
303 METH_VARARGS, termios_tcflow__doc__},
304 {NULL, NULL}
308 #if defined(VSWTCH) && !defined(VSWTC)
309 #define VSWTC VSWTCH
310 #endif
312 #if defined(VSWTC) && !defined(VSWTCH)
313 #define VSWTCH VSWTC
314 #endif
316 static struct constant {
317 char *name;
318 long value;
319 } termios_constants[] = {
320 /* cfgetospeed(), cfsetospeed() constants */
321 {"B0", B0},
322 {"B50", B50},
323 {"B75", B75},
324 {"B110", B110},
325 {"B134", B134},
326 {"B150", B150},
327 {"B200", B200},
328 {"B300", B300},
329 {"B600", B600},
330 {"B1200", B1200},
331 {"B1800", B1800},
332 {"B2400", B2400},
333 {"B4800", B4800},
334 {"B9600", B9600},
335 {"B19200", B19200},
336 {"B38400", B38400},
337 #ifdef B57600
338 {"B57600", B57600},
339 #endif
340 #ifdef B115200
341 {"B115200", B115200},
342 #endif
343 #ifdef B230400
344 {"B230400", B230400},
345 #endif
346 #ifdef CBAUDEX
347 {"CBAUDEX", CBAUDEX},
348 #endif
350 /* tcsetattr() constants */
351 {"TCSANOW", TCSANOW},
352 {"TCSADRAIN", TCSADRAIN},
353 {"TCSAFLUSH", TCSAFLUSH},
355 /* tcflush() constants */
356 {"TCIFLUSH", TCIFLUSH},
357 {"TCOFLUSH", TCOFLUSH},
358 {"TCIOFLUSH", TCIOFLUSH},
360 /* tcflow() constants */
361 {"TCOOFF", TCOOFF},
362 {"TCOON", TCOON},
363 {"TCIOFF", TCIOFF},
364 {"TCION", TCION},
366 /* struct termios.c_iflag constants */
367 {"IGNBRK", IGNBRK},
368 {"BRKINT", BRKINT},
369 {"IGNPAR", IGNPAR},
370 {"PARMRK", PARMRK},
371 {"INPCK", INPCK},
372 {"ISTRIP", ISTRIP},
373 {"INLCR", INLCR},
374 {"IGNCR", IGNCR},
375 {"ICRNL", ICRNL},
376 #ifdef IUCLC
377 {"IUCLC", IUCLC},
378 #endif
379 {"IXON", IXON},
380 {"IXANY", IXANY},
381 {"IXOFF", IXOFF},
382 #ifdef IMAXBEL
383 {"IMAXBEL", IMAXBEL},
384 #endif
386 /* struct termios.c_oflag constants */
387 {"OPOST", OPOST},
388 #ifdef OLCUC
389 {"OLCUC", OLCUC},
390 #endif
391 {"ONLCR", ONLCR},
392 #ifdef OCRNL
393 {"OCRNL", OCRNL},
394 #endif
395 #ifdef ONOCR
396 {"ONOCR", ONOCR},
397 #endif
398 #ifdef ONLRET
399 {"ONLRET", ONLRET},
400 #endif
401 #ifdef OFILL
402 {"OFILL", OFILL},
403 #endif
404 #ifdef OFDEL
405 {"OFDEL", OFDEL},
406 #endif
407 #ifdef NLDLY
408 {"NLDLY", NLDLY},
409 #endif
410 #ifdef CRDLY
411 {"CRDLY", CRDLY},
412 #endif
413 #ifdef TABDLY
414 {"TABDLY", TABDLY},
415 #endif
416 #ifdef BSDLY
417 {"BSDLY", BSDLY},
418 #endif
419 #ifdef VTDLY
420 {"VTDLY", VTDLY},
421 #endif
422 #ifdef FFDLY
423 {"FFDLY", FFDLY},
424 #endif
426 /* struct termios.c_oflag-related values (delay mask) */
427 #ifdef NL0
428 {"NL0", NL0},
429 #endif
430 #ifdef NL1
431 {"NL1", NL1},
432 #endif
433 #ifdef CR0
434 {"CR0", CR0},
435 #endif
436 #ifdef CR1
437 {"CR1", CR1},
438 #endif
439 #ifdef CR2
440 {"CR2", CR2},
441 #endif
442 #ifdef CR3
443 {"CR3", CR3},
444 #endif
445 #ifdef TAB0
446 {"TAB0", TAB0},
447 #endif
448 #ifdef TAB1
449 {"TAB1", TAB1},
450 #endif
451 #ifdef TAB2
452 {"TAB2", TAB2},
453 #endif
454 #ifdef TAB3
455 {"TAB3", TAB3},
456 #endif
457 #ifdef XTABS
458 {"XTABS", XTABS},
459 #endif
460 #ifdef BS0
461 {"BS0", BS0},
462 #endif
463 #ifdef BS1
464 {"BS1", BS1},
465 #endif
466 #ifdef VT0
467 {"VT0", VT0},
468 #endif
469 #ifdef VT1
470 {"VT1", VT1},
471 #endif
472 #ifdef FF0
473 {"FF0", FF0},
474 #endif
475 #ifdef FF1
476 {"FF1", FF1},
477 #endif
479 /* struct termios.c_cflag constants */
480 {"CSIZE", CSIZE},
481 {"CSTOPB", CSTOPB},
482 {"CREAD", CREAD},
483 {"PARENB", PARENB},
484 {"PARODD", PARODD},
485 {"HUPCL", HUPCL},
486 {"CLOCAL", CLOCAL},
487 #ifdef CIBAUD
488 {"CIBAUD", CIBAUD},
489 #endif
490 #ifdef CRTSCTS
491 {"CRTSCTS", (long)CRTSCTS},
492 #endif
494 /* struct termios.c_cflag-related values (character size) */
495 {"CS5", CS5},
496 {"CS6", CS6},
497 {"CS7", CS7},
498 {"CS8", CS8},
500 /* struct termios.c_lflag constants */
501 {"ISIG", ISIG},
502 {"ICANON", ICANON},
503 #ifdef XCASE
504 {"XCASE", XCASE},
505 #endif
506 {"ECHO", ECHO},
507 {"ECHOE", ECHOE},
508 {"ECHOK", ECHOK},
509 {"ECHONL", ECHONL},
510 #ifdef ECHOCTL
511 {"ECHOCTL", ECHOCTL},
512 #endif
513 #ifdef ECHOPRT
514 {"ECHOPRT", ECHOPRT},
515 #endif
516 #ifdef ECHOKE
517 {"ECHOKE", ECHOKE},
518 #endif
519 #ifdef FLUSHO
520 {"FLUSHO", FLUSHO},
521 #endif
522 {"NOFLSH", NOFLSH},
523 {"TOSTOP", TOSTOP},
524 #ifdef PENDIN
525 {"PENDIN", PENDIN},
526 #endif
527 {"IEXTEN", IEXTEN},
529 /* indexes into the control chars array returned by tcgetattr() */
530 {"VINTR", VINTR},
531 {"VQUIT", VQUIT},
532 {"VERASE", VERASE},
533 {"VKILL", VKILL},
534 {"VEOF", VEOF},
535 {"VTIME", VTIME},
536 {"VMIN", VMIN},
537 #ifdef VSWTC
538 /* The #defines above ensure that if either is defined, both are,
539 * but both may be omitted by the system headers. ;-( */
540 {"VSWTC", VSWTC},
541 {"VSWTCH", VSWTCH},
542 #endif
543 {"VSTART", VSTART},
544 {"VSTOP", VSTOP},
545 {"VSUSP", VSUSP},
546 {"VEOL", VEOL},
547 #ifdef VREPRINT
548 {"VREPRINT", VREPRINT},
549 #endif
550 #ifdef VDISCARD
551 {"VDISCARD", VDISCARD},
552 #endif
553 #ifdef VWERASE
554 {"VWERASE", VWERASE},
555 #endif
556 #ifdef VLNEXT
557 {"VLNEXT", VLNEXT},
558 #endif
559 {"VEOL2", VEOL2},
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 DL_EXPORT(void)
896 PyInit_termios(void)
898 PyObject *m, *d;
899 struct constant *constant = termios_constants;
901 m = Py_InitModule4("termios", termios_methods, termios__doc__,
902 (PyObject *)NULL, PYTHON_API_VERSION);
904 d = PyModule_GetDict(m);
905 TermiosError = PyErr_NewException("termios.error", NULL, NULL);
906 PyDict_SetItemString(d, "error", TermiosError);
908 while (constant->name != NULL) {
909 PyModule_AddIntConstant(m, constant->name, constant->value);
910 ++constant;