rltty.c (136644) | rltty.c (157184) |
---|---|
1/* rltty.c -- functions to prepare and restore the terminal for readline's 2 use. */ 3 | 1/* rltty.c -- functions to prepare and restore the terminal for readline's 2 use. */ 3 |
4/* Copyright (C) 1992 Free Software Foundation, Inc. | 4/* Copyright (C) 1992-2005 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. --- 134 unchanged lines hidden (view full) --- 147#if defined (TIOCGWINSZ) 148 struct winsize w; 149 150 if (ioctl (tty, TIOCGWINSZ, &w) == 0) 151 (void) ioctl (tty, TIOCSWINSZ, &w); 152#endif /* TIOCGWINSZ */ 153} 154 | 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. --- 134 unchanged lines hidden (view full) --- 147#if defined (TIOCGWINSZ) 148 struct winsize w; 149 150 if (ioctl (tty, TIOCGWINSZ, &w) == 0) 151 (void) ioctl (tty, TIOCSWINSZ, &w); 152#endif /* TIOCGWINSZ */ 153} 154 |
155#if defined (NEW_TTY_DRIVER) | 155#if defined (NO_TTY_DRIVER) 156/* Nothing */ 157#elif defined (NEW_TTY_DRIVER) |
156 157/* Values for the `flags' field of a struct bsdtty. This tells which 158 elements of the struct bsdtty have been fetched from the system and 159 are valid. */ 160#define SGTTY_SET 0x01 161#define LFLAG_SET 0x02 162#define TCHARS_SET 0x04 163#define LTCHARS_SET 0x08 --- 64 unchanged lines hidden (view full) --- 228get_tty_settings (tty, tiop) 229 int tty; 230 TIOTYPE *tiop; 231{ 232 set_winsize (tty); 233 234 tiop->flags = tiop->lflag = 0; 235 | 158 159/* Values for the `flags' field of a struct bsdtty. This tells which 160 elements of the struct bsdtty have been fetched from the system and 161 are valid. */ 162#define SGTTY_SET 0x01 163#define LFLAG_SET 0x02 164#define TCHARS_SET 0x04 165#define LTCHARS_SET 0x08 --- 64 unchanged lines hidden (view full) --- 230get_tty_settings (tty, tiop) 231 int tty; 232 TIOTYPE *tiop; 233{ 234 set_winsize (tty); 235 236 tiop->flags = tiop->lflag = 0; 237 |
238 errno = 0; |
|
236 if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) 237 return -1; 238 tiop->flags |= SGTTY_SET; 239 240#if defined (TIOCLGET) 241 if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0) 242 tiop->flags |= LFLAG_SET; 243#endif --- 269 unchanged lines hidden (view full) --- 513 514static int 515get_tty_settings (tty, tiop) 516 int tty; 517 TIOTYPE *tiop; 518{ 519 set_winsize (tty); 520 | 239 if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) 240 return -1; 241 tiop->flags |= SGTTY_SET; 242 243#if defined (TIOCLGET) 244 if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0) 245 tiop->flags |= LFLAG_SET; 246#endif --- 269 unchanged lines hidden (view full) --- 516 517static int 518get_tty_settings (tty, tiop) 519 int tty; 520 TIOTYPE *tiop; 521{ 522 set_winsize (tty); 523 |
524 errno = 0; |
|
521 if (_get_tty_settings (tty, tiop) < 0) 522 return -1; 523 524#if defined (_AIX) 525 setopost(tiop); 526#endif 527 528 return 0; --- 97 unchanged lines hidden (view full) --- 626#endif 627 628#if defined (VDSUSP) 629 tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; 630#endif 631 632#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ 633} | 525 if (_get_tty_settings (tty, tiop) < 0) 526 return -1; 527 528#if defined (_AIX) 529 setopost(tiop); 530#endif 531 532 return 0; --- 97 unchanged lines hidden (view full) --- 630#endif 631 632#if defined (VDSUSP) 633 tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; 634#endif 635 636#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ 637} |
634#endif /* NEW_TTY_DRIVER */ | 638#endif /* !NEW_TTY_DRIVER */ |
635 636/* Put the terminal in CBREAK mode so that we can detect key presses. */ | 639 640/* Put the terminal in CBREAK mode so that we can detect key presses. */ |
641#if defined (NO_TTY_DRIVER) |
|
637void 638rl_prep_terminal (meta_flag) 639 int meta_flag; 640{ | 642void 643rl_prep_terminal (meta_flag) 644 int meta_flag; 645{ |
646 readline_echoing_p = 1; 647} 648 649void 650rl_deprep_terminal () 651{ 652} 653 654#else /* ! NO_TTY_DRIVER */ 655void 656rl_prep_terminal (meta_flag) 657 int meta_flag; 658{ |
|
641 int tty; 642 TIOTYPE tio; 643 644 if (terminal_prepped) 645 return; 646 647 /* Try to keep this function from being INTerrupted. */ 648 block_sigint (); 649 650 tty = fileno (rl_instream); 651 652 if (get_tty_settings (tty, &tio) < 0) 653 { | 659 int tty; 660 TIOTYPE tio; 661 662 if (terminal_prepped) 663 return; 664 665 /* Try to keep this function from being INTerrupted. */ 666 block_sigint (); 667 668 tty = fileno (rl_instream); 669 670 if (get_tty_settings (tty, &tio) < 0) 671 { |
672#if defined (ENOTSUP) 673 /* MacOS X, at least, lies about the value of errno if tcgetattr fails. */ 674 if (errno == ENOTTY || errno == ENOTSUP) 675#else 676 if (errno == ENOTTY) 677#endif 678 readline_echoing_p = 1; /* XXX */ |
|
654 release_sigint (); 655 return; 656 } 657 658 otio = tio; 659 | 679 release_sigint (); 680 return; 681 } 682 683 otio = tio; 684 |
660 rl_tty_unset_default_bindings (_rl_keymap); | 685 if (_rl_bind_stty_chars) 686 { 687#if defined (VI_MODE) 688 /* If editing in vi mode, make sure we restore the bindings in the 689 insertion keymap no matter what keymap we ended up in. */ 690 if (rl_editing_mode == vi_mode) 691 rl_tty_unset_default_bindings (vi_insertion_keymap); 692 else 693#endif 694 rl_tty_unset_default_bindings (_rl_keymap); 695 } |
661 save_tty_chars (&otio); 662 RL_SETSTATE(RL_STATE_TTYCSAVED); | 696 save_tty_chars (&otio); 697 RL_SETSTATE(RL_STATE_TTYCSAVED); |
663 _rl_bind_tty_special_chars (_rl_keymap, tio); | 698 if (_rl_bind_stty_chars) 699 { 700#if defined (VI_MODE) 701 /* If editing in vi mode, make sure we set the bindings in the 702 insertion keymap no matter what keymap we ended up in. */ 703 if (rl_editing_mode == vi_mode) 704 _rl_bind_tty_special_chars (vi_insertion_keymap, tio); 705 else 706#endif 707 _rl_bind_tty_special_chars (_rl_keymap, tio); 708 } |
664 665 prepare_terminal_settings (meta_flag, otio, &tio); 666 667 if (set_tty_settings (tty, &tio) < 0) 668 { 669 release_sigint (); 670 return; 671 } --- 33 unchanged lines hidden (view full) --- 705 return; 706 } 707 708 terminal_prepped = 0; 709 RL_UNSETSTATE(RL_STATE_TERMPREPPED); 710 711 release_sigint (); 712} | 709 710 prepare_terminal_settings (meta_flag, otio, &tio); 711 712 if (set_tty_settings (tty, &tio) < 0) 713 { 714 release_sigint (); 715 return; 716 } --- 33 unchanged lines hidden (view full) --- 750 return; 751 } 752 753 terminal_prepped = 0; 754 RL_UNSETSTATE(RL_STATE_TERMPREPPED); 755 756 release_sigint (); 757} |
758#endif /* !NO_TTY_DRIVER */ |
|
713 714/* **************************************************************** */ 715/* */ 716/* Bogus Flow Control */ 717/* */ 718/* **************************************************************** */ 719 720int 721rl_restart_output (count, key) 722 int count, key; 723{ | 759 760/* **************************************************************** */ 761/* */ 762/* Bogus Flow Control */ 763/* */ 764/* **************************************************************** */ 765 766int 767rl_restart_output (count, key) 768 int count, key; 769{ |
770#if defined (__MINGW32__) 771 return 0; 772#else /* !__MING32__ */ 773 |
|
724 int fildes = fileno (rl_outstream); 725#if defined (TIOCSTART) 726#if defined (apollo) 727 ioctl (&fildes, TIOCSTART, 0); 728#else 729 ioctl (fildes, TIOCSTART, 0); 730#endif /* apollo */ 731 --- 11 unchanged lines hidden (view full) --- 743# else /* !TERMIOS_TTY_DRIVER */ 744# if defined (TCXONC) 745 ioctl (fildes, TCXONC, TCOON); 746# endif /* TCXONC */ 747# endif /* !TERMIOS_TTY_DRIVER */ 748#endif /* !TIOCSTART */ 749 750 return 0; | 774 int fildes = fileno (rl_outstream); 775#if defined (TIOCSTART) 776#if defined (apollo) 777 ioctl (&fildes, TIOCSTART, 0); 778#else 779 ioctl (fildes, TIOCSTART, 0); 780#endif /* apollo */ 781 --- 11 unchanged lines hidden (view full) --- 793# else /* !TERMIOS_TTY_DRIVER */ 794# if defined (TCXONC) 795 ioctl (fildes, TCXONC, TCOON); 796# endif /* TCXONC */ 797# endif /* !TERMIOS_TTY_DRIVER */ 798#endif /* !TIOCSTART */ 799 800 return 0; |
801#endif /* !__MINGW32__ */ |
|
751} 752 753int 754rl_stop_output (count, key) 755 int count, key; 756{ | 802} 803 804int 805rl_stop_output (count, key) 806 int count, key; 807{ |
808#if defined (__MINGW32__) 809 return 0; 810#else 811 |
|
757 int fildes = fileno (rl_instream); 758 759#if defined (TIOCSTOP) 760# if defined (apollo) 761 ioctl (&fildes, TIOCSTOP, 0); 762# else 763 ioctl (fildes, TIOCSTOP, 0); 764# endif /* apollo */ --- 6 unchanged lines hidden (view full) --- 771# else 772# if defined (TCXONC) 773 ioctl (fildes, TCXONC, TCOON); 774# endif /* TCXONC */ 775# endif /* !TERMIOS_TTY_DRIVER */ 776#endif /* !TIOCSTOP */ 777 778 return 0; | 812 int fildes = fileno (rl_instream); 813 814#if defined (TIOCSTOP) 815# if defined (apollo) 816 ioctl (&fildes, TIOCSTOP, 0); 817# else 818 ioctl (fildes, TIOCSTOP, 0); 819# endif /* apollo */ --- 6 unchanged lines hidden (view full) --- 826# else 827# if defined (TCXONC) 828 ioctl (fildes, TCXONC, TCOON); 829# endif /* TCXONC */ 830# endif /* !TERMIOS_TTY_DRIVER */ 831#endif /* !TIOCSTOP */ 832 833 return 0; |
834#endif /* !__MINGW32__ */ |
|
779} 780 781/* **************************************************************** */ 782/* */ 783/* Default Key Bindings */ 784/* */ 785/* **************************************************************** */ 786 | 835} 836 837/* **************************************************************** */ 838/* */ 839/* Default Key Bindings */ 840/* */ 841/* **************************************************************** */ 842 |
843#if !defined (NO_TTY_DRIVER) |
|
787#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func) | 844#define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func) |
845#endif |
|
788 | 846 |
789#if defined (NEW_TTY_DRIVER) | 847#if defined (NO_TTY_DRIVER) 848 849#define SET_SPECIAL(sc, func) 850#define RESET_SPECIAL(c) 851 852#elif defined (NEW_TTY_DRIVER) |
790static void 791set_special_char (kmap, tiop, sc, func) 792 Keymap kmap; 793 TIOTYPE *tiop; 794 int sc; 795 rl_command_func_t *func; 796{ 797 if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) --- 64 unchanged lines hidden (view full) --- 862#endif /* !NEW_TTY_DRIVER */ 863 864/* Set the system's default editing characters to their readline equivalents 865 in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ 866void 867rltty_set_default_bindings (kmap) 868 Keymap kmap; 869{ | 853static void 854set_special_char (kmap, tiop, sc, func) 855 Keymap kmap; 856 TIOTYPE *tiop; 857 int sc; 858 rl_command_func_t *func; 859{ 860 if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) --- 64 unchanged lines hidden (view full) --- 925#endif /* !NEW_TTY_DRIVER */ 926 927/* Set the system's default editing characters to their readline equivalents 928 in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ 929void 930rltty_set_default_bindings (kmap) 931 Keymap kmap; 932{ |
933#if !defined (NO_TTY_DRIVER) |
|
870 TIOTYPE ttybuff; 871 int tty; 872 static int called = 0; 873 874 tty = fileno (rl_instream); 875 876 if (get_tty_settings (tty, &ttybuff) == 0) 877 _rl_bind_tty_special_chars (kmap, ttybuff); | 934 TIOTYPE ttybuff; 935 int tty; 936 static int called = 0; 937 938 tty = fileno (rl_instream); 939 940 if (get_tty_settings (tty, &ttybuff) == 0) 941 _rl_bind_tty_special_chars (kmap, ttybuff); |
942#endif |
|
878} 879 880/* New public way to set the system default editing chars to their readline 881 equivalents. */ 882void 883rl_tty_set_default_bindings (kmap) 884 Keymap kmap; 885{ --- 21 unchanged lines hidden (view full) --- 907 908# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) 909 RESET_SPECIAL (_rl_tty_chars.t_werase); 910# endif /* VWERASE && TERMIOS_TTY_DRIVER */ 911} 912 913#if defined (HANDLE_SIGNALS) 914 | 943} 944 945/* New public way to set the system default editing chars to their readline 946 equivalents. */ 947void 948rl_tty_set_default_bindings (kmap) 949 Keymap kmap; 950{ --- 21 unchanged lines hidden (view full) --- 972 973# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) 974 RESET_SPECIAL (_rl_tty_chars.t_werase); 975# endif /* VWERASE && TERMIOS_TTY_DRIVER */ 976} 977 978#if defined (HANDLE_SIGNALS) 979 |
915#if defined (NEW_TTY_DRIVER) | 980#if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) |
916int 917_rl_disable_tty_signals () 918{ 919 return 0; 920} 921 922int 923_rl_restore_tty_signals () --- 47 unchanged lines hidden --- | 981int 982_rl_disable_tty_signals () 983{ 984 return 0; 985} 986 987int 988_rl_restore_tty_signals () --- 47 unchanged lines hidden --- |