From 07cfdad699661a0a992401e245d667469f1ed6b9 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 9 Apr 2013 07:43:04 -0700 Subject: [PATCH] fix to support synonyms within specials too -- for linux only so far. Seems to work, though the dawg2dict.pl script is broken. --- xwords4/common/dawg.h | 2 ++ xwords4/common/dictnry.c | 26 ++++++++++----- xwords4/common/dictnry.h | 1 + xwords4/dawg/Catalan/Makefile.DISC2 | 6 ++-- xwords4/dawg/Catalan/info.txt | 52 ++++++++++++++--------------- xwords4/linux/linuxdict.c | 35 +++++++++++++------ xwords4/linux/linuxmain.c | 3 +- 7 files changed, 76 insertions(+), 49 deletions(-) diff --git a/xwords4/common/dawg.h b/xwords4/common/dawg.h index 8473ed5fc..9801f19e9 100644 --- a/xwords4/common/dawg.h +++ b/xwords4/common/dawg.h @@ -83,4 +83,6 @@ typedef struct Xloc_specialEntry { short hasSmall; } Xloc_specialEntry; +#define SYNONYM_DELIM ' ' + #endif /* _DAWG_H_ */ diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 844918be7..b9412521a 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -101,24 +101,32 @@ dict_getTileString( const DictionaryCtxt* dict, Tile tile ) } const XP_UCHAR* -dict_getNextTileString( const DictionaryCtxt* ctxt, Tile tile, +dict_getNextTileString( const DictionaryCtxt* dict, Tile tile, const XP_UCHAR* cur ) { const XP_UCHAR* result = NULL; if ( NULL == cur ) { - result = dict_getTileString( ctxt, tile ); + result = dict_getTileString( dict, 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 ) { + XP_Bool isSpecial = dict_faceIsBitmap( dict, tile ); + if ( isSpecial ) { + const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile ); + if ( cur < dict->charEnds[(XP_U16)*facep] ) { result = cur; } } else { - const XP_UCHAR* nxt = dict_getTileStringRaw( ctxt, tile ); - if ( nxt != cur ) { - result = cur; + /* use cur only if it is is not now off the end or pointing to to the + next tile */ + if ( ++tile == dict->nFaces ) { + if ( cur < dict->facesEnd ) { + result = cur; + } + } else { + const XP_UCHAR* nxt = dict_getTileStringRaw( dict, tile ); + if ( nxt != cur ) { + result = cur; + } } } } diff --git a/xwords4/common/dictnry.h b/xwords4/common/dictnry.h index 065d544c8..8f618f3a2 100644 --- a/xwords4/common/dictnry.h +++ b/xwords4/common/dictnry.h @@ -81,6 +81,7 @@ struct DictionaryCtxt { SpecialBitmaps* bitmaps; XP_UCHAR** chars; + XP_UCHAR** charEnds; XP_U32 nWords; XP_LangCode langCode; diff --git a/xwords4/dawg/Catalan/Makefile.DISC2 b/xwords4/dawg/Catalan/Makefile.DISC2 index a88fcfc2e..60b63e6c9 100644 --- a/xwords4/dawg/Catalan/Makefile.DISC2 +++ b/xwords4/dawg/Catalan/Makefile.DISC2 @@ -36,9 +36,9 @@ endif endif LANG_SPECIAL_INFO = \ - "L·L" $(PBITMS)/large_ll.pbitm $(PBITMS)/small_ll.pbitm \ - "NY" $(PBITMS)/large_ny.pbitm $(PBITMS)/small_ny.pbitm \ - "QU" $(PBITMS)/large_qu.pbitm $(PBITMS)/small_qu.pbitm \ + "L·L L-L ĿL l·l l-l ŀl" $(PBITMS)/large_ll.pbitm $(PBITMS)/small_ll.pbitm \ + "NY ny" $(PBITMS)/large_ny.pbitm $(PBITMS)/small_ny.pbitm \ + "QU qu" $(PBITMS)/large_qu.pbitm $(PBITMS)/small_qu.pbitm \ include ../Makefile.langcommon diff --git a/xwords4/dawg/Catalan/info.txt b/xwords4/dawg/Catalan/info.txt index 9954db826..271a8a097 100644 --- a/xwords4/dawg/Catalan/info.txt +++ b/xwords4/dawg/Catalan/info.txt @@ -63,32 +63,32 @@ XLOC_HEADER:0x8C00 2 0 {"_"} -12 1 'A' -2 3 'B' -3 2 'C' -1 10 'Ç' -3 2 'D' -13 1 'E' -1 4 'F' -2 3 'G' -1 8 'H' -8 1 'I' -1 8 'J' -4 1 'L' -1 10 {"L·L"} -3 2 'M' -6 1 'N' -1 10 {"NY"} -5 1 'O' -2 3 'P' -1 8 {"QU"} -8 1 'R' -8 1 'S' -5 1 'T' -4 1 'U' -1 4 'V' -1 10 'X' -1 8 'Z' +12 1 'A|a' +2 3 'B|b' +3 2 'C|c' +1 10 'Ç|ç' +3 2 'D|d' +13 1 'E|e' +1 4 'F|f' +2 3 'G|g' +1 8 'H|h' +8 1 'I|i' +1 8 'J|j' +4 1 'L|l' +1 10 {"L·L|L-L|ĿL|l·l|l-l|ŀl"} +3 2 'M|m' +6 1 'N|n' +1 10 {"ny|ny"} +5 1 'O|o' +2 3 'P|p' +1 8 {"QU|qu"} +8 1 'R|r' +8 1 'S|s' +5 1 'T|t' +4 1 'U|u' +1 4 'V|v' +1 10 'X|x' +1 8 'Z|z' # # NOTES: diff --git a/xwords4/linux/linuxdict.c b/xwords4/linux/linuxdict.c index 713c0e4ec..2f82ad4da 100644 --- a/xwords4/linux/linuxdict.c +++ b/xwords4/linux/linuxdict.c @@ -146,6 +146,7 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, const XP_U8** ptrp ) XP_U16 nSpecials; XP_UCHAR* text; XP_UCHAR** texts; + XP_UCHAR** textEnds; SpecialBitmaps* bitmaps; Tile tile; const XP_U8* ptr = *ptrp; @@ -154,6 +155,8 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, const XP_U8** ptrp ) texts = (XP_UCHAR**)XP_MALLOC( ctxt->super.mpool, nSpecials * sizeof(*texts) ); + textEnds = (XP_UCHAR**)XP_MALLOC( ctxt->super.mpool, + nSpecials * sizeof(*textEnds) ); bitmaps = (SpecialBitmaps*)XP_MALLOC( ctxt->super.mpool, nSpecials * sizeof(*bitmaps) ); XP_MEMSET( bitmaps, 0, nSpecials * sizeof(*bitmaps) ); @@ -167,23 +170,35 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, const XP_U8** ptrp ) XP_ASSERT( *facep < nSpecials ); /* get the string */ - txtlen = *ptr++; - text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1); - memcpy( text, ptr, txtlen ); - ptr += txtlen; + txtlen = *ptr++; + text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1); + memcpy( text, ptr, txtlen ); + ptr += txtlen; - text[txtlen] = '\0'; - texts[(XP_U16)*facep] = text; + text[txtlen] = '\0'; + texts[(XP_U16)*facep] = text; + textEnds[(XP_U16)*facep] = text + txtlen + 1; + + /* Now replace the delimiter char with \0. It must be one byte in + length and of course equal to the delimiter */ + while ( '\0' != *text ) { + XP_UCHAR* cp = g_utf8_offset_to_pointer( text, 1 ); + if ( 1 == (cp - text) && *text == SYNONYM_DELIM ) { + *text = '\0'; + } + text = cp; + } - XP_DEBUGF( "skipping bitmaps for " XP_S, texts[asIndex] ); + XP_DEBUGF( "skipping bitmaps for " XP_S, texts[asIndex] ); - bitmaps[asIndex].largeBM = skipBitmap( ctxt, &ptr ); - bitmaps[asIndex].smallBM = skipBitmap( ctxt, &ptr ); + bitmaps[asIndex].largeBM = skipBitmap( ctxt, &ptr ); + bitmaps[asIndex].smallBM = skipBitmap( ctxt, &ptr ); } } *ptrp = ptr; ctxt->super.chars = texts; + ctxt->super.charEnds = textEnds; ctxt->super.bitmaps = bitmaps; } /* skipBitmaps */ @@ -207,7 +222,7 @@ dict_splitFaces( DictionaryCtxt* dict, const XP_U8* utf8, XP_MEMCPY( next, bytes, len ); next += len; bytes += len; - if ( ' ' != bytes[0] ) { + if ( SYNONYM_DELIM != bytes[0] ) { break; } ++bytes; /* skip delimiter */ diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 58f046310..d4745ad9a 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -1377,7 +1377,8 @@ walk_dict_test( const LaunchParams* XP_UNUSED_DBG(params), XP_UCHAR bufPrev[32] = {0}; dict_wordToString( &iter, buf, VSIZE(buf) ); - XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) ); + /* This doesn't work with synonyms like "L-L" for "L·L" */ + // XP_ASSERT( 0 == strncasecmp( buf, prefix, lenMatched ) ); DictPosition pos = dict_getPosition( &iter ); XP_ASSERT( 0 == strcmp( buf, words[pos] ) );