ecutermio.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*+-------------------------------------------------------------------------
  2. ecutermio.c
  3. Defined functions:
  4. ecubreak(fd)
  5. ecudrain(fd)
  6. ecuflow(fd, command)
  7. ecuflush(fd, flush_type)
  8. ecugetattr(fd, t)
  9. ecugetspeed(t)
  10. ecusetattr(fd, flag, t)
  11. ecusetspeed(t, speed)
  12. "Tell the moon; don't tell the March Hare: He is here to look around."
  13. -- Yes.
  14. --------------------------------------------------------------------------*/
  15. /*+:EDITS:*/
  16. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  17. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  18. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  19. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  20. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  21. /*:10-14-1995-17:08-wht@kepler-'struct termio' to 'struct TERMIO' */
  22. /*:03-06-1995-17:43-wht@n4hgf-sort out "standard" POSIX tcsendbreak() */
  23. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  24. /*:03-13-1994-18:20-wht@fep-only CFG_TermiosLineio needed */
  25. /*:03-13-1994-18:18-wht@fep-use cfsetispeed/cfsetospeed in lieu of cfsetspeed */
  26. /*:03-13-1994-18:18-wht@fep-first use of edit history */
  27. /*:12-19-1994-12:00-dharris-ecudrain added */
  28. /*:12-18-1994-12:00-dharris-transplant into 3.28.06 */
  29. /*:12-16-1994-12:00-dharris-creation */
  30. #include "ecu.h"
  31. /*+-------------------------------------------------------------------------
  32. ecugetattr(fd, t)
  33. --------------------------------------------------------------------------*/
  34. int
  35. ecugetattr(fd, t)
  36. int fd;
  37. struct TERMIO *t;
  38. {
  39. #if defined(CFG_TermiosLineio)
  40. return (tcgetattr(fd, t));
  41. #else
  42. return (ioctl(fd, TCGETA, t));
  43. #endif
  44. } /* end of ecugetattr */
  45. /*+-------------------------------------------------------------------------
  46. ecusetattr(fd, flag, t)
  47. --------------------------------------------------------------------------*/
  48. int
  49. ecusetattr(fd, flag, t)
  50. int fd, flag;
  51. struct TERMIO *t;
  52. {
  53. #if defined(CFG_TermiosLineio)
  54. return (tcsetattr(fd, flag, t));
  55. #else
  56. return (ioctl(fd, flag, (char *)t));
  57. #endif
  58. } /* end of ecusetattr */
  59. /*+-------------------------------------------------------------------------
  60. ecuflow(fd, command)
  61. --------------------------------------------------------------------------*/
  62. int
  63. ecuflow(fd, command)
  64. int fd, command;
  65. {
  66. #if defined(CFG_TermiosLineio)
  67. return (tcflow(fd, command));
  68. #else
  69. return (ioctl(fd, TCXONC, command));
  70. #endif
  71. } /* end of ecuflow */
  72. /*+-------------------------------------------------------------------------
  73. ecuflush(fd, flush_type)
  74. --------------------------------------------------------------------------*/
  75. int
  76. ecuflush(fd, flush_type)
  77. int fd, flush_type;
  78. {
  79. #if defined(CFG_TermiosLineio)
  80. return (tcflush(fd, flush_type));
  81. #else
  82. return (ioctl(fd, TCFLSH, flush_type));
  83. #endif
  84. } /* end of ecuflush */
  85. /*+-------------------------------------------------------------------------
  86. ecubreak(fd)
  87. --------------------------------------------------------------------------*/
  88. int
  89. ecubreak(fd)
  90. int fd;
  91. {
  92. #if defined(CFG_TermiosLineio)
  93. #if defined(sun) && defined(SVR4) /* Solaris */
  94. /*
  95. * Solaris 2.3 man page says:
  96. *
  97. * Line Control If the terminal is using asynchronous serial data
  98. * transmis- sion, the tcsendbreak() function causes transmission
  99. * of a continuous stream of zero-valued bits for a specific dura-
  100. * tion. If duration is zero, it causes transmission of zero- valued
  101. * bits for at least 0.25 seconds, and not more than 0.5 seconds. If
  102. * duration is not zero, it behaves in a way simi- lar to tcdrain().
  103. * ... The tcdrain() function waits until all output written to the
  104. * object referred to by fildes has been transmitted.
  105. */
  106. return (tcsendbreak(fd, 0));
  107. #else
  108. #if defined(sun) && !defined(SVR4) /* SunOS 4.1.x */
  109. /*
  110. * SunOS man page Last change: 21 January 1990
  111. *
  112. * If the terminal is using asynchronous serial data transmis- sion,
  113. * tcsendbreak() transmits a continuous stream of zero- valued bits
  114. * for a specific duration. If duration is zero, it transmits
  115. * zero-valued bits for at least 0.25 seconds, and not more that 0.5
  116. * seconds. If duration is not zero, it sends zero-valued bits
  117. * for duration*N seconds, where N is at least 0.25, and not more than
  118. * 0.5.
  119. */
  120. return (tcsendbreak(fd, 0));
  121. #else
  122. /*
  123. * use the dharris value
  124. */
  125. return (tcsendbreak(fd, 250000L));
  126. #endif
  127. #endif
  128. #else
  129. return (ioctl(fd, TCSBRK, (char *)0));
  130. #endif
  131. } /* end of ecubreak */
  132. /*+-------------------------------------------------------------------------
  133. ecudrain(fd)
  134. --------------------------------------------------------------------------*/
  135. int
  136. ecudrain(fd)
  137. int fd;
  138. {
  139. #if defined(CFG_TermiosLineio)
  140. return (tcdrain(fd));
  141. #else
  142. return (ioctl(fd, TCSBRK, 1));
  143. #endif
  144. } /* end of ecudrain */
  145. /*+-------------------------------------------------------------------------
  146. ecugetspeed(t)
  147. --------------------------------------------------------------------------*/
  148. int
  149. ecugetspeed(t)
  150. struct TERMIO *t;
  151. {
  152. #if defined(CFG_TermiosLineio)
  153. return (cfgetispeed(t));
  154. #else
  155. return ((unsigned)t->c_cflag & CBAUD);
  156. #endif
  157. } /* end of ecugetspeed */
  158. /*+-------------------------------------------------------------------------
  159. ecusetspeed(t, speed)
  160. --------------------------------------------------------------------------*/
  161. void
  162. ecusetspeed(t, speed)
  163. struct TERMIO *t;
  164. int speed;
  165. {
  166. /*
  167. * we use termios on sunos 4.1.x, but cfsetspeed() is not defined
  168. * Actually, in at least Solaris 2.3, it isn't here either.... RLipe
  169. * [not in Motorola SVR4.1 either; use i/o pair everywhere -- wht]
  170. */
  171. #if defined(CFG_TermiosLineio)
  172. #if 1
  173. cfsetospeed(t, speed);
  174. cfsetispeed(t, speed);
  175. #else
  176. cfsetspeed(t, speed);
  177. #endif /* decommitted */
  178. #else
  179. t->c_cflag &= ~CBAUD;
  180. t->c_cflag |= speed;
  181. #endif /* CFG_TermiosLineio */
  182. } /* end of ecusetspeed */
  183. /* vi: set tabstop=4 shiftwidth=4: */
  184. /* end of ecutermio.c */