diff --git a/common/dictnry.c b/common/dictnry.c index 68604c08c..6d7722ae3 100644 --- a/common/dictnry.c +++ b/common/dictnry.c @@ -80,14 +80,13 @@ dict_getTileValue( const DictionaryCtxt* dict, Tile tile ) return dict->countsAndValues[tile+1]; } /* dict_getTileValue */ -static const XP_UCHAR* -dict_getTileChar( const DictionaryCtxt* dict, Tile tile ) +const XP_UCHAR* +dict_getTileString( const DictionaryCtxt* ctxt, Tile tile ) { - XP_ASSERT( tile < dict->nFaces ); -/* XP_ASSERT( (dict->faces[tile] & 0xFF00) == 0 ); /\* no unicode yet *\/ */ - XP_U16 index = dict->faceIndices[tile]; - return &dict->faces[index]; -} /* dict_getTileValue */ + XP_ASSERT( tile < ctxt->nFaces ); + XP_U16 index = ctxt->faceIndices[tile]; + return &ctxt->faces[index]; +} XP_U16 dict_numTiles( const DictionaryCtxt* dict, Tile tile ) @@ -112,7 +111,7 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles, while ( nTiles-- ) { Tile tile = *tiles++; - const XP_UCHAR* facep = dict_getTileChar( ctxt, tile ); + const XP_UCHAR* facep = dict_getTileString( ctxt, tile ); if ( IS_SPECIAL(*facep) ) { XP_UCHAR* chars = ctxt->chars[(XP_U16)*facep]; @@ -142,12 +141,6 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles, return result; } /* dict_tilesToString */ -const XP_UCHAR* -dict_getTileString( const DictionaryCtxt* ctxt, Tile tile ) -{ - return dict_getTileChar( ctxt, tile ); -} - Tile dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key ) { @@ -156,7 +149,7 @@ dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key ) XP_Bool keyNotSpecial = XP_STRLEN(key) == 1; for ( tile = 0; tile < nFaces; ++tile ) { - const XP_UCHAR* facep = dict_getTileChar( dict, tile ); + const XP_UCHAR* facep = dict_getTileString( dict, tile ); if ( IS_SPECIAL(*facep) ) { XP_UCHAR* chars = dict->chars[(XP_U16)*facep]; if ( 0 == XP_STRNCMP( chars, key, XP_STRLEN(chars) ) ) { @@ -174,47 +167,47 @@ dict_tilesAreSame( const DictionaryCtxt* dict1, const DictionaryCtxt* dict2 ) { XP_Bool result = XP_FALSE; - Tile i; + Tile ii; XP_U16 nTileFaces = dict_numTileFaces( dict1 ); if ( nTileFaces == dict_numTileFaces( dict2 ) ) { - for ( i = 0; i < nTileFaces; ++i ) { + for ( ii = 0; ii < nTileFaces; ++ii ) { const XP_UCHAR* face1; const XP_UCHAR* face2; - if ( dict_getTileValue( dict1, i ) - != dict_getTileValue( dict2, i ) ){ + if ( dict_getTileValue( dict1, ii ) + != dict_getTileValue( dict2, ii ) ){ break; } -#if 1 - face1 = dict_getTileChar( dict1, i ); - face2 = dict_getTileChar( dict2, i ); - if ( face1 != face2 ) { +#if 0 + face1 = dict_getTileString( dict1, ii ); + face2 = dict_getTileString( dict2, ii ); + if ( 0 != XP_STRCMP( face1, face2 ) ) { break; } #else - face1 = dict_getTileChar( dict1, i ); - face2 = dict_getTileChar( dict2, i ); - if ( IS_SPECIAL(face1) != IS_SPECIAL(face2) ) { + face1 = dict_getTileString( dict1, ii ); + face2 = dict_getTileString( dict2, ii ); + if ( IS_SPECIAL(*face1) != IS_SPECIAL(*face2) ) { break; } - if ( IS_SPECIAL(face1) ) { - XP_UCHAR* chars1 = dict1->chars[face1]; - XP_UCHAR* chars2 = dict2->chars[face2]; + if ( IS_SPECIAL(*face1) ) { + XP_UCHAR* chars1 = dict1->chars[(int)*face1]; + XP_UCHAR* chars2 = dict2->chars[(int)*face2]; XP_U16 len = XP_STRLEN(chars1); if ( 0 != XP_STRNCMP( chars1, chars2, len ) ) { break; } - } else if ( face1 != face2 ) { + } else if ( 0 != XP_STRCMP( face1, face2 ) ) { break; } #endif - if ( dict_numTiles( dict1, i ) != dict_numTiles( dict2, i ) ) { + if ( dict_numTiles( dict1, ii ) != dict_numTiles( dict2, ii ) ) { break; } } - result = i == nTileFaces; /* did we get that far */ + result = ii == nTileFaces; /* did we get that far */ } return result; } /* dict_tilesAreSame */ @@ -226,10 +219,15 @@ ucharsToNarrow( const DictionaryCtxt* dict, XP_UCHAR* buf, XP_U16* bufsizep ) XP_U16 nUsed = 0; XP_U16 bufsize = *bufsizep; for ( ii = 0; ii < dict->nFaces; ++ii ) { - const XP_UCHAR* face = dict_getTileChar( dict, ii ); - nUsed += XP_SNPRINTF( &buf[nUsed], bufsize - nUsed, "%s", face ); + const XP_UCHAR* facep = dict_getTileString( dict, ii ); + if ( IS_SPECIAL(*facep) ) { + buf[nUsed++] = *facep; + } else { + nUsed += XP_SNPRINTF( &buf[nUsed], bufsize - nUsed, "%s", facep ); + } XP_ASSERT( nUsed < bufsize ); } + buf[nUsed] = 0; *bufsizep = nUsed; } @@ -275,7 +273,7 @@ dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream ) stream_putBytes( stream, buf, nBytes ); for ( nSpecials = i = 0; i < dict->nFaces; ++i ) { - const XP_UCHAR* facep = dict_getTileChar( dict, (Tile)i ); + const XP_UCHAR* facep = dict_getTileString( dict, (Tile)i ); if ( IS_SPECIAL( *facep ) ) { stringToStream( stream, dict->chars[nSpecials++] ); } @@ -289,7 +287,7 @@ freeSpecials( DictionaryCtxt* dict ) XP_U16 nSpecials; for ( nSpecials = t = 0; t < dict->nFaces; ++t ) { - const XP_UCHAR* facep = dict_getTileChar( dict, t ); + const XP_UCHAR* facep = dict_getTileString( dict, t ); if ( IS_SPECIAL( *facep ) ) { XP_ASSERT( !!dict->chars[nSpecials] ); @@ -321,13 +319,11 @@ common_destructor( DictionaryCtxt* dict ) XP_FREE( dict->mpool, dict->faceIndices ); XP_FREE( dict->mpool, dict ); -} /* dict */ +} /* common_destructor */ void dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) { - XP_ASSERT(0); - XP_U8 nFaces, nFaceBytes; XP_U16 maxCountBits, maxValueBits; XP_U16 i, nSpecials; @@ -357,10 +353,11 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) nFaceBytes = (XP_U8)stream_getU8( stream ); XP_U8 utf8[nFaceBytes]; stream_getBytes( stream, utf8, nFaceBytes ); + dict->isUTF8 = XP_TRUE; /* need to communicate this in stream */ dict_splitFaces( dict, utf8, nFaceBytes, nFaces ); for ( nSpecials = i = 0; i < nFaces; ++i ) { - const XP_UCHAR* facep = dict_getTileChar( dict, (Tile)i ); + const XP_UCHAR* facep = dict_getTileString( dict, (Tile)i ); if ( IS_SPECIAL( *facep ) ) { XP_UCHAR* txt = stringFromStream( dict->mpool, stream ); XP_ASSERT( !!txt ); @@ -393,7 +390,7 @@ dict_getName( const DictionaryCtxt* dict ) XP_Bool dict_faceIsBitmap( const DictionaryCtxt* dict, Tile tile ) { - const XP_UCHAR* facep = dict_getTileChar( dict, tile ); + const XP_UCHAR* facep = dict_getTileString( dict, tile ); return IS_SPECIAL(*facep); } /* dict_faceIsBitmap */ @@ -401,7 +398,7 @@ void dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile, XP_Bitmaps* bmps ) { SpecialBitmaps* bitmaps; - const XP_UCHAR* facep = dict_getTileChar( dict, tile ); + const XP_UCHAR* facep = dict_getTileString( dict, tile ); XP_ASSERT( dict_faceIsBitmap( dict, tile ) ); XP_ASSERT( !!dict->bitmaps );