changeset 5031:5049ab5e66f6

Re-add readline patches to work with readline 8 (Bug #55957) * src/readline-1-display.patch, src/readline-1-input.patch, src/readline-1-sigwinch.patch, src/readline-2-event-hook.patch dist-files.mk: add refes to added files
author John Donoghue
date Thu, 21 Mar 2019 09:34:09 -0400
parents eec61a755122
children e9972cd1a860
files dist-files.mk src/readline-1-display.patch src/readline-1-input.patch src/readline-1-sigwinch.patch src/readline-2-event-hook.patch
diffstat 5 files changed, 376 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dist-files.mk	Tue Mar 19 10:34:37 2019 -0400
+++ b/dist-files.mk	Thu Mar 21 09:34:09 2019 -0400
@@ -632,7 +632,11 @@
   qwt.mk \
   qwtplot3d-1-fixes.patch \
   qwtplot3d.mk \
+  readline-1-display.patch \
   readline-1-fixes.patch \
+  readline-1-input.patch \
+  readline-1-sigwinch.patch \
+  readline-2-event-hook.patch \
   readline.mk \
   release-octave-1-gnulib.patch \
   release-octave.mk \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-1-display.patch	Thu Mar 21 09:34:09 2019 -0400
@@ -0,0 +1,109 @@
+diff -ur readline-8.0.orig/display.c readline-8.0.disp/display.c
+--- readline-8.0.orig/display.c	2019-03-20 07:41:37.573786782 -0400
++++ readline-8.0.disp/display.c	2019-03-20 17:00:29.866659451 -0400
+@@ -59,6 +59,11 @@
+ #include "rlprivate.h"
+ #include "xmalloc.h"
+ 
++#if defined (_WIN32)
++#include <windows.h>
++#define hStdout GetStdHandle(STD_OUTPUT_HANDLE)
++#endif
++
+ #if !defined (strchr) && !defined (__STDC__)
+ extern char *strchr (), *strrchr ();
+ #endif /* !strchr && !__STDC__ */
+@@ -2367,6 +2372,20 @@
+   int in_invisline;
+   int mb_cur_max = MB_CUR_MAX;
+ 
++#if defined (_WIN32)
++  CONSOLE_SCREEN_BUFFER_INFO csbi;
++  if (_rl_last_c_pos != new
++      && GetConsoleScreenBufferInfo (hStdout, &csbi))
++    {
++      csbi.dwCursorPosition.X += new - _rl_last_c_pos;
++      if (SetConsoleCursorPosition(hStdout, csbi.dwCursorPosition))
++        {
++          _rl_last_c_pos = new;
++          return;
++        }
++    }
++#endif /* !_WIN32 */
++
+   woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset);
+   cpos = _rl_last_c_pos;
+ 
+@@ -2519,6 +2538,20 @@
+ {
+   register int delta, i;
+ 
++#if defined (_WIN32)
++  CONSOLE_SCREEN_BUFFER_INFO csbi;
++  if (_rl_last_v_pos != to && to <= _rl_screenheight
++      && GetConsoleScreenBufferInfo(hStdout, &csbi))
++    {
++      csbi.dwCursorPosition.Y += to - _rl_last_v_pos;
++      if (SetConsoleCursorPosition(hStdout, csbi.dwCursorPosition))
++        {
++          _rl_last_v_pos = to;
++          return;
++        }
++    }
++#endif /* !_WIN32 */
++
+   if (_rl_last_v_pos == to || to > _rl_screenheight)
+     return;
+ 
+@@ -2848,6 +2881,17 @@
+ void
+ _rl_clear_to_eol (int count)
+ {
++#if defined (_WIN32)
++  CONSOLE_SCREEN_BUFFER_INFO csbi;
++  if (GetConsoleScreenBufferInfo (hStdout, &csbi))
++    {
++      DWORD written;
++      FillConsoleOutputCharacter(hStdout, ' ', count, csbi.dwCursorPosition,
++                                 &written);
++      return;
++    }
++#endif /* !_WIN32 */
++
+ #ifndef __MSDOS__
+   if (_rl_term_clreol)
+     tputs (_rl_term_clreol, 1, _rl_output_character_function);
+@@ -2873,6 +2917,33 @@
+ void
+ _rl_clear_screen (void)
+ {
++#if defined (_WIN32)
++  COORD coordScreen = { 0, 0 };
++  DWORD cCharsWritten;
++  CONSOLE_SCREEN_BUFFER_INFO csbi; 
++  DWORD dwConSize;
++
++  if (GetConsoleScreenBufferInfo (hStdout, &csbi))
++    {
++      dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
++
++      if (FillConsoleOutputCharacter (hStdout, (TCHAR) ' ', dwConSize,
++                                      coordScreen, &cCharsWritten))
++        {
++          if (GetConsoleScreenBufferInfo (hStdout, &csbi))
++            {
++              if (FillConsoleOutputAttribute (hStdout, csbi.wAttributes,
++                                              dwConSize, coordScreen,
++                                              &cCharsWritten))
++                {
++                  SetConsoleCursorPosition (hStdout, coordScreen);
++                  return;
++                }
++            }
++        }
++    }
++#endif
++
+ #if defined (__DJGPP__)
+   ScreenClear ();
+   ScreenSetCursor (0, 0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-1-input.patch	Thu Mar 21 09:34:09 2019 -0400
@@ -0,0 +1,17 @@
+diff -ur readline-8.0.disp/input.c readline-8.0/input.c
+--- readline-8.0.disp/input.c	2019-03-20 07:56:04.897036396 -0400
++++ readline-8.0/input.c	2019-03-20 08:00:45.403401856 -0400
+@@ -519,7 +519,12 @@
+ 
+ #if defined (__MINGW32__)
+       if (isatty (fileno (stream)))
+-	return (_getch ());	/* "There is no error return." */
++        {
++          int c = _getch ();
++          if (c == 0xe0)
++            rl_execute_next (_getch ());
++          return (c);
++        }
+ #endif
+       result = 0;
+ #if defined (HAVE_PSELECT)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-1-sigwinch.patch	Thu Mar 21 09:34:09 2019 -0400
@@ -0,0 +1,89 @@
+Common subdirectories: readline-8.0.input/doc and readline-8.0/doc
+Common subdirectories: readline-8.0.input/examples and readline-8.0/examples
+diff -u readline-8.0.input/readline.c readline-8.0/readline.c
+--- readline-8.0.input/readline.c	2019-03-20 08:02:03.533512025 -0400
++++ readline-8.0/readline.c	2019-03-20 08:06:59.117185446 -0400
+@@ -1103,8 +1103,12 @@
+       RL_SETSTATE(RL_STATE_INITIALIZED);
+     }
+   else
+-    (void)_rl_init_locale ();	/* check current locale */
+-
++    {
++      (void)_rl_init_locale ();	/* check current locale */
++#if defined (__MINGW32__)
++      rl_reset_screen_size ();
++#endif      
++    }
+   /* Initialize the current line information. */
+   _rl_init_line_state ();
+ 
+Common subdirectories: readline-8.0.input/shlib and readline-8.0/shlib
+diff -u readline-8.0.input/signals.c readline-8.0/signals.c
+--- readline-8.0.input/signals.c	2019-03-20 08:02:03.529511918 -0400
++++ readline-8.0/signals.c	2019-03-20 08:13:44.347195350 -0400
+@@ -46,6 +46,11 @@
+ 
+ #include "rlprivate.h"
+ 
++#if defined (__MINGW32__)
++#  define WIN32_LEAN_AND_MEAN
++#  include <windows.h>
++#endif
++
+ #if defined (HANDLE_SIGNALS)
+ 
+ #if !defined (RETSIGTYPE)
+@@ -92,7 +97,7 @@
+ int rl_catch_signals = 1;
+ 
+ /* If non-zero, readline will install a signal handler for SIGWINCH. */
+-#ifdef SIGWINCH
++#if defined (SIGWINCH) || defined(__MINGW32__)
+ int rl_catch_sigwinch = 1;
+ #else
+ int rl_catch_sigwinch = 0;	/* for the readline state struct in readline.c */
+@@ -495,6 +500,21 @@
+     }
+ #endif /* SIGWINCH */
+ 
++#if defined (__MINGW32__)
++  if (rl_catch_sigwinch && sigwinch_set_flag == 0)
++    {
++      DWORD mode;
++      HANDLE hStdIn = GetStdHandle (STD_INPUT_HANDLE);
++
++      if (GetConsoleMode (hStdIn, &mode))
++        {
++          mode |= ENABLE_WINDOW_INPUT;
++          if (SetConsoleMode (hStdIn, mode))
++            sigwinch_set_flag = 1;
++        }
++    }
++#endif
++
+   return 0;
+ }
+ 
+@@ -545,6 +565,20 @@
+       sigwinch_set_flag = 0;
+     }
+ #endif
++#if defined (__MINGW32__)
++  if (rl_catch_sigwinch && sigwinch_set_flag == 1)
++    {
++      DWORD mode;
++      HANDLE hStdIn = GetStdHandle (STD_INPUT_HANDLE);
++
++      if (GetConsoleMode (hStdIn, &mode))
++        {
++          mode &= ~ENABLE_WINDOW_INPUT;
++          if (SetConsoleMode (hStdIn, mode))
++            sigwinch_set_flag = 0;
++        }
++    }
++#endif
+ 
+   return 0;
+ }
+Common subdirectories: readline-8.0.input/support and readline-8.0/support
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-2-event-hook.patch	Thu Mar 21 09:34:09 2019 -0400
@@ -0,0 +1,157 @@
+diff -ur readline-8.0.sigwinch/input.c readline-8.0/input.c
+--- readline-8.0.sigwinch/input.c	2019-03-20 08:15:55.450361377 -0400
++++ readline-8.0/input.c	2019-03-20 08:30:58.059756179 -0400
+@@ -140,6 +140,11 @@
+ static unsigned char ibuffer[512];
+ static int ibuffer_len = sizeof (ibuffer) - 1;
+ 
++#if defined (__MINGW32__)
++static int _win32_getch (void);
++static int _win32_kbhit (void);
++#endif
++
+ #define any_typein (push_index != pop_index)
+ 
+ int
+@@ -266,7 +271,7 @@
+ #if defined (__MINGW32__)
+   /* Use getch/_kbhit to check for available console input, in the same way
+      that we read it normally. */
+-   chars_avail = isatty (tty) ? _kbhit () : 0;
++   chars_avail = isatty (tty) ? _win32_kbhit () : 0;
+    result = 0;
+ #endif
+ 
+@@ -501,6 +506,120 @@
+   return (c);
+ }
+ 
++#if defined (__MINGW32__)
++#define _WIN32_READ_NOCHAR (-2)
++static char _win32_buf[16] = {'0'};
++static int _win32_bufidx = 0;
++
++static int
++_win32_getch_internal (int block)
++{
++  INPUT_RECORD rec;
++  DWORD evRead, waitResult;
++  HANDLE hInput = (HANDLE) _get_osfhandle (fileno (rl_instream));
++
++  if (_win32_bufidx > 0)
++    return _win32_buf[--_win32_bufidx];
++
++  hInput = (HANDLE) _get_osfhandle (fileno (rl_instream));
++
++  do
++    {
++      if (! block)
++        {
++          if (WaitForSingleObject(hInput, _keyboard_input_timeout/1000) != WAIT_OBJECT_0)
++            return _WIN32_READ_NOCHAR;
++        }
++
++      if (!ReadConsoleInput(hInput, &rec, 1, &evRead) || evRead != 1)
++        return EOF;
++
++      switch (rec.EventType)
++        {
++          case KEY_EVENT:
++            if ((rec.Event.KeyEvent.bKeyDown &&
++               (rec.Event.KeyEvent.wVirtualKeyCode < VK_SHIFT ||
++                rec.Event.KeyEvent.wVirtualKeyCode > VK_MENU)) ||
++               (!rec.Event.KeyEvent.bKeyDown &&
++                rec.Event.KeyEvent.wVirtualKeyCode == VK_MENU &&
++                rec.Event.KeyEvent.uChar.AsciiChar))
++              {
++                if (rec.Event.KeyEvent.uChar.AsciiChar)
++                  {
++                    if (rec.Event.KeyEvent.uChar.AsciiChar < 0 ||
++                        (rec.Event.KeyEvent.uChar.AsciiChar < 32 &&
++                         !(rec.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))))
++                      {
++                        char c = rec.Event.KeyEvent.uChar.AsciiChar;
++                        if (GetOEMCP () == GetConsoleCP ())
++                          OemToCharBuff (&c, &c, 1);
++                        return (int)(unsigned char)c;
++                      }
++                    else
++                      return (int)rec.Event.KeyEvent.uChar.UnicodeChar;
++                  }
++                else
++                  switch (rec.Event.KeyEvent.wVirtualKeyCode)
++                    {
++                      case VK_UP:
++                        _win32_buf[_win32_bufidx++] = 'H';
++                        return 0340;
++                      case VK_DOWN:
++                        _win32_buf[_win32_bufidx++] = 'P';
++                        return 0340;
++                      case VK_RIGHT:
++                        _win32_buf[_win32_bufidx++] = 'M';
++                        return 0340;
++                      case VK_LEFT:
++                        _win32_buf[_win32_bufidx++] = 'K';
++                        return 0340;
++                      case VK_HOME:
++                        _win32_buf[_win32_bufidx++] = 'G';
++                        return 0340;
++                      case VK_END:
++                        _win32_buf[_win32_bufidx++] = 'O';
++                        return 0340;
++                      case VK_DELETE:
++                        _win32_buf[_win32_bufidx++] = 'S';
++                        return 0340;
++                      default:
++                        break;
++                    }
++              }
++            break;
++
++          case WINDOW_BUFFER_SIZE_EVENT:
++            rl_resize_terminal ();
++            break;
++
++          default:
++            break;
++        }
++   }
++  while (1);
++}
++
++static int 
++_win32_kbhit (void)
++{
++  int result;
++
++  result = _win32_getch_internal (0);
++  if (result == _WIN32_READ_NOCHAR
++      || result == EOF)
++    return 0;
++  _win32_buf[_win32_bufidx++] = result;
++
++  return _win32_bufidx;
++}
++
++static int
++_win32_getch (void)
++{
++  return _win32_getch_internal (1);
++}
++#endif
++
+ int
+ rl_getc (FILE *stream)
+ {
+@@ -520,9 +639,9 @@
+ #if defined (__MINGW32__)
+       if (isatty (fileno (stream)))
+         {
+-          int c = _getch ();
++          int c = _win32_getch ();
+           if (c == 0xe0)
+-            rl_execute_next (_getch ());
++            rl_execute_next (_win32_getch ());
+           return (c);
+         }
+ #endif