Import readline 8.0
[deliverable/binutils-gdb.git] / readline / rltty.c
index b1c79294186f55667fce393b46d54c5892d44743..d0cd572713a9bea108e0a8bd58fbb9e7582aa3a7 100644 (file)
@@ -1,7 +1,7 @@
 /* rltty.c -- functions to prepare and restore the terminal for readline's
    use. */
 
-/* Copyright (C) 1992-2016 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2017 Free Software Foundation, Inc.
 
    This file is part of the GNU Readline Library (Readline), a library
    for reading lines of text with interactive input and history editing.
@@ -130,8 +130,7 @@ static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *));
 static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *));
 
 static void
-save_tty_chars (tiop)
-     TIOTYPE *tiop;
+save_tty_chars (TIOTYPE *tiop)
 {
   _rl_last_tty_chars = _rl_tty_chars;
 
@@ -168,9 +167,7 @@ save_tty_chars (tiop)
 }
 
 static int
-get_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+get_tty_settings (int tty, TIOTYPE *tiop)
 {
   set_winsize (tty);
 
@@ -200,9 +197,7 @@ get_tty_settings (tty, tiop)
 }
 
 static int
-set_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+set_tty_settings (int tty, TIOTYPE *tiop)
 {
   if (tiop->flags & SGTTY_SET)
     {
@@ -239,9 +234,7 @@ set_tty_settings (tty, tiop)
 }
 
 static void
-prepare_terminal_settings (meta_flag, oldtio, tiop)
-     int meta_flag;
-     TIOTYPE oldtio, *tiop;
+prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
 {
   _rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO);
   _rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL);
@@ -357,8 +350,7 @@ static void _rl_bind_tty_special_chars PARAMS((Keymap, TIOTYPE));
 #endif
 
 static void
-save_tty_chars (tiop)
-     TIOTYPE *tiop;
+save_tty_chars (TIOTYPE *tiop)
 {
   _rl_last_tty_chars = _rl_tty_chars;
 
@@ -403,8 +395,7 @@ save_tty_chars (tiop)
 #if defined (_AIX) || defined (_AIX41)
 /* Currently this is only used on AIX */
 static void
-rltty_warning (msg)
-     char *msg;
+rltty_warning (char *msg)
 {
   _rl_errmsg ("warning: %s", msg);
 }
@@ -412,8 +403,7 @@ rltty_warning (msg)
 
 #if defined (_AIX)
 void
-setopost(tp)
-TIOTYPE *tp;
+setopost (TIOTYPE *tp)
 {
   if ((tp->c_oflag & OPOST) == 0)
     {
@@ -424,9 +414,7 @@ TIOTYPE *tp;
 #endif
 
 static int
-_get_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+_get_tty_settings (int tty, TIOTYPE *tiop)
 {
   int ioctl_ret;
 
@@ -457,9 +445,7 @@ _get_tty_settings (tty, tiop)
 }
 
 static int
-get_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+get_tty_settings (int tty, TIOTYPE *tiop)
 {
   set_winsize (tty);
 
@@ -475,9 +461,7 @@ get_tty_settings (tty, tiop)
 }
 
 static int
-_set_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+_set_tty_settings (int tty, TIOTYPE *tiop)
 {
   while (SETATTR (tty, tiop) < 0)
     {
@@ -489,9 +473,7 @@ _set_tty_settings (tty, tiop)
 }
 
 static int
-set_tty_settings (tty, tiop)
-     int tty;
-     TIOTYPE *tiop;
+set_tty_settings (int tty, TIOTYPE *tiop)
 {
   if (_set_tty_settings (tty, tiop) < 0)
     return -1;
@@ -518,10 +500,11 @@ set_tty_settings (tty, tiop)
 }
 
 static void
-prepare_terminal_settings (meta_flag, oldtio, tiop)
-     int meta_flag;
-     TIOTYPE oldtio, *tiop;
+prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop)
 {
+  int sc;
+  Keymap kmap;
+
   _rl_echoing_p = (oldtio.c_lflag & ECHO);
 #if defined (ECHOCTL)
   _rl_echoctl = (oldtio.c_lflag & ECHOCTL);
@@ -578,6 +561,20 @@ prepare_terminal_settings (meta_flag, oldtio, tiop)
   tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
 #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  /* !NEW_TTY_DRIVER */
@@ -585,21 +582,19 @@ prepare_terminal_settings (meta_flag, oldtio, tiop)
 /* Put the terminal in CBREAK mode so that we can detect key presses. */
 #if defined (NO_TTY_DRIVER)
 void
-rl_prep_terminal (meta_flag)
-     int meta_flag;
+rl_prep_terminal (int meta_flag)
 {
   _rl_echoing_p = 1;
 }
 
 void
-rl_deprep_terminal ()
+rl_deprep_terminal (void)
 {
 }
 
 #else /* ! NO_TTY_DRIVER */
 void
-rl_prep_terminal (meta_flag)
-     int meta_flag;
+rl_prep_terminal (int meta_flag)
 {
   int tty, nprep;
   TIOTYPE tio;
@@ -682,7 +677,7 @@ rl_prep_terminal (meta_flag)
 
 /* Restore the terminal's normal settings and modes. */
 void
-rl_deprep_terminal ()
+rl_deprep_terminal (void)
 {
   int tty;
 
@@ -695,7 +690,11 @@ rl_deprep_terminal ()
   tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
 
   if (terminal_prepped & TPX_BRACKPASTE)
-    fprintf (rl_outstream, BRACK_PASTE_FINI);
+    {
+      fprintf (rl_outstream, BRACK_PASTE_FINI);
+      if (_rl_eof_found)
+       fprintf (rl_outstream, "\n");
+    }
 
   if (_rl_enable_keypad)
     _rl_control_keypad (0);
@@ -718,8 +717,7 @@ rl_deprep_terminal ()
 /* Set readline's idea of whether or not it is echoing output to the terminal,
    returning the old value. */
 int
-rl_tty_set_echoing (u)
-     int u;
+rl_tty_set_echoing (int u)
 {
   int o;
 
@@ -735,8 +733,7 @@ rl_tty_set_echoing (u)
 /* **************************************************************** */
 
 int
-rl_restart_output (count, key)
-     int count, key;
+rl_restart_output (int count, int key)
 {
 #if defined (__MINGW32__)
   return 0;
@@ -773,8 +770,7 @@ rl_restart_output (count, key)
 }
 
 int
-rl_stop_output (count, key)
-     int count, key;
+rl_stop_output (int count, int key)
 {
 #if defined (__MINGW32__)
   return 0;
@@ -822,11 +818,7 @@ rl_stop_output (count, key)
 
 #elif defined (NEW_TTY_DRIVER)
 static void
-set_special_char (kmap, tiop, sc, func)
-     Keymap kmap;
-     TIOTYPE *tiop;
-     int sc;
-     rl_command_func_t *func;
+set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
 {
   if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC)
     kmap[(unsigned char)sc].function = func;
@@ -837,9 +829,7 @@ set_special_char (kmap, tiop, sc, func)
     kmap[(unsigned char)c].function = rl_insert;
 
 static void
-_rl_bind_tty_special_chars (kmap, ttybuff)
-     Keymap kmap;
-     TIOTYPE ttybuff;
+_rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
 {
   if (ttybuff.flags & SGTTY_SET)
     {
@@ -858,11 +848,7 @@ _rl_bind_tty_special_chars (kmap, ttybuff)
 
 #else /* !NEW_TTY_DRIVER */
 static void
-set_special_char (kmap, tiop, sc, func)
-     Keymap kmap;
-     TIOTYPE *tiop;
-     int sc;
-     rl_command_func_t *func;
+set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func)
 {
   unsigned char uc;
 
@@ -877,9 +863,7 @@ set_special_char (kmap, tiop, sc, func)
     kmap[uc].function = rl_insert;
 
 static void
-_rl_bind_tty_special_chars (kmap, ttybuff)
-     Keymap kmap;
-     TIOTYPE ttybuff;
+_rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff)
 {
   SET_SPECIAL (VERASE, rl_rubout);
   SET_SPECIAL (VKILL, rl_unix_line_discard);
@@ -903,8 +887,7 @@ _rl_bind_tty_special_chars (kmap, ttybuff)
 /* 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. */
 void
-rltty_set_default_bindings (kmap)
-     Keymap kmap;
+rltty_set_default_bindings (Keymap kmap)
 {
 #if !defined (NO_TTY_DRIVER)
   TIOTYPE ttybuff;
@@ -920,8 +903,7 @@ rltty_set_default_bindings (kmap)
 /* New public way to set the system default editing chars to their readline
    equivalents. */
 void
-rl_tty_set_default_bindings (kmap)
-     Keymap kmap;
+rl_tty_set_default_bindings (Keymap kmap)
 {
   rltty_set_default_bindings (kmap);
 }
@@ -931,8 +913,7 @@ rl_tty_set_default_bindings (kmap)
    chars with save_tty_chars().  This only works on POSIX termios or termio
    systems. */
 void
-rl_tty_unset_default_bindings (kmap)
-     Keymap kmap;
+rl_tty_unset_default_bindings (Keymap kmap)
 {
   /* Don't bother before we've saved the tty special chars at least once. */
   if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0)
@@ -954,13 +935,13 @@ rl_tty_unset_default_bindings (kmap)
 
 #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER)
 int
-_rl_disable_tty_signals ()
+_rl_disable_tty_signals (void)
 {
   return 0;
 }
 
 int
-_rl_restore_tty_signals ()
+_rl_restore_tty_signals (void)
 {
   return 0;
 }
@@ -970,7 +951,7 @@ static TIOTYPE sigstty, nosigstty;
 static int tty_sigs_disabled = 0;
 
 int
-_rl_disable_tty_signals ()
+_rl_disable_tty_signals (void)
 {
   if (tty_sigs_disabled)
     return 0;
@@ -991,7 +972,7 @@ _rl_disable_tty_signals ()
 }
 
 int
-_rl_restore_tty_signals ()
+_rl_restore_tty_signals (void)
 {
   int r;
 
This page took 0.0323369999999999 seconds and 4 git commands to generate.