From 3a628f4375aa97bc91dbf32c6eec2d358ebaa83c Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 6 Apr 2013 11:43:57 -0700 Subject: [PATCH] load new-format dict into linux client, display default faces correctly, and search using alternate as well as default faces. Next: support for alternate specials. --- xwords4/common/dictiter.c | 36 ++++++++++++++++++++++-------------- xwords4/common/dictnry.c | 25 +++++++++++++++++++++++++ xwords4/common/dictnry.h | 7 +++++-- xwords4/linux/linuxdict.c | 18 +++++++++++++----- xwords4/linux/linuxmain.c | 2 +- 5 files changed, 66 insertions(+), 22 deletions(-) diff --git a/xwords4/common/dictiter.c b/xwords4/common/dictiter.c index fa0598abc..6cbc5f3e9 100644 --- a/xwords4/common/dictiter.c +++ b/xwords4/common/dictiter.c @@ -206,21 +206,29 @@ findStartsWithChars( DictIter* iter, const XP_UCHAR* chars, XP_U16 charsOffset, } else { const DictionaryCtxt* dict = iter->dict; XP_U16 nodeSize = dict->nodeSize; - for ( ; ; ) { + for ( ; ; ) { /* for all the tiles */ Tile tile = EDGETILE( dict, edge ); - const XP_UCHAR* facep = dict_getTileString( dict, tile ); - XP_U16 faceLen = XP_STRLEN( facep ); - if ( faceLen > charsLen ) { - faceLen = charsLen; - } - if ( 0 == XP_STRNCMP( facep, &chars[charsOffset], faceLen ) ) { - XP_S16 newOffset = findStartsWithChars( iter, chars, - charsOffset + faceLen, - dict_follow( dict, edge ), - nTilesUsed + 1 ); - if ( result < newOffset ) { - iter->edges[nTilesUsed] = edge; - result = newOffset; + const XP_UCHAR* facep = NULL; + for ( ; ; ) { /* for each string that tile can be */ + facep = dict_getNextTileString( dict, tile, facep ); + if ( NULL == facep ) { + break; + } + XP_U16 faceLen = XP_STRLEN( facep ); + if ( faceLen > charsLen ) { + faceLen = charsLen; + } + if ( 0 == XP_STRNCMP( facep, &chars[charsOffset], faceLen ) ) { + XP_S16 newOffset = + findStartsWithChars( iter, chars, + charsOffset + faceLen, + dict_follow( dict, edge ), + nTilesUsed + 1 ); + if ( result < newOffset ) { + iter->edges[nTilesUsed] = edge; + result = newOffset; + } + break; } } if ( IS_LAST_EDGE( dict, edge ) ) { diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index d4952ec2a..844918be7 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -100,6 +100,31 @@ dict_getTileString( const DictionaryCtxt* dict, Tile tile ) return facep; } +const XP_UCHAR* +dict_getNextTileString( const DictionaryCtxt* ctxt, Tile tile, + const XP_UCHAR* cur ) +{ + const XP_UCHAR* result = NULL; + if ( NULL == cur ) { + result = dict_getTileString( ctxt, tile ); + } else { + cur += XP_STRLEN( cur ) + 1; + /* use cur only if it is is not now off the end or pointing to to the + next tile */ + if ( ++tile == ctxt->nFaces ) { + if ( cur < ctxt->facesEnd ) { + result = cur; + } + } else { + const XP_UCHAR* nxt = dict_getTileStringRaw( ctxt, tile ); + if ( nxt != cur ) { + result = cur; + } + } + } + return result; +} + XP_U16 dict_numTiles( const DictionaryCtxt* dict, Tile tile ) { diff --git a/xwords4/common/dictnry.h b/xwords4/common/dictnry.h index 5eb04e6a5..065d544c8 100644 --- a/xwords4/common/dictnry.h +++ b/xwords4/common/dictnry.h @@ -72,10 +72,11 @@ struct DictionaryCtxt { necessarily the entry point for search!! */ XP_UCHAR* name; XP_UCHAR* langName; - XP_UCHAR* faces; + XP_UCHAR* faces; /* storage for faces */ + XP_UCHAR* facesEnd; XP_UCHAR* desc; XP_UCHAR* md5Sum; - const XP_UCHAR** facePtrs; + const XP_UCHAR** facePtrs; /* elems point into faces, above */ XP_U8* countsAndValues; SpecialBitmaps* bitmaps; @@ -150,6 +151,8 @@ XP_U16 dict_numTileFaces( const DictionaryCtxt* ctxt ); XP_U16 dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles, XP_U16 nTiles, XP_UCHAR* buf, XP_U16 bufSize ); const XP_UCHAR* dict_getTileString( const DictionaryCtxt* ctxt, Tile tile ); +const XP_UCHAR* dict_getNextTileString( const DictionaryCtxt* ctxt, Tile tile, + const XP_UCHAR* cur ); const XP_UCHAR* dict_getName( const DictionaryCtxt* ctxt ); const XP_UCHAR* dict_getLangName(const DictionaryCtxt* ctxt ); diff --git a/xwords4/linux/linuxdict.c b/xwords4/linux/linuxdict.c index 0c9987ec6..713c0e4ec 100644 --- a/xwords4/linux/linuxdict.c +++ b/xwords4/linux/linuxdict.c @@ -201,11 +201,18 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* utf8, for ( ii = 0; ii < nFaces; ++ii ) { ptrs[ii] = next; if ( isUTF8 ) { - gchar* cp = g_utf8_offset_to_pointer( bytes, 1 ); - XP_U16 len = cp - bytes; - XP_MEMCPY( next, bytes, len ); - next += len; - bytes += len; + for ( ; ; ) { + gchar* cp = g_utf8_offset_to_pointer( bytes, 1 ); + XP_U16 len = cp - bytes; + XP_MEMCPY( next, bytes, len ); + next += len; + bytes += len; + if ( ' ' != bytes[0] ) { + break; + } + ++bytes; /* skip delimiter */ + *next++ = '\0'; + } } else { XP_ASSERT( 0 == *bytes ); ++bytes; /* skip empty */ @@ -216,6 +223,7 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* utf8, } XP_ASSERT( !dict->faces ); dict->faces = faces; + dict->facesEnd = faces + nFaces + nBytes; XP_ASSERT( !dict->facePtrs ); dict->facePtrs = ptrs; } /* dict_splitFaces */ diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 82b7d5c04..58f046310 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1377,7 +1377,7 @@ walk_dict_test( const LaunchParams* XP_UNUSED_DBG(params), XP_UCHAR bufPrev[32] = {0}; dict_wordToString( &iter, buf, VSIZE(buf) ); - XP_ASSERT( 0 == strncmp( buf, prefix, lenMatched ) ); + XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) ); DictPosition pos = dict_getPosition( &iter ); XP_ASSERT( 0 == strcmp( buf, words[pos] ) );