annotate Modules/termios.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 9be65e6c35c8
children a79d0cef10a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* termiosmodule.c -- POSIX terminal I/O module implementation. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
1888
be956b1efb97 * various modules: #include "Python.h" and remove most remporary
Guido van Rossum <guido@python.org>
parents: 1879
diff changeset
3 #include <Python.h>
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #define PyInit_termios inittermios
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #include <termios.h>
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #define BAD "bad termios argument"
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 static PyObject *TermiosError;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 /* termios = tcgetattr(fd)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 termios is
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]]
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 Return the attributes of the terminal device. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 termios_tcgetattr(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 int fd;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 struct termios mode;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 PyObject *cc;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 speed_t ispeed, ospeed;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 PyObject *v;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 int i;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 char ch;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 if (!PyArg_Parse(args, "i", &fd))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 if (tcgetattr(fd, &mode) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 ispeed = cfgetispeed(&mode);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 ospeed = cfgetospeed(&mode);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 cc = PyList_New(NCCS);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 if (cc == NULL)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 for (i = 0; i < NCCS; i++) {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 ch = (char)mode.c_cc[i];
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 v = PyString_FromStringAndSize(&ch, 1);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 if (v == NULL)
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
48 goto err;
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 PyList_SetItem(cc, i, v);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 /* Convert the MIN and TIME slots to integer. On some systems, the
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 MIN and TIME slots are the same as the EOF and EOL slots. So we
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 only do this in noncanonical input mode. */
4653
3b7cd83b602d Fix operator priority bug found thanks to gcc -Wall.
Guido van Rossum <guido@python.org>
parents: 1888
diff changeset
55 if ((mode.c_lflag & ICANON) == 0) {
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 v = PyInt_FromLong((long)mode.c_cc[VMIN]);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if (v == NULL)
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
58 goto err;
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 PyList_SetItem(cc, VMIN, v);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 v = PyInt_FromLong((long)mode.c_cc[VTIME]);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if (v == NULL)
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
62 goto err;
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 PyList_SetItem(cc, VTIME, v);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
66 if (!(v = PyList_New(7)))
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
67 goto err;
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
68
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 PyList_SetItem(v, 3, PyInt_FromLong((long)mode.c_lflag));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 PyList_SetItem(v, 6, cc);
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
76 if (PyErr_Occurred()){
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
77 Py_DECREF(v);
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
78 goto err;
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
79 }
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 return v;
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
81 err:
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
82 Py_DECREF(cc);
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
83 return NULL;
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 /* tcsetattr(fd, when, termios)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 Set the attributes of the terminal device. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 termios_tcsetattr(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 int fd, when;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 struct termios mode;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 speed_t ispeed, ospeed;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 PyObject *term, *cc, *v;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 int i;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 if (!PyList_Check(term) || PyList_Size(term) != 7) {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 PyErr_SetString(PyExc_TypeError, BAD);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 mode.c_cflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 2));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 mode.c_lflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 3));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 cc = PyList_GetItem(term, 6);
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
114 if (PyErr_Occurred())
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
115 return NULL;
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 PyErr_SetString(PyExc_TypeError, BAD);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 for (i = 0; i < NCCS; i++) {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 v = PyList_GetItem(cc, i);
4928
9be65e6c35c8 The usual return-value and memory management checks. I'm not planning
Barry Warsaw <barry@python.org>
parents: 4653
diff changeset
124
1879
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 if (PyString_Check(v) && PyString_Size(v) == 1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 mode.c_cc[i] = (cc_t) * PyString_AsString(v);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 else if (PyInt_Check(v))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 else {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 PyErr_SetString(PyExc_TypeError, BAD);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 if (tcsetattr(fd, when, &mode) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 Py_INCREF(Py_None);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 return Py_None;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 /* tcsendbreak(fd, duration)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 Generate a break condition. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 termios_tcsendbreak(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 int fd, duration;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 if (!PyArg_Parse(args, "(ii)", &fd, &duration))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 if (tcsendbreak(fd, duration) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 Py_INCREF(Py_None);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 return Py_None;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 /* tcdrain(fd)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 Wait until all queued output to the terminal has been
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 transmitted. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 termios_tcdrain(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 int fd;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 if (!PyArg_Parse(args, "i", &fd))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 if (tcdrain(fd) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 Py_INCREF(Py_None);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 return Py_None;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 /* tcflush(fd, queue)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 Clear the input and/or output queues associated with
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 the terminal. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 termios_tcflush(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 int fd, queue;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 if (!PyArg_Parse(args, "(ii)", &fd, &queue))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 if (tcflush(fd, queue) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 Py_INCREF(Py_None);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 return Py_None;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 /* tcflow(fd, action)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 Perform operations relating to XON/XOFF flow control on
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 the terminal. */
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 static PyObject *
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 termios_tcflow(self, args)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 PyObject *self;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 PyObject *args;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 int fd, action;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 if (!PyArg_Parse(args, "(ii)", &fd, &action))
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 return NULL;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 if (tcflow(fd, action) == -1)
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 PyErr_SetFromErrno(TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 Py_INCREF(Py_None);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 return Py_None;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 }
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 static PyMethodDef termios_methods[] =
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 {"tcgetattr", termios_tcgetattr},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 {"tcsetattr", termios_tcsetattr},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 {"tcsendbreak", termios_tcsendbreak},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 {"tcdrain", termios_tcdrain},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 {"tcflush", termios_tcflush},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 {"tcflow", termios_tcflow},
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 {NULL, NULL}
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 };
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 void
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 PyInit_termios()
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 {
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 PyObject *m, *d;
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 m = Py_InitModule("termios", termios_methods);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 d = PyModule_GetDict(m);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 TermiosError = Py_BuildValue("s", "termios.error");
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 PyDict_SetItemString(d, "error", TermiosError);
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 if (PyErr_Occurred())
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 Py_FatalError("can't initialize module termios");
91bfb2771554 Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 }