diff --git a/ChangeLog b/ChangeLog index aaaf36898..ee4c4f984 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-07-28 Thomas Soumarmon + * backend/hp5400_* : moved constant initialization to sane_init + and sane_exit + removed some compilation warnings. + 2003-07-27 Henning Meier-Geinitz * Makefile.in backend/Makefile.in doc/Makefile.in diff --git a/backend/hp5400_internal.c b/backend/hp5400_internal.c index 67b973ed8..bdd9e1656 100644 --- a/backend/hp5400_internal.c +++ b/backend/hp5400_internal.c @@ -89,22 +89,38 @@ typedef struct versionString { - const char strVersion[128]; + char strVersion[128]; } versionString; -versionString MatchVersions[] = { - { "SilitekIBlizd C3 ScannerV0.84" } , - { "SilitekIBlizd C3 ScannerV0.86" } , - { "SilitekIBlizd C3 ScannerV0.87" } - }; - const int numVersions = 3; +versionString *MatchVersions; static TScannerModel Model_HP54xx = { "Hewlett-Packard", "HP54xx Flatbed Scanner" }; +int +InitHp5400_internal() { + + MatchVersions = malloc( sizeof(versionString) * numVersions ); + strcpy( MatchVersions[0].strVersion, "SilitekIBlizd C3 ScannerV0.84"); + strcpy( MatchVersions[1].strVersion, "SilitekIBlizd C3 ScannerV0.86"); + strcpy( MatchVersions[2].strVersion, "SilitekIBlizd C3 ScannerV0.87"); + + return 1; +} + +int +FreeHp5400_internal() { + + free(MatchVersions); + MatchVersions = NULL; + + return 1; +} + + int WriteByte (int iHandle, int cmd, char data) { @@ -1223,7 +1239,7 @@ HP5400Open (THWParams * params, char *filename) i = 0; versionMatched = 0; while ( !versionMatched && (i < numVersions) ) { - if (!memcmp (szVersion + 1, MatchVersions[i] .strVersion, strlen(MatchVersions[i] .strVersion) - 4)) { + if (!strncmp (szVersion + 1, MatchVersions[i] .strVersion, strlen(MatchVersions[i] .strVersion) - 4)) { versionMatched = 1; } i++; diff --git a/backend/hp5400_internal.h b/backend/hp5400_internal.h index 1b2c66f20..63cacb3e7 100644 --- a/backend/hp5400_internal.h +++ b/backend/hp5400_internal.h @@ -226,6 +226,12 @@ HP5400Detect (char *filename, char *pszDeviceName)); +int +InitHp5400_internal( void ); + +int +FreeHp5400_internal( void ); + #ifdef STANDALONE int diff --git a/backend/hp5400_sane.c b/backend/hp5400_sane.c index 79c85d73e..ee439781a 100644 --- a/backend/hp5400_sane.c +++ b/backend/hp5400_sane.c @@ -60,6 +60,7 @@ #include "sane/sanei_config.h" #include "sane/saneopts.h" #include "sane/config.h" +#include "sane/sanei_usb.h" #include /* malloc, free */ #include /* memcpy */ @@ -179,10 +180,12 @@ TDevListEntry; /* Device filename for USB access */ -char * usb_devfile = "/dev/usb/scanner0"; +char usb_devfile[128]; static TDevListEntry *_pFirstSaneDev = 0; static int iNumSaneDev = 0; + + static const SANE_Device **_pSaneDevList = 0; /* option constraints */ @@ -463,6 +466,13 @@ sane_init (SANE_Int * piVersion, SANE_Auth_Callback pfnAuth) /* prevent compiler from complaing about unused parameters */ pfnAuth = pfnAuth; + strcpy(usb_devfile, "/dev/usb/scanner0"); + _pFirstSaneDev = 0; + iNumSaneDev = 0; + + InitHp5400_internal(); + + DBG_INIT (); HP5400_DBG (DBG_MSG, "sane_init: SANE hp5400 backend version %d.%d-%d (from %s)\n", @@ -542,6 +552,9 @@ sane_exit (void) free (_pSaneDevList); _pSaneDevList = 0; } + + + FreeHp5400_internal(); } @@ -919,7 +932,7 @@ sane_read (SANE_Handle h, SANE_Byte * buf, SANE_Int maxlen, SANE_Int * len) /* Note: this is already color corrected, though some work still needs to be done to deal with the colour offsetting */ TScanner *s; - char *buffer = buf; + char *buffer = (char*)buf; HP5400_DBG (DBG_MSG, "sane_read: request %d bytes \n", maxlen); diff --git a/backend/hp5400_sanei.c b/backend/hp5400_sanei.c index 550122968..ba572a8db 100644 --- a/backend/hp5400_sanei.c +++ b/backend/hp5400_sanei.c @@ -253,13 +253,13 @@ hp5400_command_write (int iHandle, int iCmd, int iLen, void *pbData) /* returns >0 if command OK */ int -hp5400_bulk_read (int iHandle, int len, int block, FILE * file) +hp5400_bulk_read (int iHandle, size_t len, int block, FILE * file) { - int fd; + SANE_Int fd; char x1 = 0x14, x2 = 0x24; short buf[4] = { 0, 0, 0, 0 }; - unsigned char *buffer; - int res = 0; + SANE_Byte *buffer; + size_t res = 0; buf[2] = block; @@ -297,8 +297,8 @@ int hp5400_bulk_read_block (int iHandle, int iCmd, void *cmd, int cmdlen, void *buffer, int len) { - int fd; - int res = 0; + SANE_Int fd; + size_t res = 0; if (iHandle < 0) { @@ -309,7 +309,7 @@ hp5400_bulk_read_block (int iHandle, int iCmd, void *cmd, int cmdlen, _UsbWriteControl (fd, iCmd, 0, cmd, cmdlen); res = len; - sanei_usb_read_bulk (fd, buffer, &res); + sanei_usb_read_bulk (fd, (SANE_Byte *) buffer, &res); HP5400_DBG (DBG_MSG, "Read block returned %d when reading %d\n", res, len); return res; } @@ -319,8 +319,8 @@ int hp5400_bulk_command_write (int iHandle, int iCmd, void *cmd, int cmdlen, int datalen, int block, char *data) { - int fd; - int res = 0, offset = 0; + SANE_Int fd; + size_t res = 0, offset = 0; if (iHandle < 0) { @@ -346,7 +346,7 @@ hp5400_bulk_command_write (int iHandle, int iCmd, void *cmd, int cmdlen, HP5400_DBG (DBG_MSG, "\n"); } res = (datalen < block) ? datalen : block; - sanei_usb_write_bulk (fd, data + offset, &res); + sanei_usb_write_bulk (fd, (SANE_Byte *) (data + offset), &res); HP5400_DBG (DBG_MSG, "Write returned %d, %d remain\n", res, datalen); datalen -= block; offset += block; diff --git a/backend/hp5400_sanei.h b/backend/hp5400_sanei.h index 2197e06b6..1e81d887a 100644 --- a/backend/hp5400_sanei.h +++ b/backend/hp5400_sanei.h @@ -86,7 +86,7 @@ int hp5400_command_read (int iHandle, int iCmd, int iLen, void *pbData); int hp5400_command_write (int iHandle, int iCmd, int iLen, void *pbData); /* returns >0 if command OK */ -int hp5400_bulk_read (int iHandle, int len, int block, FILE * file); +int hp5400_bulk_read (int iHandle, size_t len, int block, FILE * file); /* returns >0 if command OK */ int hp5400_bulk_read_block (int iHandle, int iCmd, void *cmd, int cmdlen, diff --git a/backend/hp5400_xfer.h b/backend/hp5400_xfer.h index d9fe12a3e..bb250ad4d 100644 --- a/backend/hp5400_xfer.h +++ b/backend/hp5400_xfer.h @@ -63,7 +63,7 @@ int hp5400_command_read_noverify (int iHandle, int iCmd, int iLen, int hp5400_command_write (int iHandle, int iCmd, int iLen, void *pbData); void hp5400_command_write_noverify (int fd, int iValue, void *pabData, int iSize); -int hp5400_bulk_read (int iHandle, int size, int block, FILE * file); +int hp5400_bulk_read (int iHandle, size_t size, int block, FILE * file); int hp5400_bulk_read_block (int iHandle, int iCmd, void *cmd, int cmdlen, void *buffer, int len); int hp5400_bulk_command_write (int iHandle, int iCmd, void *cmd, int cmdlen,