Dynamically load libsane
Francois Gouget
fgouget at codeweavers.com
Sat Oct 18 16:22:32 CDT 2003
Note: autoconf must be re-run after applying this patch.
Changelog:
Mike McCormack <mike at codeweavers.com>
Francois Gouget <fgouget at codeweavers.com>
* configure.ac,
dlls/twain/Makefile.in,
dlls/twain/capability.c,
dlls/twain/ds_audio.c,
dlls/twain/ds_image.c,
dlls/twain/dsm_ctrl.c,
dlls/twain/twain32_main.c,
dlls/twain/twain_i.h,
include/config.h.in
config.h must be included before including twain_i.h
Dynamically load libsane.so
--
Francois Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: configure.ac
===================================================================
RCS file: /home/cvs/wine/configure.ac,v
retrieving revision 1.192
diff -u -r1.192 configure.ac
--- configure.ac 16 Oct 2003 05:16:05 -0000 1.192
+++ configure.ac 16 Oct 2003 12:30:22 -0000
@@ -387,26 +387,18 @@
AC_CHECK_PROG(sane_devel,sane-config,sane-config,no)
if test "$sane_devel" = "no"
then
- SANELIBS=""
SANEINCL=""
else
- SANELIBS="`$sane_devel --libs`"
SANEINCL="`$sane_devel --cflags`"
ac_save_CPPFLAGS="$CPPFLAGS"
- ac_save_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $SANEINCL"
- LIBS="$LIBS $SANELIBS"
AC_CHECK_HEADER(sane/sane.h,
[AC_CHECK_LIB(sane,sane_open,
[AC_DEFINE(HAVE_SANE, 1, [Define if we have SANE development environment])],
- [SANELIBS=""
- SANEINCL=""])],
- [SANELIBS=""
- SANEINCL=""])
- LIBS="$ac_save_LIBS"
+ [SANEINCL=""])],
+ [ SANEINCL=""])
CPPFLAGS="$ac_save_CPPFLAGS"
fi
-AC_SUBST(SANELIBS)
AC_SUBST(SANEINCL)
dnl **** Check for the ICU library ****
@@ -927,6 +919,7 @@
WINE_GET_SONAME(crypto,BIO_new_socket)
WINE_GET_SONAME(ncurses,waddch)
WINE_GET_SONAME(curses,waddch)
+ WINE_GET_SONAME(sane,sane_open)
fi
Index: dlls/twain/Makefile.in
===================================================================
RCS file: /home/cvs/wine/dlls/twain/Makefile.in,v
retrieving revision 1.5
diff -u -r1.5 Makefile.in
--- dlls/twain/Makefile.in 11 Oct 2003 01:09:17 -0000 1.5
+++ dlls/twain/Makefile.in 13 Oct 2003 19:53:07 -0000
@@ -4,7 +4,7 @@
VPATH = @srcdir@
MODULE = twain_32.dll
IMPORTS = user32 gdi32 kernel32
-EXTRALIBS = @SANELIBS@
+EXTRALIBS =
EXTRAINCL = @SANEINCL@
C_SRCS = \
Index: dlls/twain/capability.c
===================================================================
RCS file: /home/cvs/wine/dlls/twain/capability.c,v
retrieving revision 1.3
diff -u -r1.3 capability.c
--- dlls/twain/capability.c 22 Aug 2003 05:05:56 -0000 1.3
+++ dlls/twain/capability.c 13 Oct 2003 20:37:40 -0000
@@ -21,6 +21,8 @@
#include <stdarg.h>
+#include "config.h"
+
#include "windef.h"
#include "winbase.h"
#include "twain.h"
Index: dlls/twain/ds_audio.c
===================================================================
RCS file: /home/cvs/wine/dlls/twain/ds_audio.c,v
retrieving revision 1.1
diff -u -r1.1 ds_audio.c
--- dlls/twain/ds_audio.c 21 Mar 2002 02:58:39 -0000 1.1
+++ dlls/twain/ds_audio.c 13 Oct 2003 20:38:03 -0000
@@ -16,6 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "config.h"
+
#include "twain.h"
#include "twain_i.h"
#include "wine/debug.h"
Index: dlls/twain/ds_image.c
===================================================================
RCS file: /home/cvs/wine/dlls/twain/ds_image.c,v
retrieving revision 1.4
diff -u -r1.4 ds_image.c
--- dlls/twain/ds_image.c 22 Aug 2003 05:05:56 -0000 1.4
+++ dlls/twain/ds_image.c 13 Oct 2003 19:53:07 -0000
@@ -89,6 +89,12 @@
TRACE("DG_IMAGE/DAT_IMAGEINFO/MSG_GET\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (!pSource)
{
twRC = TWRC_FAILURE;
@@ -199,6 +205,12 @@
TRACE("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (!pSource)
{
twRC = TWRC_FAILURE;
Index: dlls/twain/dsm_ctrl.c
===================================================================
RCS file: /home/cvs/wine/dlls/twain/dsm_ctrl.c,v
retrieving revision 1.6
diff -u -r1.6 dsm_ctrl.c
--- dlls/twain/dsm_ctrl.c 22 Aug 2003 05:05:56 -0000 1.6
+++ dlls/twain/dsm_ctrl.c 13 Oct 2003 19:53:07 -0000
@@ -46,6 +46,12 @@
TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
for (currentDS = activeSources; currentDS; currentDS = currentDS->next)
{
if (currentDS->identity.Id == pIdentity->Id)
@@ -95,6 +101,12 @@
TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (!device_list)
{
if ((sane_get_devices (&device_list, SANE_FALSE) != SANE_STATUS_GOOD))
@@ -141,6 +153,12 @@
TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
status = sane_get_devices (&device_list, SANE_FALSE);
if (status == SANE_STATUS_GOOD)
{
@@ -185,6 +203,12 @@
TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (device_list && device_list[DSM_currentDevice])
{
pSourceIdentity->Id = DSM_sourceId ++;
@@ -222,6 +246,12 @@
TRACE("DG_CONTROL/DAT_IDENTITY/MSG_OPENDS\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (DSM_currentState != 3)
{
DSM_twCC = TWCC_SEQERROR;
@@ -299,6 +329,12 @@
TRACE("DG_CONTROL/DAT_IDENTITY/MSG_USERSELECT\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
/* FIXME: we should replace xscanimage with our own User Select UI */
system("xscanimage");
@@ -318,6 +354,12 @@
TRACE("DG_CONTROL/DAT_PARENT/MSG_CLOSEDSM\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (DSM_currentState == 3)
{
sane_exit ();
@@ -359,6 +401,12 @@
TRACE("DG_CONTROL/DAT_PARENT/MSG_OPENDSM\n");
+ if( !TWAIN32_sane_loaded )
+ {
+ DSM_twCC = TWCC_NODS;
+ return TWRC_FAILURE;
+ }
+
if (DSM_currentState == 2)
{
if (!DSM_initialized)
Index: dlls/twain/twain32_main.c
===================================================================
RCS file: /home/cvs/wine/dlls/twain/twain32_main.c,v
retrieving revision 1.6
diff -u -r1.6 twain32_main.c
--- dlls/twain/twain32_main.c 22 Aug 2003 05:05:56 -0000 1.6
+++ dlls/twain/twain32_main.c 13 Oct 2003 19:53:07 -0000
@@ -20,14 +20,93 @@
#include <stdarg.h>
+#include "config.h"
+
+#define TWAIN32_NO_REDEFINE
+
#include "windef.h"
#include "winbase.h"
#include "twain.h"
#include "twain_i.h"
#include "wine/debug.h"
+#include "wine/library.h"
+#include "wine/port.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(twain);
+BOOL TWAIN32_sane_loaded = FALSE;
+
+#ifdef HAVE_SANE
+
+static void *sane_handle = NULL;
+
+#define d(f) typeof(f) * p##f;
+
+d(sane_cancel)
+d(sane_init)
+d(sane_exit)
+d(sane_open)
+d(sane_get_devices)
+d(sane_strstatus)
+d(sane_get_parameters)
+d(sane_close)
+d(sane_read)
+d(sane_start)
+
+#undef d
+
+static BOOL load_sane(void)
+{
+ char *sane_name = SONAME_LIBSANE;
+
+ sane_handle = wine_dlopen(sane_name, RTLD_NOW, NULL, 0);
+ if (!sane_handle) {
+ WARN("Wine cannot find the SANE scanner library (%s).\n",sane_name);
+ return FALSE;
+ }
+
+#define d(f) \
+ if((p##f = wine_dlsym(sane_handle, #f, NULL, 0)) == NULL) \
+ { \
+ WARN("Can't find symbol %s\n", #f); \
+ goto sym_not_found; \
+ }
+
+ d(sane_cancel)
+ d(sane_init)
+ d(sane_exit)
+ d(sane_open)
+ d(sane_get_devices)
+ d(sane_strstatus)
+ d(sane_get_parameters)
+ d(sane_close)
+ d(sane_read)
+ d(sane_start)
+
+#undef d
+
+ return TRUE;
+
+sym_not_found:
+ WARN("Wine cannot find certain functions that it needs inside the SANE\n"
+ "scanner library. To enable Wine to use SANE please upgrade\n"
+ "your SANE libraries\n");
+ wine_dlclose(sane_handle, NULL, 0);
+ sane_handle = NULL;
+ return FALSE;
+}
+
+#else
+
+static BOOL load_sane(void)
+{
+ return FALSE;
+}
+
+#endif
+
+
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
@@ -35,6 +114,7 @@
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
+ TWAIN32_sane_loaded = load_sane();
DisableThreadLibraryCalls(hinstDLL);
DSM_currentState = 2;
break;
Index: dlls/twain/twain_i.h
===================================================================
RCS file: /home/cvs/wine/dlls/twain/twain_i.h,v
retrieving revision 1.4
diff -u -r1.4 twain_i.h
--- dlls/twain/twain_i.h 5 Sep 2003 23:08:30 -0000 1.4
+++ dlls/twain/twain_i.h 13 Oct 2003 20:40:33 -0000
@@ -239,4 +241,36 @@
TW_UINT16 TWAIN_ICAPXferMech
(activeDS *pSource, pTW_CAPABILITY pCapability, TW_UINT16 action);
+#ifdef HAVE_SANE
+#ifndef TWAIN32_NO_REDEFINE
+
+#define d(f) extern typeof(f) * p##f;
+d(sane_cancel)
+d(sane_init)
+d(sane_exit)
+d(sane_open)
+d(sane_get_devices)
+d(sane_strstatus)
+d(sane_get_parameters)
+d(sane_close)
+d(sane_read)
+d(sane_start)
+#undef d
+
+#define sane_cancel psane_cancel
+#define sane_init psane_init
+#define sane_exit psane_exit
+#define sane_open psane_open
+#define sane_get_devices psane_get_devices
+#define sane_strstatus psane_strstatus
+#define sane_get_parameters psane_get_parameters
+#define sane_close psane_close
+#define sane_read psane_read
+#define sane_start psane_start
+
+#endif
+#endif
+
+extern BOOL TWAIN32_sane_loaded;
+
#endif
Index: include/config.h.in
===================================================================
RCS file: /home/cvs/wine/include/config.h.in,v
retrieving revision 1.167
diff -u -r1.167 config.h.in
--- include/config.h.in 15 Oct 2003 03:28:04 -0000 1.167
+++ include/config.h.in 15 Oct 2003 09:58:18 -0000
@@ -812,6 +812,9 @@
/* Define to the soname of the libXrender library. */
#undef SONAME_LIBXRENDER
+/* Define to the soname of the libsane library. */
+#undef SONAME_LIBSANE
+
/* 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.
More information about the wine-patches
mailing list