1 /*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)tty.h 8.1 (Berkeley) 06/04/93 11 */ 12 13 /* 14 * el.tty.h: Local terminal header 15 */ 16 #ifndef _h_el_tty 17 #define _h_el_tty 18 19 #include "histedit.h" 20 #include <termios.h> 21 22 /* Define our own since everyone gets it wrong! */ 23 #define CONTROL(A) ((A) & 037) 24 25 /* 26 * Aix compatible names 27 */ 28 # if defined(VWERSE) && !defined(VWERASE) 29 # define VWERASE VWERSE 30 # endif /* VWERSE && !VWERASE */ 31 32 # if defined(VDISCRD) && !defined(VDISCARD) 33 # define VDISCARD VDISCRD 34 # endif /* VDISCRD && !VDISCARD */ 35 36 # if defined(VFLUSHO) && !defined(VDISCARD) 37 # define VDISCARD VFLUSHO 38 # endif /* VFLUSHO && VDISCARD */ 39 40 # if defined(VSTRT) && !defined(VSTART) 41 # define VSTART VSTRT 42 # endif /* VSTRT && ! VSTART */ 43 44 # if defined(VSTAT) && !defined(VSTATUS) 45 # define VSTATUS VSTAT 46 # endif /* VSTAT && ! VSTATUS */ 47 48 # ifndef ONLRET 49 # define ONLRET 0 50 # endif /* ONLRET */ 51 52 # ifndef TAB3 53 # ifdef OXTABS 54 # define TAB3 OXTABS 55 # else 56 # define TAB3 0 57 # endif /* OXTABS */ 58 # endif /* !TAB3 */ 59 60 # if defined(OXTABS) && !defined(XTABS) 61 # define XTABS OXTABS 62 # endif /* OXTABS && !XTABS */ 63 64 # ifndef ONLCR 65 # define ONLCR 0 66 # endif /* ONLCR */ 67 68 # ifndef IEXTEN 69 # define IEXTEN 0 70 # endif /* IEXTEN */ 71 72 # ifndef ECHOCTL 73 # define ECHOCTL 0 74 # endif /* ECHOCTL */ 75 76 # ifndef PARENB 77 # define PARENB 0 78 # endif /* PARENB */ 79 80 # ifndef EXTPROC 81 # define EXTPROC 0 82 # endif /* EXTPROC */ 83 84 # ifndef FLUSHO 85 # define FLUSHO 0 86 # endif /* FLUSHO */ 87 88 89 # if defined(VDISABLE) && !defined(_POSIX_VDISABLE) 90 # define _POSIX_VDISABLE VDISABLE 91 # endif /* VDISABLE && ! _POSIX_VDISABLE */ 92 93 /* 94 * Work around ISC's definition of IEXTEN which is 95 * XCASE! 96 */ 97 # ifdef ISC 98 # if defined(IEXTEN) && defined(XCASE) 99 # if IEXTEN == XCASE 100 # undef IEXTEN 101 # define IEXTEN 0 102 # endif /* IEXTEN == XCASE */ 103 # endif /* IEXTEN && XCASE */ 104 # if defined(IEXTEN) && !defined(XCASE) 105 # define XCASE IEXTEN 106 # undef IEXTEN 107 # define IEXTEN 0 108 # endif /* IEXTEN && !XCASE */ 109 # endif /* ISC */ 110 111 /* 112 * Work around convex weirdness where turning off IEXTEN makes us 113 * lose all postprocessing! 114 */ 115 #if defined(convex) || defined(__convex__) 116 # if defined(IEXTEN) && IEXTEN != 0 117 # undef IEXTEN 118 # define IEXTEN 0 119 # endif /* IEXTEN != 0 */ 120 #endif /* convex || __convex__ */ 121 122 123 124 #ifndef _POSIX_VDISABLE 125 # define _POSIX_VDISABLE ((unsigned char) -1) 126 #endif /* _POSIX_VDISABLE */ 127 128 #if !defined(CREPRINT) && defined(CRPRNT) 129 # define CREPRINT CRPRNT 130 #endif /* !CREPRINT && CRPRNT */ 131 #if !defined(CDISCARD) && defined(CFLUSH) 132 # define CDISCARD CFLUSH 133 #endif /* !CDISCARD && CFLUSH */ 134 135 #ifndef CINTR 136 # define CINTR CONTROL('c') 137 #endif /* CINTR */ 138 #ifndef CQUIT 139 # define CQUIT 034 /* ^\ */ 140 #endif /* CQUIT */ 141 #ifndef CERASE 142 # define CERASE 0177 /* ^? */ 143 #endif /* CERASE */ 144 #ifndef CKILL 145 # define CKILL CONTROL('u') 146 #endif /* CKILL */ 147 #ifndef CEOF 148 # define CEOF CONTROL('d') 149 #endif /* CEOF */ 150 #ifndef CEOL 151 # define CEOL _POSIX_VDISABLE 152 #endif /* CEOL */ 153 #ifndef CEOL2 154 # define CEOL2 _POSIX_VDISABLE 155 #endif /* CEOL2 */ 156 #ifndef CSWTCH 157 # define CSWTCH _POSIX_VDISABLE 158 #endif /* CSWTCH */ 159 #ifndef CDSWTCH 160 # define CDSWTCH _POSIX_VDISABLE 161 #endif /* CDSWTCH */ 162 #ifndef CERASE2 163 # define CERASE2 _POSIX_VDISABLE 164 #endif /* CERASE2 */ 165 #ifndef CSTART 166 # define CSTART CONTROL('q') 167 #endif /* CSTART */ 168 #ifndef CSTOP 169 # define CSTOP CONTROL('s') 170 #endif /* CSTOP */ 171 #ifndef CSUSP 172 # define CSUSP CONTROL('z') 173 #endif /* CSUSP */ 174 #ifndef CDSUSP 175 # define CDSUSP CONTROL('y') 176 #endif /* CDSUSP */ 177 178 #ifdef hpux 179 180 # ifndef CREPRINT 181 # define CREPRINT _POSIX_VDISABLE 182 # endif /* CREPRINT */ 183 # ifndef CDISCARD 184 # define CDISCARD _POSIX_VDISABLE 185 # endif /* CDISCARD */ 186 # ifndef CLNEXT 187 # define CLNEXT _POSIX_VDISABLE 188 # endif /* CLNEXT */ 189 # ifndef CWERASE 190 # define CWERASE _POSIX_VDISABLE 191 # endif /* CWERASE */ 192 193 #else /* !hpux */ 194 195 # ifndef CREPRINT 196 # define CREPRINT CONTROL('r') 197 # endif /* CREPRINT */ 198 # ifndef CDISCARD 199 # define CDISCARD CONTROL('o') 200 # endif /* CDISCARD */ 201 # ifndef CLNEXT 202 # define CLNEXT CONTROL('v') 203 # endif /* CLNEXT */ 204 # ifndef CWERASE 205 # define CWERASE CONTROL('w') 206 # endif /* CWERASE */ 207 208 #endif /* hpux */ 209 210 #ifndef CSTATUS 211 # define CSTATUS CONTROL('t') 212 #endif /* CSTATUS */ 213 #ifndef CPAGE 214 # define CPAGE ' ' 215 #endif /* CPAGE */ 216 #ifndef CPGOFF 217 # define CPGOFF CONTROL('m') 218 #endif /* CPGOFF */ 219 #ifndef CKILL2 220 # define CKILL2 _POSIX_VDISABLE 221 #endif /* CKILL2 */ 222 #ifndef CBRK 223 # ifndef masscomp 224 # define CBRK 0377 225 # else 226 # define CBRK '\0' 227 # endif /* masscomp */ 228 #endif /* CBRK */ 229 #ifndef CMIN 230 # define CMIN CEOF 231 #endif /* CMIN */ 232 #ifndef CTIME 233 # define CTIME CEOL 234 #endif /* CTIME */ 235 236 /* 237 * Fix for sun inconsistency. On termio VSUSP and the rest of the 238 * ttychars > NCC are defined. So we undefine them. 239 */ 240 #if defined(TERMIO) || defined(POSIX) 241 # if defined(POSIX) && defined(NCCS) 242 # define NUMCC NCCS 243 # else 244 # ifdef NCC 245 # define NUMCC NCC 246 # endif /* NCC */ 247 # endif /* POSIX && NCCS */ 248 # ifdef NUMCC 249 # ifdef VINTR 250 # if NUMCC <= VINTR 251 # undef VINTR 252 # endif /* NUMCC <= VINTR */ 253 # endif /* VINTR */ 254 # ifdef VQUIT 255 # if NUMCC <= VQUIT 256 # undef VQUIT 257 # endif /* NUMCC <= VQUIT */ 258 # endif /* VQUIT */ 259 # ifdef VERASE 260 # if NUMCC <= VERASE 261 # undef VERASE 262 # endif /* NUMCC <= VERASE */ 263 # endif /* VERASE */ 264 # ifdef VKILL 265 # if NUMCC <= VKILL 266 # undef VKILL 267 # endif /* NUMCC <= VKILL */ 268 # endif /* VKILL */ 269 # ifdef VEOF 270 # if NUMCC <= VEOF 271 # undef VEOF 272 # endif /* NUMCC <= VEOF */ 273 # endif /* VEOF */ 274 # ifdef VEOL 275 # if NUMCC <= VEOL 276 # undef VEOL 277 # endif /* NUMCC <= VEOL */ 278 # endif /* VEOL */ 279 # ifdef VEOL2 280 # if NUMCC <= VEOL2 281 # undef VEOL2 282 # endif /* NUMCC <= VEOL2 */ 283 # endif /* VEOL2 */ 284 # ifdef VSWTCH 285 # if NUMCC <= VSWTCH 286 # undef VSWTCH 287 # endif /* NUMCC <= VSWTCH */ 288 # endif /* VSWTCH */ 289 # ifdef VDSWTCH 290 # if NUMCC <= VDSWTCH 291 # undef VDSWTCH 292 # endif /* NUMCC <= VDSWTCH */ 293 # endif /* VDSWTCH */ 294 # ifdef VERASE2 295 # if NUMCC <= VERASE2 296 # undef VERASE2 297 # endif /* NUMCC <= VERASE2 */ 298 # endif /* VERASE2 */ 299 # ifdef VSTART 300 # if NUMCC <= VSTART 301 # undef VSTART 302 # endif /* NUMCC <= VSTART */ 303 # endif /* VSTART */ 304 # ifdef VSTOP 305 # if NUMCC <= VSTOP 306 # undef VSTOP 307 # endif /* NUMCC <= VSTOP */ 308 # endif /* VSTOP */ 309 # ifdef VWERASE 310 # if NUMCC <= VWERASE 311 # undef VWERASE 312 # endif /* NUMCC <= VWERASE */ 313 # endif /* VWERASE */ 314 # ifdef VSUSP 315 # if NUMCC <= VSUSP 316 # undef VSUSP 317 # endif /* NUMCC <= VSUSP */ 318 # endif /* VSUSP */ 319 # ifdef VDSUSP 320 # if NUMCC <= VDSUSP 321 # undef VDSUSP 322 # endif /* NUMCC <= VDSUSP */ 323 # endif /* VDSUSP */ 324 # ifdef VREPRINT 325 # if NUMCC <= VREPRINT 326 # undef VREPRINT 327 # endif /* NUMCC <= VREPRINT */ 328 # endif /* VREPRINT */ 329 # ifdef VDISCARD 330 # if NUMCC <= VDISCARD 331 # undef VDISCARD 332 # endif /* NUMCC <= VDISCARD */ 333 # endif /* VDISCARD */ 334 # ifdef VLNEXT 335 # if NUMCC <= VLNEXT 336 # undef VLNEXT 337 # endif /* NUMCC <= VLNEXT */ 338 # endif /* VLNEXT */ 339 # ifdef VSTATUS 340 # if NUMCC <= VSTATUS 341 # undef VSTATUS 342 # endif /* NUMCC <= VSTATUS */ 343 # endif /* VSTATUS */ 344 # ifdef VPAGE 345 # if NUMCC <= VPAGE 346 # undef VPAGE 347 # endif /* NUMCC <= VPAGE */ 348 # endif /* VPAGE */ 349 # ifdef VPGOFF 350 # if NUMCC <= VPGOFF 351 # undef VPGOFF 352 # endif /* NUMCC <= VPGOFF */ 353 # endif /* VPGOFF */ 354 # ifdef VKILL2 355 # if NUMCC <= VKILL2 356 # undef VKILL2 357 # endif /* NUMCC <= VKILL2 */ 358 # endif /* VKILL2 */ 359 # ifdef VBRK 360 # if NUMCC <= VBRK 361 # undef VBRK 362 # endif /* NUMCC <= VBRK */ 363 # endif /* VBRK */ 364 # ifdef VMIN 365 # if NUMCC <= VMIN 366 # undef VMIN 367 # endif /* NUMCC <= VMIN */ 368 # endif /* VMIN */ 369 # ifdef VTIME 370 # if NUMCC <= VTIME 371 # undef VTIME 372 # endif /* NUMCC <= VTIME */ 373 # endif /* VTIME */ 374 # endif /* NUMCC */ 375 #endif /* !POSIX */ 376 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 /* 406 * Terminal dependend data structures 407 */ 408 #define EX_IO 0 /* while we are executing */ 409 #define ED_IO 1 /* while we are editing */ 410 #define TS_IO 2 /* new mode from terminal */ 411 #define QU_IO 2 /* used only for quoted chars */ 412 #define NN_IO 3 /* The number of entries */ 413 414 #define M_INP 0 415 #define M_OUT 1 416 #define M_CTL 2 417 #define M_LIN 3 418 #define M_CHAR 4 419 #define M_NN 5 420 421 typedef struct { 422 char *t_name; 423 int t_setmask; 424 int t_clrmask; 425 } ttyperm_t[NN_IO][M_NN]; 426 427 typedef unsigned char ttychar_t[NN_IO][C_NCC]; 428 429 protected int tty_init __P((EditLine *)); 430 protected void tty_end __P((EditLine *)); 431 protected int tty_stty __P((EditLine *, int, char**)); 432 protected int tty_rawmode __P((EditLine *)); 433 protected int tty_cookedmode __P((EditLine *)); 434 protected int tty_quotemode __P((EditLine *)); 435 protected int tty_noquotemode __P((EditLine *)); 436 protected void tty_bind_char __P((EditLine *, int)); 437 438 typedef struct { 439 ttyperm_t t_t; 440 ttychar_t t_c; 441 struct termios t_ex, t_ed, t_ts; 442 int t_tabs; 443 int t_eight; 444 speed_t t_speed; 445 int t_mode; 446 unsigned char t_vdisable; 447 } el_tty_t; 448 449 450 #endif /* _h_el_tty */ 451