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