/* termios.c -- POSIX terminal I/O module implementation. */ // Need limited C API version 3.13 for PyLong_AsInt() // in code generated by Argument Clinic. #include "pyconfig.h" // Py_GIL_DISABLED #ifndef Py_GIL_DISABLED #define Py_LIMITED_API … #endif #include "Python.h" #include <string.h> // memset() #include <sys/ioctl.h> #include <termios.h> #include <unistd.h> // _POSIX_VDISABLE // On QNX 6, struct termio must be declared by including sys/termio.h // if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must // be included before termios.h or it will generate an error. #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux) # include <sys/termio.h> #endif // Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE // is defined, so we define it here. #if defined(__sgi) #define CTRL … #endif // We could do better. Check bpo-32660 #if defined(__sun) # include <sys/filio.h> # include <sys/sockio.h> #endif /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR, * MDTR, MRI, and MRTS (apparently used internally by some things * defined as macros; these are not used here directly). */ #ifdef HAVE_SYS_MODEM_H # include <sys/modem.h> #endif /* HP-UX requires that this be included to pick up TIOCGPGRP and friends */ #ifdef HAVE_SYS_BSDTTY_H # include <sys/bsdtty.h> #endif /*[clinic input] module termios [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=01105c85d0ca7252]*/ #include "clinic/termios.c.h" PyDoc_STRVAR(termios__doc__, "This module provides an interface to the Posix calls for tty I/O control.\n\ For a complete description of these calls, see the Posix or Unix manual\n\ pages. It is only available for those Unix versions that support Posix\n\ termios style tty I/O control.\n\ \n\ All functions in this module take a file descriptor fd as their first\n\ argument. This can be an integer file descriptor, such as returned by\n\ sys.stdin.fileno(), or a file object, such as sys.stdin itself."); termiosmodulestate; static inline termiosmodulestate* get_termios_state(PyObject *module) { … } static struct PyModuleDef termiosmodule; /*[clinic input] termios.tcgetattr fd: fildes / Get the tty attributes for file descriptor fd. Returns a list [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list of the tty special characters (each a string of length 1, except the items with indices VMIN and VTIME, which are integers when these fields are defined). The interpretation of the flags and the speeds as well as the indexing in the cc array must be done using the symbolic constants defined in this module. [clinic start generated code]*/ static PyObject * termios_tcgetattr_impl(PyObject *module, int fd) /*[clinic end generated code: output=2b3da39db870e629 input=54dad9779ebe74b1]*/ { … } /*[clinic input] termios.tcsetattr fd: fildes when: int attributes as term: object / Set the tty attributes for file descriptor fd. The attributes to be set are taken from the attributes argument, which is a list like the one returned by tcgetattr(). The when argument determines when the attributes are changed: termios.TCSANOW to change immediately, termios.TCSADRAIN to change after transmitting all queued output, or termios.TCSAFLUSH to change after transmitting all queued output and discarding all queued input. [clinic start generated code]*/ static PyObject * termios_tcsetattr_impl(PyObject *module, int fd, int when, PyObject *term) /*[clinic end generated code: output=bcd2b0a7b98a4bf5 input=5dafabdd5a08f018]*/ { … } /*[clinic input] termios.tcsendbreak fd: fildes duration: int / Send a break on file descriptor fd. A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration has a system dependent meaning. [clinic start generated code]*/ static PyObject * termios_tcsendbreak_impl(PyObject *module, int fd, int duration) /*[clinic end generated code: output=5945f589b5d3ac66 input=dc2f32417691f8ed]*/ { … } /*[clinic input] termios.tcdrain fd: fildes / Wait until all output written to file descriptor fd has been transmitted. [clinic start generated code]*/ static PyObject * termios_tcdrain_impl(PyObject *module, int fd) /*[clinic end generated code: output=5fd86944c6255955 input=c99241b140b32447]*/ { … } /*[clinic input] termios.tcflush fd: fildes queue: int / Discard queued data on file descriptor fd. The queue selector specifies which queue: termios.TCIFLUSH for the input queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for both queues. [clinic start generated code]*/ static PyObject * termios_tcflush_impl(PyObject *module, int fd, int queue) /*[clinic end generated code: output=2424f80312ec2f21 input=0f7d08122ddc07b5]*/ { … } /*[clinic input] termios.tcflow fd: fildes action: int / Suspend or resume input or output on file descriptor fd. The action argument can be termios.TCOOFF to suspend output, termios.TCOON to restart output, termios.TCIOFF to suspend input, or termios.TCION to restart input. [clinic start generated code]*/ static PyObject * termios_tcflow_impl(PyObject *module, int fd, int action) /*[clinic end generated code: output=afd10928e6ea66eb input=c6aff0640b6efd9c]*/ { … } /*[clinic input] termios.tcgetwinsize fd: fildes / Get the tty winsize for file descriptor fd. Returns a tuple (ws_row, ws_col). [clinic start generated code]*/ static PyObject * termios_tcgetwinsize_impl(PyObject *module, int fd) /*[clinic end generated code: output=31825977d5325fb6 input=5706c379d7fd984d]*/ { … } /*[clinic input] termios.tcsetwinsize fd: fildes winsize as winsz: object / Set the tty winsize for file descriptor fd. The winsize to be set is taken from the winsize argument, which is a two-item tuple (ws_row, ws_col) like the one returned by tcgetwinsize(). [clinic start generated code]*/ static PyObject * termios_tcsetwinsize_impl(PyObject *module, int fd, PyObject *winsz) /*[clinic end generated code: output=2ac3c9bb6eda83e1 input=4a06424465b24aee]*/ { … } static PyMethodDef termios_methods[] = …; #if defined(VSWTCH) && !defined(VSWTC) #define VSWTC … #endif #if defined(VSWTC) && !defined(VSWTCH) #define VSWTCH … #endif static struct constant { … } termios_constants[] = …; static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) { … } static int termiosmodule_clear(PyObject *m) { … } static void termiosmodule_free(void *m) { … } static int termios_exec(PyObject *mod) { … } static PyModuleDef_Slot termios_slots[] = …; static struct PyModuleDef termiosmodule = …; PyMODINIT_FUNC PyInit_termios(void) { … }