tty.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /* $NetBSD: tty.h,v 1.9 2002/03/18 16:01:01 christos Exp $ */
  2. /*-
  3. * Copyright (c) 1992, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Christos Zoulas of Cornell University.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the University of
  20. * California, Berkeley and its contributors.
  21. * 4. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * @(#)tty.h 8.1 (Berkeley) 6/4/93
  38. */
  39. /*
  40. * el.tty.h: Local terminal header
  41. */
  42. #ifndef _h_el_tty
  43. #define _h_el_tty
  44. #include "histedit.h"
  45. #include <termios.h>
  46. #include <unistd.h>
  47. /* Define our own since everyone gets it wrong! */
  48. #define CONTROL(A) ((A) & 037)
  49. /*
  50. * Aix compatible names
  51. */
  52. # if defined(VWERSE) && !defined(VWERASE)
  53. # define VWERASE VWERSE
  54. # endif /* VWERSE && !VWERASE */
  55. # if defined(VDISCRD) && !defined(VDISCARD)
  56. # define VDISCARD VDISCRD
  57. # endif /* VDISCRD && !VDISCARD */
  58. # if defined(VFLUSHO) && !defined(VDISCARD)
  59. # define VDISCARD VFLUSHO
  60. # endif /* VFLUSHO && VDISCARD */
  61. # if defined(VSTRT) && !defined(VSTART)
  62. # define VSTART VSTRT
  63. # endif /* VSTRT && ! VSTART */
  64. # if defined(VSTAT) && !defined(VSTATUS)
  65. # define VSTATUS VSTAT
  66. # endif /* VSTAT && ! VSTATUS */
  67. # ifndef ONLRET
  68. # define ONLRET 0
  69. # endif /* ONLRET */
  70. # ifndef TAB3
  71. # ifdef OXTABS
  72. # define TAB3 OXTABS
  73. # else
  74. # define TAB3 0
  75. # endif /* OXTABS */
  76. # endif /* !TAB3 */
  77. # if defined(OXTABS) && !defined(XTABS)
  78. # define XTABS OXTABS
  79. # endif /* OXTABS && !XTABS */
  80. # ifndef ONLCR
  81. # define ONLCR 0
  82. # endif /* ONLCR */
  83. # ifndef IEXTEN
  84. # define IEXTEN 0
  85. # endif /* IEXTEN */
  86. # ifndef ECHOCTL
  87. # define ECHOCTL 0
  88. # endif /* ECHOCTL */
  89. # ifndef PARENB
  90. # define PARENB 0
  91. # endif /* PARENB */
  92. # ifndef EXTPROC
  93. # define EXTPROC 0
  94. # endif /* EXTPROC */
  95. # ifndef FLUSHO
  96. # define FLUSHO 0
  97. # endif /* FLUSHO */
  98. # if defined(VDISABLE) && !defined(_POSIX_VDISABLE)
  99. # define _POSIX_VDISABLE VDISABLE
  100. # endif /* VDISABLE && ! _POSIX_VDISABLE */
  101. /*
  102. * Work around ISC's definition of IEXTEN which is
  103. * XCASE!
  104. */
  105. # ifdef ISC
  106. # if defined(IEXTEN) && defined(XCASE)
  107. # if IEXTEN == XCASE
  108. # undef IEXTEN
  109. # define IEXTEN 0
  110. # endif /* IEXTEN == XCASE */
  111. # endif /* IEXTEN && XCASE */
  112. # if defined(IEXTEN) && !defined(XCASE)
  113. # define XCASE IEXTEN
  114. # undef IEXTEN
  115. # define IEXTEN 0
  116. # endif /* IEXTEN && !XCASE */
  117. # endif /* ISC */
  118. /*
  119. * Work around convex weirdness where turning off IEXTEN makes us
  120. * lose all postprocessing!
  121. */
  122. #if defined(convex) || defined(__convex__)
  123. # if defined(IEXTEN) && IEXTEN != 0
  124. # undef IEXTEN
  125. # define IEXTEN 0
  126. # endif /* IEXTEN != 0 */
  127. #endif /* convex || __convex__ */
  128. /*
  129. * So that we don't lose job control.
  130. */
  131. #ifdef __SVR4
  132. # undef CSWTCH
  133. #endif
  134. #ifndef _POSIX_VDISABLE
  135. # define _POSIX_VDISABLE ((unsigned char) -1)
  136. #endif /* _POSIX_VDISABLE */
  137. #if !defined(CREPRINT) && defined(CRPRNT)
  138. # define CREPRINT CRPRNT
  139. #endif /* !CREPRINT && CRPRNT */
  140. #if !defined(CDISCARD) && defined(CFLUSH)
  141. # define CDISCARD CFLUSH
  142. #endif /* !CDISCARD && CFLUSH */
  143. #ifndef CINTR
  144. # define CINTR CONTROL('c')
  145. #endif /* CINTR */
  146. #ifndef CQUIT
  147. # define CQUIT 034 /* ^\ */
  148. #endif /* CQUIT */
  149. #ifndef CERASE
  150. # define CERASE 0177 /* ^? */
  151. #endif /* CERASE */
  152. #ifndef CKILL
  153. # define CKILL CONTROL('u')
  154. #endif /* CKILL */
  155. #ifndef CEOF
  156. # define CEOF CONTROL('d')
  157. #endif /* CEOF */
  158. #ifndef CEOL
  159. # define CEOL _POSIX_VDISABLE
  160. #endif /* CEOL */
  161. #ifndef CEOL2
  162. # define CEOL2 _POSIX_VDISABLE
  163. #endif /* CEOL2 */
  164. #ifndef CSWTCH
  165. # define CSWTCH _POSIX_VDISABLE
  166. #endif /* CSWTCH */
  167. #ifndef CDSWTCH
  168. # define CDSWTCH _POSIX_VDISABLE
  169. #endif /* CDSWTCH */
  170. #ifndef CERASE2
  171. # define CERASE2 _POSIX_VDISABLE
  172. #endif /* CERASE2 */
  173. #ifndef CSTART
  174. # define CSTART CONTROL('q')
  175. #endif /* CSTART */
  176. #ifndef CSTOP
  177. # define CSTOP CONTROL('s')
  178. #endif /* CSTOP */
  179. #ifndef CSUSP
  180. # define CSUSP CONTROL('z')
  181. #endif /* CSUSP */
  182. #ifndef CDSUSP
  183. # define CDSUSP CONTROL('y')
  184. #endif /* CDSUSP */
  185. #ifdef hpux
  186. # ifndef CREPRINT
  187. # define CREPRINT _POSIX_VDISABLE
  188. # endif /* CREPRINT */
  189. # ifndef CDISCARD
  190. # define CDISCARD _POSIX_VDISABLE
  191. # endif /* CDISCARD */
  192. # ifndef CLNEXT
  193. # define CLNEXT _POSIX_VDISABLE
  194. # endif /* CLNEXT */
  195. # ifndef CWERASE
  196. # define CWERASE _POSIX_VDISABLE
  197. # endif /* CWERASE */
  198. #else /* !hpux */
  199. # ifndef CREPRINT
  200. # define CREPRINT CONTROL('r')
  201. # endif /* CREPRINT */
  202. # ifndef CDISCARD
  203. # define CDISCARD CONTROL('o')
  204. # endif /* CDISCARD */
  205. # ifndef CLNEXT
  206. # define CLNEXT CONTROL('v')
  207. # endif /* CLNEXT */
  208. # ifndef CWERASE
  209. # define CWERASE CONTROL('w')
  210. # endif /* CWERASE */
  211. #endif /* hpux */
  212. #ifndef CSTATUS
  213. # define CSTATUS CONTROL('t')
  214. #endif /* CSTATUS */
  215. #ifndef CPAGE
  216. # define CPAGE ' '
  217. #endif /* CPAGE */
  218. #ifndef CPGOFF
  219. # define CPGOFF CONTROL('m')
  220. #endif /* CPGOFF */
  221. #ifndef CKILL2
  222. # define CKILL2 _POSIX_VDISABLE
  223. #endif /* CKILL2 */
  224. #ifndef CBRK
  225. # ifndef masscomp
  226. # define CBRK 0377
  227. # else
  228. # define CBRK '\0'
  229. # endif /* masscomp */
  230. #endif /* CBRK */
  231. #ifndef CMIN
  232. # define CMIN CEOF
  233. #endif /* CMIN */
  234. #ifndef CTIME
  235. # define CTIME CEOL
  236. #endif /* CTIME */
  237. /*
  238. * Fix for sun inconsistency. On termio VSUSP and the rest of the
  239. * ttychars > NCC are defined. So we undefine them.
  240. */
  241. #if defined(TERMIO) || defined(POSIX)
  242. # if defined(POSIX) && defined(NCCS)
  243. # define NUMCC NCCS
  244. # else
  245. # ifdef NCC
  246. # define NUMCC NCC
  247. # endif /* NCC */
  248. # endif /* POSIX && NCCS */
  249. # ifdef NUMCC
  250. # ifdef VINTR
  251. # if NUMCC <= VINTR
  252. # undef VINTR
  253. # endif /* NUMCC <= VINTR */
  254. # endif /* VINTR */
  255. # ifdef VQUIT
  256. # if NUMCC <= VQUIT
  257. # undef VQUIT
  258. # endif /* NUMCC <= VQUIT */
  259. # endif /* VQUIT */
  260. # ifdef VERASE
  261. # if NUMCC <= VERASE
  262. # undef VERASE
  263. # endif /* NUMCC <= VERASE */
  264. # endif /* VERASE */
  265. # ifdef VKILL
  266. # if NUMCC <= VKILL
  267. # undef VKILL
  268. # endif /* NUMCC <= VKILL */
  269. # endif /* VKILL */
  270. # ifdef VEOF
  271. # if NUMCC <= VEOF
  272. # undef VEOF
  273. # endif /* NUMCC <= VEOF */
  274. # endif /* VEOF */
  275. # ifdef VEOL
  276. # if NUMCC <= VEOL
  277. # undef VEOL
  278. # endif /* NUMCC <= VEOL */
  279. # endif /* VEOL */
  280. # ifdef VEOL2
  281. # if NUMCC <= VEOL2
  282. # undef VEOL2
  283. # endif /* NUMCC <= VEOL2 */
  284. # endif /* VEOL2 */
  285. # ifdef VSWTCH
  286. # if NUMCC <= VSWTCH
  287. # undef VSWTCH
  288. # endif /* NUMCC <= VSWTCH */
  289. # endif /* VSWTCH */
  290. # ifdef VDSWTCH
  291. # if NUMCC <= VDSWTCH
  292. # undef VDSWTCH
  293. # endif /* NUMCC <= VDSWTCH */
  294. # endif /* VDSWTCH */
  295. # ifdef VERASE2
  296. # if NUMCC <= VERASE2
  297. # undef VERASE2
  298. # endif /* NUMCC <= VERASE2 */
  299. # endif /* VERASE2 */
  300. # ifdef VSTART
  301. # if NUMCC <= VSTART
  302. # undef VSTART
  303. # endif /* NUMCC <= VSTART */
  304. # endif /* VSTART */
  305. # ifdef VSTOP
  306. # if NUMCC <= VSTOP
  307. # undef VSTOP
  308. # endif /* NUMCC <= VSTOP */
  309. # endif /* VSTOP */
  310. # ifdef VWERASE
  311. # if NUMCC <= VWERASE
  312. # undef VWERASE
  313. # endif /* NUMCC <= VWERASE */
  314. # endif /* VWERASE */
  315. # ifdef VSUSP
  316. # if NUMCC <= VSUSP
  317. # undef VSUSP
  318. # endif /* NUMCC <= VSUSP */
  319. # endif /* VSUSP */
  320. # ifdef VDSUSP
  321. # if NUMCC <= VDSUSP
  322. # undef VDSUSP
  323. # endif /* NUMCC <= VDSUSP */
  324. # endif /* VDSUSP */
  325. # ifdef VREPRINT
  326. # if NUMCC <= VREPRINT
  327. # undef VREPRINT
  328. # endif /* NUMCC <= VREPRINT */
  329. # endif /* VREPRINT */
  330. # ifdef VDISCARD
  331. # if NUMCC <= VDISCARD
  332. # undef VDISCARD
  333. # endif /* NUMCC <= VDISCARD */
  334. # endif /* VDISCARD */
  335. # ifdef VLNEXT
  336. # if NUMCC <= VLNEXT
  337. # undef VLNEXT
  338. # endif /* NUMCC <= VLNEXT */
  339. # endif /* VLNEXT */
  340. # ifdef VSTATUS
  341. # if NUMCC <= VSTATUS
  342. # undef VSTATUS
  343. # endif /* NUMCC <= VSTATUS */
  344. # endif /* VSTATUS */
  345. # ifdef VPAGE
  346. # if NUMCC <= VPAGE
  347. # undef VPAGE
  348. # endif /* NUMCC <= VPAGE */
  349. # endif /* VPAGE */
  350. # ifdef VPGOFF
  351. # if NUMCC <= VPGOFF
  352. # undef VPGOFF
  353. # endif /* NUMCC <= VPGOFF */
  354. # endif /* VPGOFF */
  355. # ifdef VKILL2
  356. # if NUMCC <= VKILL2
  357. # undef VKILL2
  358. # endif /* NUMCC <= VKILL2 */
  359. # endif /* VKILL2 */
  360. # ifdef VBRK
  361. # if NUMCC <= VBRK
  362. # undef VBRK
  363. # endif /* NUMCC <= VBRK */
  364. # endif /* VBRK */
  365. # ifdef VMIN
  366. # if NUMCC <= VMIN
  367. # undef VMIN
  368. # endif /* NUMCC <= VMIN */
  369. # endif /* VMIN */
  370. # ifdef VTIME
  371. # if NUMCC <= VTIME
  372. # undef VTIME
  373. # endif /* NUMCC <= VTIME */
  374. # endif /* VTIME */
  375. # endif /* NUMCC */
  376. #endif /* !POSIX */
  377. #define C_INTR 0
  378. #define C_QUIT 1
  379. #define C_ERASE 2
  380. #define C_KILL 3
  381. #define C_EOF 4
  382. #define C_EOL 5
  383. #define C_EOL2 6
  384. #define C_SWTCH 7
  385. #define C_DSWTCH 8
  386. #define C_ERASE2 9
  387. #define C_START 10
  388. #define C_STOP 11
  389. #define C_WERASE 12
  390. #define C_SUSP 13
  391. #define C_DSUSP 14
  392. #define C_REPRINT 15
  393. #define C_DISCARD 16
  394. #define C_LNEXT 17
  395. #define C_STATUS 18
  396. #define C_PAGE 19
  397. #define C_PGOFF 20
  398. #define C_KILL2 21
  399. #define C_BRK 22
  400. #define C_MIN 23
  401. #define C_TIME 24
  402. #define C_NCC 25
  403. #define C_SH(A) (1 << (A))
  404. /*
  405. * Terminal dependend data structures
  406. */
  407. #define EX_IO 0 /* while we are executing */
  408. #define ED_IO 1 /* while we are editing */
  409. #define TS_IO 2 /* new mode from terminal */
  410. #define QU_IO 2 /* used only for quoted chars */
  411. #define NN_IO 3 /* The number of entries */
  412. #define MD_INP 0
  413. #define MD_OUT 1
  414. #define MD_CTL 2
  415. #define MD_LIN 3
  416. #define MD_CHAR 4
  417. #define MD_NN 5
  418. typedef struct {
  419. const char *t_name;
  420. u_int t_setmask;
  421. u_int t_clrmask;
  422. } ttyperm_t[NN_IO][MD_NN];
  423. typedef unsigned char ttychar_t[NN_IO][C_NCC];
  424. protected int tty_init(EditLine *);
  425. protected void tty_end(EditLine *);
  426. protected int tty_stty(EditLine *, int, const char **);
  427. protected int tty_rawmode(EditLine *);
  428. protected int tty_cookedmode(EditLine *);
  429. protected int tty_quotemode(EditLine *);
  430. protected int tty_noquotemode(EditLine *);
  431. protected void tty_bind_char(EditLine *, int);
  432. typedef struct {
  433. ttyperm_t t_t;
  434. ttychar_t t_c;
  435. struct termios t_ex, t_ed, t_ts;
  436. int t_tabs;
  437. int t_eight;
  438. speed_t t_speed;
  439. int t_mode;
  440. unsigned char t_vdisable;
  441. } el_tty_t;
  442. #endif /* _h_el_tty */