1 diff -ru sane-pre1.01-4/ChangeLog sane-pre1.01-4-pere/ChangeLog
2 --- sane-pre1.01-4/ChangeLog Sun Apr 4 01:17:20 1999
3 +++ sane-pre1.01-4-pere/ChangeLog Fri Apr 9 14:25:28 1999
5 +1999-04-08 Petter Reinholdtsen <pere@td.org.uit.no>
6 + * include/sane/config.h.in include/sane/sane.h backend/dll.c
7 + backend/net.c: Added initial Win32 patches. Win32 dll support
10 1999-04-03 David Mosberger-Tang <David.Mosberger@acm.org>
12 * include/sane/sanei_debug.h: Define sanei_debug_BACKEND_NAME only
13 diff -ru sane-pre1.01-4/backend/dll.c sane-pre1.01-4-pere/backend/dll.c
14 --- sane-pre1.01-4/backend/dll.c Sun Feb 28 00:51:37 1999
15 +++ sane-pre1.01-4-pere/backend/dll.c Fri Apr 9 01:20:39 1999
20 +#ifdef HAVE_WINDOWS_H
21 +# include <windows.h>
24 #if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
31 +# define DLL_PATH_ENV "LIBPATH"
33 +# define DLL_PATH_ENV "LD_LIBRARY_PATH"
35 +# define DLL_PATH_SEPARATOR ":"
36 +# define DLL_SLASH "/"
37 +# define DLL_NAME "libsane-%s.so." STRINGIFY(V_MAJOR)
41 +#elif defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
42 /* HP/UX DLL support */
43 -#if defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
45 +# define DLL_PATH_ENV "SHLIB_PATH"
46 +# define DLL_PATH_SEPARATOR ":"
47 +# define DLL_SLASH "/"
48 +# define DLL_NAME "libsane-%s.sl." STRINGIFY(V_MAJOR)
50 +#elif defined(HAVE_LOADLIBRARY)
52 +# define DLL_PATH_ENV "PATH"
53 +# define DLL_PATH_SEPARATOR ";"
54 +# define DLL_SLASH "\\"
55 +# define DLL_NAME "sane%s.dll"
60 load (struct backend *be)
64 char *funcname, *src, *dir, *path = 0;
65 char libname[PATH_MAX];
69 -#if defined(HAVE_DLOPEN)
70 -# define PREFIX "libsane-"
71 -# define POSTFIX ".so.%u"
72 - mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
73 -#elif defined(HAVE_SHL_LOAD)
74 -# define PREFIX "libsane-"
75 -# define POSTFIX ".sl.%u"
76 - mode = BIND_DEFERRED;
78 -# error "Tried to compile unsupported DLL."
79 -#endif /* HAVE_DLOPEN */
81 DBG(1, "loading backend %s\n", be->name);
83 /* initialize all ops to "unsupported" so we can "use" the backend
85 dir = STRINGIFY(LIBDIR);
88 - snprintf (libname, sizeof (libname), "%s/"PREFIX"%s"POSTFIX,
89 - dir, be->name, V_MAJOR);
90 + snprintf (libname, sizeof (libname), "%s" DLL_SLASH DLL_NAME,
92 fp = fopen (libname, "r");
98 - path = getenv ("LD_LIBRARY_PATH");
101 - path = getenv ("SHLIB_PATH"); /* for HP-UX */
103 - path = getenv ("LIBPATH"); /* for AIX */
105 + path = getenv (DLL_PATH_ENV);
109 path = strdup (path);
112 - dir = strsep (&src, ":");
113 + dir = strsep (&src, DLL_PATH_SEPARATOR);
118 DBG(2, "dlopen()ing `%s'\n", libname);
121 - be->handle = dlopen (libname, mode);
122 + be->handle = dlopen (libname, getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY);
123 #elif defined(HAVE_SHL_LOAD)
124 - be->handle = (shl_t)shl_load (libname, mode, 0L);
125 + be->handle = (shl_t)shl_load (libname, BIND_DEFERRED, 0L);
126 +#elif defined(HAVE_LOADLIBRARY)
127 + be->handle = LoadLibrary(libname);
129 # error "Tried to compile unsupported DLL."
130 #endif /* HAVE_DLOPEN */
132 op = (void *(*)()) dlsym (be->handle, funcname + 1);
133 #elif defined(HAVE_SHL_LOAD)
134 shl_findsym ((shl_t*)&(be->handle), funcname + 1, TYPE_UNDEFINED, &op);
135 +#elif defined(HAVE_LOADLIBRARY)
136 + op = GetProcAddress(be->handle, funcname + 1);
138 # error "Tried to compile unsupported DLL."
139 #endif /* HAVE_DLOPEN */
141 op = (void *(*)()) dlsym (be->handle, funcname);
142 #elif defined(HAVE_SHL_LOAD)
143 shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
144 +#elif defined(HAVE_LOADLIBRARY)
145 + op = GetProcAddress(be->handle, funcname);
147 # error "Tried to compile unsupported DLL."
148 #endif /* HAVE_DLOPEN */
151 return SANE_STATUS_GOOD;
156 DBG(1, "load: ignoring attempt to load `%s'; compiled without dl support\n",
159 return SANE_STATUS_GOOD;
163 +DLLEXPORT SANE_Status DLLCALL
164 sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
166 char backend_name[PATH_MAX];
168 return SANE_STATUS_GOOD;
172 +DLLEXPORT void DLLCALL
175 struct backend *be, *next;
176 @@ -441,15 +446,18 @@
177 (*be->op[OP_EXIT]) ();
182 - dlclose (be->handle);
185 + dlclose (be->handle);
186 #elif defined(HAVE_SHL_LOAD)
188 - shl_unload(be->handle);
189 + shl_unload(be->handle);
190 +#elif defined(HAVE_LOADLIBRARY)
191 + FreeLibrary(be->handle);
193 # error "Tried to compile unsupported DLL."
194 #endif /* HAVE_DLOPEN */
197 #endif /* HAVE_DLL */
200 (assuming you know the name of the backend/device). This is
201 appropriate for the command-line interface of SANE, for example.
204 +DLLEXPORT SANE_Status DLLCALL
205 sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
207 static int devlist_size = 0, devlist_len = 0;
209 return SANE_STATUS_GOOD;
213 +DLLEXPORT SANE_Status DLLCALL
214 sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
216 const char *be_name, *dev_name;
218 return SANE_STATUS_GOOD;
222 +DLLEXPORT void DLLCALL
223 sane_close (SANE_Handle handle)
225 struct meta_scanner *s = handle;
230 -const SANE_Option_Descriptor *
231 +DLLEXPORT const SANE_Option_Descriptor * DLLCALL
232 sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
234 struct meta_scanner *s = handle;
236 return (*s->be->op[OP_GET_OPTION_DESC]) (s->handle, option);
240 +DLLEXPORT SANE_Status DLLCALL
241 sane_control_option (SANE_Handle handle, SANE_Int option,
242 SANE_Action action, void *value, SANE_Word * info)
249 +DLLEXPORT SANE_Status DLLCALL
250 sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
252 struct meta_scanner *s = handle;
254 return (long) (*s->be->op[OP_GET_PARAMS]) (s->handle, params);
258 +DLLEXPORT SANE_Status DLLCALL
259 sane_start (SANE_Handle handle)
261 struct meta_scanner *s = handle;
263 return (long) (*s->be->op[OP_START]) (s->handle);
267 +DLLEXPORT SANE_Status DLLCALL
268 sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
272 return (long) (*s->be->op[OP_READ]) (s->handle, data, max_length, length);
276 +DLLEXPORT void DLLCALL
277 sane_cancel (SANE_Handle handle)
279 struct meta_scanner *s = handle;
281 (*s->be->op[OP_CANCEL]) (s->handle);
285 +DLLEXPORT SANE_Status DLLCALL
286 sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
288 struct meta_scanner *s = handle;
290 return (long) (*s->be->op[OP_SET_IO_MODE]) (s->handle, non_blocking);
294 +DLLEXPORT SANE_Status DLLCALL
295 sane_get_select_fd (SANE_Handle handle, SANE_Int * fd)
297 struct meta_scanner *s = handle;
298 diff -ru sane-pre1.01-4/backend/net.c sane-pre1.01-4-pere/backend/net.c
299 --- sane-pre1.01-4/backend/net.c Sat Apr 3 06:43:01 1999
300 +++ sane-pre1.01-4-pere/backend/net.c Fri Apr 9 13:02:41 1999
302 #include <netinet/in.h>
303 #include <netdb.h> /* OS/2 needs this _after_ <netinet/in.h>, grrr... */
305 +#ifdef HAVE_WINDOWS_H
307 +# include <windows.h>
309 +# include <winsock.h>
310 +# include <malloc.h>
311 +# define NETREAD recv
312 +# define NETWRITE send
313 +# define NETCLOSE closesocket
314 +# warning "Username is hardcoded!"
315 +# define USERNAME "hardcoded"
316 +# define SOCKET_OK(s) (s != INVALID_SOCKET)
318 +# define NETREAD read
319 +# define NETWRITE write
320 +# define NETCLOSE close
321 +# define USERNAME getlogin()
322 +# define SOCKET_OK(s) (s >= 0)
325 #include <sane/sane.h>
326 #include <sane/sanei.h>
327 #include <sane/sanei_net.h>
331 dev->ctl = socket (dev->addr.sa_family, SOCK_STREAM, 0);
333 + if (!SOCKET_OK(dev->ctl))
335 DBG(1, "connect_dev: failed to obtain socket (%s)\n", strerror (errno));
337 @@ -188,13 +208,13 @@
339 sanei_w_init (&dev->wire, sanei_codec_bin_init);
340 dev->wire.io.fd = dev->ctl;
341 - dev->wire.io.read = read;
342 - dev->wire.io.write = write;
343 + dev->wire.io.read = NETREAD;
344 + dev->wire.io.write = NETWRITE;
346 /* exchange version codes with the server: */
347 req.version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR,
348 SANEI_NET_PROTOCOL_VERSION);
349 - req.username = getlogin ();
350 + req.username = USERNAME;
351 sanei_w_call (&dev->wire, SANE_NET_INIT,
352 (WireCodecFunc) sanei_w_init_req, &req,
353 (WireCodecFunc) sanei_w_init_reply, &reply);
355 return SANE_STATUS_GOOD;
359 + NETCLOSE (dev->ctl);
361 return SANE_STATUS_IO_ERROR;
364 s->hw->auth_active = 0;
368 + NETCLOSE (s->data);
371 return SANE_STATUS_CANCELLED;
377 +DLLEXPORT SANE_Status DLLCALL
378 sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
380 char device_name[PATH_MAX];
390 + mVer = MAKEWORD(1,1);
391 + if (0 != WSAStartup(wVer, &wsadata))
393 + DBG(1, "WSAStartup(1.1, ptr) failed.");
394 + return SANE_STATUS_UNSUPPORTED; /* XXX check this error value */
397 + /* Check WINSOCK.DLL version */
398 + if (1 != LOBYTE(wsadata.mVersion) || 1 != HIBYTE(wsadata.mVersion))
400 + DBG(1, "WINSOCK.DLL does not support v1.1.");
401 + return SANE_STATUS_UNSUPPORTED; /* XXX check this error value */
406 auth_callback = authorize;
410 saned_port = htons (6566);
412 "init: could not find `sane' service (%s); using default port %d\n",
413 - strerror (errno), htons (saned_port));
414 + strerror (errno), htons ((unsigned short)saned_port));
417 fp = sanei_config_open (NET_CONFIG_FILE);
419 return SANE_STATUS_GOOD;
423 +DLLEXPORT void DLLCALL
426 Net_Scanner *handle, *next_handle;
427 @@ -382,10 +423,19 @@
428 sanei_w_call (&dev->wire, SANE_NET_EXIT,
429 (WireCodecFunc) sanei_w_void, 0,
430 (WireCodecFunc) sanei_w_void, 0);
432 + NETCLOSE (dev->ctl);
437 + /* Release Windows socket DLL */
438 + if (SOCKET_ERROR == WSACleanup())
439 + if (WSAEINPROGRESS == WSAGetLastError())
441 + WSACancelBlockingCall();
447 /* Note that a call to get_devices() implies that we'll have to
449 backend/device). This is appropriate for the command-line
450 interface of SANE, for example.
453 +DLLEXPORT SANE_Status DLLCALL
454 sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
456 static int devlist_size = 0, devlist_len = 0;
458 return SANE_STATUS_GOOD;
462 +DLLEXPORT SANE_Status DLLCALL
463 sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
465 SANE_Open_Reply reply;
467 return SANE_STATUS_GOOD;
471 +DLLEXPORT void DLLCALL
472 sane_close (SANE_Handle handle)
474 Net_Scanner *prev, *s;
475 @@ -636,11 +686,11 @@
476 (WireCodecFunc) sanei_w_word, &s->handle,
477 (WireCodecFunc) sanei_w_word, &ack);
480 + NETCLOSE (s->data);
484 -const SANE_Option_Descriptor *
485 +DLLEXPORT const SANE_Option_Descriptor * DLLCALL
486 sane_get_option_descriptor (SANE_Handle handle, SANE_Int option)
488 Net_Scanner *s = handle;
490 return s->opt.desc[option];
494 +DLLEXPORT SANE_Status DLLCALL
495 sane_control_option (SANE_Handle handle, SANE_Int option,
496 SANE_Action action, void *value, SANE_Word * info)
503 +DLLEXPORT SANE_Status DLLCALL
504 sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
506 Net_Scanner *s = handle;
512 +DLLEXPORT SANE_Status DLLCALL
513 sane_start (SANE_Handle handle)
515 Net_Scanner *s = handle;
519 fd = socket (s->hw->addr.sa_family, SOCK_STREAM, 0);
521 + if (!SOCKET_OK(fd))
523 DBG(1, "start: socket() failed (%s)\n", strerror (errno));
524 return SANE_STATUS_IO_ERROR;
527 if (status != SANE_STATUS_GOOD)
535 if (connect (fd, (struct sockaddr *) &sin, len) < 0)
537 DBG(1, "start: connect() failed (%s)\n", strerror (errno));
540 return SANE_STATUS_IO_ERROR;
548 +DLLEXPORT SANE_Status DLLCALL
549 sane_read (SANE_Handle handle, SANE_Byte * data, SANE_Int max_length,
554 /* boy, is this painful or what? */
556 - nread = read (s->data, s->reclen_buf + s->reclen_buf_offset,
557 + nread = NETREAD (s->data, s->reclen_buf + s->reclen_buf_offset,
558 4 - s->reclen_buf_offset);
562 fcntl (s->data, F_SETFL, 0);
564 /* read the status byte: */
565 - if (read (s->data, &ch, sizeof (ch)) != 1)
566 + if (NETREAD (s->data, &ch, sizeof (ch)) != 1)
567 ch = SANE_STATUS_IO_ERROR;
569 return (SANE_Status) ch;
571 if (max_length > s->bytes_remaining)
572 max_length = s->bytes_remaining;
574 - nread = read (s->data, data, max_length);
575 + nread = NETREAD (s->data, data, max_length);
580 return SANE_STATUS_GOOD;
584 +DLLEXPORT void DLLCALL
585 sane_cancel (SANE_Handle handle)
587 Net_Scanner *s = handle;
593 +DLLEXPORT SANE_Status DLLCALL
594 sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
596 Net_Scanner *s = handle;
598 return SANE_STATUS_GOOD;
602 +DLLEXPORT SANE_Status DLLCALL
603 sane_get_select_fd (SANE_Handle handle, SANE_Int *fd)
605 Net_Scanner *s = handle;
606 diff -ru sane-pre1.01-4/include/sane/config.h.in sane-pre1.01-4-pere/include/sane/config.h.in
607 --- sane-pre1.01-4/include/sane/config.h.in Tue Mar 9 06:50:03 1999
608 +++ sane-pre1.01-4-pere/include/sane/config.h.in Fri Apr 9 01:02:29 1999
610 # define __EXTENSIONS__
614 +# define HAVE_WINDOWS_H
615 +# define HAVE_LOADLIBRARY
618 #endif /* SANE_CONFIG_H */
619 diff -ru sane-pre1.01-4/include/sane/sane.h sane-pre1.01-4-pere/include/sane/sane.h
620 --- sane-pre1.01-4/include/sane/sane.h Sun Feb 28 00:54:08 1999
621 +++ sane-pre1.01-4-pere/include/sane/sane.h Fri Apr 9 00:37:53 1999
626 +#if defined(_WINDOWS)
627 +# define DLLEXPORT __declspec( dllexport )
628 +# define DLLCALL __cdecl
634 typedef unsigned char SANE_Byte;
635 typedef int SANE_Word;
636 typedef SANE_Word SANE_Bool;
637 @@ -185,29 +193,29 @@
638 SANE_Char username[SANE_MAX_USERNAME_LEN],
639 SANE_Char password[SANE_MAX_PASSWORD_LEN]);
641 -extern SANE_Status sane_init (SANE_Int * version_code,
642 +extern DLLEXPORT SANE_Status DLLCALL sane_init (SANE_Int * version_code,
643 SANE_Auth_Callback authorize);
644 -extern void sane_exit (void);
645 -extern SANE_Status sane_get_devices (const SANE_Device *** device_list,
646 +extern DLLEXPORT void DLLCALL sane_exit (void);
647 +extern DLLEXPORT SANE_Status DLLCALL sane_get_devices (const SANE_Device *** device_list,
648 SANE_Bool local_only);
649 -extern SANE_Status sane_open (SANE_String_Const devicename,
650 +extern DLLEXPORT SANE_Status DLLCALL sane_open (SANE_String_Const devicename,
651 SANE_Handle * handle);
652 -extern void sane_close (SANE_Handle handle);
653 -extern const SANE_Option_Descriptor *
654 - sane_get_option_descriptor (SANE_Handle handle, SANE_Int option);
655 -extern SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option,
656 +extern DLLEXPORT void DLLCALL sane_close (SANE_Handle handle);
657 +extern DLLEXPORT const SANE_Option_Descriptor *
658 + DLLCALL sane_get_option_descriptor (SANE_Handle handle, SANE_Int option);
659 +extern DLLEXPORT SANE_Status DLLCALL sane_control_option (SANE_Handle handle, SANE_Int option,
660 SANE_Action action, void *value,
662 -extern SANE_Status sane_get_parameters (SANE_Handle handle,
663 +extern DLLEXPORT SANE_Status DLLCALL sane_get_parameters (SANE_Handle handle,
664 SANE_Parameters * params);
665 -extern SANE_Status sane_start (SANE_Handle handle);
666 -extern SANE_Status sane_read (SANE_Handle handle, SANE_Byte * data,
667 +extern DLLEXPORT SANE_Status DLLCALL sane_start (SANE_Handle handle);
668 +extern DLLEXPORT SANE_Status DLLCALL sane_read (SANE_Handle handle, SANE_Byte * data,
669 SANE_Int max_length, SANE_Int * length);
670 -extern void sane_cancel (SANE_Handle handle);
671 -extern SANE_Status sane_set_io_mode (SANE_Handle handle,
672 +extern DLLEXPORT void DLLCALL sane_cancel (SANE_Handle handle);
673 +extern DLLEXPORT SANE_Status DLLCALL sane_set_io_mode (SANE_Handle handle,
674 SANE_Bool non_blocking);
675 -extern SANE_Status sane_get_select_fd (SANE_Handle handle,
676 +extern DLLEXPORT SANE_Status DLLCALL sane_get_select_fd (SANE_Handle handle,
678 -extern SANE_String_Const sane_strstatus (SANE_Status status);
679 +extern DLLEXPORT SANE_String_Const DLLCALL sane_strstatus (SANE_Status status);