1 /* rltty.c -- functions to prepare and restore the terminal for readline's
4 /* Copyright (C) 1992-2016 Free Software Foundation, Inc.
6 This file is part of the GNU Readline Library (Readline), a library
7 for reading lines of text with interactive input and history editing.
9 Readline is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Readline is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Readline. If not, see <http://www.gnu.org/licenses/>.
23 #define READLINE_LIBRARY
25 #if defined (HAVE_CONFIG_H)
29 #include <sys/types.h>
34 #if defined (HAVE_UNISTD_H)
36 #endif /* HAVE_UNISTD_H */
41 #if defined (HAVE_SYS_IOCTL_H)
42 # include <sys/ioctl.h> /* include for declaration of ioctl */
46 #include "rlprivate.h"
52 rl_vintfunc_t
*rl_prep_term_function
= rl_prep_terminal
;
53 rl_voidfunc_t
*rl_deprep_term_function
= rl_deprep_terminal
;
55 static void set_winsize
PARAMS((int));
57 /* **************************************************************** */
59 /* Saving and Restoring the TTY */
61 /* **************************************************************** */
63 /* Non-zero means that the terminal is in a prepped state. There are several
64 flags that are OR'd in to denote whether or not we have sent various
65 init strings to the terminal. */
66 #define TPX_PREPPED 0x01
67 #define TPX_BRACKPASTE 0x02
68 #define TPX_METAKEY 0x04
70 static int terminal_prepped
;
72 static _RL_TTY_CHARS _rl_tty_chars
, _rl_last_tty_chars
;
74 /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
75 and output is suspended. */
76 #if defined (__ksr1__)
80 /* Dummy call to force a backgrounded readline to stop before it tries
81 to get the tty settings. */
86 #if defined (TIOCGWINSZ)
89 if (ioctl (tty
, TIOCGWINSZ
, &w
) == 0)
90 (void) ioctl (tty
, TIOCSWINSZ
, &w
);
91 #endif /* TIOCGWINSZ */
94 #if defined (NO_TTY_DRIVER)
96 #elif defined (NEW_TTY_DRIVER)
98 /* Values for the `flags' field of a struct bsdtty. This tells which
99 elements of the struct bsdtty have been fetched from the system and
101 #define SGTTY_SET 0x01
102 #define LFLAG_SET 0x02
103 #define TCHARS_SET 0x04
104 #define LTCHARS_SET 0x08
107 struct sgttyb sgttyb
; /* Basic BSD tty driver information. */
108 int lflag
; /* Local mode flags, like LPASS8. */
109 #if defined (TIOCGETC)
110 struct tchars tchars
; /* Terminal special characters, including ^S and ^Q. */
112 #if defined (TIOCGLTC)
113 struct ltchars ltchars
; /* 4.2 BSD editing characters */
115 int flags
; /* Bitmap saying which parts of the struct are valid. */
118 #define TIOTYPE struct bsdtty
122 static void save_tty_chars
PARAMS((TIOTYPE
*));
123 static int _get_tty_settings
PARAMS((int, TIOTYPE
*));
124 static int get_tty_settings
PARAMS((int, TIOTYPE
*));
125 static int _set_tty_settings
PARAMS((int, TIOTYPE
*));
126 static int set_tty_settings
PARAMS((int, TIOTYPE
*));
128 static void prepare_terminal_settings
PARAMS((int, TIOTYPE
, TIOTYPE
*));
130 static void set_special_char
PARAMS((Keymap
, TIOTYPE
*, int, rl_command_func_t
*));
133 save_tty_chars (tiop
)
136 _rl_last_tty_chars
= _rl_tty_chars
;
138 if (tiop
->flags
& SGTTY_SET
)
140 _rl_tty_chars
.t_erase
= tiop
->sgttyb
.sg_erase
;
141 _rl_tty_chars
.t_kill
= tiop
->sgttyb
.sg_kill
;
144 if (tiop
->flags
& TCHARS_SET
)
146 _rl_intr_char
= _rl_tty_chars
.t_intr
= tiop
->tchars
.t_intrc
;
147 _rl_quit_char
= _rl_tty_chars
.t_quit
= tiop
->tchars
.t_quitc
;
149 _rl_tty_chars
.t_start
= tiop
->tchars
.t_startc
;
150 _rl_tty_chars
.t_stop
= tiop
->tchars
.t_stopc
;
151 _rl_tty_chars
.t_eof
= tiop
->tchars
.t_eofc
;
152 _rl_tty_chars
.t_eol
= '\n';
153 _rl_tty_chars
.t_eol2
= tiop
->tchars
.t_brkc
;
156 if (tiop
->flags
& LTCHARS_SET
)
158 _rl_susp_char
= _rl_tty_chars
.t_susp
= tiop
->ltchars
.t_suspc
;
160 _rl_tty_chars
.t_dsusp
= tiop
->ltchars
.t_dsuspc
;
161 _rl_tty_chars
.t_reprint
= tiop
->ltchars
.t_rprntc
;
162 _rl_tty_chars
.t_flush
= tiop
->ltchars
.t_flushc
;
163 _rl_tty_chars
.t_werase
= tiop
->ltchars
.t_werasc
;
164 _rl_tty_chars
.t_lnext
= tiop
->ltchars
.t_lnextc
;
167 _rl_tty_chars
.t_status
= -1;
171 get_tty_settings (tty
, tiop
)
177 tiop
->flags
= tiop
->lflag
= 0;
180 if (ioctl (tty
, TIOCGETP
, &(tiop
->sgttyb
)) < 0)
182 tiop
->flags
|= SGTTY_SET
;
184 #if defined (TIOCLGET)
185 if (ioctl (tty
, TIOCLGET
, &(tiop
->lflag
)) == 0)
186 tiop
->flags
|= LFLAG_SET
;
189 #if defined (TIOCGETC)
190 if (ioctl (tty
, TIOCGETC
, &(tiop
->tchars
)) == 0)
191 tiop
->flags
|= TCHARS_SET
;
194 #if defined (TIOCGLTC)
195 if (ioctl (tty
, TIOCGLTC
, &(tiop
->ltchars
)) == 0)
196 tiop
->flags
|= LTCHARS_SET
;
203 set_tty_settings (tty
, tiop
)
207 if (tiop
->flags
& SGTTY_SET
)
209 ioctl (tty
, TIOCSETN
, &(tiop
->sgttyb
));
210 tiop
->flags
&= ~SGTTY_SET
;
214 #if defined (TIOCLSET)
215 if (tiop
->flags
& LFLAG_SET
)
217 ioctl (tty
, TIOCLSET
, &(tiop
->lflag
));
218 tiop
->flags
&= ~LFLAG_SET
;
222 #if defined (TIOCSETC)
223 if (tiop
->flags
& TCHARS_SET
)
225 ioctl (tty
, TIOCSETC
, &(tiop
->tchars
));
226 tiop
->flags
&= ~TCHARS_SET
;
230 #if defined (TIOCSLTC)
231 if (tiop
->flags
& LTCHARS_SET
)
233 ioctl (tty
, TIOCSLTC
, &(tiop
->ltchars
));
234 tiop
->flags
&= ~LTCHARS_SET
;
242 prepare_terminal_settings (meta_flag
, oldtio
, tiop
)
244 TIOTYPE oldtio
, *tiop
;
246 _rl_echoing_p
= (oldtio
.sgttyb
.sg_flags
& ECHO
);
247 _rl_echoctl
= (oldtio
.sgttyb
.sg_flags
& ECHOCTL
);
249 /* Copy the original settings to the structure we're going to use for
251 tiop
->sgttyb
= oldtio
.sgttyb
;
252 tiop
->lflag
= oldtio
.lflag
;
253 #if defined (TIOCGETC)
254 tiop
->tchars
= oldtio
.tchars
;
256 #if defined (TIOCGLTC)
257 tiop
->ltchars
= oldtio
.ltchars
;
259 tiop
->flags
= oldtio
.flags
;
261 /* First, the basic settings to put us into character-at-a-time, no-echo
263 tiop
->sgttyb
.sg_flags
&= ~(ECHO
| CRMOD
);
264 tiop
->sgttyb
.sg_flags
|= CBREAK
;
266 /* If this terminal doesn't care how the 8th bit is used, then we can
267 use it for the meta-key. If only one of even or odd parity is
268 specified, then the terminal is using parity, and we cannot. */
270 # define ANYP (EVENP | ODDP)
272 if (((oldtio
.sgttyb
.sg_flags
& ANYP
) == ANYP
) ||
273 ((oldtio
.sgttyb
.sg_flags
& ANYP
) == 0))
275 tiop
->sgttyb
.sg_flags
|= ANYP
;
277 /* Hack on local mode flags if we can. */
278 #if defined (TIOCLGET)
279 # if defined (LPASS8)
280 tiop
->lflag
|= LPASS8
;
282 #endif /* TIOCLGET */
285 #if defined (TIOCGETC)
286 # if defined (USE_XON_XOFF)
287 /* Get rid of terminal output start and stop characters. */
288 tiop
->tchars
.t_stopc
= -1; /* C-s */
289 tiop
->tchars
.t_startc
= -1; /* C-q */
291 /* If there is an XON character, bind it to restart the output. */
292 if (oldtio
.tchars
.t_startc
!= -1)
293 rl_bind_key (oldtio
.tchars
.t_startc
, rl_restart_output
);
294 # endif /* USE_XON_XOFF */
296 /* If there is an EOF char, bind _rl_eof_char to it. */
297 if (oldtio
.tchars
.t_eofc
!= -1)
298 _rl_eof_char
= oldtio
.tchars
.t_eofc
;
300 # if defined (NO_KILL_INTR)
301 /* Get rid of terminal-generated SIGQUIT and SIGINT. */
302 tiop
->tchars
.t_quitc
= -1; /* C-\ */
303 tiop
->tchars
.t_intrc
= -1; /* C-c */
304 # endif /* NO_KILL_INTR */
305 #endif /* TIOCGETC */
307 #if defined (TIOCGLTC)
308 /* Make the interrupt keys go away. Just enough to make people happy. */
309 tiop
->ltchars
.t_dsuspc
= -1; /* C-y */
310 tiop
->ltchars
.t_lnextc
= -1; /* C-v */
311 #endif /* TIOCGLTC */
314 #else /* !defined (NEW_TTY_DRIVER) */
324 #if defined (TERMIOS_TTY_DRIVER)
325 # define TIOTYPE struct termios
326 # define DRAIN_OUTPUT(fd) tcdrain (fd)
327 # define GETATTR(tty, tiop) (tcgetattr (tty, tiop))
329 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop))
331 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop))
332 # endif /* !M_UNIX */
334 # define TIOTYPE struct termio
335 # define DRAIN_OUTPUT(fd)
336 # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop))
337 # define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop))
338 #endif /* !TERMIOS_TTY_DRIVER */
342 static void save_tty_chars
PARAMS((TIOTYPE
*));
343 static int _get_tty_settings
PARAMS((int, TIOTYPE
*));
344 static int get_tty_settings
PARAMS((int, TIOTYPE
*));
345 static int _set_tty_settings
PARAMS((int, TIOTYPE
*));
346 static int set_tty_settings
PARAMS((int, TIOTYPE
*));
348 static void prepare_terminal_settings
PARAMS((int, TIOTYPE
, TIOTYPE
*));
350 static void set_special_char
PARAMS((Keymap
, TIOTYPE
*, int, rl_command_func_t
*));
351 static void _rl_bind_tty_special_chars
PARAMS((Keymap
, TIOTYPE
));
354 # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO)
356 # define OUTPUT_BEING_FLUSHED(tp) 0
360 save_tty_chars (tiop
)
363 _rl_last_tty_chars
= _rl_tty_chars
;
365 _rl_tty_chars
.t_eof
= tiop
->c_cc
[VEOF
];
366 _rl_tty_chars
.t_eol
= tiop
->c_cc
[VEOL
];
368 _rl_tty_chars
.t_eol2
= tiop
->c_cc
[VEOL2
];
370 _rl_tty_chars
.t_erase
= tiop
->c_cc
[VERASE
];
372 _rl_tty_chars
.t_werase
= tiop
->c_cc
[VWERASE
];
374 _rl_tty_chars
.t_kill
= tiop
->c_cc
[VKILL
];
376 _rl_tty_chars
.t_reprint
= tiop
->c_cc
[VREPRINT
];
378 _rl_intr_char
= _rl_tty_chars
.t_intr
= tiop
->c_cc
[VINTR
];
379 _rl_quit_char
= _rl_tty_chars
.t_quit
= tiop
->c_cc
[VQUIT
];
381 _rl_susp_char
= _rl_tty_chars
.t_susp
= tiop
->c_cc
[VSUSP
];
384 _rl_tty_chars
.t_dsusp
= tiop
->c_cc
[VDSUSP
];
387 _rl_tty_chars
.t_start
= tiop
->c_cc
[VSTART
];
390 _rl_tty_chars
.t_stop
= tiop
->c_cc
[VSTOP
];
393 _rl_tty_chars
.t_lnext
= tiop
->c_cc
[VLNEXT
];
396 _rl_tty_chars
.t_flush
= tiop
->c_cc
[VDISCARD
];
399 _rl_tty_chars
.t_status
= tiop
->c_cc
[VSTATUS
];
403 #if defined (_AIX) || defined (_AIX41)
404 /* Currently this is only used on AIX */
409 _rl_errmsg ("warning: %s", msg
);
418 if ((tp
->c_oflag
& OPOST
) == 0)
420 _rl_errmsg ("warning: turning on OPOST for terminal\r");
421 tp
->c_oflag
|= OPOST
|ONLCR
;
427 _get_tty_settings (tty
, tiop
)
435 ioctl_ret
= GETATTR (tty
, tiop
);
443 if (OUTPUT_BEING_FLUSHED (tiop
))
446 _rl_errmsg ("warning: turning off output flushing");
447 tiop
->c_lflag
&= ~FLUSHO
;
460 get_tty_settings (tty
, tiop
)
467 if (_get_tty_settings (tty
, tiop
) < 0)
478 _set_tty_settings (tty
, tiop
)
482 while (SETATTR (tty
, tiop
) < 0)
492 set_tty_settings (tty
, tiop
)
496 if (_set_tty_settings (tty
, tiop
) < 0)
501 #if defined (TERMIOS_TTY_DRIVER)
502 # if defined (__ksr1__)
509 tcflow (tty
, TCOON
); /* Simulate a ^Q. */
512 ioctl (tty
, TCXONC
, 1); /* Simulate a ^Q. */
513 #endif /* !TERMIOS_TTY_DRIVER */
521 prepare_terminal_settings (meta_flag
, oldtio
, tiop
)
523 TIOTYPE oldtio
, *tiop
;
525 _rl_echoing_p
= (oldtio
.c_lflag
& ECHO
);
526 #if defined (ECHOCTL)
527 _rl_echoctl
= (oldtio
.c_lflag
& ECHOCTL
);
530 tiop
->c_lflag
&= ~(ICANON
| ECHO
);
532 if ((unsigned char) oldtio
.c_cc
[VEOF
] != (unsigned char) _POSIX_VDISABLE
)
533 _rl_eof_char
= oldtio
.c_cc
[VEOF
];
535 #if defined (USE_XON_XOFF)
537 tiop
->c_iflag
&= ~(IXON
| IXANY
);
539 /* `strict' Posix systems do not define IXANY. */
540 tiop
->c_iflag
&= ~IXON
;
542 #endif /* USE_XON_XOFF */
544 /* Only turn this off if we are using all 8 bits. */
545 if (((tiop
->c_cflag
& CSIZE
) == CS8
) || meta_flag
)
546 tiop
->c_iflag
&= ~(ISTRIP
| INPCK
);
548 /* Make sure we differentiate between CR and NL on input. */
549 tiop
->c_iflag
&= ~(ICRNL
| INLCR
);
551 #if !defined (HANDLE_SIGNALS)
552 tiop
->c_lflag
&= ~ISIG
;
554 tiop
->c_lflag
|= ISIG
;
557 tiop
->c_cc
[VMIN
] = 1;
558 tiop
->c_cc
[VTIME
] = 0;
561 if (OUTPUT_BEING_FLUSHED (tiop
))
563 tiop
->c_lflag
&= ~FLUSHO
;
564 oldtio
.c_lflag
&= ~FLUSHO
;
568 /* Turn off characters that we need on Posix systems with job control,
569 just to be sure. This includes ^Y and ^V. This should not really
571 #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
574 tiop
->c_cc
[VLNEXT
] = _POSIX_VDISABLE
;
578 tiop
->c_cc
[VDSUSP
] = _POSIX_VDISABLE
;
581 #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
583 #endif /* !NEW_TTY_DRIVER */
585 /* Put the terminal in CBREAK mode so that we can detect key presses. */
586 #if defined (NO_TTY_DRIVER)
588 rl_prep_terminal (meta_flag
)
595 rl_deprep_terminal ()
599 #else /* ! NO_TTY_DRIVER */
601 rl_prep_terminal (meta_flag
)
607 if (terminal_prepped
)
610 /* Try to keep this function from being INTerrupted. */
613 tty
= rl_instream
? fileno (rl_instream
) : fileno (stdin
);
615 if (get_tty_settings (tty
, &tio
) < 0)
617 #if defined (ENOTSUP)
618 /* MacOS X and Linux, at least, lie about the value of errno if
620 if (errno
== ENOTTY
|| errno
== EINVAL
|| errno
== ENOTSUP
)
622 if (errno
== ENOTTY
|| errno
== EINVAL
)
624 _rl_echoing_p
= 1; /* XXX */
626 _rl_release_sigint ();
632 if (_rl_bind_stty_chars
)
634 #if defined (VI_MODE)
635 /* If editing in vi mode, make sure we restore the bindings in the
636 insertion keymap no matter what keymap we ended up in. */
637 if (rl_editing_mode
== vi_mode
)
638 rl_tty_unset_default_bindings (vi_insertion_keymap
);
641 rl_tty_unset_default_bindings (_rl_keymap
);
643 save_tty_chars (&otio
);
644 RL_SETSTATE(RL_STATE_TTYCSAVED
);
645 if (_rl_bind_stty_chars
)
647 #if defined (VI_MODE)
648 /* If editing in vi mode, make sure we set the bindings in the
649 insertion keymap no matter what keymap we ended up in. */
650 if (rl_editing_mode
== vi_mode
)
651 _rl_bind_tty_special_chars (vi_insertion_keymap
, tio
);
654 _rl_bind_tty_special_chars (_rl_keymap
, tio
);
657 prepare_terminal_settings (meta_flag
, otio
, &tio
);
659 if (set_tty_settings (tty
, &tio
) < 0)
661 _rl_release_sigint ();
665 if (_rl_enable_keypad
)
666 _rl_control_keypad (1);
670 if (_rl_enable_bracketed_paste
)
672 fprintf (rl_outstream
, BRACK_PASTE_INIT
);
673 nprep
|= TPX_BRACKPASTE
;
676 fflush (rl_outstream
);
677 terminal_prepped
= nprep
;
678 RL_SETSTATE(RL_STATE_TERMPREPPED
);
680 _rl_release_sigint ();
683 /* Restore the terminal's normal settings and modes. */
685 rl_deprep_terminal ()
689 if (terminal_prepped
== 0)
692 /* Try to keep this function from being interrupted. */
695 tty
= rl_instream
? fileno (rl_instream
) : fileno (stdin
);
697 if (terminal_prepped
& TPX_BRACKPASTE
)
698 fprintf (rl_outstream
, BRACK_PASTE_FINI
);
700 if (_rl_enable_keypad
)
701 _rl_control_keypad (0);
703 fflush (rl_outstream
);
705 if (set_tty_settings (tty
, &otio
) < 0)
707 _rl_release_sigint ();
711 terminal_prepped
= 0;
712 RL_UNSETSTATE(RL_STATE_TERMPREPPED
);
714 _rl_release_sigint ();
716 #endif /* !NO_TTY_DRIVER */
718 /* Set readline's idea of whether or not it is echoing output to the terminal,
719 returning the old value. */
721 rl_tty_set_echoing (u
)
731 /* **************************************************************** */
733 /* Bogus Flow Control */
735 /* **************************************************************** */
738 rl_restart_output (count
, key
)
741 #if defined (__MINGW32__)
743 #else /* !__MING32__ */
745 int fildes
= fileno (rl_outstream
);
746 #if defined (TIOCSTART)
748 ioctl (&fildes
, TIOCSTART
, 0);
750 ioctl (fildes
, TIOCSTART
, 0);
753 #else /* !TIOCSTART */
754 # if defined (TERMIOS_TTY_DRIVER)
755 # if defined (__ksr1__)
759 tcflow (fildes
, TCOON
);
762 tcflow (fildes
, TCOON
); /* Simulate a ^Q. */
764 # else /* !TERMIOS_TTY_DRIVER */
765 # if defined (TCXONC)
766 ioctl (fildes
, TCXONC
, TCOON
);
768 # endif /* !TERMIOS_TTY_DRIVER */
769 #endif /* !TIOCSTART */
772 #endif /* !__MINGW32__ */
776 rl_stop_output (count
, key
)
779 #if defined (__MINGW32__)
783 int fildes
= fileno (rl_instream
);
785 #if defined (TIOCSTOP)
786 # if defined (apollo)
787 ioctl (&fildes
, TIOCSTOP
, 0);
789 ioctl (fildes
, TIOCSTOP
, 0);
791 #else /* !TIOCSTOP */
792 # if defined (TERMIOS_TTY_DRIVER)
793 # if defined (__ksr1__)
796 tcflow (fildes
, TCOOFF
);
798 # if defined (TCXONC)
799 ioctl (fildes
, TCXONC
, TCOON
);
801 # endif /* !TERMIOS_TTY_DRIVER */
802 #endif /* !TIOCSTOP */
805 #endif /* !__MINGW32__ */
808 /* **************************************************************** */
810 /* Default Key Bindings */
812 /* **************************************************************** */
814 #if !defined (NO_TTY_DRIVER)
815 #define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func)
818 #if defined (NO_TTY_DRIVER)
820 #define SET_SPECIAL(sc, func)
821 #define RESET_SPECIAL(c)
823 #elif defined (NEW_TTY_DRIVER)
825 set_special_char (kmap
, tiop
, sc
, func
)
829 rl_command_func_t
*func
;
831 if (sc
!= -1 && kmap
[(unsigned char)sc
].type
== ISFUNC
)
832 kmap
[(unsigned char)sc
].function
= func
;
835 #define RESET_SPECIAL(c) \
836 if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) \
837 kmap[(unsigned char)c].function = rl_insert;
840 _rl_bind_tty_special_chars (kmap
, ttybuff
)
844 if (ttybuff
.flags
& SGTTY_SET
)
846 SET_SPECIAL (ttybuff
.sgttyb
.sg_erase
, rl_rubout
);
847 SET_SPECIAL (ttybuff
.sgttyb
.sg_kill
, rl_unix_line_discard
);
850 # if defined (TIOCGLTC)
851 if (ttybuff
.flags
& LTCHARS_SET
)
853 SET_SPECIAL (ttybuff
.ltchars
.t_werasc
, rl_unix_word_rubout
);
854 SET_SPECIAL (ttybuff
.ltchars
.t_lnextc
, rl_quoted_insert
);
856 # endif /* TIOCGLTC */
859 #else /* !NEW_TTY_DRIVER */
861 set_special_char (kmap
, tiop
, sc
, func
)
865 rl_command_func_t
*func
;
870 if (uc
!= (unsigned char)_POSIX_VDISABLE
&& kmap
[uc
].type
== ISFUNC
)
871 kmap
[uc
].function
= func
;
875 #define RESET_SPECIAL(uc) \
876 if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
877 kmap[uc].function = rl_insert;
880 _rl_bind_tty_special_chars (kmap
, ttybuff
)
884 SET_SPECIAL (VERASE
, rl_rubout
);
885 SET_SPECIAL (VKILL
, rl_unix_line_discard
);
887 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
888 SET_SPECIAL (VLNEXT
, rl_quoted_insert
);
889 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
891 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
892 # if defined (VI_MODE)
893 if (rl_editing_mode
== vi_mode
)
894 SET_SPECIAL (VWERASE
, rl_vi_unix_word_rubout
);
897 SET_SPECIAL (VWERASE
, rl_unix_word_rubout
);
898 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
901 #endif /* !NEW_TTY_DRIVER */
903 /* Set the system's default editing characters to their readline equivalents
904 in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */
906 rltty_set_default_bindings (kmap
)
909 #if !defined (NO_TTY_DRIVER)
913 tty
= fileno (rl_instream
);
915 if (get_tty_settings (tty
, &ttybuff
) == 0)
916 _rl_bind_tty_special_chars (kmap
, ttybuff
);
920 /* New public way to set the system default editing chars to their readline
923 rl_tty_set_default_bindings (kmap
)
926 rltty_set_default_bindings (kmap
);
929 /* Rebind all of the tty special chars that readline worries about back
930 to self-insert. Call this before saving the current terminal special
931 chars with save_tty_chars(). This only works on POSIX termios or termio
934 rl_tty_unset_default_bindings (kmap
)
937 /* Don't bother before we've saved the tty special chars at least once. */
938 if (RL_ISSTATE(RL_STATE_TTYCSAVED
) == 0)
941 RESET_SPECIAL (_rl_tty_chars
.t_erase
);
942 RESET_SPECIAL (_rl_tty_chars
.t_kill
);
944 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
945 RESET_SPECIAL (_rl_tty_chars
.t_lnext
);
946 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
948 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
949 RESET_SPECIAL (_rl_tty_chars
.t_werase
);
950 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
953 #if defined (HANDLE_SIGNALS)
955 #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
957 _rl_disable_tty_signals ()
963 _rl_restore_tty_signals ()
969 static TIOTYPE sigstty
, nosigstty
;
970 static int tty_sigs_disabled
= 0;
973 _rl_disable_tty_signals ()
975 if (tty_sigs_disabled
)
978 if (_get_tty_settings (fileno (rl_instream
), &sigstty
) < 0)
983 nosigstty
.c_lflag
&= ~ISIG
;
984 nosigstty
.c_iflag
&= ~IXON
;
986 if (_set_tty_settings (fileno (rl_instream
), &nosigstty
) < 0)
987 return (_set_tty_settings (fileno (rl_instream
), &sigstty
));
989 tty_sigs_disabled
= 1;
994 _rl_restore_tty_signals ()
998 if (tty_sigs_disabled
== 0)
1001 r
= _set_tty_settings (fileno (rl_instream
), &sigstty
);
1004 tty_sigs_disabled
= 0;
1008 #endif /* !NEW_TTY_DRIVER */
1010 #endif /* HANDLE_SIGNALS */