# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1533470455 -7200
#      Sun Aug 05 14:00:55 2018 +0200
# Node ID be1f38fbf86232bfc4d3115dd296a7a2d8ed2b2c
# Parent  14328ca36f61e2ff97793358323f1d5d5e696289
Update GNU Readline to 7.0 (bug #47571).

* readline.mk: Update version and checksum. Add "autoconf" to build rule.

* readline-1-display.patch, readline-1-binding.patch, readline-1-paste.patch,
readline-1-sigwinch.patch: Remove changes that are applied upstream.

* readline-1-input.patch, readline-1-sigwinch.patch, readline-3-s_is.patch,
readline-5-chown.patch: Add changes necessary for cross-compilation.

* readline-4-nls.patch: Work-around Windows not supporting UTF-8 as a codepage.

* octave.vbs: Set LC_CTYPE to use UTF-8 codepage.

* dist-files.mk: Update file list.

diff -r 14328ca36f61 -r be1f38fbf862 dist-files.mk
--- a/dist-files.mk	Fri Aug 24 12:52:01 2018 -0400
+++ b/dist-files.mk	Sun Aug 05 14:00:55 2018 +0200
@@ -627,12 +627,13 @@
   qwt.mk \
   qwtplot3d-1-fixes.patch \
   qwtplot3d.mk \
-  readline-1-binding.patch \
   readline-1-display.patch \
   readline-1-input.patch \
-  readline-1-paste.patch \
   readline-1-sigwinch.patch \
   readline-2-event-hook.patch \
+  readline-3-s_is.patch \
+  readline-4-nls.patch \
+  readline-5-chown.patch \
   readline.mk \
   release-octave-1-defaults.patch \
   release-octave-1-gnulib.patch \
diff -r 14328ca36f61 -r be1f38fbf862 installer-files/octave.vbs
--- a/installer-files/octave.vbs	Fri Aug 24 12:52:01 2018 -0400
+++ b/installer-files/octave.vbs	Sun Aug 05 14:00:55 2018 +0200
@@ -41,6 +41,9 @@
 
 wshSystemEnv("GS") = "gs.exe"
 
+' set locale to use UTF-8 for GNU Readline
+wshSystemEnv("LC_CTYPE") = "en_US.UTF-8"
+
 If wshShell.ExpandEnvironmentStrings("%HOME%") = "%HOME%" Then
   Home = wshSystemEnv("USERPROFILE")
   Set fo = fso.GetFolder(Home)
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-1-binding.patch
--- a/src/readline-1-binding.patch	Fri Aug 24 12:52:01 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-diff -uNr a/readline.c b/readline.c
---- a/readline.c	2010-07-25 17:07:40.000000000 -0400
-+++ b/readline.c	2013-04-17 20:38:42.637674309 -0400
-@@ -1158,7 +1163,10 @@
-   rl_bind_keyseq_if_unbound ("\340H", rl_get_previous_history);
-   rl_bind_keyseq_if_unbound ("\340P", rl_get_next_history);
-   rl_bind_keyseq_if_unbound ("\340M", rl_forward_char);
-   rl_bind_keyseq_if_unbound ("\340K", rl_backward_char);
-+  rl_bind_keyseq_if_unbound ("\340G", rl_beg_of_line);
-+  rl_bind_keyseq_if_unbound ("\340O", rl_end_of_line);
-+  rl_bind_keyseq_if_unbound ("\340S", rl_delete);
- #endif
- 
-   _rl_keymap = xkeymap;
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-1-display.patch
--- a/src/readline-1-display.patch	Fri Aug 24 12:52:01 2018 -0400
+++ b/src/readline-1-display.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -1,7 +1,7 @@
 diff -uNr a/display.c b/display.c
 --- a/display.c	2009-09-26 14:37:33.000000000 -0400
 +++ b/display.c	2013-04-17 17:51:18.323642508 -0400
-@@ -55,6 +55,11 @@
+@@ -59,6 +59,11 @@
  #include "rlprivate.h"
  #include "xmalloc.h"
  
@@ -13,9 +13,9 @@
  #if !defined (strchr) && !defined (__STDC__)
  extern char *strchr (), *strrchr ();
  #endif /* !strchr && !__STDC__ */
-@@ -1904,6 +1909,20 @@
-   int cpos, dpos;		/* current and desired cursor positions */
-   int adjust;
+@@ -2166,6 +2169,20 @@
+   int in_invisline;
+   int mb_cur_max = MB_CUR_MAX;
  
 +#if defined (_WIN32)
 +  CONSOLE_SCREEN_BUFFER_INFO csbi;
@@ -34,7 +34,7 @@
    woff = WRAP_OFFSET (_rl_last_v_pos, wrap_offset);
    cpos = _rl_last_c_pos;
  
-@@ -2040,6 +2059,20 @@
+@@ -2319,6 +2338,20 @@
  {
    register int delta, i;
  
@@ -55,55 +55,3 @@
    if (_rl_last_v_pos == to || to > _rl_screenheight)
      return;
  
-@@ -2318,6 +2351,17 @@
- _rl_clear_to_eol (count)
-      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 */
-+
-   if (_rl_term_clreol)
-     tputs (_rl_term_clreol, 1, _rl_output_character_function);
-   else if (count)
-@@ -2341,6 +2385,33 @@
- void
- _rl_clear_screen ()
- {
-+#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 (_rl_term_clrpag)
-     tputs (_rl_term_clrpag, 1, _rl_output_character_function);
-   else
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-1-input.patch
--- a/src/readline-1-input.patch	Fri Aug 24 12:52:01 2018 -0400
+++ b/src/readline-1-input.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -1,11 +1,11 @@
 diff -uNr a/input.c b/input.c
 --- a/input.c	2010-05-30 18:33:01.000000000 -0400
-+++ b/input.c	2013-04-17 23:50:34.759675631 -0400
-@@ -466,7 +466,12 @@
++++ b/input.c	2018-08-25 16:30:34.759675631 -0400
+@@ -508,7 +508,12 @@
  
  #if defined (__MINGW32__)
        if (isatty (fileno (stream)))
--	return (getch ());
+-	return (_getch ());	/* "There is no error return." */
 +        {
 +          int c = _getch ();
 +          if (c == 0xe0)
@@ -13,5 +13,5 @@
 +          return (c);
 +        }
  #endif
-       result = read (fileno (stream), &c, sizeof (unsigned char));
- 
+       result = 0;
+ #if defined (HAVE_PSELECT)
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-1-paste.patch
--- a/src/readline-1-paste.patch	Fri Aug 24 12:52:01 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-diff -u a/input.c b/readline-6.2/input.c
---- a/input.c	2010-05-30 18:33:01.000000000 -0400
-+++ b/input.c	2012-06-25 21:08:42.000000000 -0400
-@@ -410,5 +412,5 @@
- rl_read_key ()
- {
--  int c;
-+  int c, r;
- 
-   rl_key_sequence_length++;
-@@ -430,12 +432,16 @@
- 	  while (rl_event_hook)
- 	    {
--	      if (rl_gather_tyi () < 0)	/* XXX - EIO */
-+	      if (rl_get_char (&c) != 0)
-+		break;
-+		
-+	      if ((r = rl_gather_tyi ()) < 0)	/* XXX - EIO */
- 		{
- 		  rl_done = 1;
- 		  return ('\n');
- 		}
-+	      else if (r == 1)			/* read something */
-+		continue;
-+
- 	      RL_CHECK_SIGNALS ();
--	      if (rl_get_char (&c) != 0)
--		break;
- 	      if (rl_done)		/* XXX - experimental */
- 		return ('\n');
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-1-sigwinch.patch
--- a/src/readline-1-sigwinch.patch	Fri Aug 24 12:52:01 2018 -0400
+++ b/src/readline-1-sigwinch.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -1,7 +1,7 @@
 diff -uNr a/readline.c b/readline.c
 --- a/readline.c	2010-07-25 17:07:40.000000000 -0400
 +++ b/readline.c	2013-04-17 16:11:52.932653458 -0400
-@@ -970,6 +970,11 @@
+@@ -1103,6 +1103,11 @@
        rl_initialized++;
        RL_SETSTATE(RL_STATE_INITIALIZED);
      }
@@ -11,7 +11,7 @@
 +    rl_reset_screen_size ();
 +#endif
  
-   /* Initalize the current line information. */
+   /* Initialize the current line information. */
    _rl_init_line_state ();
 diff -uNr a/signals.c b/signals.c
 --- a/signals.c	2011-02-11 10:53:33.000000000 -0500
@@ -28,7 +28,7 @@
  #if defined (HANDLE_SIGNALS)
  
  #if !defined (RETSIGTYPE)
-@@ -91,7 +96,7 @@
+@@ -92,7 +97,7 @@
  int rl_catch_signals = 1;
  
  /* If non-zero, readline will install a signal handler for SIGWINCH. */
@@ -37,7 +37,7 @@
  int rl_catch_sigwinch = 1;
  #else
  int rl_catch_sigwinch = 0;	/* for the readline state struct in readline.c */
-@@ -422,6 +427,21 @@
+@@ -496,6 +501,21 @@
      }
  #endif /* SIGWINCH */
  
@@ -59,7 +59,7 @@
    return 0;
  }
  
-@@ -467,6 +487,21 @@
+@@ -549,6 +569,21 @@
      }
  #endif
  
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-2-event-hook.patch
--- a/src/readline-2-event-hook.patch	Fri Aug 24 12:52:01 2018 -0400
+++ b/src/readline-2-event-hook.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -1,7 +1,7 @@
 diff -ur readline-6.2-orig/input.c readline-6.2/input.c
 --- readline-6.2-orig/input.c	2013-11-24 19:19:30 -0500
 +++ readline-6.2/input.c	2013-11-29 11:19:59 -0500
-@@ -54,6 +54,11 @@
+@@ -56,6 +56,11 @@
  #include <stdio.h>
  #include <errno.h>
  
@@ -13,7 +13,7 @@
  #if !defined (errno)
  extern int errno;
  #endif /* !errno */
-@@ -96,6 +101,11 @@
+@@ -121,6 +126,11 @@
  static unsigned char ibuffer[512];
  static int ibuffer_len = sizeof (ibuffer) - 1;
  
@@ -25,7 +25,7 @@
  #define any_typein (push_index != pop_index)
  
  int
-@@ -219,8 +229,8 @@
+@@ -249,8 +259,8 @@
  #if defined (__MINGW32__)
    /* Use getch/_kbhit to check for available console input, in the same way
       that we read it normally. */
@@ -36,7 +36,7 @@
  #endif
  
    /* If there's nothing available, don't waste time trying to read
-@@ -457,6 +467,123 @@
+@@ -489,6 +499,123 @@
    return (c);
  }
  
@@ -160,7 +160,7 @@
  int
  rl_getc (stream)
       FILE *stream;
-@@ -471,9 +598,9 @@
+@@ -509,9 +636,9 @@
  #if defined (__MINGW32__)
        if (isatty (fileno (stream)))
          {
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-3-s_is.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-3-s_is.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -0,0 +1,111 @@
+diff --git a/colors.c b/colors.c
+index 89d9035..ec19844 100644
+--- a/colors.c
++++ b/colors.c
+@@ -183,14 +183,22 @@ _rl_print_color_indicator (char *f)
+         {
+           colored_filetype = C_FILE;
+ 
++#if defined (S_ISUID)
+           if ((mode & S_ISUID) != 0 && is_colored (C_SETUID))
+             colored_filetype = C_SETUID;
+-          else if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
++          else
++#endif
++#if defined (S_ISGID)
++          if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
+             colored_filetype = C_SETGID;
+-          else if (is_colored (C_CAP) && 0) //f->has_capability)
++          else
++#endif
++          if (is_colored (C_CAP) && 0) //f->has_capability)
+             colored_filetype = C_CAP;
++#if defined(S_IXUGO)
+           else if ((mode & S_IXUGO) != 0 && is_colored (C_EXEC))
+             colored_filetype = C_EXEC;
++#endif
+           else if ((1 < astat.st_nlink) && is_colored (C_MULTIHARDLINK))
+             colored_filetype = C_MULTIHARDLINK;
+         }
+@@ -204,8 +212,10 @@ _rl_print_color_indicator (char *f)
+             colored_filetype = C_STICKY_OTHER_WRITABLE;
+           else
+ #endif
++#if defined (S_IWOTH)
+           if ((mode & S_IWOTH) != 0 && is_colored (C_OTHER_WRITABLE))
+             colored_filetype = C_OTHER_WRITABLE;
++#endif
+ #if defined (S_ISVTX)
+           else if ((mode & S_ISVTX) != 0 && is_colored (C_STICKY))
+             colored_filetype = C_STICKY;
+diff --git a/colors.h b/colors.h
+index fc926e5..e62edd0 100644
+--- a/colors.h
++++ b/colors.h
+@@ -96,7 +96,7 @@ enum indicator_no
+   };
+ 
+ 
+-#if !S_IXUGO
++#if !S_IXUGO && defined(S_IXUSR) && defined(S_IXGRP) && defined(S_IXOTH)
+ # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
+ #endif
+ 
+diff --git a/posixstat.h b/posixstat.h
+index 3eb7f29..854a2c9 100644
+--- a/posixstat.h
++++ b/posixstat.h
+@@ -78,30 +78,44 @@
+ 
+ #if defined (S_IFBLK) && !defined (S_ISBLK)
+ #define	S_ISBLK(m)	(((m)&S_IFMT) == S_IFBLK)	/* block device */
++#elif !defined (S_IFBLK)
++#define S_ISBLK(m)	0
+ #endif
+ 
+ #if defined (S_IFCHR) && !defined (S_ISCHR)
+ #define	S_ISCHR(m)	(((m)&S_IFMT) == S_IFCHR)	/* character device */
++#elif !defined (S_IFCHR)
++#define S_ISCHR(m)	0
+ #endif
+ 
+ #if defined (S_IFDIR) && !defined (S_ISDIR)
+ #define	S_ISDIR(m)	(((m)&S_IFMT) == S_IFDIR)	/* directory */
++#elif !defined (S_IFDIR)
++#define S_ISDIR(m)	0
+ #endif
+ 
+ #if defined (S_IFREG) && !defined (S_ISREG)
+ #define	S_ISREG(m)	(((m)&S_IFMT) == S_IFREG)	/* file */
++#elif !defined (S_IFREG)
++#define S_ISREG(m)	0
+ #endif
+ 
+ #if defined (S_IFIFO) && !defined (S_ISFIFO)
+ #define	S_ISFIFO(m)	(((m)&S_IFMT) == S_IFIFO)	/* fifo - named pipe */
++#elif !defined (S_IFIFO)
++#define S_ISFIFO(m)	0
+ #endif
+ 
+ #if defined (S_IFLNK) && !defined (S_ISLNK)
+ #define	S_ISLNK(m)	(((m)&S_IFMT) == S_IFLNK)	/* symbolic link */
++#elif !defined (S_IFLNK)
++#define S_ISLNK(m)	0
+ #endif
+ 
+ #if defined (S_IFSOCK) && !defined (S_ISSOCK)
+ #define	S_ISSOCK(m)	(((m)&S_IFMT) == S_IFSOCK)	/* socket */
++#elif !defined (S_IFSOCK)
++#define S_ISSOCK(m)	0
+ #endif
+ 
+ /*
+@@ -137,6 +151,8 @@
+ /* These are non-standard, but are used in builtins.c$symbolic_umask() */
+ #define S_IRUGO		(S_IRUSR | S_IRGRP | S_IROTH)
+ #define S_IWUGO		(S_IWUSR | S_IWGRP | S_IWOTH)
++#if defined(S_IXUSR) && defined(S_IXGRP) && defined(S_IXOTH)
+ #define S_IXUGO		(S_IXUSR | S_IXGRP | S_IXOTH)
++#endif
+ 
+ #endif /* _POSIXSTAT_H_ */
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-4-nls.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-4-nls.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -0,0 +1,14 @@
+--- a/nls.c	2013-03-09 20:51:10.000000000 +0100
++++ b/nls.c	2018-08-05 15:33:03.303130359 +0200
+@@ -142,6 +142,11 @@
+     lspec = "";
+   t = setlocale (LC_CTYPE, lspec);
+ 
++#if defined(__WIN32__) /* Setting codepage UTF-8 fails on Windows */
++  if (! t)
++    t = lspec;
++#endif
++
+   if (t && *t)
+     _rl_utf8locale = utf8locale (t);
+ 
diff -r 14328ca36f61 -r be1f38fbf862 src/readline-5-chown.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/readline-5-chown.patch	Sun Aug 05 14:00:55 2018 +0200
@@ -0,0 +1,24 @@
+--- a/histfile.c.orig	2018-08-25 17:30:15.030476998 +0200
++++ b/histfile.c	2018-08-25 17:27:52.402546776 +0200
+@@ -610,8 +610,10 @@
+      user is running this, it's a no-op.  If the shell is running after sudo
+      with a shared history file, we don't want to leave the history file
+      owned by root. */
++#ifdef HAVE_CHOWN
+   if (rv == 0 && exists)
+     r = chown (filename, finfo.st_uid, finfo.st_gid);
++#endif
+ 
+   xfree (filename);
+   FREE (tempname);
+@@ -757,8 +759,10 @@
+      user is running this, it's a no-op.  If the shell is running after sudo
+      with a shared history file, we don't want to leave the history file
+      owned by root. */
++#ifdef HAVE_CHOWN
+   if (rv == 0 && exists)
+     mode = chown (histname, finfo.st_uid, finfo.st_gid);
++#endif
+ 
+   FREE (histname);
+   FREE (tempname);
diff -r 14328ca36f61 -r be1f38fbf862 src/readline.mk
--- a/src/readline.mk	Fri Aug 24 12:52:01 2018 -0400
+++ b/src/readline.mk	Sun Aug 05 14:00:55 2018 +0200
@@ -3,8 +3,8 @@
 
 PKG             := readline
 $(PKG)_IGNORE   :=
-$(PKG)_VERSION  := 6.2
-$(PKG)_CHECKSUM := a9761cd9c3da485eb354175fcc2fe35856bc43ac
+$(PKG)_VERSION  := 7.0
+$(PKG)_CHECKSUM := d9095fa14a812495052357e1d678b3f2ac635463
 $(PKG)_SUBDIR   := readline-$($(PKG)_VERSION)
 $(PKG)_FILE     := readline-$($(PKG)_VERSION).tar.gz
 $(PKG)_URL      := http://ftp.gnu.org/gnu/readline/$($(PKG)_FILE)
@@ -35,7 +35,7 @@
                       -e 's/@@LIBRARY_SUFFIX@@/$(LIBRARY_SUFFIX)/g' $$f; \
         done; \
     fi
-    cd '$(1)' && ./configure \
+    cd '$(1)' && autoconf && ./configure \
         $(CONFIGURE_CPPFLAGS) $(CONFIGURE_LDFLAGS) \
         $(HOST_AND_BUILD_CONFIGURE_OPTIONS) \
         $(ENABLE_SHARED_OR_STATIC) \
