mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
add md5Sum field to dict struct, and on linux load it if present,
otherwise calculate it. In DEBUG builds always calculate and assert they match.
This commit is contained in:
parent
0b81516682
commit
5fa9b60846
2 changed files with 40 additions and 8 deletions
|
@ -74,6 +74,7 @@ struct DictionaryCtxt {
|
|||
XP_UCHAR* langName;
|
||||
XP_UCHAR* faces;
|
||||
XP_UCHAR* desc;
|
||||
XP_UCHAR* md5Sum;
|
||||
const XP_UCHAR** facePtrs;
|
||||
XP_U8* countsAndValues;
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ skipBitmap( LinuxDictionaryCtxt* XP_UNUSED_DBG(ctxt), const XP_U8** ptrp )
|
|||
|
||||
nCols = *ptr++;
|
||||
if ( nCols > 0 ) {
|
||||
nRows = *ptr++;
|
||||
nRows = *ptr++;
|
||||
|
||||
nBytes = ((nRows * nCols) + 7) / 8;
|
||||
|
||||
|
@ -116,8 +116,8 @@ skipBitmap( LinuxDictionaryCtxt* XP_UNUSED_DBG(ctxt), const XP_U8** ptrp )
|
|||
lbs->nCols = nCols;
|
||||
lbs->nBytes = nBytes;
|
||||
|
||||
memcpy( lbs + 1, ptr, nBytes );
|
||||
ptr += nBytes;
|
||||
memcpy( lbs + 1, ptr, nBytes );
|
||||
ptr += nBytes;
|
||||
}
|
||||
|
||||
*ptrp = ptr;
|
||||
|
@ -308,6 +308,17 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
|||
} else {
|
||||
XP_LOGF( "%s: no note", __func__ );
|
||||
}
|
||||
if ( 0 < headerLen ) {
|
||||
XP_U16 len = 1 + XP_STRLEN( (XP_UCHAR*)ptr );
|
||||
dctx->super.md5Sum = XP_MALLOC( dctx->super.mpool, len );
|
||||
XP_MEMCPY( dctx->super.md5Sum, ptr, len );
|
||||
XP_LOGF( "%s: got md5Sum of len %d: \"%s\"", __func__,
|
||||
headerLen-1, dctx->super.md5Sum );
|
||||
ptr += len;
|
||||
headerLen -= len;
|
||||
} else {
|
||||
XP_LOGF( "%s: no md5Sum", __func__ );
|
||||
}
|
||||
ptr += headerLen;
|
||||
}
|
||||
|
||||
|
@ -319,6 +330,25 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
|
|||
numFaceBytes = numFaces * charSize;
|
||||
}
|
||||
|
||||
if ( NULL == dctx->super.md5Sum
|
||||
#ifdef DEBUG
|
||||
|| XP_TRUE
|
||||
#endif
|
||||
) {
|
||||
XP_U32 curPos = ptr - dctx->dictBase;
|
||||
gssize dictLength = dctx->dictLength - curPos;
|
||||
GChecksum* cksum = g_checksum_new( G_CHECKSUM_MD5 );
|
||||
g_checksum_update( cksum, ptr, dictLength );
|
||||
const gchar* sum = g_checksum_get_string( cksum );
|
||||
XP_LOGF( "calculated sum on %d bytes: %s", dictLength, sum );
|
||||
if ( NULL == dctx->super.md5Sum ) {
|
||||
dctx->super.md5Sum = copyString( dctx->super.mpool, sum );
|
||||
} else {
|
||||
XP_ASSERT( 0 == XP_STRCMP( dctx->super.md5Sum, sum ) );
|
||||
}
|
||||
g_checksum_free( cksum );
|
||||
}
|
||||
|
||||
dctx->super.nFaces = numFaces;
|
||||
|
||||
dctx->super.countsAndValues = XP_MALLOC( dctx->super.mpool,
|
||||
|
@ -427,14 +457,15 @@ linux_dictionary_destroy( DictionaryCtxt* dict )
|
|||
freeSpecials( ctxt );
|
||||
|
||||
if ( !!ctxt->dictBase ) {
|
||||
if ( ctxt->useMMap ) {
|
||||
(void)munmap( ctxt->dictBase, ctxt->dictLength );
|
||||
} else {
|
||||
XP_FREE( dict->mpool, ctxt->dictBase );
|
||||
}
|
||||
if ( ctxt->useMMap ) {
|
||||
(void)munmap( ctxt->dictBase, ctxt->dictLength );
|
||||
} else {
|
||||
XP_FREE( dict->mpool, ctxt->dictBase );
|
||||
}
|
||||
}
|
||||
|
||||
XP_FREEP( dict->mpool, &ctxt->super.desc );
|
||||
XP_FREEP( dict->mpool, &ctxt->super.md5Sum );
|
||||
XP_FREE( dict->mpool, ctxt->super.countsAndValues );
|
||||
XP_FREE( dict->mpool, ctxt->super.faces );
|
||||
XP_FREE( dict->mpool, ctxt->super.facePtrs );
|
||||
|
|
Loading…
Reference in a new issue