You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

971 lines
20 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /* termiosmodule.c -- POSIX terminal I/O module implementation. */
  2. #include "Python.h"
  3. /* Apparently, on SGI, termios.h won't define CTRL if _XOPEN_SOURCE
  4. is defined, so we define it here. */
  5. #if defined(__sgi)
  6. #define CTRL(c) ((c)&037)
  7. #endif
  8. #include <termios.h>
  9. #include <sys/ioctl.h>
  10. /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
  11. * MDTR, MRI, and MRTS (appearantly used internally by some things
  12. * defined as macros; these are not used here directly).
  13. */
  14. #ifdef HAVE_SYS_MODEM_H
  15. #include <sys/modem.h>
  16. #endif
  17. /* HP-UX requires that this be included to pick up TIOCGPGRP and friends */
  18. #ifdef HAVE_SYS_BSDTTY_H
  19. #include <sys/bsdtty.h>
  20. #endif
  21. PyDoc_STRVAR(termios__doc__,
  22. "This module provides an interface to the Posix calls for tty I/O control.\n\
  23. For a complete description of these calls, see the Posix or Unix manual\n\
  24. pages. It is only available for those Unix versions that support Posix\n\
  25. termios style tty I/O control.\n\
  26. \n\
  27. All functions in this module take a file descriptor fd as their first\n\
  28. argument. This can be an integer file descriptor, such as returned by\n\
  29. sys.stdin.fileno(), or a file object, such as sys.stdin itself.");
  30. static PyObject *TermiosError;
  31. static int fdconv(PyObject* obj, void* p)
  32. {
  33. int fd;
  34. fd = PyObject_AsFileDescriptor(obj);
  35. if (fd >= 0) {
  36. *(int*)p = fd;
  37. return 1;
  38. }
  39. return 0;
  40. }
  41. PyDoc_STRVAR(termios_tcgetattr__doc__,
  42. "tcgetattr(fd) -> list_of_attrs\n\
  43. \n\
  44. Get the tty attributes for file descriptor fd, as follows:\n\
  45. [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
  46. of the tty special characters (each a string of length 1, except the items\n\
  47. with indices VMIN and VTIME, which are integers when these fields are\n\
  48. defined). The interpretation of the flags and the speeds as well as the\n\
  49. indexing in the cc array must be done using the symbolic constants defined\n\
  50. in this module.");
  51. static PyObject *
  52. termios_tcgetattr(PyObject *self, PyObject *args)
  53. {
  54. int fd;
  55. struct termios mode;
  56. PyObject *cc;
  57. speed_t ispeed, ospeed;
  58. PyObject *v;
  59. int i;
  60. char ch;
  61. if (!PyArg_ParseTuple(args, "O&:tcgetattr",
  62. fdconv, (void*)&fd))
  63. return NULL;
  64. if (tcgetattr(fd, &mode) == -1)
  65. return PyErr_SetFromErrno(TermiosError);
  66. ispeed = cfgetispeed(&mode);
  67. ospeed = cfgetospeed(&mode);
  68. cc = PyList_New(NCCS);
  69. if (cc == NULL)
  70. return NULL;
  71. for (i = 0; i < NCCS; i++) {
  72. ch = (char)mode.c_cc[i];
  73. v = PyBytes_FromStringAndSize(&ch, 1);
  74. if (v == NULL)
  75. goto err;
  76. PyList_SetItem(cc, i, v);
  77. }
  78. /* Convert the MIN and TIME slots to integer. On some systems, the
  79. MIN and TIME slots are the same as the EOF and EOL slots. So we
  80. only do this in noncanonical input mode. */
  81. if ((mode.c_lflag & ICANON) == 0) {
  82. v = PyLong_FromLong((long)mode.c_cc[VMIN]);
  83. if (v == NULL)
  84. goto err;
  85. PyList_SetItem(cc, VMIN, v);
  86. v = PyLong_FromLong((long)mode.c_cc[VTIME]);
  87. if (v == NULL)
  88. goto err;
  89. PyList_SetItem(cc, VTIME, v);
  90. }
  91. if (!(v = PyList_New(7)))
  92. goto err;
  93. PyList_SetItem(v, 0, PyLong_FromLong((long)mode.c_iflag));
  94. PyList_SetItem(v, 1, PyLong_FromLong((long)mode.c_oflag));
  95. PyList_SetItem(v, 2, PyLong_FromLong((long)mode.c_cflag));
  96. PyList_SetItem(v, 3, PyLong_FromLong((long)mode.c_lflag));
  97. PyList_SetItem(v, 4, PyLong_FromLong((long)ispeed));
  98. PyList_SetItem(v, 5, PyLong_FromLong((long)ospeed));
  99. PyList_SetItem(v, 6, cc);
  100. if (PyErr_Occurred()){
  101. Py_DECREF(v);
  102. goto err;
  103. }
  104. return v;
  105. err:
  106. Py_DECREF(cc);
  107. return NULL;
  108. }
  109. PyDoc_STRVAR(termios_tcsetattr__doc__,
  110. "tcsetattr(fd, when, attributes) -> None\n\
  111. \n\
  112. Set the tty attributes for file descriptor fd.\n\
  113. The attributes to be set are taken from the attributes argument, which\n\
  114. is a list like the one returned by tcgetattr(). The when argument\n\
  115. determines when the attributes are changed: termios.TCSANOW to\n\
  116. change immediately, termios.TCSADRAIN to change after transmitting all\n\
  117. queued output, or termios.TCSAFLUSH to change after transmitting all\n\
  118. queued output and discarding all queued input. ");
  119. static PyObject *
  120. termios_tcsetattr(PyObject *self, PyObject *args)
  121. {
  122. int fd, when;
  123. struct termios mode;
  124. speed_t ispeed, ospeed;
  125. PyObject *term, *cc, *v;
  126. int i;
  127. if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
  128. fdconv, &fd, &when, &term))
  129. return NULL;
  130. if (!PyList_Check(term) || PyList_Size(term) != 7) {
  131. PyErr_SetString(PyExc_TypeError,
  132. "tcsetattr, arg 3: must be 7 element list");
  133. return NULL;
  134. }
  135. /* Get the old mode, in case there are any hidden fields... */
  136. if (tcgetattr(fd, &mode) == -1)
  137. return PyErr_SetFromErrno(TermiosError);
  138. mode.c_iflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 0));
  139. mode.c_oflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 1));
  140. mode.c_cflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 2));
  141. mode.c_lflag = (tcflag_t) PyLong_AsLong(PyList_GetItem(term, 3));
  142. ispeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 4));
  143. ospeed = (speed_t) PyLong_AsLong(PyList_GetItem(term, 5));
  144. cc = PyList_GetItem(term, 6);
  145. if (PyErr_Occurred())
  146. return NULL;
  147. if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
  148. PyErr_Format(PyExc_TypeError,
  149. "tcsetattr: attributes[6] must be %d element list",
  150. NCCS);
  151. return NULL;
  152. }
  153. for (i = 0; i < NCCS; i++) {
  154. v = PyList_GetItem(cc, i);
  155. if (PyBytes_Check(v) && PyBytes_Size(v) == 1)
  156. mode.c_cc[i] = (cc_t) * PyBytes_AsString(v);
  157. else if (PyLong_Check(v))
  158. mode.c_cc[i] = (cc_t) PyLong_AsLong(v);
  159. else {
  160. PyErr_SetString(PyExc_TypeError,
  161. "tcsetattr: elements of attributes must be characters or integers");
  162. return NULL;
  163. }
  164. }
  165. if (cfsetispeed(&mode, (speed_t) ispeed) == -1)
  166. return PyErr_SetFromErrno(TermiosError);
  167. if (cfsetospeed(&mode, (speed_t) ospeed) == -1)
  168. return PyErr_SetFromErrno(TermiosError);
  169. if (tcsetattr(fd, when, &mode) == -1)
  170. return PyErr_SetFromErrno(TermiosError);
  171. Py_INCREF(Py_None);
  172. return Py_None;
  173. }
  174. PyDoc_STRVAR(termios_tcsendbreak__doc__,
  175. "tcsendbreak(fd, duration) -> None\n\
  176. \n\
  177. Send a break on file descriptor fd.\n\
  178. A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
  179. has a system dependent meaning.");
  180. static PyObject *
  181. termios_tcsendbreak(PyObject *self, PyObject *args)
  182. {
  183. int fd, duration;
  184. if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
  185. fdconv, &fd, &duration))
  186. return NULL;
  187. if (tcsendbreak(fd, duration) == -1)
  188. return PyErr_SetFromErrno(TermiosError);
  189. Py_INCREF(Py_None);
  190. return Py_None;
  191. }
  192. PyDoc_STRVAR(termios_tcdrain__doc__,
  193. "tcdrain(fd) -> None\n\
  194. \n\
  195. Wait until all output written to file descriptor fd has been transmitted.");
  196. static PyObject *
  197. termios_tcdrain(PyObject *self, PyObject *args)
  198. {
  199. int fd;
  200. if (!PyArg_ParseTuple(args, "O&:tcdrain",
  201. fdconv, &fd))
  202. return NULL;
  203. if (tcdrain(fd) == -1)
  204. return PyErr_SetFromErrno(TermiosError);
  205. Py_INCREF(Py_None);
  206. return Py_None;
  207. }
  208. PyDoc_STRVAR(termios_tcflush__doc__,
  209. "tcflush(fd, queue) -> None\n\
  210. \n\
  211. Discard queued data on file descriptor fd.\n\
  212. The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
  213. queue, termios.TCOFLUSH for the output queue, or termios.TCIOFLUSH for\n\
  214. both queues. ");
  215. static PyObject *
  216. termios_tcflush(PyObject *self, PyObject *args)
  217. {
  218. int fd, queue;
  219. if (!PyArg_ParseTuple(args, "O&i:tcflush",
  220. fdconv, &fd, &queue))
  221. return NULL;
  222. if (tcflush(fd, queue) == -1)
  223. return PyErr_SetFromErrno(TermiosError);
  224. Py_INCREF(Py_None);
  225. return Py_None;
  226. }
  227. PyDoc_STRVAR(termios_tcflow__doc__,
  228. "tcflow(fd, action) -> None\n\
  229. \n\
  230. Suspend or resume input or output on file descriptor fd.\n\
  231. The action argument can be termios.TCOOFF to suspend output,\n\
  232. termios.TCOON to restart output, termios.TCIOFF to suspend input,\n\
  233. or termios.TCION to restart input.");
  234. static PyObject *
  235. termios_tcflow(PyObject *self, PyObject *args)
  236. {
  237. int fd, action;
  238. if (!PyArg_ParseTuple(args, "O&i:tcflow",
  239. fdconv, &fd, &action))
  240. return NULL;
  241. if (tcflow(fd, action) == -1)
  242. return PyErr_SetFromErrno(TermiosError);
  243. Py_INCREF(Py_None);
  244. return Py_None;
  245. }
  246. static PyMethodDef termios_methods[] =
  247. {
  248. {"tcgetattr", termios_tcgetattr,
  249. METH_VARARGS, termios_tcgetattr__doc__},
  250. {"tcsetattr", termios_tcsetattr,
  251. METH_VARARGS, termios_tcsetattr__doc__},
  252. {"tcsendbreak", termios_tcsendbreak,
  253. METH_VARARGS, termios_tcsendbreak__doc__},
  254. {"tcdrain", termios_tcdrain,
  255. METH_VARARGS, termios_tcdrain__doc__},
  256. {"tcflush", termios_tcflush,
  257. METH_VARARGS, termios_tcflush__doc__},
  258. {"tcflow", termios_tcflow,
  259. METH_VARARGS, termios_tcflow__doc__},
  260. {NULL, NULL}
  261. };
  262. #if defined(VSWTCH) && !defined(VSWTC)
  263. #define VSWTC VSWTCH
  264. #endif
  265. #if defined(VSWTC) && !defined(VSWTCH)
  266. #define VSWTCH VSWTC
  267. #endif
  268. static struct constant {
  269. char *name;
  270. long value;
  271. } termios_constants[] = {
  272. /* cfgetospeed(), cfsetospeed() constants */
  273. {"B0", B0},
  274. {"B50", B50},
  275. {"B75", B75},
  276. {"B110", B110},
  277. {"B134", B134},
  278. {"B150", B150},
  279. {"B200", B200},
  280. {"B300", B300},
  281. {"B600", B600},
  282. {"B1200", B1200},
  283. {"B1800", B1800},
  284. {"B2400", B2400},
  285. {"B4800", B4800},
  286. {"B9600", B9600},
  287. {"B19200", B19200},
  288. {"B38400", B38400},
  289. #ifdef B57600
  290. {"B57600", B57600},
  291. #endif
  292. #ifdef B115200
  293. {"B115200", B115200},
  294. #endif
  295. #ifdef B230400
  296. {"B230400", B230400},
  297. #endif
  298. #ifdef B460800
  299. {"B460800", B460800},
  300. #endif
  301. #ifdef B500000
  302. {"B500000", B500000},
  303. #endif
  304. #ifdef B576000
  305. {"B576000", B576000},
  306. #endif
  307. #ifdef B921600
  308. {"B921600", B921600},
  309. #endif
  310. #ifdef B1000000
  311. {"B1000000", B1000000},
  312. #endif
  313. #ifdef B1152000
  314. {"B1152000", B1152000},
  315. #endif
  316. #ifdef B1500000
  317. {"B1500000", B1500000},
  318. #endif
  319. #ifdef B2000000
  320. {"B2000000", B2000000},
  321. #endif
  322. #ifdef B2500000
  323. {"B2500000", B2500000},
  324. #endif
  325. #ifdef B3000000
  326. {"B3000000", B3000000},
  327. #endif
  328. #ifdef B3500000
  329. {"B3500000", B3500000},
  330. #endif
  331. #ifdef B4000000
  332. {"B4000000", B4000000},
  333. #endif
  334. #ifdef CBAUDEX
  335. {"CBAUDEX", CBAUDEX},
  336. #endif
  337. /* tcsetattr() constants */
  338. {"TCSANOW", TCSANOW},
  339. {"TCSADRAIN", TCSADRAIN},
  340. {"TCSAFLUSH", TCSAFLUSH},
  341. #ifdef TCSASOFT
  342. {"TCSASOFT", TCSASOFT},
  343. #endif
  344. /* tcflush() constants */
  345. {"TCIFLUSH", TCIFLUSH},
  346. {"TCOFLUSH", TCOFLUSH},
  347. {"TCIOFLUSH", TCIOFLUSH},
  348. /* tcflow() constants */
  349. {"TCOOFF", TCOOFF},
  350. {"TCOON", TCOON},
  351. {"TCIOFF", TCIOFF},
  352. {"TCION", TCION},
  353. /* struct termios.c_iflag constants */
  354. {"IGNBRK", IGNBRK},
  355. {"BRKINT", BRKINT},
  356. {"IGNPAR", IGNPAR},
  357. {"PARMRK", PARMRK},
  358. {"INPCK", INPCK},
  359. {"ISTRIP", ISTRIP},
  360. {"INLCR", INLCR},
  361. {"IGNCR", IGNCR},
  362. {"ICRNL", ICRNL},
  363. #ifdef IUCLC
  364. {"IUCLC", IUCLC},
  365. #endif
  366. {"IXON", IXON},
  367. {"IXANY", IXANY},
  368. {"IXOFF", IXOFF},
  369. #ifdef IMAXBEL
  370. {"IMAXBEL", IMAXBEL},
  371. #endif
  372. /* struct termios.c_oflag constants */
  373. {"OPOST", OPOST},
  374. #ifdef OLCUC
  375. {"OLCUC", OLCUC},
  376. #endif
  377. #ifdef ONLCR
  378. {"ONLCR", ONLCR},
  379. #endif
  380. #ifdef OCRNL
  381. {"OCRNL", OCRNL},
  382. #endif
  383. #ifdef ONOCR
  384. {"ONOCR", ONOCR},
  385. #endif
  386. #ifdef ONLRET
  387. {"ONLRET", ONLRET},
  388. #endif
  389. #ifdef OFILL
  390. {"OFILL", OFILL},
  391. #endif
  392. #ifdef OFDEL
  393. {"OFDEL", OFDEL},
  394. #endif
  395. #ifdef NLDLY
  396. {"NLDLY", NLDLY},
  397. #endif
  398. #ifdef CRDLY
  399. {"CRDLY", CRDLY},
  400. #endif
  401. #ifdef TABDLY
  402. {"TABDLY", TABDLY},
  403. #endif
  404. #ifdef BSDLY
  405. {"BSDLY", BSDLY},
  406. #endif
  407. #ifdef VTDLY
  408. {"VTDLY", VTDLY},
  409. #endif
  410. #ifdef FFDLY
  411. {"FFDLY", FFDLY},
  412. #endif
  413. /* struct termios.c_oflag-related values (delay mask) */
  414. #ifdef NL0
  415. {"NL0", NL0},
  416. #endif
  417. #ifdef NL1
  418. {"NL1", NL1},
  419. #endif
  420. #ifdef CR0
  421. {"CR0", CR0},
  422. #endif
  423. #ifdef CR1
  424. {"CR1", CR1},
  425. #endif
  426. #ifdef CR2
  427. {"CR2", CR2},
  428. #endif
  429. #ifdef CR3
  430. {"CR3", CR3},
  431. #endif
  432. #ifdef TAB0
  433. {"TAB0", TAB0},
  434. #endif
  435. #ifdef TAB1
  436. {"TAB1", TAB1},
  437. #endif
  438. #ifdef TAB2
  439. {"TAB2", TAB2},
  440. #endif
  441. #ifdef TAB3
  442. {"TAB3", TAB3},
  443. #endif
  444. #ifdef XTABS
  445. {"XTABS", XTABS},
  446. #endif
  447. #ifdef BS0
  448. {"BS0", BS0},
  449. #endif
  450. #ifdef BS1
  451. {"BS1", BS1},
  452. #endif
  453. #ifdef VT0
  454. {"VT0", VT0},
  455. #endif
  456. #ifdef VT1
  457. {"VT1", VT1},
  458. #endif
  459. #ifdef FF0
  460. {"FF0", FF0},
  461. #endif
  462. #ifdef FF1
  463. {"FF1", FF1},
  464. #endif
  465. /* struct termios.c_cflag constants */
  466. {"CSIZE", CSIZE},
  467. {"CSTOPB", CSTOPB},
  468. {"CREAD", CREAD},
  469. {"PARENB", PARENB},
  470. {"PARODD", PARODD},
  471. {"HUPCL", HUPCL},
  472. {"CLOCAL", CLOCAL},
  473. #ifdef CIBAUD
  474. {"CIBAUD", CIBAUD},
  475. #endif
  476. #ifdef CRTSCTS
  477. {"CRTSCTS", (long)CRTSCTS},
  478. #endif
  479. /* struct termios.c_cflag-related values (character size) */
  480. {"CS5", CS5},
  481. {"CS6", CS6},
  482. {"CS7", CS7},
  483. {"CS8", CS8},
  484. /* struct termios.c_lflag constants */
  485. {"ISIG", ISIG},
  486. {"ICANON", ICANON},
  487. #ifdef XCASE
  488. {"XCASE", XCASE},
  489. #endif
  490. {"ECHO", ECHO},
  491. {"ECHOE", ECHOE},
  492. {"ECHOK", ECHOK},
  493. {"ECHONL", ECHONL},
  494. #ifdef ECHOCTL
  495. {"ECHOCTL", ECHOCTL},
  496. #endif
  497. #ifdef ECHOPRT
  498. {"ECHOPRT", ECHOPRT},
  499. #endif
  500. #ifdef ECHOKE
  501. {"ECHOKE", ECHOKE},
  502. #endif
  503. #ifdef FLUSHO
  504. {"FLUSHO", FLUSHO},
  505. #endif
  506. {"NOFLSH", NOFLSH},
  507. {"TOSTOP", TOSTOP},
  508. #ifdef PENDIN
  509. {"PENDIN", PENDIN},
  510. #endif
  511. {"IEXTEN", IEXTEN},
  512. /* indexes into the control chars array returned by tcgetattr() */
  513. {"VINTR", VINTR},
  514. {"VQUIT", VQUIT},
  515. {"VERASE", VERASE},
  516. {"VKILL", VKILL},
  517. {"VEOF", VEOF},
  518. {"VTIME", VTIME},
  519. {"VMIN", VMIN},
  520. #ifdef VSWTC
  521. /* The #defines above ensure that if either is defined, both are,
  522. * but both may be omitted by the system headers. ;-( */
  523. {"VSWTC", VSWTC},
  524. {"VSWTCH", VSWTCH},
  525. #endif
  526. {"VSTART", VSTART},
  527. {"VSTOP", VSTOP},
  528. {"VSUSP", VSUSP},
  529. {"VEOL", VEOL},
  530. #ifdef VREPRINT
  531. {"VREPRINT", VREPRINT},
  532. #endif
  533. #ifdef VDISCARD
  534. {"VDISCARD", VDISCARD},
  535. #endif
  536. #ifdef VWERASE
  537. {"VWERASE", VWERASE},
  538. #endif
  539. #ifdef VLNEXT
  540. {"VLNEXT", VLNEXT},
  541. #endif
  542. #ifdef VEOL2
  543. {"VEOL2", VEOL2},
  544. #endif
  545. #ifdef B460800
  546. {"B460800", B460800},
  547. #endif
  548. #ifdef CBAUD
  549. {"CBAUD", CBAUD},
  550. #endif
  551. #ifdef CDEL
  552. {"CDEL", CDEL},
  553. #endif
  554. #ifdef CDSUSP
  555. {"CDSUSP", CDSUSP},
  556. #endif
  557. #ifdef CEOF
  558. {"CEOF", CEOF},
  559. #endif
  560. #ifdef CEOL
  561. {"CEOL", CEOL},
  562. #endif
  563. #ifdef CEOL2
  564. {"CEOL2", CEOL2},
  565. #endif
  566. #ifdef CEOT
  567. {"CEOT", CEOT},
  568. #endif
  569. #ifdef CERASE
  570. {"CERASE", CERASE},
  571. #endif
  572. #ifdef CESC
  573. {"CESC", CESC},
  574. #endif
  575. #ifdef CFLUSH
  576. {"CFLUSH", CFLUSH},
  577. #endif
  578. #ifdef CINTR
  579. {"CINTR", CINTR},
  580. #endif
  581. #ifdef CKILL
  582. {"CKILL", CKILL},
  583. #endif
  584. #ifdef CLNEXT
  585. {"CLNEXT", CLNEXT},
  586. #endif
  587. #ifdef CNUL
  588. {"CNUL", CNUL},
  589. #endif
  590. #ifdef COMMON
  591. {"COMMON", COMMON},
  592. #endif
  593. #ifdef CQUIT
  594. {"CQUIT", CQUIT},
  595. #endif
  596. #ifdef CRPRNT
  597. {"CRPRNT", CRPRNT},
  598. #endif
  599. #ifdef CSTART
  600. {"CSTART", CSTART},
  601. #endif
  602. #ifdef CSTOP
  603. {"CSTOP", CSTOP},
  604. #endif
  605. #ifdef CSUSP
  606. {"CSUSP", CSUSP},
  607. #endif
  608. #ifdef CSWTCH
  609. {"CSWTCH", CSWTCH},
  610. #endif
  611. #ifdef CWERASE
  612. {"CWERASE", CWERASE},
  613. #endif
  614. #ifdef EXTA
  615. {"EXTA", EXTA},
  616. #endif
  617. #ifdef EXTB
  618. {"EXTB", EXTB},
  619. #endif
  620. #ifdef FIOASYNC
  621. {"FIOASYNC", FIOASYNC},
  622. #endif
  623. #ifdef FIOCLEX
  624. {"FIOCLEX", FIOCLEX},
  625. #endif
  626. #ifdef FIONBIO
  627. {"FIONBIO", FIONBIO},
  628. #endif
  629. #ifdef FIONCLEX
  630. {"FIONCLEX", FIONCLEX},
  631. #endif
  632. #ifdef FIONREAD
  633. {"FIONREAD", FIONREAD},
  634. #endif
  635. #ifdef IBSHIFT
  636. {"IBSHIFT", IBSHIFT},
  637. #endif
  638. #ifdef INIT_C_CC
  639. {"INIT_C_CC", INIT_C_CC},
  640. #endif
  641. #ifdef IOCSIZE_MASK
  642. {"IOCSIZE_MASK", IOCSIZE_MASK},
  643. #endif
  644. #ifdef IOCSIZE_SHIFT
  645. {"IOCSIZE_SHIFT", IOCSIZE_SHIFT},
  646. #endif
  647. #ifdef NCC
  648. {"NCC", NCC},
  649. #endif
  650. #ifdef NCCS
  651. {"NCCS", NCCS},
  652. #endif
  653. #ifdef NSWTCH
  654. {"NSWTCH", NSWTCH},
  655. #endif
  656. #ifdef N_MOUSE
  657. {"N_MOUSE", N_MOUSE},
  658. #endif
  659. #ifdef N_PPP
  660. {"N_PPP", N_PPP},
  661. #endif
  662. #ifdef N_SLIP
  663. {"N_SLIP", N_SLIP},
  664. #endif
  665. #ifdef N_STRIP
  666. {"N_STRIP", N_STRIP},
  667. #endif
  668. #ifdef N_TTY
  669. {"N_TTY", N_TTY},
  670. #endif
  671. #ifdef TCFLSH
  672. {"TCFLSH", TCFLSH},
  673. #endif
  674. #ifdef TCGETA
  675. {"TCGETA", TCGETA},
  676. #endif
  677. #ifdef TCGETS
  678. {"TCGETS", TCGETS},
  679. #endif
  680. #ifdef TCSBRK
  681. {"TCSBRK", TCSBRK},
  682. #endif
  683. #ifdef TCSBRKP
  684. {"TCSBRKP", TCSBRKP},
  685. #endif
  686. #ifdef TCSETA
  687. {"TCSETA", TCSETA},
  688. #endif
  689. #ifdef TCSETAF
  690. {"TCSETAF", TCSETAF},
  691. #endif
  692. #ifdef TCSETAW
  693. {"TCSETAW", TCSETAW},
  694. #endif
  695. #ifdef TCSETS
  696. {"TCSETS", TCSETS},
  697. #endif
  698. #ifdef TCSETSF
  699. {"TCSETSF", TCSETSF},
  700. #endif
  701. #ifdef TCSETSW
  702. {"TCSETSW", TCSETSW},
  703. #endif
  704. #ifdef TCXONC
  705. {"TCXONC", TCXONC},
  706. #endif
  707. #ifdef TIOCCONS
  708. {"TIOCCONS", TIOCCONS},
  709. #endif
  710. #ifdef TIOCEXCL
  711. {"TIOCEXCL", TIOCEXCL},
  712. #endif
  713. #ifdef TIOCGETD
  714. {"TIOCGETD", TIOCGETD},
  715. #endif
  716. #ifdef TIOCGICOUNT
  717. {"TIOCGICOUNT", TIOCGICOUNT},
  718. #endif
  719. #ifdef TIOCGLCKTRMIOS
  720. {"TIOCGLCKTRMIOS", TIOCGLCKTRMIOS},
  721. #endif
  722. #ifdef TIOCGPGRP
  723. {"TIOCGPGRP", TIOCGPGRP},
  724. #endif
  725. #ifdef TIOCGSERIAL
  726. {"TIOCGSERIAL", TIOCGSERIAL},
  727. #endif
  728. #ifdef TIOCGSOFTCAR
  729. {"TIOCGSOFTCAR", TIOCGSOFTCAR},
  730. #endif
  731. #ifdef TIOCGWINSZ
  732. {"TIOCGWINSZ", TIOCGWINSZ},
  733. #endif
  734. #ifdef TIOCINQ
  735. {"TIOCINQ", TIOCINQ},
  736. #endif
  737. #ifdef TIOCLINUX
  738. {"TIOCLINUX", TIOCLINUX},
  739. #endif
  740. #ifdef TIOCMBIC
  741. {"TIOCMBIC", TIOCMBIC},
  742. #endif
  743. #ifdef TIOCMBIS
  744. {"TIOCMBIS", TIOCMBIS},
  745. #endif
  746. #ifdef TIOCMGET
  747. {"TIOCMGET", TIOCMGET},
  748. #endif
  749. #ifdef TIOCMIWAIT
  750. {"TIOCMIWAIT", TIOCMIWAIT},
  751. #endif
  752. #ifdef TIOCMSET
  753. {"TIOCMSET", TIOCMSET},
  754. #endif
  755. #ifdef TIOCM_CAR
  756. {"TIOCM_CAR", TIOCM_CAR},
  757. #endif
  758. #ifdef TIOCM_CD
  759. {"TIOCM_CD", TIOCM_CD},
  760. #endif
  761. #ifdef TIOCM_CTS
  762. {"TIOCM_CTS", TIOCM_CTS},
  763. #endif
  764. #ifdef TIOCM_DSR
  765. {"TIOCM_DSR", TIOCM_DSR},
  766. #endif
  767. #ifdef TIOCM_DTR
  768. {"TIOCM_DTR", TIOCM_DTR},
  769. #endif
  770. #ifdef TIOCM_LE
  771. {"TIOCM_LE", TIOCM_LE},
  772. #endif
  773. #ifdef TIOCM_RI
  774. {"TIOCM_RI", TIOCM_RI},
  775. #endif
  776. #ifdef TIOCM_RNG
  777. {"TIOCM_RNG", TIOCM_RNG},
  778. #endif
  779. #ifdef TIOCM_RTS
  780. {"TIOCM_RTS", TIOCM_RTS},
  781. #endif
  782. #ifdef TIOCM_SR
  783. {"TIOCM_SR", TIOCM_SR},
  784. #endif
  785. #ifdef TIOCM_ST
  786. {"TIOCM_ST", TIOCM_ST},
  787. #endif
  788. #ifdef TIOCNOTTY
  789. {"TIOCNOTTY", TIOCNOTTY},
  790. #endif
  791. #ifdef TIOCNXCL
  792. {"TIOCNXCL", TIOCNXCL},
  793. #endif
  794. #ifdef TIOCOUTQ
  795. {"TIOCOUTQ", TIOCOUTQ},
  796. #endif
  797. #ifdef TIOCPKT
  798. {"TIOCPKT", TIOCPKT},
  799. #endif
  800. #ifdef TIOCPKT_DATA
  801. {"TIOCPKT_DATA", TIOCPKT_DATA},
  802. #endif
  803. #ifdef TIOCPKT_DOSTOP
  804. {"TIOCPKT_DOSTOP", TIOCPKT_DOSTOP},
  805. #endif
  806. #ifdef TIOCPKT_FLUSHREAD
  807. {"TIOCPKT_FLUSHREAD", TIOCPKT_FLUSHREAD},
  808. #endif
  809. #ifdef TIOCPKT_FLUSHWRITE
  810. {"TIOCPKT_FLUSHWRITE", TIOCPKT_FLUSHWRITE},
  811. #endif
  812. #ifdef TIOCPKT_NOSTOP
  813. {"TIOCPKT_NOSTOP", TIOCPKT_NOSTOP},
  814. #endif
  815. #ifdef TIOCPKT_START
  816. {"TIOCPKT_START", TIOCPKT_START},
  817. #endif
  818. #ifdef TIOCPKT_STOP
  819. {"TIOCPKT_STOP", TIOCPKT_STOP},
  820. #endif
  821. #ifdef TIOCSCTTY
  822. {"TIOCSCTTY", TIOCSCTTY},
  823. #endif
  824. #ifdef TIOCSERCONFIG
  825. {"TIOCSERCONFIG", TIOCSERCONFIG},
  826. #endif
  827. #ifdef TIOCSERGETLSR
  828. {"TIOCSERGETLSR", TIOCSERGETLSR},
  829. #endif
  830. #ifdef TIOCSERGETMULTI
  831. {"TIOCSERGETMULTI", TIOCSERGETMULTI},
  832. #endif
  833. #ifdef TIOCSERGSTRUCT
  834. {"TIOCSERGSTRUCT", TIOCSERGSTRUCT},
  835. #endif
  836. #ifdef TIOCSERGWILD
  837. {"TIOCSERGWILD", TIOCSERGWILD},
  838. #endif
  839. #ifdef TIOCSERSETMULTI
  840. {"TIOCSERSETMULTI", TIOCSERSETMULTI},
  841. #endif
  842. #ifdef TIOCSERSWILD
  843. {"TIOCSERSWILD", TIOCSERSWILD},
  844. #endif
  845. #ifdef TIOCSER_TEMT
  846. {"TIOCSER_TEMT", TIOCSER_TEMT},
  847. #endif
  848. #ifdef TIOCSETD
  849. {"TIOCSETD", TIOCSETD},
  850. #endif
  851. #ifdef TIOCSLCKTRMIOS
  852. {"TIOCSLCKTRMIOS", TIOCSLCKTRMIOS},
  853. #endif
  854. #ifdef TIOCSPGRP
  855. {"TIOCSPGRP", TIOCSPGRP},
  856. #endif
  857. #ifdef TIOCSSERIAL
  858. {"TIOCSSERIAL", TIOCSSERIAL},
  859. #endif
  860. #ifdef TIOCSSOFTCAR
  861. {"TIOCSSOFTCAR", TIOCSSOFTCAR},
  862. #endif
  863. #ifdef TIOCSTI
  864. {"TIOCSTI", TIOCSTI},
  865. #endif
  866. #ifdef TIOCSWINSZ
  867. {"TIOCSWINSZ", TIOCSWINSZ},
  868. #endif
  869. #ifdef TIOCTTYGSTRUCT
  870. {"TIOCTTYGSTRUCT", TIOCTTYGSTRUCT},
  871. #endif
  872. /* sentinel */
  873. {NULL, 0}
  874. };
  875. static struct PyModuleDef termiosmodule = {
  876. PyModuleDef_HEAD_INIT,
  877. "termios",
  878. termios__doc__,
  879. -1,
  880. termios_methods,
  881. NULL,
  882. NULL,
  883. NULL,
  884. NULL
  885. };
  886. PyMODINIT_FUNC
  887. PyInit_termios(void)
  888. {
  889. PyObject *m;
  890. struct constant *constant = termios_constants;
  891. m = PyModule_Create(&termiosmodule);
  892. if (m == NULL)
  893. return NULL;
  894. if (TermiosError == NULL) {
  895. TermiosError = PyErr_NewException("termios.error", NULL, NULL);
  896. }
  897. Py_INCREF(TermiosError);
  898. PyModule_AddObject(m, "error", TermiosError);
  899. while (constant->name != NULL) {
  900. PyModule_AddIntConstant(m, constant->name, constant->value);
  901. ++constant;
  902. }
  903. return m;
  904. }