|
version 1.1.1.1, 2014/07/30 08:16:45
|
version 1.1.1.2, 2021/03/17 01:01:01
|
|
Line 1
|
Line 1
|
| /* rltty.c -- functions to prepare and restore the terminal for readline's |
/* rltty.c -- functions to prepare and restore the terminal for readline's |
| use. */ |
use. */ |
| |
|
| /* Copyright (C) 1992-2005 Free Software Foundation, Inc. | /* Copyright (C) 1992-2017 Free Software Foundation, Inc. |
| |
|
| This file is part of the GNU Readline Library (Readline), a library |
This file is part of the GNU Readline Library (Readline), a library |
| for reading lines of text with interactive input and history editing. | for reading lines of text with interactive input and history editing. |
| |
|
| Readline is free software: you can redistribute it and/or modify |
Readline is free software: you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
|
Line 37
|
Line 37
|
| |
|
| #include "rldefs.h" |
#include "rldefs.h" |
| |
|
| #if defined (GWINSZ_IN_SYS_IOCTL) |
|
| # include <sys/ioctl.h> |
|
| #endif /* GWINSZ_IN_SYS_IOCTL */ |
|
| |
|
| #include "rltty.h" |
#include "rltty.h" |
| |
#if defined (HAVE_SYS_IOCTL_H) |
| |
# include <sys/ioctl.h> /* include for declaration of ioctl */ |
| |
#endif |
| |
|
| #include "readline.h" |
#include "readline.h" |
| #include "rlprivate.h" |
#include "rlprivate.h" |
| |
|
|
Line 60 static void set_winsize PARAMS((int));
|
Line 60 static void set_winsize PARAMS((int));
|
| /* */ |
/* */ |
| /* **************************************************************** */ |
/* **************************************************************** */ |
| |
|
| /* Non-zero means that the terminal is in a prepped state. */ | /* Non-zero means that the terminal is in a prepped state. There are several |
| | flags that are OR'd in to denote whether or not we have sent various |
| | init strings to the terminal. */ |
| | #define TPX_PREPPED 0x01 |
| | #define TPX_BRACKPASTE 0x02 |
| | #define TPX_METAKEY 0x04 |
| | |
| static int terminal_prepped; |
static int terminal_prepped; |
| |
|
| static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; |
static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; |
|
Line 124 static void prepare_terminal_settings PARAMS((int, TIO
|
Line 130 static void prepare_terminal_settings PARAMS((int, TIO
|
| static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *)); |
static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *)); |
| |
|
| static void |
static void |
| save_tty_chars (tiop) | save_tty_chars (TIOTYPE *tiop) |
| TIOTYPE *tiop; | |
| { |
{ |
| _rl_last_tty_chars = _rl_tty_chars; |
_rl_last_tty_chars = _rl_tty_chars; |
| |
|
|
Line 162 save_tty_chars (tiop)
|
Line 167 save_tty_chars (tiop)
|
| } |
} |
| |
|
| static int |
static int |
| get_tty_settings (tty, tiop) | get_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| set_winsize (tty); |
set_winsize (tty); |
| |
|
|
Line 194 get_tty_settings (tty, tiop)
|
Line 197 get_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static int |
static int |
| set_tty_settings (tty, tiop) | set_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| if (tiop->flags & SGTTY_SET) |
if (tiop->flags & SGTTY_SET) |
| { |
{ |
|
Line 233 set_tty_settings (tty, tiop)
|
Line 234 set_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static void |
static void |
| prepare_terminal_settings (meta_flag, oldtio, tiop) | prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop) |
| int meta_flag; | |
| TIOTYPE oldtio, *tiop; | |
| { |
{ |
| _rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO); |
_rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO); |
| _rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL); |
_rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL); |
|
Line 351 static void _rl_bind_tty_special_chars PARAMS((Keymap,
|
Line 350 static void _rl_bind_tty_special_chars PARAMS((Keymap,
|
| #endif |
#endif |
| |
|
| static void |
static void |
| save_tty_chars (tiop) | save_tty_chars (TIOTYPE *tiop) |
| TIOTYPE *tiop; | |
| { |
{ |
| _rl_last_tty_chars = _rl_tty_chars; |
_rl_last_tty_chars = _rl_tty_chars; |
| |
|
|
Line 397 save_tty_chars (tiop)
|
Line 395 save_tty_chars (tiop)
|
| #if defined (_AIX) || defined (_AIX41) |
#if defined (_AIX) || defined (_AIX41) |
| /* Currently this is only used on AIX */ |
/* Currently this is only used on AIX */ |
| static void |
static void |
| rltty_warning (msg) | rltty_warning (char *msg) |
| char *msg; | |
| { |
{ |
| _rl_errmsg ("warning: %s", msg); |
_rl_errmsg ("warning: %s", msg); |
| } |
} |
|
Line 406 rltty_warning (msg)
|
Line 403 rltty_warning (msg)
|
| |
|
| #if defined (_AIX) |
#if defined (_AIX) |
| void |
void |
| setopost(tp) | setopost (TIOTYPE *tp) |
| TIOTYPE *tp; | |
| { |
{ |
| if ((tp->c_oflag & OPOST) == 0) |
if ((tp->c_oflag & OPOST) == 0) |
| { |
{ |
|
Line 418 TIOTYPE *tp;
|
Line 414 TIOTYPE *tp;
|
| #endif |
#endif |
| |
|
| static int |
static int |
| _get_tty_settings (tty, tiop) | _get_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| int ioctl_ret; |
int ioctl_ret; |
| |
|
|
Line 451 _get_tty_settings (tty, tiop)
|
Line 445 _get_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static int |
static int |
| get_tty_settings (tty, tiop) | get_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| set_winsize (tty); |
set_winsize (tty); |
| |
|
|
Line 469 get_tty_settings (tty, tiop)
|
Line 461 get_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static int |
static int |
| _set_tty_settings (tty, tiop) | _set_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| while (SETATTR (tty, tiop) < 0) |
while (SETATTR (tty, tiop) < 0) |
| { |
{ |
|
Line 483 _set_tty_settings (tty, tiop)
|
Line 473 _set_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static int |
static int |
| set_tty_settings (tty, tiop) | set_tty_settings (int tty, TIOTYPE *tiop) |
| int tty; | |
| TIOTYPE *tiop; | |
| { |
{ |
| if (_set_tty_settings (tty, tiop) < 0) |
if (_set_tty_settings (tty, tiop) < 0) |
| return -1; |
return -1; |
|
Line 512 set_tty_settings (tty, tiop)
|
Line 500 set_tty_settings (tty, tiop)
|
| } |
} |
| |
|
| static void |
static void |
| prepare_terminal_settings (meta_flag, oldtio, tiop) | prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop) |
| int meta_flag; | |
| TIOTYPE oldtio, *tiop; | |
| { |
{ |
| |
int sc; |
| |
Keymap kmap; |
| |
|
| _rl_echoing_p = (oldtio.c_lflag & ECHO); |
_rl_echoing_p = (oldtio.c_lflag & ECHO); |
| #if defined (ECHOCTL) |
#if defined (ECHOCTL) |
| _rl_echoctl = (oldtio.c_lflag & ECHOCTL); |
_rl_echoctl = (oldtio.c_lflag & ECHOCTL); |
|
Line 572 prepare_terminal_settings (meta_flag, oldtio, tiop)
|
Line 561 prepare_terminal_settings (meta_flag, oldtio, tiop)
|
| tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; |
tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; |
| #endif |
#endif |
| |
|
| |
/* Conditionally disable some other tty special characters if there is a |
| |
key binding for them in the current keymap. Readline ordinarily doesn't |
| |
bind these characters, but an application or user might. */ |
| |
#if defined (VI_MODE) |
| |
kmap = (rl_editing_mode == vi_mode) ? vi_insertion_keymap : _rl_keymap; |
| |
#else |
| |
kmap = _rl_keymap; |
| |
#endif |
| |
#if defined (VDISCARD) |
| |
sc = tiop->c_cc[VDISCARD]; |
| |
if (sc != _POSIX_VDISABLE && kmap[(unsigned char)sc].type == ISFUNC) |
| |
tiop->c_cc[VDISCARD] = _POSIX_VDISABLE; |
| |
#endif /* VDISCARD */ |
| |
|
| #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ |
#endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ |
| } |
} |
| #endif /* !NEW_TTY_DRIVER */ |
#endif /* !NEW_TTY_DRIVER */ |
|
Line 579 prepare_terminal_settings (meta_flag, oldtio, tiop)
|
Line 582 prepare_terminal_settings (meta_flag, oldtio, tiop)
|
| /* Put the terminal in CBREAK mode so that we can detect key presses. */ |
/* Put the terminal in CBREAK mode so that we can detect key presses. */ |
| #if defined (NO_TTY_DRIVER) |
#if defined (NO_TTY_DRIVER) |
| void |
void |
| rl_prep_terminal (meta_flag) | rl_prep_terminal (int meta_flag) |
| int meta_flag; | |
| { |
{ |
| _rl_echoing_p = 1; |
_rl_echoing_p = 1; |
| } |
} |
| |
|
| void |
void |
| rl_deprep_terminal () | rl_deprep_terminal (void) |
| { |
{ |
| } |
} |
| |
|
| #else /* ! NO_TTY_DRIVER */ |
#else /* ! NO_TTY_DRIVER */ |
| void |
void |
| rl_prep_terminal (meta_flag) | rl_prep_terminal (int meta_flag) |
| int meta_flag; | |
| { |
{ |
| int tty; | int tty, nprep; |
| TIOTYPE tio; |
TIOTYPE tio; |
| |
|
| if (terminal_prepped) |
if (terminal_prepped) |
|
Line 642 rl_prep_terminal (meta_flag)
|
Line 643 rl_prep_terminal (meta_flag)
|
| /* If editing in vi mode, make sure we set the bindings in the |
/* If editing in vi mode, make sure we set the bindings in the |
| insertion keymap no matter what keymap we ended up in. */ |
insertion keymap no matter what keymap we ended up in. */ |
| if (rl_editing_mode == vi_mode) |
if (rl_editing_mode == vi_mode) |
| _rl_bind_tty_special_chars (vi_insertion_keymap, tio); | _rl_bind_tty_special_chars (vi_insertion_keymap, tio); |
| else |
else |
| #endif |
#endif |
| _rl_bind_tty_special_chars (_rl_keymap, tio); |
_rl_bind_tty_special_chars (_rl_keymap, tio); |
|
Line 659 rl_prep_terminal (meta_flag)
|
Line 660 rl_prep_terminal (meta_flag)
|
| if (_rl_enable_keypad) |
if (_rl_enable_keypad) |
| _rl_control_keypad (1); |
_rl_control_keypad (1); |
| |
|
| |
nprep = TPX_PREPPED; |
| |
|
| |
if (_rl_enable_bracketed_paste) |
| |
{ |
| |
fprintf (rl_outstream, BRACK_PASTE_INIT); |
| |
nprep |= TPX_BRACKPASTE; |
| |
} |
| |
|
| fflush (rl_outstream); |
fflush (rl_outstream); |
| terminal_prepped = 1; | terminal_prepped = nprep; |
| RL_SETSTATE(RL_STATE_TERMPREPPED); |
RL_SETSTATE(RL_STATE_TERMPREPPED); |
| |
|
| _rl_release_sigint (); |
_rl_release_sigint (); |
|
Line 668 rl_prep_terminal (meta_flag)
|
Line 677 rl_prep_terminal (meta_flag)
|
| |
|
| /* Restore the terminal's normal settings and modes. */ |
/* Restore the terminal's normal settings and modes. */ |
| void |
void |
| rl_deprep_terminal () | rl_deprep_terminal (void) |
| { |
{ |
| int tty; |
int tty; |
| |
|
| if (!terminal_prepped) | if (terminal_prepped == 0) |
| return; |
return; |
| |
|
| /* Try to keep this function from being interrupted. */ |
/* Try to keep this function from being interrupted. */ |
|
Line 680 rl_deprep_terminal ()
|
Line 689 rl_deprep_terminal ()
|
| |
|
| tty = rl_instream ? fileno (rl_instream) : fileno (stdin); |
tty = rl_instream ? fileno (rl_instream) : fileno (stdin); |
| |
|
| |
if (terminal_prepped & TPX_BRACKPASTE) |
| |
{ |
| |
fprintf (rl_outstream, BRACK_PASTE_FINI); |
| |
if (_rl_eof_found) |
| |
fprintf (rl_outstream, "\n"); |
| |
} |
| |
|
| if (_rl_enable_keypad) |
if (_rl_enable_keypad) |
| _rl_control_keypad (0); |
_rl_control_keypad (0); |
| |
|
|
Line 697 rl_deprep_terminal ()
|
Line 713 rl_deprep_terminal ()
|
| _rl_release_sigint (); |
_rl_release_sigint (); |
| } |
} |
| #endif /* !NO_TTY_DRIVER */ |
#endif /* !NO_TTY_DRIVER */ |
| |
|
| |
/* Set readline's idea of whether or not it is echoing output to the terminal, |
| |
returning the old value. */ |
| |
int |
| |
rl_tty_set_echoing (int u) |
| |
{ |
| |
int o; |
| |
|
| |
o = _rl_echoing_p; |
| |
_rl_echoing_p = u; |
| |
return o; |
| |
} |
| |
|
| /* **************************************************************** */ |
/* **************************************************************** */ |
| /* */ |
/* */ |
|
Line 705 rl_deprep_terminal ()
|
Line 733 rl_deprep_terminal ()
|
| /* **************************************************************** */ |
/* **************************************************************** */ |
| |
|
| int |
int |
| rl_restart_output (count, key) | rl_restart_output (int count, int key) |
| int count, key; | |
| { |
{ |
| #if defined (__MINGW32__) |
#if defined (__MINGW32__) |
| return 0; |
return 0; |
|
Line 743 rl_restart_output (count, key)
|
Line 770 rl_restart_output (count, key)
|
| } |
} |
| |
|
| int |
int |
| rl_stop_output (count, key) | rl_stop_output (int count, int key) |
| int count, key; | |
| { |
{ |
| #if defined (__MINGW32__) |
#if defined (__MINGW32__) |
| return 0; |
return 0; |
|
Line 792 rl_stop_output (count, key)
|
Line 818 rl_stop_output (count, key)
|
| |
|
| #elif defined (NEW_TTY_DRIVER) |
#elif defined (NEW_TTY_DRIVER) |
| static void |
static void |
| set_special_char (kmap, tiop, sc, func) | set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func) |
| Keymap kmap; | |
| TIOTYPE *tiop; | |
| int sc; | |
| rl_command_func_t *func; | |
| { |
{ |
| if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) |
if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) |
| kmap[(unsigned char)sc].function = func; |
kmap[(unsigned char)sc].function = func; |
|
Line 807 set_special_char (kmap, tiop, sc, func)
|
Line 829 set_special_char (kmap, tiop, sc, func)
|
| kmap[(unsigned char)c].function = rl_insert; |
kmap[(unsigned char)c].function = rl_insert; |
| |
|
| static void |
static void |
| _rl_bind_tty_special_chars (kmap, ttybuff) | _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff) |
| Keymap kmap; | |
| TIOTYPE ttybuff; | |
| { |
{ |
| if (ttybuff.flags & SGTTY_SET) |
if (ttybuff.flags & SGTTY_SET) |
| { |
{ |
|
Line 828 _rl_bind_tty_special_chars (kmap, ttybuff)
|
Line 848 _rl_bind_tty_special_chars (kmap, ttybuff)
|
| |
|
| #else /* !NEW_TTY_DRIVER */ |
#else /* !NEW_TTY_DRIVER */ |
| static void |
static void |
| set_special_char (kmap, tiop, sc, func) | set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func) |
| Keymap kmap; | |
| TIOTYPE *tiop; | |
| int sc; | |
| rl_command_func_t *func; | |
| { |
{ |
| unsigned char uc; |
unsigned char uc; |
| |
|
|
Line 847 set_special_char (kmap, tiop, sc, func)
|
Line 863 set_special_char (kmap, tiop, sc, func)
|
| kmap[uc].function = rl_insert; |
kmap[uc].function = rl_insert; |
| |
|
| static void |
static void |
| _rl_bind_tty_special_chars (kmap, ttybuff) | _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff) |
| Keymap kmap; | |
| TIOTYPE ttybuff; | |
| { |
{ |
| SET_SPECIAL (VERASE, rl_rubout); |
SET_SPECIAL (VERASE, rl_rubout); |
| SET_SPECIAL (VKILL, rl_unix_line_discard); |
SET_SPECIAL (VKILL, rl_unix_line_discard); |
|
Line 859 _rl_bind_tty_special_chars (kmap, ttybuff)
|
Line 873 _rl_bind_tty_special_chars (kmap, ttybuff)
|
| # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ |
# endif /* VLNEXT && TERMIOS_TTY_DRIVER */ |
| |
|
| # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) |
# if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) |
| |
# if defined (VI_MODE) |
| |
if (rl_editing_mode == vi_mode) |
| |
SET_SPECIAL (VWERASE, rl_vi_unix_word_rubout); |
| |
else |
| |
# endif |
| SET_SPECIAL (VWERASE, rl_unix_word_rubout); |
SET_SPECIAL (VWERASE, rl_unix_word_rubout); |
| # endif /* VWERASE && TERMIOS_TTY_DRIVER */ |
# endif /* VWERASE && TERMIOS_TTY_DRIVER */ |
| } |
} |
|
Line 868 _rl_bind_tty_special_chars (kmap, ttybuff)
|
Line 887 _rl_bind_tty_special_chars (kmap, ttybuff)
|
| /* Set the system's default editing characters to their readline equivalents |
/* Set the system's default editing characters to their readline equivalents |
| in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ |
in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ |
| void |
void |
| rltty_set_default_bindings (kmap) | rltty_set_default_bindings (Keymap kmap) |
| Keymap kmap; | |
| { |
{ |
| #if !defined (NO_TTY_DRIVER) |
#if !defined (NO_TTY_DRIVER) |
| TIOTYPE ttybuff; |
TIOTYPE ttybuff; |
|
Line 885 rltty_set_default_bindings (kmap)
|
Line 903 rltty_set_default_bindings (kmap)
|
| /* New public way to set the system default editing chars to their readline |
/* New public way to set the system default editing chars to their readline |
| equivalents. */ |
equivalents. */ |
| void |
void |
| rl_tty_set_default_bindings (kmap) | rl_tty_set_default_bindings (Keymap kmap) |
| Keymap kmap; | |
| { |
{ |
| rltty_set_default_bindings (kmap); |
rltty_set_default_bindings (kmap); |
| } |
} |
|
Line 896 rl_tty_set_default_bindings (kmap)
|
Line 913 rl_tty_set_default_bindings (kmap)
|
| chars with save_tty_chars(). This only works on POSIX termios or termio |
chars with save_tty_chars(). This only works on POSIX termios or termio |
| systems. */ |
systems. */ |
| void |
void |
| rl_tty_unset_default_bindings (kmap) | rl_tty_unset_default_bindings (Keymap kmap) |
| Keymap kmap; | |
| { |
{ |
| /* Don't bother before we've saved the tty special chars at least once. */ |
/* Don't bother before we've saved the tty special chars at least once. */ |
| if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0) |
if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0) |
|
Line 919 rl_tty_unset_default_bindings (kmap)
|
Line 935 rl_tty_unset_default_bindings (kmap)
|
| |
|
| #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) |
#if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) |
| int |
int |
| _rl_disable_tty_signals () | _rl_disable_tty_signals (void) |
| { |
{ |
| return 0; |
return 0; |
| } |
} |
| |
|
| int |
int |
| _rl_restore_tty_signals () | _rl_restore_tty_signals (void) |
| { |
{ |
| return 0; |
return 0; |
| } |
} |
|
Line 935 static TIOTYPE sigstty, nosigstty;
|
Line 951 static TIOTYPE sigstty, nosigstty;
|
| static int tty_sigs_disabled = 0; |
static int tty_sigs_disabled = 0; |
| |
|
| int |
int |
| _rl_disable_tty_signals () | _rl_disable_tty_signals (void) |
| { |
{ |
| if (tty_sigs_disabled) |
if (tty_sigs_disabled) |
| return 0; |
return 0; |
|
Line 956 _rl_disable_tty_signals ()
|
Line 972 _rl_disable_tty_signals ()
|
| } |
} |
| |
|
| int |
int |
| _rl_restore_tty_signals () | _rl_restore_tty_signals (void) |
| { |
{ |
| int r; |
int r; |
| |
|