termios.c.h 8.0 KB

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