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.

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