Mercurial > cpython-lru_cache-weakref
annotate Modules/termios.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | be956b1efb97 |
| children | 3b7cd83b602d |
| 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) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 return NULL; |
|
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. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 if (mode.c_lflag & ICANON == 0) { |
|
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) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 return NULL; |
|
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) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 return NULL; |
|
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 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 v = PyList_New(7); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed)); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed)); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 PyList_SetItem(v, 6, cc); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 return v; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 /* tcsetattr(fd, when, termios) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 Set the attributes of the terminal device. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 static PyObject * |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 termios_tcsetattr(self, args) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 PyObject *self; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 PyObject *args; |
|
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 int fd, when; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 struct termios mode; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 speed_t ispeed, ospeed; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 PyObject *term, *cc, *v; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 int i; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 if (!PyList_Check(term) || PyList_Size(term) != 7) { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 PyErr_SetString(PyExc_TypeError, BAD); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 for (i = 0; i < 6; i++) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 if (!PyInt_Check(PyList_GetItem(term, i))) { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 PyErr_SetString(PyExc_TypeError, BAD); |
|
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 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 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
|
108 ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4)); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5)); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 cc = PyList_GetItem(term, 6); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 PyErr_SetString(PyExc_TypeError, BAD); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 } |
|
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 for (i = 0; i < NCCS; i++) { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 v = PyList_GetItem(cc, i); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 if (PyString_Check(v) && PyString_Size(v) == 1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 mode.c_cc[i] = (cc_t) * PyString_AsString(v); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 else if (PyInt_Check(v)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 mode.c_cc[i] = (cc_t) PyInt_AsLong(v); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 else { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 PyErr_SetString(PyExc_TypeError, BAD); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 if (cfsetispeed(&mode, (speed_t) ispeed) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 if (cfsetospeed(&mode, (speed_t) ospeed) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 if (tcsetattr(fd, when, &mode) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 Py_INCREF(Py_None); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 return Py_None; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 /* tcsendbreak(fd, duration) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 Generate a break condition. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 static PyObject * |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 termios_tcsendbreak(self, args) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 PyObject *self; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 PyObject *args; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 int fd, duration; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 if (!PyArg_Parse(args, "(ii)", &fd, &duration)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 if (tcsendbreak(fd, duration) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 Py_INCREF(Py_None); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 return Py_None; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 /* tcdrain(fd) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 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
|
161 transmitted. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 static PyObject * |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 termios_tcdrain(self, args) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 PyObject *self; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 PyObject *args; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 int fd; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 if (!PyArg_Parse(args, "i", &fd)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 if (tcdrain(fd) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 Py_INCREF(Py_None); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 return Py_None; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 /* tcflush(fd, queue) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 Clear the input and/or output queues associated with |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 the terminal. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 static PyObject * |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 termios_tcflush(self, args) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 PyObject *self; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 PyObject *args; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 int fd, queue; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 if (!PyArg_Parse(args, "(ii)", &fd, &queue)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 if (tcflush(fd, queue) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 Py_INCREF(Py_None); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 return Py_None; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 /* tcflow(fd, action) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 Perform operations relating to XON/XOFF flow control on |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 the terminal. */ |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 static PyObject * |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 termios_tcflow(self, args) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 PyObject *self; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 PyObject *args; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 int fd, action; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 if (!PyArg_Parse(args, "(ii)", &fd, &action)) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 return NULL; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 if (tcflow(fd, action) == -1) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 PyErr_SetFromErrno(TermiosError); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 Py_INCREF(Py_None); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 return Py_None; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 } |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 static PyMethodDef termios_methods[] = |
|
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 {"tcgetattr", termios_tcgetattr}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 {"tcsetattr", termios_tcsetattr}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 {"tcsendbreak", termios_tcsendbreak}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 {"tcdrain", termios_tcdrain}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 {"tcflush", termios_tcflush}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 {"tcflow", termios_tcflow}, |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 {NULL, NULL} |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 }; |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 void |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 PyInit_termios() |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 { |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 PyObject *m, *d; |
|
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 m = Py_InitModule("termios", termios_methods); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 d = PyModule_GetDict(m); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 TermiosError = Py_BuildValue("s", "termios.error"); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 PyDict_SetItemString(d, "error", TermiosError); |
|
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 if (PyErr_Occurred()) |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 Py_FatalError("can't initialize module termios"); |
|
91bfb2771554
Steen Lumholt's termios interface.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 } |
