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