dlopen libncurses.so in wineconsole (take 2)

Mike McCormack mike at codeweavers.com
Thu Aug 14 13:02:09 CDT 2003


Eric Pouech wrote:

 > 1/ in configure.ac
 > why not checking also for curses if ncurses isn't present ?
 > BTW, you can also remove the ncurses library lookup in configure.ac, we
 > no longer need it.


Hi Eric,

Thanks for the comments. I think we still need to detect libncurses in 
configure, because it is still linked with the ttydrv.

Does this patch look better?

Mike


ChangeLog:
* dlopen libncurses.so in wineconsole
-------------- next part --------------
Index: configure.ac
===================================================================
RCS file: /home/wine/wine/configure.ac,v
retrieving revision 1.171
diff -u -r1.171 configure.ac
--- configure.ac	13 Aug 2003 01:27:48 -0000	1.171
+++ configure.ac	14 Aug 2003 17:38:30 -0000
@@ -919,6 +919,8 @@
   WINE_GET_SONAME(jack,jack_client_new)
   WINE_GET_SONAME(ssl,SSL_library_init)
   WINE_GET_SONAME(crypto,BIO_new_socket)
+  WINE_GET_SONAME(ncurses,waddch)
+  WINE_GET_SONAME(curses,waddch)
 fi
 
 
Index: include/config.h.in
===================================================================
RCS file: /home/wine/wine/include/config.h.in,v
retrieving revision 1.157
diff -u -r1.157 config.h.in
--- include/config.h.in	20 Jun 2003 23:26:56 -0000	1.157
+++ include/config.h.in	14 Aug 2003 17:38:30 -0000
@@ -791,6 +791,12 @@
 /* Define to the soname of the libXrender library. */
 #undef SONAME_LIBXRENDER
 
+/* Define to the soname of the libncurses library. */
+#undef SONAME_LIBNCURSES
+
+/* Define to the soname of the libncurses library. */
+#undef SONAME_LIBCURSES
+
 /* If using the C implementation of alloca, define if you know the
    direction of stack growth for your system; otherwise it will be
    automatically deduced at run-time.
Index: programs/wineconsole/Makefile.in
===================================================================
RCS file: /home/wine/wine/programs/wineconsole/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- programs/wineconsole/Makefile.in	13 Dec 2002 23:37:06 -0000	1.7
+++ programs/wineconsole/Makefile.in	14 Aug 2003 17:38:30 -0000
@@ -4,7 +4,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = wineconsole.exe
-EXTRALIBS = @CURSESLIBS@
+EXTRALIBS = 
 APPMODE   = gui
 IMPORTS   = advapi32 kernel32 ntdll
 DELAYIMPORTS = comctl32 user32 gdi32
Index: programs/wineconsole/curses.c
===================================================================
RCS file: /home/wine/wine/programs/wineconsole/curses.c,v
retrieving revision 1.10
diff -u -r1.10 curses.c
--- programs/wineconsole/curses.c	14 Jun 2003 01:34:53 -0000	1.10
+++ programs/wineconsole/curses.c	14 Aug 2003 17:38:30 -0000
@@ -44,6 +44,8 @@
 #include <winnls.h>
 #include "winecon_private.h"
 
+#include "wine/library.h"
+#include "wine/port.h"
 #include "wine/server.h"
 #include "wine/debug.h"
 
@@ -63,6 +65,138 @@
 };
 
 
+static void *nc_handle = NULL;
+
+#define MAKE_FUNCPTR(f) typeof(f) * p_##f = NULL;
+
+MAKE_FUNCPTR(curs_set)
+MAKE_FUNCPTR(delwin)
+MAKE_FUNCPTR(endwin)
+MAKE_FUNCPTR(getmouse)
+MAKE_FUNCPTR(has_colors)
+MAKE_FUNCPTR(init_pair)
+#ifndef initscr
+MAKE_FUNCPTR(initscr)
+#endif
+#ifndef intrflush
+MAKE_FUNCPTR(intrflush)
+#endif
+MAKE_FUNCPTR(keypad)
+MAKE_FUNCPTR(mouseinterval)
+MAKE_FUNCPTR(mousemask)
+MAKE_FUNCPTR(newpad)
+#ifndef nodelay
+MAKE_FUNCPTR(nodelay)
+#endif
+#ifndef noecho
+MAKE_FUNCPTR(noecho)
+#endif
+MAKE_FUNCPTR(prefresh)
+MAKE_FUNCPTR(raw)
+MAKE_FUNCPTR(start_color)
+MAKE_FUNCPTR(stdscr)
+MAKE_FUNCPTR(waddchnstr)
+MAKE_FUNCPTR(wmove)
+MAKE_FUNCPTR(wgetch)
+
+#undef MAKE_FUNCPTR
+
+/**********************************************************************/
+
+typedef struct {
+    LPVOID lpCallback;
+    LPVOID lpContext;
+} DirectDrawEnumerateProcData;
+
+static BOOL WCCURSES_bind_libcurses()
+{
+#ifdef HAVE_NCURSES_H
+    char *ncname = SONAME_LIBNCURSES;
+#else
+    char *ncname = SONAME_LIBCURSES;
+#endif
+
+    nc_handle = wine_dlopen(ncname, RTLD_NOW, NULL, 0);
+    if(!nc_handle)
+    {
+        WINE_MESSAGE("Wine cannot find the ncurses library (%s).\n",ncname);
+	return FALSE;
+    }
+
+#define LOAD_FUNCPTR(f,needed)                               \
+    if((p_##f = wine_dlsym(nc_handle, #f, NULL, 0)) == NULL) \
+    {                                                        \
+        WINE_WARN("Can't find symbol %s\n", #f);             \
+        if(needed)                                           \
+            goto sym_not_found;                              \
+    }
+
+    LOAD_FUNCPTR(curs_set,TRUE)
+    LOAD_FUNCPTR(delwin,TRUE)
+    LOAD_FUNCPTR(endwin,TRUE)
+    LOAD_FUNCPTR(getmouse,TRUE)
+    LOAD_FUNCPTR(has_colors,TRUE)
+    LOAD_FUNCPTR(init_pair,TRUE)
+    LOAD_FUNCPTR(initscr,FALSE)
+    LOAD_FUNCPTR(intrflush,FALSE)
+    LOAD_FUNCPTR(keypad,TRUE)
+    LOAD_FUNCPTR(mouseinterval,TRUE)
+    LOAD_FUNCPTR(mousemask,TRUE)
+    LOAD_FUNCPTR(newpad,TRUE)
+    LOAD_FUNCPTR(nodelay,FALSE)
+    LOAD_FUNCPTR(noecho,FALSE)
+    LOAD_FUNCPTR(prefresh,TRUE)
+    LOAD_FUNCPTR(raw,TRUE)
+    LOAD_FUNCPTR(start_color,TRUE)
+    LOAD_FUNCPTR(stdscr,TRUE)
+    LOAD_FUNCPTR(waddchnstr,TRUE)
+    LOAD_FUNCPTR(wmove,TRUE)
+    LOAD_FUNCPTR(wgetch,TRUE)
+
+#undef LOAD_FUNCPTR
+
+    return TRUE;
+
+sym_not_found:
+    WINE_MESSAGE(
+      "Wine cannot find certain functions that it needs inside the ncurses\n"
+      "library.  To enable Wine to use ncurses please upgrade your ncurses\n"
+      "libraries\n");
+    wine_dlclose(nc_handle, NULL, 0);
+    nc_handle = NULL;
+    return FALSE;
+}
+
+#define curs_set p_curs_set
+#define delwin p_delwin
+#define endwin p_endwin
+#define getmouse p_getmouse
+#define has_colors p_has_colors
+#define init_pair p_init_pair
+#ifndef initscr
+#define initscr p_initscr
+#endif
+#ifndef intrflush
+#define intrflush p_intrflush
+#endif
+#define keypad p_keypad
+#define mouseinterval p_mouseinterval
+#define mousemask p_mousemask
+#define newpad p_newpad
+#ifndef nodelay
+#define nodelay p_nodelay
+#endif
+#ifndef noecho
+#define noecho p_noecho
+#endif
+#define prefresh p_prefresh
+#define raw p_raw
+#define start_color p_start_color
+#define stdscr (*p_stdscr)
+#define waddchnstr p_waddchnstr
+#define wmove p_wmove
+#define wgetch p_wgetch
+
 /******************************************************************
  *		WCCURSES_ResizeScreenBuffer
  *
@@ -719,6 +853,9 @@
  */
 enum init_return WCCURSES_InitBackend(struct inner_data* data)
 {
+    if( !WCCURSES_bind_libcurses() )
+        return init_failed;
+
     data->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct inner_data_curse));
     if (!data->private) return init_failed;
 


More information about the wine-patches mailing list