Fix to compile (and so dicts are read into new internal format) on Palm.

This commit is contained in:
ehouse 2009-04-07 04:33:47 +00:00
parent 669e423ca8
commit 9df574b6f6
6 changed files with 57 additions and 22 deletions

View file

@ -84,8 +84,9 @@ dict_getTileValue( const DictionaryCtxt* dict, Tile tile )
const XP_UCHAR*
dict_getTileString( const DictionaryCtxt* dict, Tile tile )
{
const XP_UCHAR* start;
XP_ASSERT( tile < dict->nFaces );
const XP_UCHAR* start = dict->faceStarts[tile];
start = dict->faceStarts[tile];
if ( IS_SPECIAL(*start) ) {
start = dict->chars[(int)*start];
}
@ -226,6 +227,8 @@ dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream )
XP_U16 maxValue = 0;
XP_U16 ii, nSpecials;
XP_U16 maxCountBits, maxValueBits;
XP_UCHAR buf[64];
XP_U16 nFaceBytes;
/* Need to keep format identical for non-utf so new versions can play
against old using not UTF8 dicts. The old ones won't even recognize
@ -258,8 +261,7 @@ dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream )
stream_putBits( stream, maxValueBits, dict->countsAndValues[ii+1] );
}
XP_UCHAR buf[64];
XP_U16 nFaceBytes = sizeof(buf);
nFaceBytes = sizeof(buf);
unsplitFaces( dict, buf, &nFaceBytes );
if ( dict_isUTF8( dict ) ) {
/* nBytes == nFaces for non-UTF8 dicts */
@ -327,6 +329,7 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
XP_UCHAR* localTexts[32];
XP_U16 streamVersion = stream_getVersion( stream );
XP_Bool isUTF8 = streamVersion >= STREAM_VERS_UTF8;
XP_U8 utf8[96];
XP_ASSERT( !dict->destructor );
dict->destructor = common_destructor;
@ -354,7 +357,8 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
} else {
nFaceBytes = nFaces;
}
XP_U8 utf8[nFaceBytes];
XP_ASSERT( nFaceBytes < VSIZE(utf8) );
stream_getBytes( stream, utf8, nFaceBytes );
dict->isUTF8 = isUTF8;
dict_splitFaces( dict, utf8, nFaceBytes, nFaces );

View file

@ -1,6 +1,7 @@
/* -*- mode: c; compile-command: "cd .. && make ARCH=68K_ONLY MEMDEBUG=TRUE"; -*- */
/*
* Copyright 1997 - 2008 by Eric House (xwords@eehouse.org) and others. All rights reserved.
* Copyright 1997 - 2009 by Eric House (xwords@eehouse.org) and others. All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -165,7 +166,7 @@
/* "xwords@eehouse.org. Enjoy!\n\n" */
/* #endif */
"Crosswords " XW_PALM_VERSION_STRING " (rev. " SVN_REV ").\n" \
"Copyright 1998-2008 by Eric House. "\
"Copyright 1998-2009 by Eric House. "\
"Released under the GNU Public License.\n\n"\
"See the manual at xwords.sf.net or "

View file

@ -1,6 +1,6 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
/*
* Copyright 1999 - 2006 by Eric House (xwords@eehouse.org). All rights
* Copyright 1999 - 2009 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
@ -518,6 +518,8 @@ palmEnableAttrProc(void* closure, NewGameAttr attr, XP_TriEnable ngEnable )
case NG_ATTR_REMHEADER:
objID = XW_LOCAL_LABEL_ID;
break;
case NG_ATTR_CANCONFIG: /* not needed on palm */
break;
#endif
case NG_ATTR_NPLAYERS:
objID = XW_NPLAYERS_SELECTOR_ID;
@ -628,6 +630,7 @@ palmSetAttrProc( void* closure, NewGameAttr attr, const NGValue value )
break;
case NG_ATTR_CANJUGGLE:
XP_ASSERT(0); /* doesn't make sense */
case NG_ATTR_CANCONFIG: /* not needed on palm */
break;
}
} /* palmSetAttrProc */

View file

@ -1,6 +1,6 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4;-*- */
/*
* Copyright 1997-2005 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 1997-2009 by Eric House (xwords@eehouse.org). All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -83,7 +83,7 @@ palm_dictionary_make( MPFORMAL PalmAppGlobals* globals,
XP_U32 offset;
DictListEntry* dle;
Err err;
XP_U16 i;
XP_U16 ii;
FaceType* facePtr;
#ifdef NODE_CAN_4
XP_U16 flags;
@ -115,6 +115,7 @@ palm_dictionary_make( MPFORMAL PalmAppGlobals* globals,
dict_super_init( (DictionaryCtxt*)ctxt );
if ( !!dictName ) {
XP_U8 buf[64];
XP_ASSERT( XP_STRLEN((const char*)dictName) > 0 );
ctxt->super.name = copyString( mpool, dictName );
@ -170,16 +171,15 @@ palm_dictionary_make( MPFORMAL PalmAppGlobals* globals,
facePtr = (FaceType*)MemHandleLock( tmpH );
XP_ASSERT( MemHandleLockCount( tmpH ) == 1 );
ctxt->super.nFaces = nChars = MemPtrSize(facePtr) / sizeof(*facePtr);
ctxt->super.faces16 =
XP_MALLOC( mpool, nChars * sizeof(ctxt->super.faces16[0]));
XP_ASSERT( !!ctxt->super.faces16 );
for ( i = 0; i < nChars; ++i ) {
for ( ii = 0; ii < nChars; ++ii ) {
XP_ASSERT( ii < VSIZE(buf) );
#ifdef NODE_CAN_4
ctxt->super.faces16[i] = READ_UNALIGNED16( &facePtr[i] );
buf[ii] = READ_UNALIGNED16( &facePtr[ii] );
#else
ctxt->super.faces16[i] = facePtr[i];
buf[ii] = facePtr[ii];
#endif
}
dict_splitFaces( &ctxt->super, buf, nChars, nChars );
nSpecials = countSpecials( facePtr, nChars );
MemPtrUnlock( facePtr );
@ -310,6 +310,28 @@ palm_dictionary_make( MPFORMAL PalmAppGlobals* globals,
return NULL;
} /* palm_dictionary_make */
void
dict_splitFaces( DictionaryCtxt* dict, const XP_U8* bytes,
XP_U16 nBytes, XP_U16 nFaces )
{
XP_U16 facesLen = nFaces * 2;
XP_UCHAR* faces = XP_MALLOC( dict->mpool, facesLen );
XP_UCHAR** starts = XP_MALLOC( dict->mpool, nFaces * sizeof(starts[0]));
XP_U16 ii;
XP_UCHAR* next = faces;
for ( ii = 0; ii < nFaces; ++ii ) {
starts[ii] = next;
*next++ = *bytes++;
*next++ = '\0';
}
XP_ASSERT( next == faces + facesLen );
XP_ASSERT( !dict->faces );
dict->faces = faces;
XP_ASSERT( !dict->faceStarts );
dict->faceStarts = starts;
} /* dict_splitFaces */
static XP_U16
countSpecials( FaceType* ptr, UInt16 nChars )
{
@ -392,7 +414,8 @@ palm_dictionary_destroy( DictionaryCtxt* dict )
MemPtrUnlock( ctxt->super.countsAndValues - 2 );//sizeof(Xloc_header) );
XP_FREE( dict->mpool, ctxt->super.faces16 );
XP_FREE( dict->mpool, ctxt->super.faceStarts );
XP_FREE( dict->mpool, ctxt->super.faces );
#ifdef XWFEATURE_COMBINEDAWG
/* Try first to delete the feature. */

View file

@ -1,6 +1,7 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; compile-command: "make ARCH=ARM_ONLY MEMDEBUG=TRUE"; -*- */
/*
* Copyright 1999 - 2007 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 1999 - 2009 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -107,7 +108,7 @@ static XWBonusType palm_util_getSquareBonus( XW_UtilCtxt* uc,
const ModelCtxt* model,
XP_U16 col, XP_U16 row );
static XP_S16 palm_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
XP_U16 playerNum, const XP_UCHAR4* texts,
XP_U16 playerNum, const XP_UCHAR** texts,
XP_U16 nTiles );
static XP_Bool palm_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
XP_UCHAR* buf, XP_U16* len );
@ -3512,7 +3513,7 @@ handleKeysInBlank( EventPtr event )
static XP_S16
askBlankValue( PalmAppGlobals* globals, XP_U16 playerNum, const PickInfo* pi,
XP_U16 nTiles, const XP_UCHAR4* texts )
XP_U16 nTiles, const XP_UCHAR** texts )
{
FormPtr form, prevForm;
ListPtr lettersList;
@ -3531,7 +3532,7 @@ askBlankValue( PalmAppGlobals* globals, XP_U16 playerNum, const PickInfo* pi,
initListData( MEMPOOL &ld, nTiles );
for ( i = 0; i < nTiles; ++i ) {
addListTextItem( MEMPOOL &ld, (XP_UCHAR*)texts[i] );
addListTextItem( MEMPOOL &ld, texts[i] );
}
prevForm = FrmGetActiveForm();
@ -3767,7 +3768,7 @@ palm_util_getSquareBonus( XW_UtilCtxt* uc, const ModelCtxt* model,
static XP_S16
palm_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
XP_U16 playerNum, const XP_UCHAR4* texts,
XP_U16 playerNum, const XP_UCHAR** texts,
XP_U16 nTiles )
{
PalmAppGlobals* globals = (PalmAppGlobals*)uc->closure;

View file

@ -1,6 +1,7 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/*
* Copyright 1999-2000 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 1999-2009 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -51,6 +52,7 @@ XP_S16 palm_memcmp( XP_U8* p1, XP_U8* p2, XP_U16 nBytes );
XP_U8* palm_realloc(XP_U8* in, XP_U16 size);
#define XP_CR "\n"
#define XP_S "%s"
#define XP_RANDOM() SysRandom(0)
@ -76,6 +78,7 @@ XP_U8* palm_realloc(XP_U8* in, XP_U16 size);
#define XP_STRCMP(s1,s2) StrCompare((s1),(s2))
#define XP_STRCAT(d,s) StrCat((d),(s))
#define XP_SNPRINTF palm_snprintf
#define XP_STRNCPY( out, in, len ) StrCopy( out, in )
#define XP_MIN(a,b) ((a)<(b)?(a):(b))
#define XP_MAX(a,b) ((a)>(b)?(a):(b))