bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-readline] Building Readline with ncurses on MS-Windows


From: Eli Zaretskii
Subject: [Bug-readline] Building Readline with ncurses on MS-Windows
Date: Fri, 02 Jan 2015 12:33:18 +0200

[Please CC me on any replies, as I'm not subscribed to this list.]

Hi,

I needed the following patches to be able to build and run Readline
(as part of GDB) on MS-Windows when ncurses is used as the
termcap/terminfo library.  The patches are relative to Readline 6.2
that is bundled with GDB, but I looked in Readline 6.3, and the issues
mentioned below are still applicable.

Thanks in advance.

This patch fixes the deficiency in Windows runtime's isatty
implementation, and also makes sure Readline doesn't call 'getch' from
ncurses, which will always err out, since initscr was not called, and
the output bypasses ncurses:

--- input.c~0   2014-06-11 18:34:41 +0300
+++ input.c     2014-12-30 14:03:58 +0200
@@ -86,6 +86,24 @@
 static int rl_get_char PARAMS((int *));
 static int rl_gather_tyi PARAMS((void));
 
+#if defined (_WIN32) && !defined (__CYGWIN__)
+
+/* 'isatty' in the Windows runtime returns non-zero for every
+   character device, including the null device.  Repair that.  */
+#include <io.h>
+#define WIN32_LEAN_AND_MEAN 1
+#include <windows.h>
+
+int w32_isatty (int fd)
+{
+  if (_isatty(fd))
+    return (((long) (HANDLE) _get_osfhandle(fd)) & 3) == 3;
+  return 0;
+}
+
+#define isatty(x)  w32_isatty(x)
+#endif
+
 /* **************************************************************** */
 /*                                                                 */
 /*                     Character Input Buffering                   */
@@ -465,8 +483,10 @@
       RL_CHECK_SIGNALS ();
 
 #if defined (__MINGW32__)
+      /* Use _getch to make sure we call the function from MS runtime,
+        even if some curses library is linked in.  */
       if (isatty (fileno (stream)))
-       return (getch ());
+       return (_getch ());
 #endif
       result = read (fileno (stream), &c, sizeof (unsigned char));
 


This patch makes sure Readline includes the necessary ncurses header
files, which (at least on Windows) are installed into a subdirectory
of $includedir:

--- tcap.h~0    2014-06-11 18:34:41 +0300
+++ tcap.h      2014-12-30 13:52:44 +0200
@@ -31,6 +31,8 @@
 #    include "rltty.h"
 #  endif
 #  include <termcap.h>
+#elif defined (HAVE_NCURSES_TERMCAP_H)
+#  include <ncurses/termcap.h>
 #else
 
 /* On Solaris2, sys/types.h #includes sys/reg.h, which #defines PC.
--- readline/configure.in~0     2014-06-11 18:34:41 +0300
+++ readline/configure.in       2014-12-30 13:45:41 +0200
@@ -198,6 +198,9 @@
                TERMCAP_LIB=-ltermcap   #default
        fi
 fi
+if test "$TERMCAP_LIB" = "-lncurses"; then
+       AC_CHECK_HEADERS(ncurses/termcap.h)
+fi
 
 BASH_CHECK_MULTIBYTE
 

--- config.h.in~0       2014-06-11 18:34:41 +0300
+++ config.h.in 2014-12-30 13:50:44 +0200
@@ -186,6 +186,9 @@
 /* Define if you have the <termcap.h> header file.  */
 #undef HAVE_TERMCAP_H
 
+/* Define if you have the <ncurses/termcap.h> header file.  */
+#undef HAVE_NCURSES_TERMCAP_H
+
 /* Define if you have the <termio.h> header file.  */
 #undef HAVE_TERMIO_H
 


This patch is not really necessary, but it paves the way for perhaps
removing the Windows conditionals at some future point, if Readline on
Windows is to be built with ncurses.

--- display.c~0 2014-06-11 18:34:41 +0300
+++ display.c   2014-12-30 13:56:26 +0200
@@ -2374,7 +2374,7 @@
      char *string;
      int count, col;
 {
-#if defined (__MSDOS__) || defined (__MINGW32__)
+#if defined (__MSDOS__) || (defined (__MINGW32__) && !defined 
(NCURSES_VERSION))
   _rl_output_some_chars (string, count);
 #else
   /* DEBUGGING */
@@ -2426,7 +2426,7 @@
   if (count > _rl_screenwidth) /* XXX */
     return;
 
-#if !defined (__MSDOS__) && !defined (__MINGW32__)
+#if !defined (__MSDOS__) && !(defined (__MINGW32__) && !defined 
(NCURSES_VERSION))
   if (_rl_term_DC && *_rl_term_DC)
     {
       char *buffer;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]