1 /* rltty.c -- functions to prepare and restore the terminal for readline's 2 use. */ 3 4 /* Copyright (C) 1992 Free Software Foundation, Inc. 5 6 This file is part of the GNU Readline Library, a library for 7 reading lines of text with interactive input and history editing. 8 9 The GNU Readline Library is free software; you can redistribute it 10 and/or modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2, or 12 (at your option) any later version. 13 14 The GNU Readline Library is distributed in the hope that it will be 15 useful, but WITHOUT ANY WARRANTY; without even the implied warranty 16 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 The GNU General Public License is often shipped with GNU software, and 20 is generally kept in a file called COPYING or LICENSE. If you do not 21 have a copy of the license, write to the Free Software Foundation, 22 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ 23 #define READLINE_LIBRARY 24 25 #if defined (HAVE_CONFIG_H) 26 # include <config.h> 27 #endif 28 29 #include <sys/types.h> 30 #include <signal.h> 31 #include <errno.h> 32 #include <stdio.h> 33 34 #if defined (HAVE_UNISTD_H) 35 # include <unistd.h> 36 #endif /* HAVE_UNISTD_H */ 37 38 #include "rldefs.h" 39 40 #if defined (GWINSZ_IN_SYS_IOCTL) 41 # include <sys/ioctl.h> 42 #endif /* GWINSZ_IN_SYS_IOCTL */ 43 44 #include "rltty.h" 45 #include "readline.h" 46 #include "rlprivate.h" 47 48 #if !defined (errno) 49 extern int errno; 50 #endif /* !errno */ 51 52 VFunction *rl_prep_term_function = rl_prep_terminal; 53 VFunction *rl_deprep_term_function = rl_deprep_terminal; 54 55 /* **************************************************************** */ 56 /* */ 57 /* Signal Management */ 58 /* */ 59 /* **************************************************************** */ 60 61 #if defined (HAVE_POSIX_SIGNALS) 62 static sigset_t sigint_set, sigint_oset; 63 #else /* !HAVE_POSIX_SIGNALS */ 64 # if defined (HAVE_BSD_SIGNALS) 65 static int sigint_oldmask; 66 # endif /* HAVE_BSD_SIGNALS */ 67 #endif /* !HAVE_POSIX_SIGNALS */ 68 69 static int sigint_blocked; 70 71 /* Cause SIGINT to not be delivered until the corresponding call to 72 release_sigint(). */ 73 static void 74 block_sigint () 75 { 76 if (sigint_blocked) 77 return; 78 79 #if defined (HAVE_POSIX_SIGNALS) 80 sigemptyset (&sigint_set); 81 sigemptyset (&sigint_oset); 82 sigaddset (&sigint_set, SIGINT); 83 sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset); 84 #else /* !HAVE_POSIX_SIGNALS */ 85 # if defined (HAVE_BSD_SIGNALS) 86 sigint_oldmask = sigblock (sigmask (SIGINT)); 87 # else /* !HAVE_BSD_SIGNALS */ 88 # if defined (HAVE_USG_SIGHOLD) 89 sighold (SIGINT); 90 # endif /* HAVE_USG_SIGHOLD */ 91 # endif /* !HAVE_BSD_SIGNALS */ 92 #endif /* !HAVE_POSIX_SIGNALS */ 93 94 sigint_blocked = 1; 95 } 96 97 /* Allow SIGINT to be delivered. */ 98 static void 99 release_sigint () 100 { 101 if (sigint_blocked == 0) 102 return; 103 104 #if defined (HAVE_POSIX_SIGNALS) 105 sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL); 106 #else 107 # if defined (HAVE_BSD_SIGNALS) 108 sigsetmask (sigint_oldmask); 109 # else /* !HAVE_BSD_SIGNALS */ 110 # if defined (HAVE_USG_SIGHOLD) 111 sigrelse (SIGINT); 112 # endif /* HAVE_USG_SIGHOLD */ 113 # endif /* !HAVE_BSD_SIGNALS */ 114 #endif /* !HAVE_POSIX_SIGNALS */ 115 116 sigint_blocked = 0; 117 } 118 119 /* **************************************************************** */ 120 /* */ 121 /* Saving and Restoring the TTY */ 122 /* */ 123 /* **************************************************************** */ 124 125 /* Non-zero means that the terminal is in a prepped state. */ 126 static int terminal_prepped; 127 128 static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; 129 130 /* If non-zero, means that this process has called tcflow(fd, TCOOFF) 131 and output is suspended. */ 132 #if defined (__ksr1__) 133 static int ksrflow; 134 #endif 135 136 /* Dummy call to force a backgrounded readline to stop before it tries 137 to get the tty settings. */ 138 static void 139 set_winsize (tty) 140 int tty; 141 { 142 #if defined (TIOCGWINSZ) 143 struct winsize w; 144 145 if (ioctl (tty, TIOCGWINSZ, &w) == 0) 146 (void) ioctl (tty, TIOCSWINSZ, &w); 147 #endif /* TIOCGWINSZ */ 148 } 149 150 #if defined (NEW_TTY_DRIVER) 151 152 /* Values for the `flags' field of a struct bsdtty. This tells which 153 elements of the struct bsdtty have been fetched from the system and 154 are valid. */ 155 #define SGTTY_SET 0x01 156 #define LFLAG_SET 0x02 157 #define TCHARS_SET 0x04 158 #define LTCHARS_SET 0x08 159 160 struct bsdtty { 161 struct sgttyb sgttyb; /* Basic BSD tty driver information. */ 162 int lflag; /* Local mode flags, like LPASS8. */ 163 #if defined (TIOCGETC) 164 struct tchars tchars; /* Terminal special characters, including ^S and ^Q. */ 165 #endif 166 #if defined (TIOCGLTC) 167 struct ltchars ltchars; /* 4.2 BSD editing characters */ 168 #endif 169 int flags; /* Bitmap saying which parts of the struct are valid. */ 170 }; 171 172 #define TIOTYPE struct bsdtty 173 174 static TIOTYPE otio; 175 176 static void 177 save_tty_chars (tiop) 178 TIOTYPE *tiop; 179 { 180 _rl_last_tty_chars = _rl_tty_chars; 181 182 if (tiop->flags & SGTTY_SET) 183 { 184 _rl_tty_chars.t_erase = tiop->sgttyb.sg_erase; 185 _rl_tty_chars.t_kill = tiop->sgttyb.sg_kill; 186 } 187 188 if (tiop->flags & TCHARS_SET) 189 { 190 _rl_tty_chars.t_intr = tiop->tchars.t_intrc; 191 _rl_tty_chars.t_quit = tiop->tchars.t_quitc; 192 _rl_tty_chars.t_start = tiop->tchars.t_startc; 193 _rl_tty_chars.t_stop = tiop->tchars.t_stopc; 194 _rl_tty_chars.t_eof = tiop->tchars.t_eofc; 195 _rl_tty_chars.t_eol = '\n'; 196 _rl_tty_chars.t_eol2 = tiop->tchars.t_brkc; 197 } 198 199 if (tiop->flags & LTCHARS_SET) 200 { 201 _rl_tty_chars.t_susp = tiop->ltchars.t_suspc; 202 _rl_tty_chars.t_dsusp = tiop->ltchars.t_dsuspc; 203 _rl_tty_chars.t_reprint = tiop->ltchars.t_rprntc; 204 _rl_tty_chars.t_flush = tiop->ltchars.t_flushc; 205 _rl_tty_chars.t_werase = tiop->ltchars.t_werasc; 206 _rl_tty_chars.t_lnext = tiop->ltchars.t_lnextc; 207 } 208 209 _rl_tty_chars.t_status = -1; 210 } 211 212 static int 213 get_tty_settings (tty, tiop) 214 int tty; 215 TIOTYPE *tiop; 216 { 217 set_winsize (tty); 218 219 tiop->flags = tiop->lflag = 0; 220 221 ioctl (tty, TIOCGETP, &(tiop->sgttyb)); 222 tiop->flags |= SGTTY_SET; 223 224 #if defined (TIOCLGET) 225 ioctl (tty, TIOCLGET, &(tiop->lflag)); 226 tiop->flags |= LFLAG_SET; 227 #endif 228 229 #if defined (TIOCGETC) 230 ioctl (tty, TIOCGETC, &(tiop->tchars)); 231 tiop->flags |= TCHARS_SET; 232 #endif 233 234 #if defined (TIOCGLTC) 235 ioctl (tty, TIOCGLTC, &(tiop->ltchars)); 236 tiop->flags |= LTCHARS_SET; 237 #endif 238 239 return 0; 240 } 241 242 static int 243 set_tty_settings (tty, tiop) 244 int tty; 245 TIOTYPE *tiop; 246 { 247 if (tiop->flags & SGTTY_SET) 248 { 249 ioctl (tty, TIOCSETN, &(tiop->sgttyb)); 250 tiop->flags &= ~SGTTY_SET; 251 } 252 readline_echoing_p = 1; 253 254 #if defined (TIOCLSET) 255 if (tiop->flags & LFLAG_SET) 256 { 257 ioctl (tty, TIOCLSET, &(tiop->lflag)); 258 tiop->flags &= ~LFLAG_SET; 259 } 260 #endif 261 262 #if defined (TIOCSETC) 263 if (tiop->flags & TCHARS_SET) 264 { 265 ioctl (tty, TIOCSETC, &(tiop->tchars)); 266 tiop->flags &= ~TCHARS_SET; 267 } 268 #endif 269 270 #if defined (TIOCSLTC) 271 if (tiop->flags & LTCHARS_SET) 272 { 273 ioctl (tty, TIOCSLTC, &(tiop->ltchars)); 274 tiop->flags &= ~LTCHARS_SET; 275 } 276 #endif 277 278 return 0; 279 } 280 281 static void 282 prepare_terminal_settings (meta_flag, otio, tiop) 283 int meta_flag; 284 TIOTYPE otio, *tiop; 285 { 286 readline_echoing_p = (otio.sgttyb.sg_flags & ECHO); 287 288 /* Copy the original settings to the structure we're going to use for 289 our settings. */ 290 tiop->sgttyb = otio.sgttyb; 291 tiop->lflag = otio.lflag; 292 #if defined (TIOCGETC) 293 tiop->tchars = otio.tchars; 294 #endif 295 #if defined (TIOCGLTC) 296 tiop->ltchars = otio.ltchars; 297 #endif 298 tiop->flags = otio.flags; 299 300 /* First, the basic settings to put us into character-at-a-time, no-echo 301 input mode. */ 302 tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD); 303 tiop->sgttyb.sg_flags |= CBREAK; 304 305 /* If this terminal doesn't care how the 8th bit is used, then we can 306 use it for the meta-key. If only one of even or odd parity is 307 specified, then the terminal is using parity, and we cannot. */ 308 #if !defined (ANYP) 309 # define ANYP (EVENP | ODDP) 310 #endif 311 if (((otio.sgttyb.sg_flags & ANYP) == ANYP) || 312 ((otio.sgttyb.sg_flags & ANYP) == 0)) 313 { 314 tiop->sgttyb.sg_flags |= ANYP; 315 316 /* Hack on local mode flags if we can. */ 317 #if defined (TIOCLGET) 318 # if defined (LPASS8) 319 tiop->lflag |= LPASS8; 320 # endif /* LPASS8 */ 321 #endif /* TIOCLGET */ 322 } 323 324 #if defined (TIOCGETC) 325 # if defined (USE_XON_XOFF) 326 /* Get rid of terminal output start and stop characters. */ 327 tiop->tchars.t_stopc = -1; /* C-s */ 328 tiop->tchars.t_startc = -1; /* C-q */ 329 330 /* If there is an XON character, bind it to restart the output. */ 331 if (otio.tchars.t_startc != -1) 332 rl_bind_key (otio.tchars.t_startc, rl_restart_output); 333 # endif /* USE_XON_XOFF */ 334 335 /* If there is an EOF char, bind _rl_eof_char to it. */ 336 if (otio.tchars.t_eofc != -1) 337 _rl_eof_char = otio.tchars.t_eofc; 338 339 # if defined (NO_KILL_INTR) 340 /* Get rid of terminal-generated SIGQUIT and SIGINT. */ 341 tiop->tchars.t_quitc = -1; /* C-\ */ 342 tiop->tchars.t_intrc = -1; /* C-c */ 343 # endif /* NO_KILL_INTR */ 344 #endif /* TIOCGETC */ 345 346 #if defined (TIOCGLTC) 347 /* Make the interrupt keys go away. Just enough to make people happy. */ 348 tiop->ltchars.t_dsuspc = -1; /* C-y */ 349 tiop->ltchars.t_lnextc = -1; /* C-v */ 350 #endif /* TIOCGLTC */ 351 } 352 353 #else /* !defined (NEW_TTY_DRIVER) */ 354 355 #if !defined (VMIN) 356 # define VMIN VEOF 357 #endif 358 359 #if !defined (VTIME) 360 # define VTIME VEOL 361 #endif 362 363 #if defined (TERMIOS_TTY_DRIVER) 364 # define TIOTYPE struct termios 365 # define DRAIN_OUTPUT(fd) tcdrain (fd) 366 # define GETATTR(tty, tiop) (tcgetattr (tty, tiop)) 367 # ifdef M_UNIX 368 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) 369 # else 370 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop)) 371 # endif /* !M_UNIX */ 372 #else 373 # define TIOTYPE struct termio 374 # define DRAIN_OUTPUT(fd) 375 # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop)) 376 # define SETATTR(tty, tiop) (ioctl (tty, TCSETA, tiop)) 377 #endif /* !TERMIOS_TTY_DRIVER */ 378 379 static TIOTYPE otio; 380 381 #if defined (FLUSHO) 382 # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO) 383 #else 384 # define OUTPUT_BEING_FLUSHED(tp) 0 385 #endif 386 387 static void 388 save_tty_chars (tiop) 389 TIOTYPE *tiop; 390 { 391 _rl_last_tty_chars = _rl_tty_chars; 392 393 _rl_tty_chars.t_eof = tiop->c_cc[VEOF]; 394 _rl_tty_chars.t_eol = tiop->c_cc[VEOL]; 395 #ifdef VEOL2 396 _rl_tty_chars.t_eol2 = tiop->c_cc[VEOL2]; 397 #endif 398 _rl_tty_chars.t_erase = tiop->c_cc[VERASE]; 399 #ifdef VWERASE 400 _rl_tty_chars.t_werase = tiop->c_cc[VWERASE]; 401 #endif 402 _rl_tty_chars.t_kill = tiop->c_cc[VKILL]; 403 #ifdef VREPRINT 404 _rl_tty_chars.t_reprint = tiop->c_cc[VREPRINT]; 405 #endif 406 _rl_tty_chars.t_intr = tiop->c_cc[VINTR]; 407 _rl_tty_chars.t_quit = tiop->c_cc[VQUIT]; 408 #ifdef VSUSP 409 _rl_tty_chars.t_susp = tiop->c_cc[VSUSP]; 410 #endif 411 #ifdef VDSUSP 412 _rl_tty_chars.t_dsusp = tiop->c_cc[VDSUSP]; 413 #endif 414 #ifdef VSTART 415 _rl_tty_chars.t_start = tiop->c_cc[VSTART]; 416 #endif 417 #ifdef VSTOP 418 _rl_tty_chars.t_stop = tiop->c_cc[VSTOP]; 419 #endif 420 #ifdef VLNEXT 421 _rl_tty_chars.t_lnext = tiop->c_cc[VLNEXT]; 422 #endif 423 #ifdef VDISCARD 424 _rl_tty_chars.t_flush = tiop->c_cc[VDISCARD]; 425 #endif 426 #ifdef VSTATUS 427 _rl_tty_chars.t_status = tiop->c_cc[VSTATUS]; 428 #endif 429 } 430 431 #if defined (_AIX) || defined (_AIX41) 432 /* Currently this is only used on AIX */ 433 static void 434 rltty_warning (msg) 435 char *msg; 436 { 437 fprintf (stderr, "readline: warning: %s\n", msg); 438 } 439 #endif 440 441 #if defined (_AIX) 442 void 443 setopost(tp) 444 TIOTYPE *tp; 445 { 446 if ((tp->c_oflag & OPOST) == 0) 447 { 448 rltty_warning ("turning on OPOST for terminal\r"); 449 tp->c_oflag |= OPOST|ONLCR; 450 } 451 } 452 #endif 453 454 static int 455 _get_tty_settings (tty, tiop) 456 int tty; 457 TIOTYPE *tiop; 458 { 459 int ioctl_ret; 460 461 while (1) 462 { 463 ioctl_ret = GETATTR (tty, tiop); 464 if (ioctl_ret < 0) 465 { 466 if (errno != EINTR) 467 return -1; 468 else 469 continue; 470 } 471 if (OUTPUT_BEING_FLUSHED (tiop)) 472 { 473 #if defined (FLUSHO) && defined (_AIX41) 474 rltty_warning ("turning off output flushing"); 475 tiop->c_lflag &= ~FLUSHO; 476 break; 477 #else 478 continue; 479 #endif 480 } 481 break; 482 } 483 484 return 0; 485 } 486 487 static int 488 get_tty_settings (tty, tiop) 489 int tty; 490 TIOTYPE *tiop; 491 { 492 set_winsize (tty); 493 494 if (_get_tty_settings (tty, tiop) < 0) 495 return -1; 496 497 #if defined (_AIX) 498 setopost(tiop); 499 #endif 500 501 return 0; 502 } 503 504 static int 505 _set_tty_settings (tty, tiop) 506 int tty; 507 TIOTYPE *tiop; 508 { 509 while (SETATTR (tty, tiop) < 0) 510 { 511 if (errno != EINTR) 512 return -1; 513 errno = 0; 514 } 515 return 0; 516 } 517 518 static int 519 set_tty_settings (tty, tiop) 520 int tty; 521 TIOTYPE *tiop; 522 { 523 if (_set_tty_settings (tty, tiop) < 0) 524 return -1; 525 526 #if 0 527 528 #if defined (TERMIOS_TTY_DRIVER) 529 # if defined (__ksr1__) 530 if (ksrflow) 531 { 532 ksrflow = 0; 533 tcflow (tty, TCOON); 534 } 535 # else /* !ksr1 */ 536 tcflow (tty, TCOON); /* Simulate a ^Q. */ 537 # endif /* !ksr1 */ 538 #else 539 ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ 540 #endif /* !TERMIOS_TTY_DRIVER */ 541 542 #endif /* 0 */ 543 544 return 0; 545 } 546 547 static void 548 prepare_terminal_settings (meta_flag, otio, tiop) 549 int meta_flag; 550 TIOTYPE otio, *tiop; 551 { 552 readline_echoing_p = (otio.c_lflag & ECHO); 553 554 tiop->c_lflag &= ~(ICANON | ECHO); 555 556 if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE) 557 _rl_eof_char = otio.c_cc[VEOF]; 558 559 #if defined (USE_XON_XOFF) 560 #if defined (IXANY) 561 tiop->c_iflag &= ~(IXON | IXOFF | IXANY); 562 #else 563 /* `strict' Posix systems do not define IXANY. */ 564 tiop->c_iflag &= ~(IXON | IXOFF); 565 #endif /* IXANY */ 566 #endif /* USE_XON_XOFF */ 567 568 /* Only turn this off if we are using all 8 bits. */ 569 if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag) 570 tiop->c_iflag &= ~(ISTRIP | INPCK); 571 572 /* Make sure we differentiate between CR and NL on input. */ 573 tiop->c_iflag &= ~(ICRNL | INLCR); 574 575 #if !defined (HANDLE_SIGNALS) 576 tiop->c_lflag &= ~ISIG; 577 #else 578 tiop->c_lflag |= ISIG; 579 #endif 580 581 tiop->c_cc[VMIN] = 1; 582 tiop->c_cc[VTIME] = 0; 583 584 #if defined (FLUSHO) 585 if (OUTPUT_BEING_FLUSHED (tiop)) 586 { 587 tiop->c_lflag &= ~FLUSHO; 588 otio.c_lflag &= ~FLUSHO; 589 } 590 #endif 591 592 /* Turn off characters that we need on Posix systems with job control, 593 just to be sure. This includes ^Y and ^V. This should not really 594 be necessary. */ 595 #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE) 596 597 #if defined (VLNEXT) 598 tiop->c_cc[VLNEXT] = _POSIX_VDISABLE; 599 #endif 600 601 #if defined (VDSUSP) 602 tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; 603 #endif 604 605 #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ 606 } 607 #endif /* NEW_TTY_DRIVER */ 608 609 /* Put the terminal in CBREAK mode so that we can detect key presses. */ 610 void 611 rl_prep_terminal (meta_flag) 612 int meta_flag; 613 { 614 int tty; 615 TIOTYPE tio; 616 617 if (terminal_prepped) 618 return; 619 620 /* Try to keep this function from being INTerrupted. */ 621 block_sigint (); 622 623 tty = fileno (rl_instream); 624 625 if (get_tty_settings (tty, &tio) < 0) 626 { 627 release_sigint (); 628 return; 629 } 630 631 otio = tio; 632 633 save_tty_chars (&otio); 634 635 prepare_terminal_settings (meta_flag, otio, &tio); 636 637 if (set_tty_settings (tty, &tio) < 0) 638 { 639 release_sigint (); 640 return; 641 } 642 643 if (_rl_enable_keypad) 644 _rl_control_keypad (1); 645 646 fflush (rl_outstream); 647 terminal_prepped = 1; 648 649 release_sigint (); 650 } 651 652 /* Restore the terminal's normal settings and modes. */ 653 void 654 rl_deprep_terminal () 655 { 656 int tty; 657 658 if (!terminal_prepped) 659 return; 660 661 /* Try to keep this function from being interrupted. */ 662 block_sigint (); 663 664 tty = fileno (rl_instream); 665 666 if (_rl_enable_keypad) 667 _rl_control_keypad (0); 668 669 fflush (rl_outstream); 670 671 if (set_tty_settings (tty, &otio) < 0) 672 { 673 release_sigint (); 674 return; 675 } 676 677 terminal_prepped = 0; 678 679 release_sigint (); 680 } 681 682 /* **************************************************************** */ 683 /* */ 684 /* Bogus Flow Control */ 685 /* */ 686 /* **************************************************************** */ 687 688 int 689 rl_restart_output (count, key) 690 int count, key; 691 { 692 int fildes = fileno (rl_outstream); 693 #if defined (TIOCSTART) 694 #if defined (apollo) 695 ioctl (&fildes, TIOCSTART, 0); 696 #else 697 ioctl (fildes, TIOCSTART, 0); 698 #endif /* apollo */ 699 700 #else /* !TIOCSTART */ 701 # if defined (TERMIOS_TTY_DRIVER) 702 # if defined (__ksr1__) 703 if (ksrflow) 704 { 705 ksrflow = 0; 706 tcflow (fildes, TCOON); 707 } 708 # else /* !ksr1 */ 709 tcflow (fildes, TCOON); /* Simulate a ^Q. */ 710 # endif /* !ksr1 */ 711 # else /* !TERMIOS_TTY_DRIVER */ 712 # if defined (TCXONC) 713 ioctl (fildes, TCXONC, TCOON); 714 # endif /* TCXONC */ 715 # endif /* !TERMIOS_TTY_DRIVER */ 716 #endif /* !TIOCSTART */ 717 718 return 0; 719 } 720 721 int 722 rl_stop_output (count, key) 723 int count, key; 724 { 725 int fildes = fileno (rl_instream); 726 727 #if defined (TIOCSTOP) 728 # if defined (apollo) 729 ioctl (&fildes, TIOCSTOP, 0); 730 # else 731 ioctl (fildes, TIOCSTOP, 0); 732 # endif /* apollo */ 733 #else /* !TIOCSTOP */ 734 # if defined (TERMIOS_TTY_DRIVER) 735 # if defined (__ksr1__) 736 ksrflow = 1; 737 # endif /* ksr1 */ 738 tcflow (fildes, TCOOFF); 739 # else 740 # if defined (TCXONC) 741 ioctl (fildes, TCXONC, TCOON); 742 # endif /* TCXONC */ 743 # endif /* !TERMIOS_TTY_DRIVER */ 744 #endif /* !TIOCSTOP */ 745 746 return 0; 747 } 748 749 /* **************************************************************** */ 750 /* */ 751 /* Default Key Bindings */ 752 /* */ 753 /* **************************************************************** */ 754 void 755 rltty_set_default_bindings (kmap) 756 Keymap kmap; 757 { 758 TIOTYPE ttybuff; 759 int tty = fileno (rl_instream); 760 761 #if defined (NEW_TTY_DRIVER) 762 763 #define SET_SPECIAL(sc, func) \ 764 do \ 765 { \ 766 int ic; \ 767 ic = sc; \ 768 if (ic != -1 && kmap[ic].type == ISFUNC) \ 769 kmap[ic].function = func; \ 770 } \ 771 while (0) 772 773 if (get_tty_settings (tty, &ttybuff) == 0) 774 { 775 if (ttybuff.flags & SGTTY_SET) 776 { 777 SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); 778 SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); 779 } 780 781 # if defined (TIOCGLTC) 782 if (ttybuff.flags & LTCHARS_SET) 783 { 784 SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); 785 SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); 786 } 787 # endif /* TIOCGLTC */ 788 } 789 790 #else /* !NEW_TTY_DRIVER */ 791 792 #define SET_SPECIAL(sc, func) \ 793 do \ 794 { \ 795 unsigned char uc; \ 796 uc = ttybuff.c_cc[sc]; \ 797 if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ 798 kmap[uc].function = func; \ 799 } \ 800 while (0) 801 802 if (get_tty_settings (tty, &ttybuff) == 0) 803 { 804 SET_SPECIAL (VERASE, rl_rubout); 805 SET_SPECIAL (VKILL, rl_unix_line_discard); 806 807 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) 808 SET_SPECIAL (VLNEXT, rl_quoted_insert); 809 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ 810 811 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) 812 SET_SPECIAL (VWERASE, rl_unix_word_rubout); 813 # endif /* VWERASE && TERMIOS_TTY_DRIVER */ 814 } 815 #endif /* !NEW_TTY_DRIVER */ 816 } 817 818 #if defined (HANDLE_SIGNALS) 819 820 #if defined (NEW_TTY_DRIVER) 821 int 822 _rl_disable_tty_signals () 823 { 824 return 0; 825 } 826 827 int 828 _rl_restore_tty_signals () 829 { 830 return 0; 831 } 832 #else 833 834 static TIOTYPE sigstty, nosigstty; 835 static int tty_sigs_disabled = 0; 836 837 int 838 _rl_disable_tty_signals () 839 { 840 if (tty_sigs_disabled) 841 return 0; 842 843 if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0) 844 return -1; 845 846 nosigstty = sigstty; 847 848 nosigstty.c_lflag &= ~ISIG; 849 850 if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0) 851 return (_set_tty_settings (fileno (rl_instream), &sigstty)); 852 853 tty_sigs_disabled = 1; 854 return 0; 855 } 856 857 int 858 _rl_restore_tty_signals () 859 { 860 if (tty_sigs_disabled == 0) 861 return 0; 862 863 return (_set_tty_settings (fileno (rl_instream), &sigstty)); 864 } 865 #endif /* !NEW_TTY_DRIVER */ 866 867 #endif /* HANDLE_SIGNALS */ 868