[TWAIN] Reconcile sane's long names to TWAIN's 32 byte limit

Robert Shearman rob at codeweavers.com
Mon Feb 13 10:44:21 CST 2006


Robert Shearman wrote:

> Jeremy White wrote:
>
>> libsane can return arbitrarily long names, but TWAIN supports only a 
>> maximum of 32.
>> Further, the name is a unique identifier, and so must be returned to 
>> libsane for processing.
>>
>> This algorithm tries to convert a long libsane name into a more 
>> reasonable short name,
>> but adds a crude signature process in an attempt to ensure a unique 
>> short identifier.
>>
>>  
>>
>> ------------------------------------------------------------------------
>>
>>
>> dlls/twain/dsm_ctrl.c |   85 
>> ++++++++++++++++++++++++++++++++++++++++++-------
>> 1 files changed, 73 insertions(+), 12 deletions(-)
>>
>> eabadf1c3584adda1a36b199f82bc6bbb17b71da
>> diff --git a/dlls/twain/dsm_ctrl.c b/dlls/twain/dsm_ctrl.c
>> index f744939..6d1318d 100644
>> --- a/dlls/twain/dsm_ctrl.c
>> +++ b/dlls/twain/dsm_ctrl.c
>> @@ -22,6 +22,7 @@
>>
>> #include <stdlib.h>
>> #include <stdarg.h>
>> +#include <stdio.h>
>>
>> #define NONAMELESSUNION
>> #define NONAMELESSSTRUCT
>> @@ -33,6 +34,14 @@
>>
>> WINE_DEFAULT_DEBUG_CHANNEL(twain);
>>
>> +inline static LPSTR TWAIN_strdup( LPCSTR str )
>> +{
>> +    LPSTR ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 );
>> +    if (ret) strcpy( ret, str );
>> +    return ret;
>> +}
>> +
>> +
>> /* DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS */
>> TW_UINT16 TWAIN_CloseDS (pTW_IDENTITY pOrigin, TW_MEMREF pData)
>> {
>> @@ -83,6 +92,38 @@ TW_UINT16 TWAIN_CloseDS (pTW_IDENTITY pO
>> #endif
>> }
>>
>> +/* Sane returns device names that are longer than the 32 bytes allowed
>> +   by TWAIN.  However, it colon separates them, and the last bit is
>> +   the most interesting.  So we use the last bit, and add a signature
>> +   to ensure uniqueness */
>> +static char * get_sane_short_name(const char *in)
>> +{
>> +    char *p;
>> +    LPSTR ret;
>> +    int  signature = 0;
>> +
>> +    if (strlen(in) <= 32)
>> +        return TWAIN_strdup((char *) in);
>> +
>> +    for (p = (char *) in; *p; p++)
>> +        signature += *p;
>>  
>>
>
> These casts from const char * to char * shouldn't be necessary.
>

See attached patch.

-- 
Rob Shearman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dsm_ctrl.diff
Type: text/x-patch
Size: 7217 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20060213/97437958/dsm_ctrl.diff


More information about the wine-devel mailing list