|
| 1 | +/* Copyright (c) 2024, Oracle and/or its affiliates. |
| 2 | + * Copyright (C) 1996-2024 Python Software Foundation |
| 3 | + * |
| 4 | + * Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 |
| 5 | + */ |
| 6 | +/*[clinic input] |
| 7 | +preserve |
| 8 | +[clinic start generated code]*/ |
| 9 | + |
| 10 | +PyDoc_STRVAR(termios_tcgetattr__doc__, |
| 11 | +"tcgetattr($module, fd, /)\n" |
| 12 | +"--\n" |
| 13 | +"\n" |
| 14 | +"Get the tty attributes for file descriptor fd.\n" |
| 15 | +"\n" |
| 16 | +"Returns a list [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]\n" |
| 17 | +"where cc is a list of the tty special characters (each a string of\n" |
| 18 | +"length 1, except the items with indices VMIN and VTIME, which are\n" |
| 19 | +"integers when these fields are defined). The interpretation of the\n" |
| 20 | +"flags and the speeds as well as the indexing in the cc array must be\n" |
| 21 | +"done using the symbolic constants defined in this module."); |
| 22 | + |
| 23 | +#define TERMIOS_TCGETATTR_METHODDEF \ |
| 24 | + {"tcgetattr", (PyCFunction)termios_tcgetattr, METH_O, termios_tcgetattr__doc__}, |
| 25 | + |
| 26 | +static PyObject * |
| 27 | +termios_tcgetattr_impl(PyObject *module, int fd); |
| 28 | + |
| 29 | +static PyObject * |
| 30 | +termios_tcgetattr(PyObject *module, PyObject *arg) |
| 31 | +{ |
| 32 | + PyObject *return_value = NULL; |
| 33 | + int fd; |
| 34 | + |
| 35 | + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { |
| 36 | + goto exit; |
| 37 | + } |
| 38 | + return_value = termios_tcgetattr_impl(module, fd); |
| 39 | + |
| 40 | +exit: |
| 41 | + return return_value; |
| 42 | +} |
| 43 | + |
| 44 | +PyDoc_STRVAR(termios_tcsetattr__doc__, |
| 45 | +"tcsetattr($module, fd, when, attributes, /)\n" |
| 46 | +"--\n" |
| 47 | +"\n" |
| 48 | +"Set the tty attributes for file descriptor fd.\n" |
| 49 | +"\n" |
| 50 | +"The attributes to be set are taken from the attributes argument, which\n" |
| 51 | +"is a list like the one returned by tcgetattr(). The when argument\n" |
| 52 | +"determines when the attributes are changed: termios.TCSANOW to\n" |
| 53 | +"change immediately, termios.TCSADRAIN to change after transmitting all\n" |
| 54 | +"queued output, or termios.TCSAFLUSH to change after transmitting all\n" |
| 55 | +"queued output and discarding all queued input."); |
| 56 | + |
| 57 | +#define TERMIOS_TCSETATTR_METHODDEF \ |
| 58 | + {"tcsetattr", _PyCFunction_CAST(termios_tcsetattr), METH_FASTCALL, termios_tcsetattr__doc__}, |
| 59 | + |
| 60 | +static PyObject * |
| 61 | +termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term); |
| 62 | + |
| 63 | +static PyObject * |
| 64 | +termios_tcsetattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 65 | +{ |
| 66 | + PyObject *return_value = NULL; |
| 67 | + int fd; |
| 68 | + int when; |
| 69 | + PyObject *term; |
| 70 | + |
| 71 | + if (!_PyArg_CheckPositional("tcsetattr", nargs, 3, 3)) { |
| 72 | + goto exit; |
| 73 | + } |
| 74 | + if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
| 75 | + goto exit; |
| 76 | + } |
| 77 | + when = _PyLong_AsInt(args[1]); |
| 78 | + if (when == -1 && PyErr_Occurred()) { |
| 79 | + goto exit; |
| 80 | + } |
| 81 | + term = args[2]; |
| 82 | + return_value = termios_tcsetattr_impl(module, fd, when, term); |
| 83 | + |
| 84 | +exit: |
| 85 | + return return_value; |
| 86 | +} |
| 87 | + |
| 88 | +PyDoc_STRVAR(termios_tcsendbreak__doc__, |
| 89 | +"tcsendbreak($module, fd, duration, /)\n" |
| 90 | +"--\n" |
| 91 | +"\n" |
| 92 | +"Send a break on file descriptor fd.\n" |
| 93 | +"\n" |
| 94 | +"A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n" |
| 95 | +"has a system dependent meaning."); |
| 96 | + |
| 97 | +#define TERMIOS_TCSENDBREAK_METHODDEF \ |
| 98 | + {"tcsendbreak", _PyCFunction_CAST(termios_tcsendbreak), METH_FASTCALL, termios_tcsendbreak__doc__}, |
| 99 | + |
| 100 | +static PyObject * |
| 101 | +termios_tcsendbreak_impl(PyObject *module, int fd, int duration); |
| 102 | + |
| 103 | +static PyObject * |
| 104 | +termios_tcsendbreak(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 105 | +{ |
| 106 | + PyObject *return_value = NULL; |
| 107 | + int fd; |
| 108 | + int duration; |
| 109 | + |
| 110 | + if (!_PyArg_CheckPositional("tcsendbreak", nargs, 2, 2)) { |
| 111 | + goto exit; |
| 112 | + } |
| 113 | + if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
| 114 | + goto exit; |
| 115 | + } |
| 116 | + duration = _PyLong_AsInt(args[1]); |
| 117 | + if (duration == -1 && PyErr_Occurred()) { |
| 118 | + goto exit; |
| 119 | + } |
| 120 | + return_value = termios_tcsendbreak_impl(module, fd, duration); |
| 121 | + |
| 122 | +exit: |
| 123 | + return return_value; |
| 124 | +} |
| 125 | + |
| 126 | +PyDoc_STRVAR(termios_tcdrain__doc__, |
| 127 | +"tcdrain($module, fd, /)\n" |
| 128 | +"--\n" |
| 129 | +"\n" |
| 130 | +"Wait until all output written to file descriptor fd has been transmitted."); |
| 131 | + |
| 132 | +#define TERMIOS_TCDRAIN_METHODDEF \ |
| 133 | + {"tcdrain", (PyCFunction)termios_tcdrain, METH_O, termios_tcdrain__doc__}, |
| 134 | + |
| 135 | +static PyObject * |
| 136 | +termios_tcdrain_impl(PyObject *module, int fd); |
| 137 | + |
| 138 | +static PyObject * |
| 139 | +termios_tcdrain(PyObject *module, PyObject *arg) |
| 140 | +{ |
| 141 | + PyObject *return_value = NULL; |
| 142 | + int fd; |
| 143 | + |
| 144 | + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { |
| 145 | + goto exit; |
| 146 | + } |
| 147 | + return_value = termios_tcdrain_impl(module, fd); |
| 148 | + |
| 149 | +exit: |
| 150 | + return return_value; |
| 151 | +} |
| 152 | + |
| 153 | +PyDoc_STRVAR(termios_tcflush__doc__, |
| 154 | +"tcflush($module, fd, queue, /)\n" |
| 155 | +"--\n" |
| 156 | +"\n" |
| 157 | +"Discard queued data on file descriptor fd.\n" |
| 158 | +"\n" |
| 159 | +"The queue selector specifies which queue: termios.TCIFLUSH for the input\n" |
| 160 | +"queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n" |
| 161 | +"both queues."); |
| 162 | + |
| 163 | +#define TERMIOS_TCFLUSH_METHODDEF \ |
| 164 | + {"tcflush", _PyCFunction_CAST(termios_tcflush), METH_FASTCALL, termios_tcflush__doc__}, |
| 165 | + |
| 166 | +static PyObject * |
| 167 | +termios_tcflush_impl(PyObject *module, int fd, int queue); |
| 168 | + |
| 169 | +static PyObject * |
| 170 | +termios_tcflush(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 171 | +{ |
| 172 | + PyObject *return_value = NULL; |
| 173 | + int fd; |
| 174 | + int queue; |
| 175 | + |
| 176 | + if (!_PyArg_CheckPositional("tcflush", nargs, 2, 2)) { |
| 177 | + goto exit; |
| 178 | + } |
| 179 | + if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
| 180 | + goto exit; |
| 181 | + } |
| 182 | + queue = _PyLong_AsInt(args[1]); |
| 183 | + if (queue == -1 && PyErr_Occurred()) { |
| 184 | + goto exit; |
| 185 | + } |
| 186 | + return_value = termios_tcflush_impl(module, fd, queue); |
| 187 | + |
| 188 | +exit: |
| 189 | + return return_value; |
| 190 | +} |
| 191 | + |
| 192 | +PyDoc_STRVAR(termios_tcflow__doc__, |
| 193 | +"tcflow($module, fd, action, /)\n" |
| 194 | +"--\n" |
| 195 | +"\n" |
| 196 | +"Suspend or resume input or output on file descriptor fd.\n" |
| 197 | +"\n" |
| 198 | +"The action argument can be termios.TCOOFF to suspend output,\n" |
| 199 | +"termios.TCOON to restart output, termios.TCIOFF to suspend input,\n" |
| 200 | +"or termios.TCION to restart input."); |
| 201 | + |
| 202 | +#define TERMIOS_TCFLOW_METHODDEF \ |
| 203 | + {"tcflow", _PyCFunction_CAST(termios_tcflow), METH_FASTCALL, termios_tcflow__doc__}, |
| 204 | + |
| 205 | +static PyObject * |
| 206 | +termios_tcflow_impl(PyObject *module, int fd, int action); |
| 207 | + |
| 208 | +static PyObject * |
| 209 | +termios_tcflow(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 210 | +{ |
| 211 | + PyObject *return_value = NULL; |
| 212 | + int fd; |
| 213 | + int action; |
| 214 | + |
| 215 | + if (!_PyArg_CheckPositional("tcflow", nargs, 2, 2)) { |
| 216 | + goto exit; |
| 217 | + } |
| 218 | + if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
| 219 | + goto exit; |
| 220 | + } |
| 221 | + action = _PyLong_AsInt(args[1]); |
| 222 | + if (action == -1 && PyErr_Occurred()) { |
| 223 | + goto exit; |
| 224 | + } |
| 225 | + return_value = termios_tcflow_impl(module, fd, action); |
| 226 | + |
| 227 | +exit: |
| 228 | + return return_value; |
| 229 | +} |
| 230 | + |
| 231 | +PyDoc_STRVAR(termios_tcgetwinsize__doc__, |
| 232 | +"tcgetwinsize($module, fd, /)\n" |
| 233 | +"--\n" |
| 234 | +"\n" |
| 235 | +"Get the tty winsize for file descriptor fd.\n" |
| 236 | +"\n" |
| 237 | +"Returns a tuple (ws_row, ws_col)."); |
| 238 | + |
| 239 | +#define TERMIOS_TCGETWINSIZE_METHODDEF \ |
| 240 | + {"tcgetwinsize", (PyCFunction)termios_tcgetwinsize, METH_O, termios_tcgetwinsize__doc__}, |
| 241 | + |
| 242 | +static PyObject * |
| 243 | +termios_tcgetwinsize_impl(PyObject *module, int fd); |
| 244 | + |
| 245 | +static PyObject * |
| 246 | +termios_tcgetwinsize(PyObject *module, PyObject *arg) |
| 247 | +{ |
| 248 | + PyObject *return_value = NULL; |
| 249 | + int fd; |
| 250 | + |
| 251 | + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { |
| 252 | + goto exit; |
| 253 | + } |
| 254 | + return_value = termios_tcgetwinsize_impl(module, fd); |
| 255 | + |
| 256 | +exit: |
| 257 | + return return_value; |
| 258 | +} |
| 259 | + |
| 260 | +PyDoc_STRVAR(termios_tcsetwinsize__doc__, |
| 261 | +"tcsetwinsize($module, fd, winsize, /)\n" |
| 262 | +"--\n" |
| 263 | +"\n" |
| 264 | +"Set the tty winsize for file descriptor fd.\n" |
| 265 | +"\n" |
| 266 | +"The winsize to be set is taken from the winsize argument, which\n" |
| 267 | +"is a two-item tuple (ws_row, ws_col) like the one returned by tcgetwinsize()."); |
| 268 | + |
| 269 | +#define TERMIOS_TCSETWINSIZE_METHODDEF \ |
| 270 | + {"tcsetwinsize", _PyCFunction_CAST(termios_tcsetwinsize), METH_FASTCALL, termios_tcsetwinsize__doc__}, |
| 271 | + |
| 272 | +static PyObject * |
| 273 | +termios_tcsetwinsize_impl(PyObject *module, int fd, PyObject *winsz); |
| 274 | + |
| 275 | +static PyObject * |
| 276 | +termios_tcsetwinsize(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 277 | +{ |
| 278 | + PyObject *return_value = NULL; |
| 279 | + int fd; |
| 280 | + PyObject *winsz; |
| 281 | + |
| 282 | + if (!_PyArg_CheckPositional("tcsetwinsize", nargs, 2, 2)) { |
| 283 | + goto exit; |
| 284 | + } |
| 285 | + if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) { |
| 286 | + goto exit; |
| 287 | + } |
| 288 | + winsz = args[1]; |
| 289 | + return_value = termios_tcsetwinsize_impl(module, fd, winsz); |
| 290 | + |
| 291 | +exit: |
| 292 | + return return_value; |
| 293 | +} |
| 294 | +/*[clinic end generated code: output=ef9ab888876fac17 input=a9049054013a1b77]*/ |
0 commit comments