2011-10-25 03:27:16 +02:00
|
|
|
/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */
|
2003-11-01 06:35:29 +01:00
|
|
|
/*
|
2011-10-25 03:27:16 +02:00
|
|
|
* Copyright 1997-2011 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_STDIO
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "comtypes.h"
|
|
|
|
#include "dictnryp.h"
|
2011-11-01 04:56:48 +01:00
|
|
|
#include "dictiter.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
#include "xwstream.h"
|
|
|
|
#include "strutils.h"
|
2011-11-01 02:30:55 +01:00
|
|
|
#include "dictiter.h"
|
2009-04-05 21:02:21 +02:00
|
|
|
#include "game.h"
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#ifdef CPLUS
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2014-03-09 05:57:27 +01:00
|
|
|
|
|
|
|
DictionaryCtxt*
|
2014-03-11 02:59:10 +01:00
|
|
|
p_dict_ref( DictionaryCtxt* dict
|
|
|
|
#ifdef DEBUG_REF
|
|
|
|
,const char* func, const char* file, int line
|
|
|
|
#endif
|
|
|
|
)
|
2014-03-09 05:57:27 +01:00
|
|
|
{
|
|
|
|
if ( !!dict ) {
|
2014-03-12 06:01:11 +01:00
|
|
|
pthread_mutex_lock( &dict->mutex );
|
2014-03-09 05:57:27 +01:00
|
|
|
++dict->refCount;
|
2014-03-11 02:59:10 +01:00
|
|
|
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
|
|
|
__func__, dict, dict->refCount, line, func, file );
|
2014-03-12 06:01:11 +01:00
|
|
|
pthread_mutex_unlock( &dict->mutex );
|
2014-03-09 05:57:27 +01:00
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-11 02:59:10 +01:00
|
|
|
p_dict_unref( DictionaryCtxt* dict
|
|
|
|
#ifdef DEBUG_REF
|
|
|
|
,const char* func, const char* file, int line
|
|
|
|
#endif
|
|
|
|
)
|
2014-03-09 05:57:27 +01:00
|
|
|
{
|
|
|
|
if ( !!dict ) {
|
2014-03-12 06:01:11 +01:00
|
|
|
pthread_mutex_lock( &dict->mutex );
|
2014-03-09 05:57:27 +01:00
|
|
|
--dict->refCount;
|
|
|
|
XP_ASSERT( 0 <= dict->refCount );
|
2014-03-11 02:59:10 +01:00
|
|
|
XP_LOGF( "%s(dict=%p): refCount now %d (from line %d of %s() in %s)",
|
|
|
|
__func__, dict, dict->refCount, line, func, file );
|
2014-03-12 06:01:11 +01:00
|
|
|
pthread_mutex_unlock( &dict->mutex );
|
2014-03-09 05:57:27 +01:00
|
|
|
if ( 0 == dict->refCount ) {
|
|
|
|
(*dict->destructor)( dict );
|
2014-03-12 06:01:11 +01:00
|
|
|
pthread_mutex_destroy( &dict->mutex );
|
2014-03-09 05:57:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dict_unref_all( PlayerDicts* pd )
|
|
|
|
{
|
|
|
|
XP_U16 ii;
|
|
|
|
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
|
|
|
|
dict_unref( pd->dicts[ii] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
void
|
2009-09-13 07:28:12 +02:00
|
|
|
setBlankTile( DictionaryCtxt* dict )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2009-04-05 21:02:21 +02:00
|
|
|
XP_U16 ii;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-09-13 07:28:12 +02:00
|
|
|
dict->blankTile = -1; /* no known blank */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-09-13 07:28:12 +02:00
|
|
|
for ( ii = 0; ii < dict->nFaces; ++ii ) {
|
|
|
|
if ( dict->facePtrs[ii][0] == 0 ) {
|
|
|
|
XP_ASSERT( dict->blankTile == -1 ); /* only one passes test? */
|
|
|
|
dict->blankTile = (XP_S8)ii;
|
2008-09-09 14:20:09 +02:00
|
|
|
#ifndef DEBUG
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
2008-09-09 14:20:09 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* setBlankTile */
|
|
|
|
|
2008-09-09 14:20:09 +02:00
|
|
|
/* #if defined BLANKS_FIRST || defined DEBUG */
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Bool
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_hasBlankTile( const DictionaryCtxt* dict )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
return dict->blankTile >= 0;
|
|
|
|
} /* dict_hasBlankTile */
|
2008-09-09 14:20:09 +02:00
|
|
|
/* #endif */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
Tile
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_getBlankTile( const DictionaryCtxt* dict )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_ASSERT( dict_hasBlankTile(dict) );
|
|
|
|
return (Tile)dict->blankTile;
|
|
|
|
} /* dict_getBlankTile */
|
|
|
|
|
|
|
|
XP_U16
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_getTileValue( const DictionaryCtxt* dict, Tile tile )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2013-11-29 19:15:22 +01:00
|
|
|
XP_ASSERT( !!dict );
|
2004-07-20 17:08:45 +02:00
|
|
|
if ( (tile & TILE_VALUE_MASK) != tile ) {
|
|
|
|
XP_ASSERT( tile == 32 &&
|
|
|
|
tile == dict_getBlankTile( dict ) );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_ASSERT( tile < dict->nFaces );
|
|
|
|
tile *= 2;
|
2014-02-07 16:41:50 +01:00
|
|
|
XP_ASSERT( !!dict->countsAndValues );
|
2003-11-01 06:35:29 +01:00
|
|
|
return dict->countsAndValues[tile+1];
|
|
|
|
} /* dict_getTileValue */
|
|
|
|
|
2009-09-13 06:57:44 +02:00
|
|
|
static const XP_UCHAR*
|
|
|
|
dict_getTileStringRaw( const DictionaryCtxt* dict, Tile tile )
|
|
|
|
{
|
|
|
|
XP_ASSERT( tile < dict->nFaces );
|
2009-09-13 07:28:12 +02:00
|
|
|
return dict->facePtrs[tile];
|
2009-09-13 06:57:44 +02:00
|
|
|
}
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
const XP_UCHAR*
|
|
|
|
dict_getTileString( const DictionaryCtxt* dict, Tile tile )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile );
|
|
|
|
if ( IS_SPECIAL(*facep) ) {
|
|
|
|
facep = dict->chars[(XP_U16)*facep];
|
|
|
|
}
|
|
|
|
return facep;
|
2009-04-05 21:02:21 +02:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2013-04-06 20:43:57 +02:00
|
|
|
const XP_UCHAR*
|
2013-04-09 16:43:04 +02:00
|
|
|
dict_getNextTileString( const DictionaryCtxt* dict, Tile tile,
|
2013-04-06 20:43:57 +02:00
|
|
|
const XP_UCHAR* cur )
|
|
|
|
{
|
|
|
|
const XP_UCHAR* result = NULL;
|
|
|
|
if ( NULL == cur ) {
|
2013-04-09 16:43:04 +02:00
|
|
|
result = dict_getTileString( dict, tile );
|
2013-04-06 20:43:57 +02:00
|
|
|
} else {
|
|
|
|
cur += XP_STRLEN( cur ) + 1;
|
2013-04-09 16:43:04 +02:00
|
|
|
XP_Bool isSpecial = dict_faceIsBitmap( dict, tile );
|
2013-05-15 07:00:22 +02:00
|
|
|
if ( isSpecial || tile == dict->blankTile ) {
|
2013-04-09 16:43:04 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile );
|
|
|
|
if ( cur < dict->charEnds[(XP_U16)*facep] ) {
|
2013-04-06 20:43:57 +02:00
|
|
|
result = cur;
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-09 16:43:04 +02:00
|
|
|
/* 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;
|
|
|
|
}
|
2013-04-06 20:43:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_numTiles( const DictionaryCtxt* dict, Tile tile )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
tile *= 2;
|
|
|
|
return dict->countsAndValues[tile];
|
|
|
|
} /* dict_numTiles */
|
|
|
|
|
|
|
|
XP_U16
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_numTileFaces( const DictionaryCtxt* dict )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
return dict->nFaces;
|
|
|
|
} /* dict_numTileFaces */
|
|
|
|
|
|
|
|
XP_U16
|
2009-09-13 06:57:44 +02:00
|
|
|
dict_tilesToString( const DictionaryCtxt* dict, const Tile* tiles,
|
2006-09-02 07:30:51 +02:00
|
|
|
XP_U16 nTiles, XP_UCHAR* buf, XP_U16 bufSize )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2005-07-08 05:06:08 +02:00
|
|
|
XP_UCHAR* bufp = buf;
|
2009-09-04 14:30:10 +02:00
|
|
|
XP_UCHAR* end = bufp + bufSize;
|
2005-07-08 05:06:08 +02:00
|
|
|
XP_U16 result = 0;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-09-04 14:30:10 +02:00
|
|
|
while ( nTiles-- ) {
|
|
|
|
Tile tile = *tiles++;
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile );
|
2009-09-04 14:30:10 +02:00
|
|
|
|
|
|
|
if ( IS_SPECIAL(*facep) ) {
|
2009-09-13 06:57:44 +02:00
|
|
|
XP_UCHAR* chars = dict->chars[(XP_U16)*facep];
|
2009-09-04 14:30:10 +02:00
|
|
|
XP_U16 len = XP_STRLEN( chars );
|
|
|
|
if ( bufp + len >= end ) {
|
|
|
|
bufp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
XP_MEMCPY( bufp, chars, len );
|
|
|
|
bufp += len;
|
|
|
|
} else {
|
2009-09-13 06:57:44 +02:00
|
|
|
XP_ASSERT ( tile != dict->blankTile ); /* printing blank should be
|
2009-09-04 14:30:10 +02:00
|
|
|
handled by specials
|
|
|
|
mechanism */
|
|
|
|
if ( bufp + 1 >= end ) {
|
|
|
|
bufp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
bufp += XP_SNPRINTF( bufp, end - bufp, XP_S, facep );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2009-09-04 14:30:10 +02:00
|
|
|
}
|
2005-07-08 05:06:08 +02:00
|
|
|
|
2009-09-04 14:30:10 +02:00
|
|
|
if ( bufp != NULL && bufp < end ) {
|
|
|
|
*bufp = '\0';
|
|
|
|
result = bufp - buf;
|
2005-07-08 05:06:08 +02:00
|
|
|
}
|
|
|
|
return result;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* dict_tilesToString */
|
|
|
|
|
2011-11-01 04:56:48 +01:00
|
|
|
/* Convert str to an array of tiles, continuing until we fail to match or we
|
|
|
|
* run out of room in which to return tiles. Failure to match means return of
|
|
|
|
* XP_FALSE, but if we run out of room before failing we return XP_TRUE.
|
2009-04-05 21:02:21 +02:00
|
|
|
*/
|
2012-08-27 16:10:40 +02:00
|
|
|
static XP_S16
|
|
|
|
tilesForStringImpl( const DictionaryCtxt* dict, const XP_UCHAR* str,
|
|
|
|
Tile* tiles, XP_U16 nTiles, XP_U16 nFound )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2012-08-27 16:10:40 +02:00
|
|
|
XP_S16 result = -1;
|
|
|
|
if ( nFound == nTiles || '\0' == str[0] ) {
|
|
|
|
result = nFound;
|
|
|
|
} else {
|
|
|
|
XP_U16 nFaces = dict_numTileFaces( dict );
|
2011-11-01 04:56:48 +01:00
|
|
|
Tile tile;
|
|
|
|
for ( tile = 0; tile < nFaces; ++tile ) {
|
|
|
|
if ( tile != dict->blankTile ) {
|
|
|
|
const XP_UCHAR* facep = dict_getTileString( dict, tile );
|
|
|
|
XP_U16 faceLen = XP_STRLEN( facep );
|
|
|
|
if ( 0 == XP_STRNCMP( facep, str, faceLen ) ) {
|
2012-08-27 16:10:40 +02:00
|
|
|
XP_S16 maxFound = tilesForStringImpl( dict, str + faceLen,
|
|
|
|
tiles, nTiles,
|
|
|
|
nFound + 1 );
|
|
|
|
if ( 0 <= maxFound ) {
|
|
|
|
tiles[nFound] = tile;
|
|
|
|
result = maxFound;
|
2011-11-01 04:56:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-27 16:10:40 +02:00
|
|
|
return result;
|
|
|
|
} /* tilesForStringImpl */
|
|
|
|
|
|
|
|
XP_Bool
|
|
|
|
dict_tilesForString( const DictionaryCtxt* dict, const XP_UCHAR* str,
|
|
|
|
Tile* tiles, XP_U16* nTilesP )
|
|
|
|
{
|
|
|
|
XP_S16 nFound = tilesForStringImpl( dict, str, tiles, *nTilesP, 0 );
|
|
|
|
XP_Bool success = 0 <= nFound;
|
|
|
|
if ( success ) {
|
|
|
|
*nTilesP = nFound;
|
|
|
|
}
|
2011-11-01 04:56:48 +01:00
|
|
|
return success;
|
|
|
|
} /* dict_tilesForString */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_Bool
|
2006-09-02 07:30:51 +02:00
|
|
|
dict_tilesAreSame( const DictionaryCtxt* dict1, const DictionaryCtxt* dict2 )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_Bool result = XP_FALSE;
|
|
|
|
|
2011-04-26 05:17:54 +02:00
|
|
|
XP_ASSERT( !!dict1 );
|
|
|
|
XP_ASSERT( !!dict2 );
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
Tile ii;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 nTileFaces = dict_numTileFaces( dict1 );
|
|
|
|
|
|
|
|
if ( nTileFaces == dict_numTileFaces( dict2 ) ) {
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( ii = 0; ii < nTileFaces; ++ii ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
const XP_UCHAR* face1;
|
|
|
|
const XP_UCHAR* face2;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( dict_getTileValue( dict1, ii )
|
|
|
|
!= dict_getTileValue( dict2, ii ) ){
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-09-13 06:57:44 +02:00
|
|
|
face1 = dict_getTileStringRaw( dict1, ii );
|
|
|
|
face2 = dict_getTileStringRaw( dict2, ii );
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL(*face1) != IS_SPECIAL(*face2) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL(*face1) ) {
|
|
|
|
XP_UCHAR* chars1 = dict1->chars[(int)*face1];
|
|
|
|
XP_UCHAR* chars2 = dict2->chars[(int)*face2];
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 len = XP_STRLEN(chars1);
|
|
|
|
if ( 0 != XP_STRNCMP( chars1, chars2, len ) ) {
|
|
|
|
break;
|
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
} else if ( 0 != XP_STRCMP( face1, face2 ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( dict_numTiles( dict1, ii ) != dict_numTiles( dict2, ii ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
result = ii == nTileFaces; /* did we get that far */
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} /* dict_tilesAreSame */
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
|
|
|
static void
|
2009-09-04 14:30:10 +02:00
|
|
|
ucharsToNarrow( const DictionaryCtxt* dict, XP_UCHAR* buf, XP_U16* bufsizep )
|
2009-04-05 21:02:21 +02:00
|
|
|
{
|
|
|
|
XP_U16 ii;
|
|
|
|
XP_U16 nUsed = 0;
|
|
|
|
XP_U16 bufsize = *bufsizep;
|
|
|
|
for ( ii = 0; ii < dict->nFaces; ++ii ) {
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, ii );
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL(*facep) ) {
|
|
|
|
buf[nUsed++] = *facep;
|
|
|
|
} else {
|
|
|
|
nUsed += XP_SNPRINTF( &buf[nUsed], bufsize - nUsed, "%s", facep );
|
|
|
|
}
|
|
|
|
XP_ASSERT( nUsed < bufsize );
|
|
|
|
}
|
2009-09-04 14:30:10 +02:00
|
|
|
buf[nUsed] = 0;
|
2009-04-05 21:02:21 +02:00
|
|
|
*bufsizep = nUsed;
|
2009-09-04 14:30:10 +02:00
|
|
|
}
|
2009-04-05 21:02:21 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
void
|
2008-09-05 14:11:37 +02:00
|
|
|
dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_U16 maxCount = 0;
|
|
|
|
XP_U16 maxValue = 0;
|
2009-04-05 21:02:21 +02:00
|
|
|
XP_U16 ii, nSpecials;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 maxCountBits, maxValueBits;
|
2009-09-12 17:35:03 +02:00
|
|
|
XP_UCHAR buf[64];
|
|
|
|
XP_U16 nBytes;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
stream_putBits( stream, 6, dict->nFaces );
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( ii = 0; ii < dict->nFaces*2; ii+=2 ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 count, value;
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
count = dict->countsAndValues[ii];
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( maxCount < count ) {
|
|
|
|
maxCount = count;
|
|
|
|
}
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
value = dict->countsAndValues[ii+1];
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( maxValue < value ) {
|
|
|
|
maxValue = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maxCountBits = bitsForMax( maxCount );
|
|
|
|
maxValueBits = bitsForMax( maxValue );
|
|
|
|
|
|
|
|
stream_putBits( stream, 3, maxCountBits ); /* won't be bigger than 5 */
|
|
|
|
stream_putBits( stream, 3, maxValueBits );
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( ii = 0; ii < dict->nFaces*2; ii+=2 ) {
|
|
|
|
stream_putBits( stream, maxCountBits, dict->countsAndValues[ii] );
|
|
|
|
stream_putBits( stream, maxValueBits, dict->countsAndValues[ii+1] );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2009-09-05 15:14:42 +02:00
|
|
|
/* Stream format of the faces is unchanged: chars run together, which
|
|
|
|
* happens to equal utf-8 for ascii. But now there may be more than one
|
|
|
|
* byte per face. Old code assumes that, but compatibility is ensured by
|
|
|
|
* the caller which will not accept an incoming message if the version's
|
|
|
|
* too new. And utf-8 dicts are flagged as newer by the sender.
|
|
|
|
*/
|
|
|
|
|
2009-09-12 17:35:03 +02:00
|
|
|
nBytes = sizeof(buf);
|
2009-09-04 14:30:10 +02:00
|
|
|
ucharsToNarrow( dict, buf, &nBytes );
|
|
|
|
stream_putU8( stream, nBytes );
|
|
|
|
stream_putBytes( stream, buf, nBytes );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( nSpecials = ii = 0; ii < dict->nFaces; ++ii ) {
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, (Tile)ii );
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL( *facep ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
stringToStream( stream, dict->chars[nSpecials++] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* dict_writeToStream */
|
2009-04-05 21:02:21 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
freeSpecials( DictionaryCtxt* dict )
|
|
|
|
{
|
2009-04-05 21:02:21 +02:00
|
|
|
Tile tt;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 nSpecials;
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( nSpecials = tt = 0; tt < dict->nFaces; ++tt ) {
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tt );
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL( *facep ) ) {
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_ASSERT( !!dict->chars[nSpecials] );
|
|
|
|
XP_FREE( dict->mpool, dict->chars[nSpecials] );
|
|
|
|
|
2011-04-08 03:07:45 +02:00
|
|
|
XP_FREEP( dict->mpool, &dict->bitmaps[nSpecials].largeBM );
|
|
|
|
XP_FREEP( dict->mpool, &dict->bitmaps[nSpecials].smallBM );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
++nSpecials;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( nSpecials > 0 ) {
|
|
|
|
XP_FREE( dict->mpool, dict->chars );
|
|
|
|
XP_FREE( dict->mpool, dict->bitmaps );
|
|
|
|
}
|
|
|
|
} /* freeSpecials */
|
|
|
|
|
|
|
|
static void
|
|
|
|
common_destructor( DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
freeSpecials( dict );
|
|
|
|
|
|
|
|
XP_FREE( dict->mpool, dict->countsAndValues );
|
2009-04-05 21:02:21 +02:00
|
|
|
XP_FREE( dict->mpool, dict->faces );
|
2009-09-13 07:28:12 +02:00
|
|
|
XP_FREE( dict->mpool, dict->facePtrs );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_FREE( dict->mpool, dict );
|
2009-04-05 21:02:21 +02:00
|
|
|
} /* common_destructor */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
2003-11-01 06:35:29 +01:00
|
|
|
void
|
|
|
|
dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
|
|
|
|
{
|
2009-09-04 14:30:10 +02:00
|
|
|
XP_U8 nFaces, nFaceBytes;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 maxCountBits, maxValueBits;
|
2009-04-05 21:02:21 +02:00
|
|
|
XP_U16 ii, nSpecials;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_UCHAR* localTexts[32];
|
2009-09-12 17:35:03 +02:00
|
|
|
XP_U8 utf8[MAX_UNIQUE_TILES];
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_ASSERT( !dict->destructor );
|
|
|
|
dict->destructor = common_destructor;
|
2004-12-18 02:04:57 +01:00
|
|
|
dict->func_dict_getShortName = dict_getName; /* default */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
nFaces = (XP_U8)stream_getBits( stream, 6 );
|
|
|
|
maxCountBits = (XP_U16)stream_getBits( stream, 3 );
|
|
|
|
maxValueBits = (XP_U16)stream_getBits( stream, 3 );
|
|
|
|
|
|
|
|
dict->nFaces = nFaces;
|
|
|
|
|
|
|
|
dict->countsAndValues =
|
|
|
|
(XP_U8*)XP_MALLOC( dict->mpool,
|
|
|
|
sizeof(dict->countsAndValues[0]) * nFaces * 2 );
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
for ( ii = 0; ii < dict->nFaces*2; ii+=2 ) {
|
|
|
|
dict->countsAndValues[ii] = (XP_U8)stream_getBits( stream,
|
2009-09-04 14:30:10 +02:00
|
|
|
maxCountBits );
|
2009-04-05 21:02:21 +02:00
|
|
|
dict->countsAndValues[ii+1] = (XP_U8)stream_getBits( stream,
|
2009-09-04 14:30:10 +02:00
|
|
|
maxValueBits );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2009-04-07 06:33:47 +02:00
|
|
|
|
2009-09-04 14:30:10 +02:00
|
|
|
nFaceBytes = (XP_U8)stream_getU8( stream );
|
2009-09-12 17:35:03 +02:00
|
|
|
XP_ASSERT( nFaceBytes < VSIZE(utf8) );
|
2009-04-05 21:02:21 +02:00
|
|
|
stream_getBytes( stream, utf8, nFaceBytes );
|
2009-09-04 14:30:10 +02:00
|
|
|
dict->isUTF8 = XP_TRUE; /* need to communicate this in stream */
|
2009-04-05 21:02:21 +02:00
|
|
|
dict_splitFaces( dict, utf8, nFaceBytes, nFaces );
|
|
|
|
|
|
|
|
for ( nSpecials = ii = 0; ii < nFaces; ++ii ) {
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, (Tile)ii );
|
2009-04-05 21:02:21 +02:00
|
|
|
if ( IS_SPECIAL( *facep ) ) {
|
2007-03-19 00:31:51 +01:00
|
|
|
XP_UCHAR* txt = stringFromStream( dict->mpool, stream );
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_ASSERT( !!txt );
|
|
|
|
localTexts[nSpecials] = txt;
|
|
|
|
|
|
|
|
++nSpecials;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( nSpecials > 0 ) {
|
|
|
|
dict->bitmaps =
|
|
|
|
(SpecialBitmaps*)XP_MALLOC( dict->mpool,
|
|
|
|
nSpecials * sizeof(*dict->bitmaps) );
|
|
|
|
XP_MEMSET( dict->bitmaps, 0, nSpecials * sizeof(*dict->bitmaps) );
|
|
|
|
|
|
|
|
dict->chars = (XP_UCHAR**)XP_MALLOC( dict->mpool,
|
|
|
|
nSpecials * sizeof(*dict->chars) );
|
|
|
|
XP_MEMCPY(dict->chars, localTexts, nSpecials * sizeof(*dict->chars));
|
|
|
|
}
|
|
|
|
setBlankTile( dict );
|
|
|
|
} /* dict_loadFromStream */
|
2009-04-05 21:02:21 +02:00
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2011-04-13 15:45:22 +02:00
|
|
|
#ifdef TEXT_MODEL
|
|
|
|
/* Return the strlen of the longest face, e.g. 1 for English and Italian;
|
|
|
|
2 for Spanish; 3 for Catalan */
|
|
|
|
XP_U16
|
|
|
|
dict_getMaxWidth( const DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
XP_U16 result = 0;
|
|
|
|
Tile tile;
|
|
|
|
XP_U16 nFaces = dict_numTileFaces( dict );
|
|
|
|
|
|
|
|
for ( tile = 0; tile < nFaces; ++tile ) {
|
|
|
|
const XP_UCHAR* face = dict_getTileString( dict, tile );
|
|
|
|
XP_U16 len = XP_STRLEN( face );
|
|
|
|
if ( len > result ) {
|
|
|
|
result = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-09-24 17:28:15 +02:00
|
|
|
const XP_UCHAR*
|
2006-09-02 07:30:51 +02:00
|
|
|
dict_getName( const DictionaryCtxt* dict )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
XP_ASSERT( !!dict );
|
2006-04-30 15:58:24 +02:00
|
|
|
XP_ASSERT( !!dict->name );
|
2003-11-01 06:35:29 +01:00
|
|
|
return dict->name;
|
|
|
|
} /* dict_getName */
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
XP_Bool
|
|
|
|
dict_isUTF8( const DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
XP_ASSERT( !!dict );
|
|
|
|
return dict->isUTF8;
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Bool
|
2006-09-02 07:30:51 +02:00
|
|
|
dict_faceIsBitmap( const DictionaryCtxt* dict, Tile tile )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile );
|
2010-03-08 07:11:42 +01:00
|
|
|
return IS_SPECIAL(*facep) && (tile != dict->blankTile);
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* dict_faceIsBitmap */
|
|
|
|
|
2009-01-13 13:57:56 +01:00
|
|
|
void
|
|
|
|
dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile, XP_Bitmaps* bmps )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
SpecialBitmaps* bitmaps;
|
2009-09-13 06:57:44 +02:00
|
|
|
const XP_UCHAR* facep = dict_getTileStringRaw( dict, tile );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_ASSERT( dict_faceIsBitmap( dict, tile ) );
|
|
|
|
XP_ASSERT( !!dict->bitmaps );
|
|
|
|
|
2009-04-05 21:02:21 +02:00
|
|
|
bitmaps = &dict->bitmaps[(XP_U16)*facep];
|
2009-01-13 13:57:56 +01:00
|
|
|
bmps->nBitmaps = 2;
|
|
|
|
bmps->bmps[0] = bitmaps->smallBM;
|
|
|
|
bmps->bmps[1] = bitmaps->largeBM;
|
2009-01-25 21:31:13 +01:00
|
|
|
} /* dict_getFaceBitmaps */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-07-07 05:46:07 +02:00
|
|
|
XP_LangCode
|
2006-02-18 07:39:40 +01:00
|
|
|
dict_getLangCode( const DictionaryCtxt* dict )
|
2005-07-07 05:46:07 +02:00
|
|
|
{
|
|
|
|
return dict->langCode;
|
|
|
|
}
|
|
|
|
|
2010-12-07 03:24:31 +01:00
|
|
|
XP_U32
|
|
|
|
dict_getWordCount( const DictionaryCtxt* dict )
|
|
|
|
{
|
2011-10-25 03:27:16 +02:00
|
|
|
XP_U32 nWords = dict->nWords;
|
|
|
|
#ifdef XWFEATURE_WALKDICT
|
2011-10-29 05:27:16 +02:00
|
|
|
if ( 0 == nWords ) {
|
2011-11-04 05:25:51 +01:00
|
|
|
DictIter iter;
|
2011-11-18 16:56:02 +01:00
|
|
|
dict_initIter( &iter, dict, 0, MAX_COLS_DICT );
|
2011-11-18 17:15:21 +01:00
|
|
|
nWords = dict_countWords( &iter, NULL );
|
2011-10-29 05:27:16 +02:00
|
|
|
}
|
2011-10-25 03:27:16 +02:00
|
|
|
#endif
|
|
|
|
return nWords;
|
2010-12-07 03:24:31 +01:00
|
|
|
}
|
|
|
|
|
2012-08-27 05:58:28 +02:00
|
|
|
const XP_UCHAR*
|
|
|
|
dict_getDesc( const DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
return dict->desc;
|
|
|
|
}
|
|
|
|
|
2012-09-08 19:09:31 +02:00
|
|
|
const XP_UCHAR*
|
|
|
|
dict_getMd5Sum( const DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
return dict->md5Sum;
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#ifdef STUBBED_DICT
|
|
|
|
|
|
|
|
#define BLANK_FACE '\0'
|
|
|
|
|
|
|
|
static XP_U8 stub_english_data[] = {
|
|
|
|
/* count value face */
|
2008-05-31 05:26:16 +02:00
|
|
|
9, 1, 'A',
|
|
|
|
2, 3, 'B',
|
|
|
|
2, 3, 'C',
|
|
|
|
4, 2, 'D',
|
|
|
|
12, 1, 'E',
|
|
|
|
2, 4, 'F',
|
|
|
|
3, 2, 'G',
|
|
|
|
2, 4, 'H',
|
|
|
|
9, 1, 'I',
|
|
|
|
1, 8, 'J',
|
|
|
|
1, 5, 'K',
|
|
|
|
4, 1, 'L',
|
|
|
|
2, 3, 'M',
|
|
|
|
6, 1, 'N',
|
|
|
|
8, 1, 'O',
|
|
|
|
2, 3, 'P',
|
|
|
|
1, 10, 'Q',
|
|
|
|
6, 1, 'R',
|
|
|
|
4, 1, 'S',
|
|
|
|
6, 1, 'T',
|
|
|
|
4, 1, 'U',
|
|
|
|
2, 4, 'V',
|
|
|
|
2, 4, 'W',
|
|
|
|
1, 8, 'X',
|
|
|
|
2, 4, 'Y',
|
|
|
|
1, 10, 'Z',
|
|
|
|
2, 0, BLANK_FACE, /* BLANK1 */
|
2003-11-01 06:35:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
setStubbedSpecials( DictionaryCtxt* dict )
|
|
|
|
{
|
2005-01-04 05:06:37 +01:00
|
|
|
dict->chars = (XP_UCHAR**)XP_MALLOC( dict->mpool, sizeof(char*) );
|
2003-11-01 06:35:29 +01:00
|
|
|
dict->chars[0] = "_";
|
|
|
|
|
|
|
|
} /* setStubbedSpecials */
|
|
|
|
|
|
|
|
void
|
|
|
|
destroy_stubbed_dict( DictionaryCtxt* dict )
|
|
|
|
{
|
|
|
|
XP_FREE( dict->mpool, dict->countsAndValues );
|
2010-01-02 02:40:25 +01:00
|
|
|
XP_FREE( dict->mpool, dict->faces );
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_FREE( dict->mpool, dict->chars );
|
|
|
|
XP_FREE( dict->mpool, dict->name );
|
2011-04-12 03:55:42 +02:00
|
|
|
XP_FREE( dict->mpool, dict->langName );
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_FREE( dict->mpool, dict->bitmaps );
|
|
|
|
XP_FREE( dict->mpool, dict );
|
|
|
|
} /* destroy_stubbed_dict */
|
|
|
|
|
|
|
|
DictionaryCtxt*
|
|
|
|
make_stubbed_dict( MPFORMAL_NOCOMMA )
|
|
|
|
{
|
2005-01-04 05:06:37 +01:00
|
|
|
DictionaryCtxt* dict = (DictionaryCtxt*)XP_MALLOC( mpool, sizeof(*dict) );
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U8* data = stub_english_data;
|
|
|
|
XP_U16 datasize = sizeof(stub_english_data);
|
2010-01-02 02:40:25 +01:00
|
|
|
XP_U16 ii;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
XP_MEMSET( dict, 0, sizeof(*dict) );
|
|
|
|
|
|
|
|
MPASSIGN( dict->mpool, mpool );
|
2006-09-15 09:32:39 +02:00
|
|
|
dict->name = copyString( mpool, "Stub dictionary" );
|
2003-11-01 06:35:29 +01:00
|
|
|
dict->nFaces = datasize/3;
|
|
|
|
|
|
|
|
dict->destructor = destroy_stubbed_dict;
|
|
|
|
|
2010-01-02 02:40:25 +01:00
|
|
|
dict->faces = (XP_UCHAR*)
|
|
|
|
XP_MALLOC( mpool, 2 * dict->nFaces * sizeof(dict->faces[0]) );
|
|
|
|
dict->facePtrs = (XP_UCHAR**)
|
|
|
|
XP_MALLOC( mpool, dict->nFaces * sizeof(dict->facePtrs[0]) );
|
|
|
|
|
|
|
|
XP_UCHAR* nextChar = dict->faces;
|
|
|
|
XP_UCHAR** nextPtr = dict->facePtrs;
|
|
|
|
for ( ii = 0; ii < datasize/3; ++ii ) {
|
|
|
|
*nextPtr++ = nextChar;
|
|
|
|
*nextChar++ = (XP_UCHAR)data[(ii*3)+2];
|
|
|
|
*nextChar++ = '\0';
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-01-04 05:06:37 +01:00
|
|
|
dict->countsAndValues = (XP_U8*)XP_MALLOC( mpool, dict->nFaces*2 );
|
2010-01-02 02:40:25 +01:00
|
|
|
for ( ii = 0; ii < datasize/3; ++ii ) {
|
|
|
|
dict->countsAndValues[ii*2] = data[(ii*3)];
|
|
|
|
dict->countsAndValues[(ii*2)+1] = data[(ii*3)+1];
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-01-04 05:06:37 +01:00
|
|
|
dict->bitmaps = (SpecialBitmaps*)XP_MALLOC( mpool, sizeof(SpecialBitmaps) );
|
2003-11-01 06:35:29 +01:00
|
|
|
dict->bitmaps->largeBM = dict->bitmaps->largeBM = NULL;
|
|
|
|
|
|
|
|
setStubbedSpecials( dict );
|
|
|
|
|
|
|
|
setBlankTile( dict );
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
} /* make_subbed_dict */
|
|
|
|
|
|
|
|
#endif /* STUBBED_DICT */
|
|
|
|
|
2004-10-07 15:23:20 +02:00
|
|
|
static array_edge*
|
2006-09-02 07:30:51 +02:00
|
|
|
dict_super_edge_for_index( const DictionaryCtxt* dict, XP_U32 index )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
array_edge* result;
|
|
|
|
|
|
|
|
if ( index == 0 ) {
|
|
|
|
result = NULL;
|
|
|
|
} else {
|
|
|
|
XP_ASSERT( index < dict->numEdges );
|
2004-10-07 15:23:20 +02:00
|
|
|
/* avoid long-multiplication lib call on Palm... */
|
|
|
|
if ( dict->nodeSize == 3 ) {
|
|
|
|
index += (index << 1);
|
|
|
|
} else {
|
|
|
|
XP_ASSERT( dict->nodeSize == 4 );
|
|
|
|
index <<= 2;
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
result = &dict->base[index];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} /* dict_edge_for_index */
|
2004-10-07 15:23:20 +02:00
|
|
|
|
|
|
|
static array_edge*
|
2006-09-02 07:30:51 +02:00
|
|
|
dict_super_getTopEdge( const DictionaryCtxt* dict )
|
2004-10-07 15:23:20 +02:00
|
|
|
{
|
|
|
|
return dict->topEdge;
|
|
|
|
} /* dict_super_getTopEdge */
|
|
|
|
|
2014-03-13 03:24:00 +01:00
|
|
|
static XP_U32
|
2011-10-22 03:51:33 +02:00
|
|
|
dict_super_index_from( const DictionaryCtxt* dict, array_edge* p_edge )
|
|
|
|
{
|
|
|
|
unsigned long result;
|
|
|
|
|
|
|
|
array_edge_new* edge = (array_edge_new*)p_edge;
|
|
|
|
result = ((edge->highByte << 8) | edge->lowByte) & 0x0000FFFF;
|
|
|
|
|
|
|
|
if ( dict->is_4_byte ) {
|
|
|
|
result |= ((XP_U32)edge->moreBits) << 16;
|
|
|
|
} else {
|
|
|
|
XP_ASSERT( dict->nodeSize == 3 );
|
|
|
|
if ( (edge->bits & EXTRABITMASK_NEW) != 0 ) {
|
|
|
|
result |= 0x00010000; /* using | instead of + saves 4 bytes */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} /* dict_super_index_from */
|
|
|
|
|
|
|
|
static array_edge*
|
|
|
|
dict_super_follow( const DictionaryCtxt* dict, array_edge* in )
|
|
|
|
{
|
|
|
|
XP_U32 index = dict_index_from( dict, in );
|
|
|
|
array_edge* result = index > 0?
|
|
|
|
dict_edge_for_index( dict, index ): (array_edge*)NULL;
|
|
|
|
return result;
|
|
|
|
} /* dict_super_follow */
|
|
|
|
|
2011-10-29 05:27:16 +02:00
|
|
|
static array_edge*
|
|
|
|
dict_super_edge_with_tile( const DictionaryCtxt* dict, array_edge* from,
|
|
|
|
Tile tile )
|
|
|
|
{
|
|
|
|
for ( ; ; ) {
|
|
|
|
Tile candidate = EDGETILE(dict,from);
|
|
|
|
if ( candidate == tile ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( IS_LAST_EDGE(dict, from ) ) {
|
|
|
|
from = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
from += dict->nodeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return from;
|
|
|
|
} /* edge_with_tile */
|
|
|
|
|
2004-10-07 15:23:20 +02:00
|
|
|
void
|
2009-09-13 06:57:44 +02:00
|
|
|
dict_super_init( DictionaryCtxt* dict )
|
2004-10-07 15:23:20 +02:00
|
|
|
{
|
|
|
|
/* subclass may change these later.... */
|
2009-09-13 06:57:44 +02:00
|
|
|
dict->func_edge_for_index = dict_super_edge_for_index;
|
|
|
|
dict->func_dict_getTopEdge = dict_super_getTopEdge;
|
2011-10-22 03:51:33 +02:00
|
|
|
dict->func_dict_index_from = dict_super_index_from;
|
|
|
|
dict->func_dict_follow = dict_super_follow;
|
2011-10-29 05:27:16 +02:00
|
|
|
dict->func_dict_edge_with_tile = dict_super_edge_with_tile;
|
2009-09-13 06:57:44 +02:00
|
|
|
dict->func_dict_getShortName = dict_getName;
|
2014-03-12 06:01:11 +01:00
|
|
|
|
|
|
|
pthread_mutex_init( &dict->mutex, NULL );
|
2004-10-07 15:23:20 +02:00
|
|
|
} /* dict_super_init */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2011-04-12 03:55:42 +02:00
|
|
|
const XP_UCHAR*
|
|
|
|
dict_getLangName( const DictionaryCtxt* ctxt )
|
|
|
|
{
|
|
|
|
return ctxt->langName;
|
|
|
|
}
|
|
|
|
|
2011-11-09 15:51:12 +01:00
|
|
|
#ifdef XWFEATURE_DICTSANITY
|
|
|
|
XP_Bool
|
|
|
|
checkSanity( DictionaryCtxt* dict, const XP_U32 numEdges )
|
|
|
|
{
|
|
|
|
XP_U32 ii;
|
|
|
|
XP_Bool passed = XP_TRUE;
|
2011-11-11 03:24:45 +01:00
|
|
|
|
2011-11-09 15:51:12 +01:00
|
|
|
array_edge* edge = dict->base;
|
2011-11-22 03:06:46 +01:00
|
|
|
if ( NULL != edge ) { /* not empty dict */
|
|
|
|
XP_U16 nFaces = dict_numTileFaces( dict );
|
|
|
|
Tile prevTile = 0;
|
|
|
|
for ( ii = 0; ii < numEdges && passed; ++ii ) {
|
|
|
|
Tile tile = EDGETILE( dict, edge );
|
|
|
|
if ( tile < prevTile || tile >= nFaces ) {
|
2014-01-07 15:58:20 +01:00
|
|
|
XP_LOGF( "%s: node %d (out of %d) has too-large or "
|
2011-11-22 03:06:46 +01:00
|
|
|
"out-of-order tile", __func__, ii, numEdges );
|
|
|
|
passed = XP_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevTile = tile;
|
2011-11-09 15:51:12 +01:00
|
|
|
|
2014-03-13 03:24:00 +01:00
|
|
|
XP_U32 index = dict_index_from( dict, edge );
|
2011-11-22 03:06:46 +01:00
|
|
|
if ( index >= numEdges ) {
|
2014-03-13 03:24:00 +01:00
|
|
|
XP_LOGF( "%s: node %d (out of %d) has too-high index %d",
|
2011-11-22 03:06:46 +01:00
|
|
|
__func__, ii, numEdges, index );
|
|
|
|
passed = XP_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-09 15:51:12 +01:00
|
|
|
|
2011-11-22 03:06:46 +01:00
|
|
|
if ( IS_LAST_EDGE( dict, edge ) ) {
|
|
|
|
prevTile = 0;
|
|
|
|
}
|
|
|
|
edge += dict->nodeSize;
|
2011-11-09 15:51:12 +01:00
|
|
|
}
|
|
|
|
|
2011-11-22 03:06:46 +01:00
|
|
|
if ( passed ) {
|
|
|
|
passed = 0 == prevTile; /* last edge seen was a LAST_EDGE */
|
|
|
|
}
|
2011-11-09 15:51:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return passed;
|
|
|
|
} /* checkSanity */
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
#ifdef CPLUS
|
|
|
|
}
|
|
|
|
#endif
|