ยปCore Development>Code coverage>Modules/termios.c

Python code coverage for Modules/termios.c

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