Eric Pouech : kernel32: Added support for terminfo/termcap in console code.

Alexandre Julliard julliard at winehq.org
Wed Jan 19 11:46:13 CST 2011


Module: wine
Branch: master
Commit: ef3c46a9bf4e454e27e8f24b12a401b4af6e38cc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ef3c46a9bf4e454e27e8f24b12a401b4af6e38cc

Author: Eric Pouech <eric.pouech at orange.fr>
Date:   Tue Jan 18 22:02:24 2011 +0100

kernel32: Added support for terminfo/termcap in console code.

---

 dlls/kernel32/Makefile.in       |    1 +
 dlls/kernel32/console.c         |    2 +
 dlls/kernel32/console_private.h |    4 +
 dlls/kernel32/term.c            |  117 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/Makefile.in b/dlls/kernel32/Makefile.in
index 58a4497..9e03243 100644
--- a/dlls/kernel32/Makefile.in
+++ b/dlls/kernel32/Makefile.in
@@ -35,6 +35,7 @@ C_SRCS = \
 	string.c \
 	sync.c \
 	tape.c \
+	term.c \
 	thread.c \
 	time.c \
 	toolhelp.c \
diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index f1bc3bc..1541858 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -216,6 +216,7 @@ static BOOL restore_console_mode(HANDLE hin)
     if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
     ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
     close(fd);
+    TERM_Exit();
     return ret;
 }
 
@@ -3086,6 +3087,7 @@ BOOL CONSOLE_Init(RTL_USER_PROCESS_PARAMETERS *params)
         /* This is wine specific: we have no parent (we're started from unix)
          * so, create a simple console with bare handles
          */
+        TERM_Init();
         wine_server_send_fd(0);
         SERVER_START_REQ( alloc_console )
         {
diff --git a/dlls/kernel32/console_private.h b/dlls/kernel32/console_private.h
index 06a8bd6..bb16d0b 100644
--- a/dlls/kernel32/console_private.h
+++ b/dlls/kernel32/console_private.h
@@ -33,4 +33,8 @@ extern BOOL     CONSOLE_GetEditionMode(HANDLE, int*);
 /* editline.c */
 extern WCHAR*   CONSOLE_Readline(HANDLE, BOOL);
 
+/* term.c */
+extern BOOL     TERM_Init(void);
+extern BOOL     TERM_Exit(void);
+
 #endif  /* __WINE_CONSOLE_PRIVATE_H */
diff --git a/dlls/kernel32/term.c b/dlls/kernel32/term.c
new file mode 100644
index 0000000..56ddd67
--- /dev/null
+++ b/dlls/kernel32/term.c
@@ -0,0 +1,117 @@
+/*
+ * Interface to terminfo and termcap libraries
+ *
+ * Copyright 2010 Eric Pouech
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#ifdef HAVE_NCURSES_H
+# include <ncurses.h>
+#elif defined(HAVE_CURSES_H)
+# include <curses.h>
+#endif
+/* avoid redefinition warnings */
+#undef KEY_EVENT
+#undef MOUSE_MOVED
+
+#include <term.h>
+
+#include <windef.h>
+#include <winbase.h>
+#include <winnls.h>
+#include <wincon.h>
+#include "console_private.h"
+#include "wine/library.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(console);
+
+#if defined(SONAME_LIBCURSES) || defined(SONAME_LIBNCURSES)
+
+#ifdef HAVE_NCURSES_H
+# define CURSES_NAME "ncurses"
+#else
+# define CURSES_NAME "curses"
+#endif
+
+static void *nc_handle = NULL;
+
+#define MAKE_FUNCPTR(f) static typeof(f) * p_##f;
+
+MAKE_FUNCPTR(setupterm)
+
+#undef MAKE_FUNCPTR
+
+/**********************************************************************/
+
+static BOOL TERM_bind_libcurses(void)
+{
+#ifdef SONAME_LIBNCURSES
+    static const char ncname[] = SONAME_LIBNCURSES;
+#else
+    static const char ncname[] = SONAME_LIBCURSES;
+#endif
+
+    if (!(nc_handle = wine_dlopen(ncname, RTLD_NOW, NULL, 0)))
+    {
+        WINE_MESSAGE("Wine cannot find the " CURSES_NAME " library (%s).\n",
+                     ncname);
+        return FALSE;
+    }
+
+#define LOAD_FUNCPTR(f)                                      \
+    if((p_##f = wine_dlsym(nc_handle, #f, NULL, 0)) == NULL) \
+    {                                                        \
+        WINE_WARN("Can't find symbol %s\n", #f);             \
+        goto sym_not_found;                                  \
+    }
+
+    LOAD_FUNCPTR(setupterm)
+
+#undef LOAD_FUNCPTR
+
+    return TRUE;
+
+sym_not_found:
+    WINE_MESSAGE(
+      "Wine cannot find certain functions that it needs inside the "
+       CURSES_NAME "\nlibrary.  To enable Wine to use " CURSES_NAME
+      " please upgrade your " CURSES_NAME "\nlibraries\n");
+    wine_dlclose(nc_handle, NULL, 0);
+    nc_handle = NULL;
+    return FALSE;
+}
+
+#define setupterm p_setupterm
+
+BOOL TERM_Init(void)
+{
+    if (!TERM_bind_libcurses()) return FALSE;
+    if (setupterm(NULL, 1 /* really ?? */, NULL) == -1) return FALSE;
+    return TRUE;
+}
+
+BOOL TERM_Exit(void)
+{
+    return TRUE;
+}
+#else
+BOOL     TERM_Init(void) {return FALSE;}
+BOOL     TERM_Exit(void) {return FALSE;}
+#endif




More information about the wine-cvs mailing list