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