1 /* rltty.c -- functions to prepare and restore the terminal for readline's
4 /* Copyright (C) 1992-2005 Free Software Foundation, Inc.
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
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.
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.
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
25 #if defined (HAVE_CONFIG_H)
29 #include <sys/types.h>
34 #if defined (HAVE_UNISTD_H)
36 #endif /* HAVE_UNISTD_H */
40 #if defined (GWINSZ_IN_SYS_IOCTL)
41 # include <sys/ioctl.h>
42 #endif /* GWINSZ_IN_SYS_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 block_sigint
PARAMS((void));
56 static void release_sigint
PARAMS((void));
58 static void set_winsize
PARAMS((int));
60 /* **************************************************************** */
62 /* Signal Management */
64 /* **************************************************************** */
66 #if defined (HAVE_POSIX_SIGNALS)
67 static sigset_t sigint_set
, sigint_oset
;
68 #else /* !HAVE_POSIX_SIGNALS */
69 # if defined (HAVE_BSD_SIGNALS)
70 static int sigint_oldmask
;
71 # endif /* HAVE_BSD_SIGNALS */
72 #endif /* !HAVE_POSIX_SIGNALS */
74 static int sigint_blocked
;
76 /* Cause SIGINT to not be delivered until the corresponding call to
84 #if defined (HAVE_POSIX_SIGNALS)
85 sigemptyset (&sigint_set
);
86 sigemptyset (&sigint_oset
);
87 sigaddset (&sigint_set
, SIGINT
);
88 sigprocmask (SIG_BLOCK
, &sigint_set
, &sigint_oset
);
89 #else /* !HAVE_POSIX_SIGNALS */
90 # if defined (HAVE_BSD_SIGNALS)
91 sigint_oldmask
= sigblock (sigmask (SIGINT
));
92 # else /* !HAVE_BSD_SIGNALS */
93 # if defined (HAVE_USG_SIGHOLD)
95 # endif /* HAVE_USG_SIGHOLD */
96 # endif /* !HAVE_BSD_SIGNALS */
97 #endif /* !HAVE_POSIX_SIGNALS */
102 /* Allow SIGINT to be delivered. */
106 if (sigint_blocked
== 0)
109 #if defined (HAVE_POSIX_SIGNALS)
110 sigprocmask (SIG_SETMASK
, &sigint_oset
, (sigset_t
*)NULL
);
112 # if defined (HAVE_BSD_SIGNALS)
113 sigsetmask (sigint_oldmask
);
114 # else /* !HAVE_BSD_SIGNALS */
115 # if defined (HAVE_USG_SIGHOLD)
117 # endif /* HAVE_USG_SIGHOLD */
118 # endif /* !HAVE_BSD_SIGNALS */
119 #endif /* !HAVE_POSIX_SIGNALS */
124 /* **************************************************************** */
126 /* Saving and Restoring the TTY */
128 /* **************************************************************** */
130 /* Non-zero means that the terminal is in a prepped state. */
131 static int terminal_prepped
;
133 static _RL_TTY_CHARS _rl_tty_chars
, _rl_last_tty_chars
;
135 /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
136 and output is suspended. */
137 #if defined (__ksr1__)
141 /* Dummy call to force a backgrounded readline to stop before it tries
142 to get the tty settings. */
147 #if defined (TIOCGWINSZ)
150 if (ioctl (tty
, TIOCGWINSZ
, &w
) == 0)
151 (void) ioctl (tty
, TIOCSWINSZ
, &w
);
152 #endif /* TIOCGWINSZ */
155 #if defined (NO_TTY_DRIVER)
157 #elif defined (NEW_TTY_DRIVER)
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
162 #define SGTTY_SET 0x01
163 #define LFLAG_SET 0x02
164 #define TCHARS_SET 0x04
165 #define LTCHARS_SET 0x08
168 struct sgttyb sgttyb
; /* Basic BSD tty driver information. */
169 int lflag
; /* Local mode flags, like LPASS8. */
170 #if defined (TIOCGETC)
171 struct tchars tchars
; /* Terminal special characters, including ^S and ^Q. */
173 #if defined (TIOCGLTC)
174 struct ltchars ltchars
; /* 4.2 BSD editing characters */
176 int flags
; /* Bitmap saying which parts of the struct are valid. */
179 #define TIOTYPE struct bsdtty
183 static void save_tty_chars
PARAMS((TIOTYPE
*));
184 static int _get_tty_settings
PARAMS((int, TIOTYPE
*));
185 static int get_tty_settings
PARAMS((int, TIOTYPE
*));
186 static int _set_tty_settings
PARAMS((int, TIOTYPE
*));
187 static int set_tty_settings
PARAMS((int, TIOTYPE
*));
189 static void prepare_terminal_settings
PARAMS((int, TIOTYPE
, TIOTYPE
*));
191 static void set_special_char
PARAMS((Keymap
, TIOTYPE
*, int, rl_command_func_t
));
194 save_tty_chars (tiop
)
197 _rl_last_tty_chars
= _rl_tty_chars
;
199 if (tiop
->flags
& SGTTY_SET
)
201 _rl_tty_chars
.t_erase
= tiop
->sgttyb
.sg_erase
;
202 _rl_tty_chars
.t_kill
= tiop
->sgttyb
.sg_kill
;
205 if (tiop
->flags
& TCHARS_SET
)
207 _rl_tty_chars
.t_intr
= tiop
->tchars
.t_intrc
;
208 _rl_tty_chars
.t_quit
= tiop
->tchars
.t_quitc
;
209 _rl_tty_chars
.t_start
= tiop
->tchars
.t_startc
;
210 _rl_tty_chars
.t_stop
= tiop
->tchars
.t_stopc
;
211 _rl_tty_chars
.t_eof
= tiop
->tchars
.t_eofc
;
212 _rl_tty_chars
.t_eol
= '\n';
213 _rl_tty_chars
.t_eol2
= tiop
->tchars
.t_brkc
;
216 if (tiop
->flags
& LTCHARS_SET
)
218 _rl_tty_chars
.t_susp
= tiop
->ltchars
.t_suspc
;
219 _rl_tty_chars
.t_dsusp
= tiop
->ltchars
.t_dsuspc
;
220 _rl_tty_chars
.t_reprint
= tiop
->ltchars
.t_rprntc
;
221 _rl_tty_chars
.t_flush
= tiop
->ltchars
.t_flushc
;
222 _rl_tty_chars
.t_werase
= tiop
->ltchars
.t_werasc
;
223 _rl_tty_chars
.t_lnext
= tiop
->ltchars
.t_lnextc
;
226 _rl_tty_chars
.t_status
= -1;
230 get_tty_settings (tty
, tiop
)
236 tiop
->flags
= tiop
->lflag
= 0;
239 if (ioctl (tty
, TIOCGETP
, &(tiop
->sgttyb
)) < 0)
241 tiop
->flags
|= SGTTY_SET
;
243 #if defined (TIOCLGET)
244 if (ioctl (tty
, TIOCLGET
, &(tiop
->lflag
)) == 0)
245 tiop
->flags
|= LFLAG_SET
;
248 #if defined (TIOCGETC)
249 if (ioctl (tty
, TIOCGETC
, &(tiop
->tchars
)) == 0)
250 tiop
->flags
|= TCHARS_SET
;
253 #if defined (TIOCGLTC)
254 if (ioctl (tty
, TIOCGLTC
, &(tiop
->ltchars
)) == 0)
255 tiop
->flags
|= LTCHARS_SET
;
262 set_tty_settings (tty
, tiop
)
266 if (tiop
->flags
& SGTTY_SET
)
268 ioctl (tty
, TIOCSETN
, &(tiop
->sgttyb
));
269 tiop
->flags
&= ~SGTTY_SET
;
271 readline_echoing_p
= 1;
273 #if defined (TIOCLSET)
274 if (tiop
->flags
& LFLAG_SET
)
276 ioctl (tty
, TIOCLSET
, &(tiop
->lflag
));
277 tiop
->flags
&= ~LFLAG_SET
;
281 #if defined (TIOCSETC)
282 if (tiop
->flags
& TCHARS_SET
)
284 ioctl (tty
, TIOCSETC
, &(tiop
->tchars
));
285 tiop
->flags
&= ~TCHARS_SET
;
289 #if defined (TIOCSLTC)
290 if (tiop
->flags
& LTCHARS_SET
)
292 ioctl (tty
, TIOCSLTC
, &(tiop
->ltchars
));
293 tiop
->flags
&= ~LTCHARS_SET
;
301 prepare_terminal_settings (meta_flag
, oldtio
, tiop
)
303 TIOTYPE oldtio
, *tiop
;
305 readline_echoing_p
= (oldtio
.sgttyb
.sg_flags
& ECHO
);
307 /* Copy the original settings to the structure we're going to use for
309 tiop
->sgttyb
= oldtio
.sgttyb
;
310 tiop
->lflag
= oldtio
.lflag
;
311 #if defined (TIOCGETC)
312 tiop
->tchars
= oldtio
.tchars
;
314 #if defined (TIOCGLTC)
315 tiop
->ltchars
= oldtio
.ltchars
;
317 tiop
->flags
= oldtio
.flags
;
319 /* First, the basic settings to put us into character-at-a-time, no-echo
321 tiop
->sgttyb
.sg_flags
&= ~(ECHO
| CRMOD
);
322 tiop
->sgttyb
.sg_flags
|= CBREAK
;
324 /* If this terminal doesn't care how the 8th bit is used, then we can
325 use it for the meta-key. If only one of even or odd parity is
326 specified, then the terminal is using parity, and we cannot. */
328 # define ANYP (EVENP | ODDP)
330 if (((oldtio
.sgttyb
.sg_flags
& ANYP
) == ANYP
) ||
331 ((oldtio
.sgttyb
.sg_flags
& ANYP
) == 0))
333 tiop
->sgttyb
.sg_flags
|= ANYP
;
335 /* Hack on local mode flags if we can. */
336 #if defined (TIOCLGET)
337 # if defined (LPASS8)
338 tiop
->lflag
|= LPASS8
;
340 #endif /* TIOCLGET */
343 #if defined (TIOCGETC)
344 # if defined (USE_XON_XOFF)
345 /* Get rid of terminal output start and stop characters. */
346 tiop
->tchars
.t_stopc
= -1; /* C-s */
347 tiop
->tchars
.t_startc
= -1; /* C-q */
349 /* If there is an XON character, bind it to restart the output. */
350 if (oldtio
.tchars
.t_startc
!= -1)
351 rl_bind_key (oldtio
.tchars
.t_startc
, rl_restart_output
);
352 # endif /* USE_XON_XOFF */
354 /* If there is an EOF char, bind _rl_eof_char to it. */
355 if (oldtio
.tchars
.t_eofc
!= -1)
356 _rl_eof_char
= oldtio
.tchars
.t_eofc
;
358 # if defined (NO_KILL_INTR)
359 /* Get rid of terminal-generated SIGQUIT and SIGINT. */
360 tiop
->tchars
.t_quitc
= -1; /* C-\ */
361 tiop
->tchars
.t_intrc
= -1; /* C-c */
362 # endif /* NO_KILL_INTR */
363 #endif /* TIOCGETC */
365 #if defined (TIOCGLTC)
366 /* Make the interrupt keys go away. Just enough to make people happy. */
367 tiop
->ltchars
.t_dsuspc
= -1; /* C-y */
368 tiop
->ltchars
.t_lnextc
= -1; /* C-v */
369 #endif /* TIOCGLTC */
372 #else /* !defined (NEW_TTY_DRIVER) */
382 #if defined (TERMIOS_TTY_DRIVER)
383 # define TIOTYPE struct termios
384 # define DRAIN_OUTPUT(fd) tcdrain (fd)
385 # define GETATTR(tty, tiop) (tcgetattr (tty, tiop))
387 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop))
389 # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop))
390 # endif /* !M_UNIX */
392 # define TIOTYPE struct termio
393 # define DRAIN_OUTPUT(fd)
394 # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop))
395 # define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop))
396 #endif /* !TERMIOS_TTY_DRIVER */
400 static void save_tty_chars
PARAMS((TIOTYPE
*));
401 static int _get_tty_settings
PARAMS((int, TIOTYPE
*));
402 static int get_tty_settings
PARAMS((int, TIOTYPE
*));
403 static int _set_tty_settings
PARAMS((int, TIOTYPE
*));
404 static int set_tty_settings
PARAMS((int, TIOTYPE
*));
406 static void prepare_terminal_settings
PARAMS((int, TIOTYPE
, TIOTYPE
*));
408 static void set_special_char
PARAMS((Keymap
, TIOTYPE
*, int, rl_command_func_t
));
409 static void _rl_bind_tty_special_chars
PARAMS((Keymap
, TIOTYPE
));
412 # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO)
414 # define OUTPUT_BEING_FLUSHED(tp) 0
418 save_tty_chars (tiop
)
421 _rl_last_tty_chars
= _rl_tty_chars
;
423 _rl_tty_chars
.t_eof
= tiop
->c_cc
[VEOF
];
424 _rl_tty_chars
.t_eol
= tiop
->c_cc
[VEOL
];
426 _rl_tty_chars
.t_eol2
= tiop
->c_cc
[VEOL2
];
428 _rl_tty_chars
.t_erase
= tiop
->c_cc
[VERASE
];
430 _rl_tty_chars
.t_werase
= tiop
->c_cc
[VWERASE
];
432 _rl_tty_chars
.t_kill
= tiop
->c_cc
[VKILL
];
434 _rl_tty_chars
.t_reprint
= tiop
->c_cc
[VREPRINT
];
436 _rl_tty_chars
.t_intr
= tiop
->c_cc
[VINTR
];
437 _rl_tty_chars
.t_quit
= tiop
->c_cc
[VQUIT
];
439 _rl_tty_chars
.t_susp
= tiop
->c_cc
[VSUSP
];
442 _rl_tty_chars
.t_dsusp
= tiop
->c_cc
[VDSUSP
];
445 _rl_tty_chars
.t_start
= tiop
->c_cc
[VSTART
];
448 _rl_tty_chars
.t_stop
= tiop
->c_cc
[VSTOP
];
451 _rl_tty_chars
.t_lnext
= tiop
->c_cc
[VLNEXT
];
454 _rl_tty_chars
.t_flush
= tiop
->c_cc
[VDISCARD
];
457 _rl_tty_chars
.t_status
= tiop
->c_cc
[VSTATUS
];
461 #if defined (_AIX) || defined (_AIX41)
462 /* Currently this is only used on AIX */
467 fprintf (stderr
, "readline: warning: %s\n", msg
);
476 if ((tp
->c_oflag
& OPOST
) == 0)
478 rltty_warning ("turning on OPOST for terminal\r");
479 tp
->c_oflag
|= OPOST
|ONLCR
;
485 _get_tty_settings (tty
, tiop
)
493 ioctl_ret
= GETATTR (tty
, tiop
);
501 if (OUTPUT_BEING_FLUSHED (tiop
))
503 #if defined (FLUSHO) && defined (_AIX41)
504 rltty_warning ("turning off output flushing");
505 tiop
->c_lflag
&= ~FLUSHO
;
518 get_tty_settings (tty
, tiop
)
525 if (_get_tty_settings (tty
, tiop
) < 0)
536 _set_tty_settings (tty
, tiop
)
540 while (SETATTR (tty
, tiop
) < 0)
550 set_tty_settings (tty
, tiop
)
554 if (_set_tty_settings (tty
, tiop
) < 0)
559 #if defined (TERMIOS_TTY_DRIVER)
560 # if defined (__ksr1__)
567 tcflow (tty
, TCOON
); /* Simulate a ^Q. */
570 ioctl (tty
, TCXONC
, 1); /* Simulate a ^Q. */
571 #endif /* !TERMIOS_TTY_DRIVER */
579 prepare_terminal_settings (meta_flag
, oldtio
, tiop
)
581 TIOTYPE oldtio
, *tiop
;
583 readline_echoing_p
= (oldtio
.c_lflag
& ECHO
);
585 tiop
->c_lflag
&= ~(ICANON
| ECHO
);
587 if ((unsigned char) oldtio
.c_cc
[VEOF
] != (unsigned char) _POSIX_VDISABLE
)
588 _rl_eof_char
= oldtio
.c_cc
[VEOF
];
590 #if defined (USE_XON_XOFF)
592 tiop
->c_iflag
&= ~(IXON
| IXOFF
| IXANY
);
594 /* `strict' Posix systems do not define IXANY. */
595 tiop
->c_iflag
&= ~(IXON
| IXOFF
);
597 #endif /* USE_XON_XOFF */
599 /* Only turn this off if we are using all 8 bits. */
600 if (((tiop
->c_cflag
& CSIZE
) == CS8
) || meta_flag
)
601 tiop
->c_iflag
&= ~(ISTRIP
| INPCK
);
603 /* Make sure we differentiate between CR and NL on input. */
604 tiop
->c_iflag
&= ~(ICRNL
| INLCR
);
606 #if !defined (HANDLE_SIGNALS)
607 tiop
->c_lflag
&= ~ISIG
;
609 tiop
->c_lflag
|= ISIG
;
612 tiop
->c_cc
[VMIN
] = 1;
613 tiop
->c_cc
[VTIME
] = 0;
616 if (OUTPUT_BEING_FLUSHED (tiop
))
618 tiop
->c_lflag
&= ~FLUSHO
;
619 oldtio
.c_lflag
&= ~FLUSHO
;
623 /* Turn off characters that we need on Posix systems with job control,
624 just to be sure. This includes ^Y and ^V. This should not really
626 #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
629 tiop
->c_cc
[VLNEXT
] = _POSIX_VDISABLE
;
633 tiop
->c_cc
[VDSUSP
] = _POSIX_VDISABLE
;
636 #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
638 #endif /* !NEW_TTY_DRIVER */
640 /* Put the terminal in CBREAK mode so that we can detect key presses. */
641 #if defined (NO_TTY_DRIVER)
643 rl_prep_terminal (meta_flag
)
646 readline_echoing_p
= 1;
650 rl_deprep_terminal ()
654 #else /* ! NO_TTY_DRIVER */
656 rl_prep_terminal (meta_flag
)
662 if (terminal_prepped
)
665 /* Try to keep this function from being INTerrupted. */
668 tty
= fileno (rl_instream
);
670 if (get_tty_settings (tty
, &tio
) < 0)
672 #if defined (ENOTSUP)
673 /* MacOS X, at least, lies about the value of errno if tcgetattr fails. */
674 if (errno
== ENOTTY
|| errno
== ENOTSUP
)
678 readline_echoing_p
= 1; /* XXX */
685 if (_rl_bind_stty_chars
)
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
);
694 rl_tty_unset_default_bindings (_rl_keymap
);
696 save_tty_chars (&otio
);
697 RL_SETSTATE(RL_STATE_TTYCSAVED
);
698 if (_rl_bind_stty_chars
)
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
);
707 _rl_bind_tty_special_chars (_rl_keymap
, tio
);
710 prepare_terminal_settings (meta_flag
, otio
, &tio
);
712 if (set_tty_settings (tty
, &tio
) < 0)
718 if (_rl_enable_keypad
)
719 _rl_control_keypad (1);
721 fflush (rl_outstream
);
722 terminal_prepped
= 1;
723 RL_SETSTATE(RL_STATE_TERMPREPPED
);
728 /* Restore the terminal's normal settings and modes. */
730 rl_deprep_terminal ()
734 if (!terminal_prepped
)
737 /* Try to keep this function from being interrupted. */
740 tty
= fileno (rl_instream
);
742 if (_rl_enable_keypad
)
743 _rl_control_keypad (0);
745 fflush (rl_outstream
);
747 if (set_tty_settings (tty
, &otio
) < 0)
753 terminal_prepped
= 0;
754 RL_UNSETSTATE(RL_STATE_TERMPREPPED
);
758 #endif /* !NO_TTY_DRIVER */
760 /* **************************************************************** */
762 /* Bogus Flow Control */
764 /* **************************************************************** */
767 rl_restart_output (count
, key
)
770 #if defined (__MINGW32__)
772 #else /* !__MING32__ */
774 int fildes
= fileno (rl_outstream
);
775 #if defined (TIOCSTART)
777 ioctl (&fildes
, TIOCSTART
, 0);
779 ioctl (fildes
, TIOCSTART
, 0);
782 #else /* !TIOCSTART */
783 # if defined (TERMIOS_TTY_DRIVER)
784 # if defined (__ksr1__)
788 tcflow (fildes
, TCOON
);
791 tcflow (fildes
, TCOON
); /* Simulate a ^Q. */
793 # else /* !TERMIOS_TTY_DRIVER */
794 # if defined (TCXONC)
795 ioctl (fildes
, TCXONC
, TCOON
);
797 # endif /* !TERMIOS_TTY_DRIVER */
798 #endif /* !TIOCSTART */
801 #endif /* !__MINGW32__ */
805 rl_stop_output (count
, key
)
808 #if defined (__MINGW32__)
812 int fildes
= fileno (rl_instream
);
814 #if defined (TIOCSTOP)
815 # if defined (apollo)
816 ioctl (&fildes
, TIOCSTOP
, 0);
818 ioctl (fildes
, TIOCSTOP
, 0);
820 #else /* !TIOCSTOP */
821 # if defined (TERMIOS_TTY_DRIVER)
822 # if defined (__ksr1__)
825 tcflow (fildes
, TCOOFF
);
827 # if defined (TCXONC)
828 ioctl (fildes
, TCXONC
, TCOON
);
830 # endif /* !TERMIOS_TTY_DRIVER */
831 #endif /* !TIOCSTOP */
834 #endif /* !__MINGW32__ */
837 /* **************************************************************** */
839 /* Default Key Bindings */
841 /* **************************************************************** */
843 #if !defined (NO_TTY_DRIVER)
844 #define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func)
847 #if defined (NO_TTY_DRIVER)
849 #define SET_SPECIAL(sc, func)
850 #define RESET_SPECIAL(c)
852 #elif defined (NEW_TTY_DRIVER)
854 set_special_char (kmap
, tiop
, sc
, func
)
858 rl_command_func_t
*func
;
860 if (sc
!= -1 && kmap
[(unsigned char)sc
].type
== ISFUNC
)
861 kmap
[(unsigned char)sc
].function
= func
;
864 #define RESET_SPECIAL(c) \
865 if (c != -1 && kmap[(unsigned char)c].type == ISFUNC)
866 kmap
[(unsigned char)c
].function
= rl_insert
;
869 _rl_bind_tty_special_chars (kmap
, ttybuff
)
873 if (ttybuff
.flags
& SGTTY_SET
)
875 SET_SPECIAL (ttybuff
.sgttyb
.sg_erase
, rl_rubout
);
876 SET_SPECIAL (ttybuff
.sgttyb
.sg_kill
, rl_unix_line_discard
);
879 # if defined (TIOCGLTC)
880 if (ttybuff
.flags
& LTCHARS_SET
)
882 SET_SPECIAL (ttybuff
.ltchars
.t_werasc
, rl_unix_word_rubout
);
883 SET_SPECIAL (ttybuff
.ltchars
.t_lnextc
, rl_quoted_insert
);
885 # endif /* TIOCGLTC */
888 #else /* !NEW_TTY_DRIVER */
890 set_special_char (kmap
, tiop
, sc
, func
)
894 rl_command_func_t
*func
;
899 if (uc
!= (unsigned char)_POSIX_VDISABLE
&& kmap
[uc
].type
== ISFUNC
)
900 kmap
[uc
].function
= func
;
904 #define RESET_SPECIAL(uc) \
905 if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
906 kmap[uc].function = rl_insert;
909 _rl_bind_tty_special_chars (kmap
, ttybuff
)
913 SET_SPECIAL (VERASE
, rl_rubout
);
914 SET_SPECIAL (VKILL
, rl_unix_line_discard
);
916 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
917 SET_SPECIAL (VLNEXT
, rl_quoted_insert
);
918 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
920 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
921 SET_SPECIAL (VWERASE
, rl_unix_word_rubout
);
922 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
925 #endif /* !NEW_TTY_DRIVER */
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. */
930 rltty_set_default_bindings (kmap
)
933 #if !defined (NO_TTY_DRIVER)
936 static int called
= 0;
938 tty
= fileno (rl_instream
);
940 if (get_tty_settings (tty
, &ttybuff
) == 0)
941 _rl_bind_tty_special_chars (kmap
, ttybuff
);
945 /* New public way to set the system default editing chars to their readline
948 rl_tty_set_default_bindings (kmap
)
951 rltty_set_default_bindings (kmap
);
954 /* Rebind all of the tty special chars that readline worries about back
955 to self-insert. Call this before saving the current terminal special
956 chars with save_tty_chars(). This only works on POSIX termios or termio
959 rl_tty_unset_default_bindings (kmap
)
962 /* Don't bother before we've saved the tty special chars at least once. */
963 if (RL_ISSTATE(RL_STATE_TTYCSAVED
) == 0)
966 RESET_SPECIAL (_rl_tty_chars
.t_erase
);
967 RESET_SPECIAL (_rl_tty_chars
.t_kill
);
969 # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
970 RESET_SPECIAL (_rl_tty_chars
.t_lnext
);
971 # endif /* VLNEXT && TERMIOS_TTY_DRIVER */
973 # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
974 RESET_SPECIAL (_rl_tty_chars
.t_werase
);
975 # endif /* VWERASE && TERMIOS_TTY_DRIVER */
978 #if defined (HANDLE_SIGNALS)
980 #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
982 _rl_disable_tty_signals ()
988 _rl_restore_tty_signals ()
994 static TIOTYPE sigstty
, nosigstty
;
995 static int tty_sigs_disabled
= 0;
998 _rl_disable_tty_signals ()
1000 if (tty_sigs_disabled
)
1003 if (_get_tty_settings (fileno (rl_instream
), &sigstty
) < 0)
1006 nosigstty
= sigstty
;
1008 nosigstty
.c_lflag
&= ~ISIG
;
1009 nosigstty
.c_iflag
&= ~IXON
;
1011 if (_set_tty_settings (fileno (rl_instream
), &nosigstty
) < 0)
1012 return (_set_tty_settings (fileno (rl_instream
), &sigstty
));
1014 tty_sigs_disabled
= 1;
1019 _rl_restore_tty_signals ()
1023 if (tty_sigs_disabled
== 0)
1026 r
= _set_tty_settings (fileno (rl_instream
), &sigstty
);
1029 tty_sigs_disabled
= 0;
1033 #endif /* !NEW_TTY_DRIVER */
1035 #endif /* HANDLE_SIGNALS */