Too many changes to list. Linux works to display utf-8 dict text on

gtk and curses, but crashes when saving game (-f option.)  Wince
doesn't even compile.  This is to backup partial changes, not a
revision to build.
This commit is contained in:
ehouse 2009-03-22 23:58:22 +00:00
parent b7f32f28be
commit 2d33d47d67
46 changed files with 767 additions and 463 deletions

View file

@ -600,9 +600,8 @@ board_commitTurn( BoardCtxt* board )
const XP_UCHAR* str = util_getUserString(board->util,
STR_COMMIT_CONFIRM);
stream_putBytes( stream, (void*)str,
(XP_U16)XP_STRLEN((const char*)str) );
stream_putString( stream, str );
warn = board->util->gameInfo->phoniesAction == PHONIES_WARN;
board->badWordRejected = XP_FALSE;

View file

@ -392,7 +392,7 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks )
if ( board->showCellValues ) {
Tile valTile = isBlank? dict_getBlankTile( dict ) : tile;
XP_U16 val = dict_getTileValue( dict, valTile );
XP_SNPRINTF( ch, sizeof(ch), (XP_UCHAR*)"%d", val );
XP_SNPRINTF( ch, sizeof(ch), XP_L("%d"), val );
textP = ch;
} else {
if ( dict_faceIsBitmap( dict, tile ) ) {

View file

@ -561,7 +561,7 @@ addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP )
/* nothing to write */
break;
case COMMS_CONN_BT:
stringToStream( stream, addr.u.bt.hostName );
stream_putString( stream, addr.u.bt.hostName );
/* sizeof(.bits) below defeats ARM's padding. */
stream_putBytes( stream, &addr.u.bt.btAddr.bits,
sizeof(addr.u.bt.btAddr.bits) );
@ -570,18 +570,18 @@ addrToStream( XWStreamCtxt* stream, const CommsAddrRec* addrP )
/* nothing to save */
break;
case COMMS_CONN_IP_DIRECT:
stringToStream( stream, addr.u.ip.hostName_ip );
stream_putString( stream, addr.u.ip.hostName_ip );
stream_putU32( stream, addr.u.ip.ipAddr_ip );
stream_putU16( stream, addr.u.ip.port_ip );
break;
case COMMS_CONN_RELAY:
stringToStream( stream, addr.u.ip_relay.cookie );
stringToStream( stream, addr.u.ip_relay.hostName );
stream_putString( stream, addr.u.ip_relay.cookie );
stream_putString( stream, addr.u.ip_relay.hostName );
stream_putU32( stream, addr.u.ip_relay.ipAddr );
stream_putU16( stream, addr.u.ip_relay.port );
break;
case COMMS_CONN_SMS:
stringToStream( stream, addr.u.sms.phone );
stream_putString( stream, addr.u.sms.phone );
stream_putU16( stream, addr.u.sms.port );
break;
default:
@ -608,7 +608,7 @@ comms_writeToStream( const CommsCtxt* comms, XWStreamCtxt* stream )
stream_putU16( stream, comms->nextChannelNo );
if ( comms->addr.conType == COMMS_CONN_RELAY ) {
stream_putU8( stream, comms->r.myHostID );
stringToStream( stream, comms->r.connName );
stream_putString( stream, comms->r.connName );
}
#ifdef DEBUG
@ -680,8 +680,9 @@ comms_getInitialAddr( CommsAddrRec* addr )
addr->u.ip_relay.ipAddr = 0L; /* force 'em to set it */
addr->u.ip_relay.port = 10999;
{
char* name = RELAY_NAME_DEFAULT;
XP_MEMCPY( addr->u.ip_relay.hostName, name, XP_STRLEN(name)+1 );
const XP_UCHAR* name = XP_L(RELAY_NAME_DEFAULT);
XP_SNPRINTF( addr->u.ip_relay.hostName, VSIZE(addr->u.ip_relay.hostName),
XP_L("%s"), name );
}
addr->u.ip_relay.cookie[0] = '\0';
#elif defined PLATFORM_PALM
@ -1058,7 +1059,7 @@ relayPreProcess( CommsCtxt* comms, XWStreamCtxt* stream, XWHostID* senderID )
if ( hasName ) {
stringFromStreamHere( stream, comms->r.connName,
sizeof(comms->r.connName) );
XP_LOGF( "read connName: %s", comms->r.connName );
XP_LOGF( "read connName: " XP_LS, comms->r.connName );
} else {
XP_ASSERT( comms->r.connName[0] != '\0' );
}
@ -1529,7 +1530,7 @@ comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream )
for ( elem = comms->msgQueueHead; !!elem; elem = elem->next ) {
XP_SNPRINTF( buf, sizeof(buf),
" - channelNo=%d; msgID=" XP_LD "; len=%d\n",
XP_L(" - channelNo=%d; msgID=") XP_LD "; len=%d\n",
elem->channelNo, elem->msgID, elem->len );
stream_putString( stream, buf );
}
@ -1675,7 +1676,7 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
break;
case XWRELAY_GAME_CONNECT:
stream_putU8( tmpStream, XWRELAY_PROTO_VERSION );
stringToStream( tmpStream, addr.u.ip_relay.cookie );
stream_putString( tmpStream, addr.u.ip_relay.cookie );
stream_putU8( tmpStream, comms->r.myHostID );
stream_putU8( tmpStream, comms->r.nPlayersHere );
stream_putU8( tmpStream, comms->r.nPlayersTotal );
@ -1688,7 +1689,7 @@ send_via_relay( CommsCtxt* comms, XWRELAY_Cmd cmd, XWHostID destID,
stream_putU8( tmpStream, comms->r.myHostID );
stream_putU8( tmpStream, comms->r.nPlayersHere );
stream_putU8( tmpStream, comms->r.nPlayersTotal );
stringToStream( tmpStream, comms->r.connName );
stream_putString( tmpStream, comms->r.connName );
comms->r.relayState = COMMS_RELAYSTATE_CONNECT_PENDING;
break;

View file

@ -159,7 +159,7 @@ typedef struct CommonPrefs {
#define OFFSET_OF(typ,var) ((XP_U16)&(((typ*) 0)->var))
#ifndef RELAY_NAME_DEFAULT
# define RELAY_NAME_DEFAULT "eehouse.org"
# define RELAY_NAME_DEFAULT XP_L("eehouse.org")
#endif
#ifdef MEM_DEBUG

View file

@ -37,14 +37,15 @@ extern "C" {
void
setBlankTile( DictionaryCtxt* dctx )
{
XP_U16 i;
XP_U16 ii;
dctx->blankTile = -1; /* no known blank */
for ( i = 0; i < dctx->nFaces; ++i ) {
if ( dctx->faces16[i] == 0 ) {
for ( ii = 0; ii < dctx->nFaces; ++ii ) {
XP_U16 index = dctx->faceIndices[ii];
if ( dctx->faces[index] == 0 ) {
XP_ASSERT( dctx->blankTile == -1 ); /* only one passes test? */
dctx->blankTile = (XP_S8)i;
dctx->blankTile = (XP_S8)ii;
#ifndef DEBUG
break;
#endif
@ -79,12 +80,13 @@ dict_getTileValue( const DictionaryCtxt* dict, Tile tile )
return dict->countsAndValues[tile+1];
} /* dict_getTileValue */
static XP_UCHAR
static const XP_UCHAR*
dict_getTileChar( const DictionaryCtxt* dict, Tile tile )
{
XP_ASSERT( tile < dict->nFaces );
XP_ASSERT( (dict->faces16[tile] & 0xFF00) == 0 ); /* no unicode yet */
return (XP_UCHAR)dict->faces16[tile];
/* XP_ASSERT( (dict->faces[tile] & 0xFF00) == 0 ); /\* no unicode yet *\/ */
XP_U16 index = dict->faceIndices[tile];
return &dict->faces[index];
} /* dict_getTileValue */
XP_U16
@ -110,10 +112,11 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles,
while ( nTiles-- ) {
Tile tile = *tiles++;
XP_UCHAR face = dict_getTileChar(ctxt, tile);
/* XP_U16 index = ctxt->faceIndices[tile]; */
const XP_UCHAR* facep = dict_getTileChar( ctxt, tile );
if ( IS_SPECIAL(face) ) {
XP_UCHAR* chars = ctxt->chars[(XP_U16)face];
if ( IS_SPECIAL(*facep) ) {
XP_UCHAR* chars = ctxt->chars[(XP_U16)*facep];
XP_U16 len = XP_STRLEN( chars );
if ( bufp + len >= end ) {
bufp = NULL;
@ -129,7 +132,8 @@ dict_tilesToString( const DictionaryCtxt* ctxt, const Tile* tiles,
bufp = NULL;
break;
}
*bufp++ = face;
bufp += XP_SNPRINTF( bufp, end - bufp, XP_LS, facep );
/* *bufp++ = face; */
}
}
@ -145,16 +149,16 @@ dict_tileForString( const DictionaryCtxt* dict, const XP_UCHAR* key )
{
XP_U16 nFaces = dict_numTileFaces( dict );
Tile tile;
XP_Bool keyNotSpecial = XP_STRLEN((char*)key) == 1;
XP_Bool keyNotSpecial = XP_STRLEN(key) == 1;
for ( tile = 0; tile < nFaces; ++tile ) {
XP_UCHAR face = dict_getTileChar( dict, tile );
if ( IS_SPECIAL(face) ) {
XP_UCHAR* chars = dict->chars[(XP_U16)face];
const XP_UCHAR* facep = dict_getTileChar( dict, tile );
if ( IS_SPECIAL(*facep) ) {
XP_UCHAR* chars = dict->chars[(XP_U16)*facep];
if ( 0 == XP_STRNCMP( chars, key, XP_STRLEN(chars) ) ) {
return tile;
}
} else if ( keyNotSpecial && (face == *key) ) {
} else if ( keyNotSpecial && (0 == XP_STRCMP(facep, key) ) ) {
return tile;
}
}
@ -172,7 +176,8 @@ dict_tilesAreSame( const DictionaryCtxt* dict1, const DictionaryCtxt* dict2 )
if ( nTileFaces == dict_numTileFaces( dict2 ) ) {
for ( i = 0; i < nTileFaces; ++i ) {
XP_UCHAR face1, face2;
const XP_UCHAR* face1;
const XP_UCHAR* face2;
if ( dict_getTileValue( dict1, i )
!= dict_getTileValue( dict2, i ) ){
@ -246,13 +251,14 @@ dict_writeToStream( const DictionaryCtxt* dict, XWStreamCtxt* stream )
}
for ( i = 0; i < dict->nFaces; ++i ) {
stream_putU8( stream, (XP_U8)dict->faces16[i] );
XP_U16 index = dict->faceIndices[i];
stream_putString( stream, &dict->faces[index] );
}
for ( nSpecials = i = 0; i < dict->nFaces; ++i ) {
XP_UCHAR face = dict_getTileChar( dict, (Tile)i );
if ( IS_SPECIAL( face ) ) {
stringToStream( stream, dict->chars[nSpecials++] );
const XP_UCHAR* facep = dict_getTileChar( dict, (Tile)i );
if ( IS_SPECIAL( *facep ) ) {
stream_putString( stream, dict->chars[nSpecials++] );
}
}
} /* dict_writeToStream */
@ -264,8 +270,8 @@ freeSpecials( DictionaryCtxt* dict )
XP_U16 nSpecials;
for ( nSpecials = t = 0; t < dict->nFaces; ++t ) {
XP_UCHAR face = dict_getTileChar( dict, t );
if ( IS_SPECIAL( face ) ) {
XP_UCHAR* facep = dict_getTileChar( dict, t );
if ( IS_SPECIAL( *facep ) ) {
XP_ASSERT( !!dict->chars[nSpecials] );
XP_FREE( dict->mpool, dict->chars[nSpecials] );
@ -292,14 +298,19 @@ common_destructor( DictionaryCtxt* dict )
freeSpecials( dict );
XP_FREE( dict->mpool, dict->countsAndValues );
XP_FREE( dict->mpool, dict->faces16 );
XP_FREE( dict->mpool, dict->faces );
XP_FREE( dict->mpool, dict->faceIndices );
XP_FREE( dict->mpool, dict );
} /* dict */
#endif
void
dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
dict_loadFromStream( DictionaryCtxt* XP_UNUSED(dict),
XWStreamCtxt* XP_UNUSED(stream) )
{
XP_ASSERT(0);
XP_U8 nFaces;
XP_U16 maxCountBits, maxValueBits;
XP_U16 i, nSpecials;
@ -325,9 +336,8 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
dict->countsAndValues[i+1] = (XP_U8)stream_getBits( stream,
maxValueBits );
}
dict->faces16 = (XP_CHAR16*)XP_MALLOC( dict->mpool,
sizeof(dict->faces16[0]) * nFaces );
dict->faces = (XP_CHAR16*)XP_MALLOC( dict->mpool,
sizeof(dict->faces[0]) * nFaces );
for ( i = 0; i < dict->nFaces; ++i ) {
dict->faces16[i] = (XP_CHAR16)stream_getU8( stream );
}
@ -352,7 +362,6 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream )
nSpecials * sizeof(*dict->chars) );
XP_MEMCPY(dict->chars, localTexts, nSpecials * sizeof(*dict->chars));
}
setBlankTile( dict );
} /* dict_loadFromStream */
@ -367,20 +376,20 @@ dict_getName( const DictionaryCtxt* dict )
XP_Bool
dict_faceIsBitmap( const DictionaryCtxt* dict, Tile tile )
{
XP_UCHAR face = dict_getTileChar( dict, tile );
return IS_SPECIAL(face);
const XP_UCHAR* facep = dict_getTileChar( dict, tile );
return IS_SPECIAL(*facep);
} /* dict_faceIsBitmap */
void
dict_getFaceBitmaps( const DictionaryCtxt* dict, Tile tile, XP_Bitmaps* bmps )
{
SpecialBitmaps* bitmaps;
XP_UCHAR face = dict_getTileChar( dict, tile );
const XP_UCHAR* facep = dict_getTileChar( dict, tile );
XP_ASSERT( dict_faceIsBitmap( dict, tile ) );
XP_ASSERT( !!dict->bitmaps );
bitmaps = &dict->bitmaps[(XP_U16)face];
bitmaps = &dict->bitmaps[(XP_U16)*facep];
bmps->nBitmaps = 2;
bmps->bmps[0] = bitmaps->smallBM;
bmps->bmps[1] = bitmaps->largeBM;

View file

@ -1,6 +1,7 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/*
* Copyright 1997 - 2000 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
@ -31,12 +32,12 @@ extern "C" {
#endif
#define LETTER_NONE '\0'
#define IS_SPECIAL(face) (((XP_CHAR16)(face)) < 0x0020)
/* face is a XP_UCHAR, which is signed on some platforms (f*cking glib) and
might be 4 bytes on others. So cast it in the safest way (I hope.) */
#define IS_SPECIAL(face) (((XP_U32)(face)) < 0x0020)
typedef XP_U8 XP_LangCode;
typedef XP_U16 XP_CHAR16;
typedef enum {
BONUS_NONE,
BONUS_DOUBLE_LETTER,
@ -64,7 +65,8 @@ typedef struct _XP_Bitmaps {
struct DictionaryCtxt {
void (*destructor)( DictionaryCtxt* dict );
array_edge* (*func_edge_for_index)( const DictionaryCtxt* dict, XP_U32 index );
array_edge* (*func_edge_for_index)( const DictionaryCtxt* dict,
XP_U32 index );
array_edge* (*func_dict_getTopEdge)( const DictionaryCtxt* dict );
const XP_UCHAR* (*func_dict_getShortName)( const DictionaryCtxt* dict );
@ -72,7 +74,8 @@ struct DictionaryCtxt {
array_edge* base; /* the physical beginning of the dictionary; not
necessarily the entry point for search!! */
XP_UCHAR* name;
XP_CHAR16* faces16; /* 16 for unicode */
XP_UCHAR* faces;
XP_U16* faceIndices;
XP_U8* countsAndValues;
SpecialBitmaps* bitmaps;
@ -89,6 +92,7 @@ struct DictionaryCtxt {
#endif
XP_S8 blankTile; /* negative means there's no known blank */
XP_Bool isUTF8;
#ifdef DEBUG
XP_U32 numEdges;
#endif

View file

@ -459,7 +459,7 @@ gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi )
const LocalPlayer* pl;
XP_U16 i;
stringToStream( stream, gi->dictName );
stream_putString( stream, gi->dictName );
stream_putBits( stream, NPLAYERS_NBITS, gi->nPlayers );
stream_putBits( stream, 4, gi->boardSize );
@ -478,8 +478,8 @@ gi_writeToStream( XWStreamCtxt* stream, const CurGameInfo* gi )
}
for ( pl = gi->players, i = 0; i < gi->nPlayers; ++pl, ++i ) {
stringToStream( stream, pl->name );
stringToStream( stream, pl->password );
stream_putString( stream, pl->name );
stream_putString( stream, pl->password );
stream_putU16( stream, pl->secondsUsed );
stream_putBits( stream, 1, pl->isRobot );
stream_putBits( stream, 1, pl->isLocal );

View file

@ -272,7 +272,7 @@ mpool_stats( MemPoolCtx* mpool, XWStreamCtxt* stream )
total += entry->size;
}
XP_SNPRINTF( buf, sizeof(buf), "total bytes allocated: %ld\n", total );
XP_SNPRINTF( buf, sizeof(buf), XP_L("total bytes allocated: %ld\n"), total );
STREAM_OR_LOG( stream, buf );
} /* mpool_stats */

View file

@ -117,6 +117,17 @@ mem_stream_getU8( XWStreamCtxt* p_sctx )
return result;
} /* mem_stream_getU8 */
static XP_U16
mem_stream_getString( XWStreamCtxt* p_sctx, XP_UCHAR* where, XP_U16 whereLen )
{
XP_U16 len = mem_stream_getU8( p_sctx );
XP_U8 bytes[len * sizeof(XP_U8)];
mem_stream_getBytes( p_sctx, bytes, len );
XP_NARROW_TO_UCHAR( bytes, where, len, &whereLen );
return whereLen;
}
static XP_U16
mem_stream_getU16( XWStreamCtxt* p_sctx )
{
@ -215,9 +226,17 @@ mem_stream_putBytes( XWStreamCtxt* p_sctx, const void* whence,
} /* mem_stream_putBytes */
static void
mem_stream_putString( XWStreamCtxt* p_sctx, const char* whence )
mem_stream_putString( XWStreamCtxt* p_sctx, const XP_UCHAR* whence )
{
XP_U16 len = XP_STRLEN( whence );
XP_U16 wlen = 0;
XP_U16 len = 0x00FF;
XP_U8 bytes[0xFF];
if ( !!whence ) {
wlen = XP_STRLEN( whence );
}
XP_UCHAR_TO_NARROW( whence, bytes, wlen, &len );
mem_stream_putBytes( p_sctx, (void*)whence, len );
}
@ -432,6 +451,7 @@ make_vtable( MemStreamCtxt* stream )
SET_VTABLE_ENTRY( vtable, stream_getU8, mem );
SET_VTABLE_ENTRY( vtable, stream_getBytes, mem );
SET_VTABLE_ENTRY( vtable, stream_getString, mem );
SET_VTABLE_ENTRY( vtable, stream_getU16, mem );
SET_VTABLE_ENTRY( vtable, stream_getU32, mem );
SET_VTABLE_ENTRY( vtable, stream_getBits, mem );

View file

@ -1513,7 +1513,7 @@ printMovePre( ModelCtxt* model, XP_U16 XP_UNUSED(moveN), StackEntry* entry,
if ( isPass ) {
format = util_getUserString( model->vol.util, STR_PASS );
XP_SNPRINTF( buf, sizeof(buf), "%s", format );
XP_SNPRINTF( buf, VSIZE(buf), XP_L("%s"), format );
} else {
if ( isHorizontal ) {
format = util_getUserString( model->vol.util, STRS_MOVE_ACROSS );

View file

@ -1160,7 +1160,7 @@ bwiToStream( XWStreamCtxt* stream, BadWordInfo* bwi )
stream_putBits( stream, 4, nWords );
for ( sp = bwi->words; nWords > 0; --nWords, ++sp ) {
stringToStream( stream, *sp );
stream_putString( stream, *sp );
}
} /* bwiToStream */
@ -1618,7 +1618,7 @@ storeBadWords( XP_UCHAR* word, void* closure )
{
ServerCtxt* server = (ServerCtxt*)closure;
XP_STATUSF( "storeBadWords called with \"%s\"", word );
XP_STATUSF( "storeBadWords called with \"" XP_LS "\"", word );
server->illegalWordInfo.words[server->illegalWordInfo.nWords++]
= copyString( server->mpool, word );
@ -2422,7 +2422,7 @@ server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
break;
} else if ( count > 0 ) {
if ( ++nPrinted % nCols == 0 ) {
stream_putString( stream, XP_CR );
stream_putString( stream, XP_L(XP_CR) );
} else {
stream_putString( stream, (void*)" " );
}
@ -2469,7 +2469,7 @@ server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
if ( --count == 0 ) {
break;
}
stream_putString( stream, "." );
stream_putString( stream, XP_L(".") );
}
}
@ -2524,7 +2524,7 @@ server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )
if ( highestIndex == -1 ) {
break; /* we're done */
} else if ( place > 1 ) {
stream_putString( stream, XP_CR );
stream_putString( stream, XP_L(XP_CR) );
}
scores.arr[highestIndex] = IMPOSSIBLY_LOW_SCORE;

View file

@ -123,27 +123,20 @@ p_stringFromStream( MPFORMAL XWStreamCtxt* stream
XP_U16
stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 buflen )
{
XP_U16 len = stream_getU8( stream );
if ( len > 0 ) {
XP_ASSERT( len < buflen );
if ( len >= buflen ) {
/* better to leave stream in bad state than overwrite stack */
len = buflen - 1;
}
stream_getBytes( stream, buf, len );
}
XP_U16 len = stream_getString( stream, buf, buflen );
XP_ASSERT( len < buflen );
buf[len] = '\0';
return len;
}
void
stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str )
{
XP_U16 len = str==NULL? 0: XP_STRLEN( (const char*)str );
XP_ASSERT( len < 0xFF );
stream_putU8( stream, (XP_U8)len );
stream_putBytes( stream, str, len );
} /* putStringToStream */
/* void */
/* stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str ) */
/* { */
/* XP_U16 len = str==NULL? 0: XP_STRLEN( str ); */
/* XP_ASSERT( len < 0xFF ); */
/* stream_putU8( stream, (XP_U8)len ); */
/* stream_putBytes( stream, str, len ); */
/* } /\* putStringToStream *\/ */
/*****************************************************************************
*
@ -157,7 +150,7 @@ p_copyString( MPFORMAL const XP_UCHAR* instr
{
XP_UCHAR* result = (XP_UCHAR*)NULL;
if ( !!instr ) {
XP_U16 len = 1 + XP_STRLEN( (const char*)instr );
XP_U16 len = 1 + XP_STRLEN( instr );
#ifdef MEM_DEBUG
result = mpool_alloc( mpool, len, file, func, lineNo );
#else
@ -237,7 +230,7 @@ randIntArray( XP_U16* rnums, XP_U16 count )
* implementations it's needed for messages to be cross-platform.
*/
static const XP_UCHAR*
static const char*
getSMSTable( void )
{
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@ -245,7 +238,7 @@ getSMSTable( void )
#define PADCHAR '='
static void
bitsToChars( const XP_U8* bytesIn, XP_U16 nValidBytes, XP_UCHAR* out,
bitsToChars( const XP_U8* bytesIn, XP_U16 nValidBytes, XP_U8* out,
XP_U16* outlen )
{
XP_U16 nValidSextets = ((nValidBytes * 8) + 5) / 6; /* +5: round up */
@ -261,7 +254,7 @@ bitsToChars( const XP_U8* bytesIn, XP_U16 nValidBytes, XP_UCHAR* out,
/* bottom six bits of third */
bits[3] = local[2] & 0x3F;
const XP_UCHAR* table = getSMSTable();
const char* table = getSMSTable();
XP_U16 ii;
for ( ii = 0; ii < 4; ++ii ) {
@ -277,7 +270,7 @@ bitsToChars( const XP_U8* bytesIn, XP_U16 nValidBytes, XP_UCHAR* out,
} /* bitsToChars */
void
binToSms( XP_UCHAR* out, XP_U16* outlenp, const XP_U8* in, const XP_U16 inlen )
binToSms( XP_U8* out, XP_U16* outlenp, const XP_U8* in, const XP_U16 inlen )
{
XP_U16 inConsumed;
XP_U16 outlen = 0;
@ -308,7 +301,7 @@ findRank( XP_UCHAR ch )
if ( ch == PADCHAR ) {
rank = 0;
} else {
const XP_UCHAR* table = getSMSTable();
const char* table = getSMSTable();
for ( rank = 0; rank < 64; ++rank ) {
if ( table[rank] == ch ) {
break;
@ -325,11 +318,11 @@ findRank( XP_UCHAR ch )
* Also, need to check there's space before writing! PENDING
*/
XP_Bool
smsToBin( XP_U8* out, XP_U16* outlenp, const XP_UCHAR* sms, XP_U16 smslen )
smsToBin( XP_U8* out, XP_U16* outlenp, const XP_U8* sms, XP_U16 smslen )
{
const XP_UCHAR* inptr;
const XP_U8* inptr;
XP_U8* outptr = out;
const XP_UCHAR* smsend = sms + smslen;
const XP_U8* smsend = sms + smslen;
XP_U8 ch, rank;
XP_U8 last[2];
unsigned int vv = 0;
@ -374,11 +367,11 @@ log_hex( const XP_U8* memp, XP_U16 len, const char* tag )
XP_U16 offset = 0;
while ( offset < len ) {
XP_UCHAR buf[128];
XP_UCHAR vals[NUM_PER_LINE*3];
XP_UCHAR* valsp = vals;
XP_UCHAR chars[NUM_PER_LINE+1];
XP_UCHAR* charsp = chars;
char buf[128];
char vals[NUM_PER_LINE*3];
char* valsp = vals;
char chars[NUM_PER_LINE+1];
char* charsp = chars;
XP_U16 oldOffset = offset;
for ( i = 0; i < NUM_PER_LINE && offset < len; ++i ) {
@ -406,7 +399,7 @@ log_hex( const XP_U8* memp, XP_U16 len, const char* tag )
if ( (NULL == tag) || (XP_STRLEN(tag) + sizeof(vals) >= sizeof(buf)) ) {
tag = "<tag>";
}
XP_SNPRINTF( buf, sizeof(buf), "%s[%d]: %s %s", tag, oldOffset,
XP_SNPRINTF( buf, VSIZE(buf), "%s[%d]: %s %s", tag, oldOffset,
vals, chars );
XP_LOGF( "%s", buf );
}

View file

@ -52,7 +52,7 @@ XP_UCHAR* p_stringFromStream( MPFORMAL XWStreamCtxt* stream
#endif
XP_U16 stringFromStreamHere( XWStreamCtxt* stream, XP_UCHAR* buf, XP_U16 len );
void stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str );
/* void stringToStream( XWStreamCtxt* stream, const XP_UCHAR* str ); */
XP_UCHAR* p_copyString( MPFORMAL const XP_UCHAR* instr
#ifdef MEM_DEBUG
@ -87,8 +87,8 @@ XP_UCHAR* emptyStringIfNull( XP_UCHAR* str );
XP_Bool randIntArray( XP_U16* rnums, XP_U16 count );
#ifdef XWFEATURE_SMS
void binToSms( XP_UCHAR* out, XP_U16* outlen, const XP_U8* in, XP_U16 inlen );
XP_Bool smsToBin( XP_U8* out, XP_U16* outlen, const XP_UCHAR* in, XP_U16 inlen );
void binToSms( XP_U8* out, XP_U16* outlen, const XP_U8* in, XP_U16 inlen );
XP_Bool smsToBin( XP_U8* out, XP_U16* outlen, const XP_U8* in, XP_U16 inlen );
#endif
#ifdef DEBUG

View file

@ -45,6 +45,8 @@ typedef struct StreamCtxVTable {
XP_U8 (*m_stream_getU8)( XWStreamCtxt* dctx );
void (*m_stream_getBytes)( XWStreamCtxt* dctx, void* where,
XP_U16 count );
XP_U16 (*m_stream_getString)( XWStreamCtxt* dctx, XP_UCHAR* where,
XP_U16 nChars );
XP_U16 (*m_stream_getU16)( XWStreamCtxt* dctx );
XP_U32 (*m_stream_getU32)( XWStreamCtxt* dctx );
XP_U32 (*m_stream_getBits)( XWStreamCtxt* dctx, XP_U16 nBits );
@ -52,7 +54,7 @@ typedef struct StreamCtxVTable {
void (*m_stream_putU8)( XWStreamCtxt* dctx, XP_U8 byt );
void (*m_stream_putBytes)( XWStreamCtxt* dctx, const void* whence,
XP_U16 count );
void (*m_stream_putString)( XWStreamCtxt* dctx, const char* whence );
void (*m_stream_putString)( XWStreamCtxt* dctx, const XP_UCHAR* whence );
void (*m_stream_putU16)( XWStreamCtxt* dctx, XP_U16 data );
void (*m_stream_putU32)( XWStreamCtxt* dctx, XP_U32 data );
void (*m_stream_putBits)( XWStreamCtxt* dctx, XP_U16 nBits, XP_U32 bits
@ -98,6 +100,9 @@ struct XWStreamCtxt {
#define stream_getBytes(sc, wh, c ) \
(sc)->vtable->m_stream_getBytes((sc), (wh), (c))
#define stream_getString(sc, wh, c) \
(sc)->vtable->m_stream_getString((sc), (wh), (c))
#define stream_getU16(sc) \
(sc)->vtable->m_stream_getU16(sc)

View file

@ -35,6 +35,11 @@ DO_GTK = -DPLATFORM_GTK
# uncomment for standalone build
# STANDALONE = -DXWFEATURE_STANDALONE_ONLY
UNICODE ?= -DXWFEATURE_UNICODE
ifdef UNICODE
CFLAGS += -std=gnu99
endif
SVN_REV ?= "$(shell svnversion -n .)"
SVNDEF = -D'SVN_REV=$(SVN_REV)'
@ -78,6 +83,7 @@ endif
ifdef CURSES_CELL_WIDTH
DEFINES += -DCURSES_CELL_WIDTH=$(CURSES_CELL_WIDTH)
endif
DEFINES += $(UNICODE)
# Networking-related features. Only set these if STANDALONE is not set
ifeq ($(STANDALONE),)
@ -152,7 +158,7 @@ OBJ = \
$(PLATFORM)/linuxutl.o \
$(CURSES_OBJS) $(GTK_OBJS) $(MAIN_OBJS)
LIBS = -lm -lmcheck $(GPROFFLAG)
LIBS = -lm -lrt -lmcheck $(GPROFFLAG)
ifdef BLUETOOTH
LIBS += -lbluetooth
endif
@ -167,7 +173,7 @@ endif
CFLAGS += $(POINTER_SUPPORT)
ifneq (,$(findstring DPLATFORM_NCURSES,$(DEFINES)))
LIBS += $(OE_LIBDIR) -lncurses
LIBS += $(OE_LIBDIR) -lncursesw
endif
# provides an all: target

View file

@ -227,13 +227,12 @@ curses_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* XP_UNUSED(pi),
XP_U16 nTiles )
{
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
char query[128];
XP_UCHAR query[128];
XP_S16 index;
char* playerName = globals->cGlobals.params->gi.players[playerNum].name;
XP_UCHAR* playerName = globals->cGlobals.params->gi.players[playerNum].name;
snprintf( query, sizeof(query),
"Pick tile for %s! (Tab or type letter to select "
"then hit <cr>.)", playerName );
XP_SNPRINTF( query, VSIZE(query),
XP_L(Pick tile for %s! (Tab or type letter to select then hit <cr>.)), playerName );
index = curses_askLetter( globals, query, texts, nTiles );
return index;
@ -244,7 +243,7 @@ curses_util_userError( XW_UtilCtxt* uc, UtilErrID id )
{
CursesAppGlobals* globals = (CursesAppGlobals*)uc->closure;
XP_Bool silent;
const XP_UCHAR* message = linux_getErrString( id, &silent );
const char* message = linux_getErrString( id, &silent );
if ( silent ) {
XP_LOGF( "silent userError: %s", message );

View file

@ -24,12 +24,12 @@
#include "gtkask.h"
XP_Bool
gtkask( const gchar *message, GtkButtonsType buttons )
gtkask( const XP_UCHAR *message, GtkButtonsType buttons )
{
GtkWidget* dlg = gtk_message_dialog_new( NULL, /* parent */
GTK_MESSAGE_QUESTION,
GTK_DIALOG_MODAL,
buttons, "%s", message );
buttons, XP_LS, message );
gint response = gtk_dialog_run( GTK_DIALOG(dlg) );
gtk_widget_destroy( dlg );
return response == GTK_RESPONSE_OK || response == GTK_RESPONSE_YES;

View file

@ -27,7 +27,7 @@
/* Returns true for "yes" or "ok" answer, false otherwise.
*/
XP_Bool gtkask( const gchar *message, GtkButtonsType buttons );
XP_Bool gtkask( const XP_UCHAR *message, GtkButtonsType buttons );
#endif
#endif /* PLATFORM_GTK */

View file

@ -191,7 +191,7 @@ layout_for_ht( GtkDrawCtx* dctx, XP_U16 ht )
static void
draw_string_at( GtkDrawCtx* dctx, PangoLayout* layout,
const char* str, XP_U16 fontHt,
const XP_UCHAR* str, XP_U16 fontHt,
const XP_Rect* where, XP_GTK_JUST just,
const GdkColor* frground, const GdkColor* bkgrnd )
{
@ -202,7 +202,7 @@ draw_string_at( GtkDrawCtx* dctx, PangoLayout* layout,
layout = layout_for_ht( dctx, fontHt );
}
pango_layout_set_text( layout, str, strlen(str) );
pango_layout_set_text( layout, (char*)str, XP_STRLEN(str) );
if ( just != XP_GTK_JUST_NONE ) {
int width, height;
@ -466,7 +466,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
}
}
if ( (flags & CELL_ISSTAR) != 0 ) {
draw_string_at( dctx, NULL, "*", rect->height, rect,
draw_string_at( dctx, NULL, XP_L(*), rect->height, rect,
XP_GTK_JUST_CENTER, &dctx->black, NULL );
}
} else if ( !!bitmaps ) {
@ -577,8 +577,8 @@ gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP,
}
if ( !valHidden ) {
sprintf( numbuf, "%d", val );
len = strlen( numbuf );
XP_SNPRINTF( numbuf, VSIZE(numbuf), XP_L(%d), val );
len = XP_STRLEN( numbuf );
draw_string_at( dctx, NULL, numbuf, formatRect.height>>2,
&formatRect, XP_GTK_JUST_BOTTOMRIGHT,
@ -638,7 +638,7 @@ gtk_draw_drawTileBack( DrawCtx* p_dctx, const XP_Rect* rect,
gtkInsetRect( &r, 1 );
gtkFillRect( dctx, &r, hasCursor? &dctx->cursor : &dctx->tileBack );
draw_string_at( dctx, NULL, "?", r.height,
draw_string_at( dctx, NULL, XP_L(?), r.height,
&r, XP_GTK_JUST_CENTER,
&dctx->playerColors[dctx->trayOwner], NULL );
@ -690,7 +690,7 @@ gtk_draw_drawBoardArrow( DrawCtx* p_dctx, const XP_Rect* rectP,
HintAtts hintAtts, CellFlags XP_UNUSED(flags) )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
const char* curs = vertical? "|":"-";
const XP_UCHAR* curs = vertical? XP_L(|):XP_L(-);
/* font needs to be small enough that "|" doesn't overwrite cell below */
draw_string_at( dctx, NULL, curs, (rectP->height*2)/3,
@ -712,16 +712,16 @@ gtk_draw_scoreBegin( DrawCtx* p_dctx, const XP_Rect* rect,
} /* gtk_draw_scoreBegin */
static PangoLayout*
getLayoutToFitRect( GtkDrawCtx* dctx, const char* str, const XP_Rect* rect )
getLayoutToFitRect( GtkDrawCtx* dctx, const XP_UCHAR* str, const XP_Rect* rect )
{
PangoLayout* layout;
float ratio, ratioH;
int width, height;
XP_U16 len = strlen(str);
XP_U16 len = XP_STRLEN(str);
/* First measure it using any font at all */
layout = layout_for_ht( dctx, 24 );
pango_layout_set_text( layout, str, len );
pango_layout_set_text( layout, (char*)str, len );
pango_layout_get_pixel_size( layout, &width, &height );
/* Figure the ratio of is to should-be. The smaller of these is the one
@ -734,7 +734,7 @@ getLayoutToFitRect( GtkDrawCtx* dctx, const char* str, const XP_Rect* rect )
height = 24.0 * ratio;
layout = layout_for_ht( dctx, height );
pango_layout_set_text( layout, str, len );
pango_layout_set_text( layout, (char*)str, len );
return layout;
} /* getLayoutToFitRect */
@ -743,10 +743,10 @@ gtkDrawDrawRemText( DrawCtx* p_dctx, const XP_Rect* rect, XP_S16 nTilesLeft,
XP_U16* widthP, XP_U16* heightP, XP_Bool focussed )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
char buf[10];
XP_UCHAR buf[10];
PangoLayout* layout;
snprintf( buf, sizeof(buf), "rem:%d", nTilesLeft );
XP_SNPRINTF( buf, sizeof(buf), XP_L(rem:%d), nTilesLeft );
layout = getLayoutToFitRect( dctx, buf, rect );
if ( !!widthP ) {
@ -792,7 +792,7 @@ gtk_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner,
} /* gtk_draw_drawRemText */
static void
formatScoreText( char* buf, XP_U16 bufLen, const DrawScoreInfo* dsi )
formatScoreText( XP_UCHAR* buf, XP_U16 bufLen, const DrawScoreInfo* dsi )
{
XP_S16 score = dsi->totalScore;
XP_U16 nTilesLeft = dsi->nTilesLeft;
@ -804,13 +804,13 @@ formatScoreText( char* buf, XP_U16 bufLen, const DrawScoreInfo* dsi )
borders = "*";
}
used = snprintf( buf, bufLen, "%s%.3d", borders, score );
used = XP_SNPRINTF( buf, bufLen, XP_L(%s%.3d), borders, score );
if ( (nTilesLeft < MAX_TRAY_TILES) && (nTilesLeft > 0) ) {
char nbuf[10];
sprintf( nbuf, ":%d", nTilesLeft );
(void)strcat( buf, nbuf );
XP_UCHAR nbuf[10];
XP_SNPRINTF( nbuf, VSIZE(nbuf), XP_L(:%d), nTilesLeft );
(void)XP_STRCAT( buf, nbuf );
}
snprintf( buf+used, bufLen-used, "%s", borders );
XP_SNPRINTF( buf+used, bufLen-used, XP_L(%s), borders );
} /* formatScoreText */
static void
@ -819,11 +819,11 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
XP_U16* widthP, XP_U16* heightP )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
char buf[20];
XP_UCHAR buf[20];
PangoLayout* layout;
int height, width;
formatScoreText( buf, sizeof(buf), dsi );
formatScoreText( buf, VSIZE(buf), dsi );
layout = getLayoutToFitRect( dctx, buf, bounds );
pango_layout_get_pixel_size( layout, &width, &height );
@ -836,11 +836,11 @@ gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
const XP_Rect* rOuter, const DrawScoreInfo* dsi )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
char scoreBuf[20];
XP_UCHAR scoreBuf[20];
XP_Bool hasCursor = (dsi->flags & CELL_ISCURSOR) != 0;
GdkColor* cursor = NULL;
formatScoreText( scoreBuf, sizeof(scoreBuf), dsi );
formatScoreText( scoreBuf, VSIZE(scoreBuf), dsi );
if ( hasCursor ) {
cursor = &dctx->cursor;
@ -874,16 +874,16 @@ gtk_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect,
CellFlags flags )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
char buf[5];
XP_UCHAR buf[5];
XP_U16 ht;
XP_Rect localR;
GdkColor* cursor = ((flags & CELL_ISCURSOR) != 0)
? &dctx->cursor : NULL;
if ( score >= 0 ) {
sprintf( buf, "%.3d", score );
XP_SNPRINTF( buf, VSIZE(buf), XP_L(%.3d), score );
} else {
strcpy( buf, "???" );
XP_STRNCPY( buf, XP_L(\?\?\?), VSIZE(buf) );
}
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */
@ -898,7 +898,7 @@ gtk_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect,
}
ht = localR.height >> 2;
draw_string_at( dctx, NULL, "Pts:", ht,
draw_string_at( dctx, NULL, XP_L(Pts:), ht,
&localR, XP_GTK_JUST_TOPLEFT,
&dctx->black, cursor );
draw_string_at( dctx, NULL, buf, ht,
@ -919,7 +919,7 @@ gtkFormatTimerText( XP_UCHAR* buf, XP_S16 secondsLeft )
minutes = secondsLeft / 60;
seconds = secondsLeft % 60;
sprintf( buf, "% 1d:%02d", minutes, seconds );
XP_SNPRINTF( buf, VSIZE(buf), XP_L(% 1d:%02d), minutes, seconds );
} /* gtkFormatTimerText */
static void
@ -951,15 +951,15 @@ gtk_draw_getMiniWText( DrawCtx* XP_UNUSED(p_dctx), XWMiniTextType textHint )
switch( textHint ) {
case BONUS_DOUBLE_LETTER:
str = "Double letter"; break;
str = XP_L(Double letter); break;
case BONUS_DOUBLE_WORD:
str = "Double word"; break;
str = XP_L(Double word); break;
case BONUS_TRIPLE_LETTER:
str = "Triple letter"; break;
str = XP_L(Triple letter); break;
case BONUS_TRIPLE_WORD:
str = "Triple word"; break;
str = XP_L(Triple word); break;
case INTRADE_MW_TEXT:
str = "Trading tiles;\nclick D when done"; break;
str = XP_L(Trading tiles;\nclick D when done); break;
default:
XP_ASSERT( XP_FALSE );
}
@ -974,7 +974,7 @@ gtk_draw_measureMiniWText( DrawCtx* p_dctx, const XP_UCHAR* str,
int height, width;
PangoLayout* layout = layout_for_ht( dctx, GTKMIN_W_HT );
pango_layout_set_text( layout, str, strlen(str) );
pango_layout_set_text( layout, (char*)str, XP_STRLEN(str) );
pango_layout_get_pixel_size( layout, &width, &height );
*heightP = height;
*widthP = width + 6;

View file

@ -50,28 +50,33 @@ gtkletterask( XP_Bool forBlank, XP_UCHAR* name,
XP_Bool results[MAX_UNIQUE_TILES];
GtkWidget* vbox;
GtkWidget* hbox = NULL;
char* txt;
XP_S16 i;
gchar* txt;
XP_S16 ii;
GtkWidget* button;
XP_UCHAR buf[64];
gchar buf[64];
XP_MEMSET( results, 0, sizeof(results) );
vbox = gtk_vbox_new( FALSE, 0 );
for ( i = 0; i < nTiles; ++i ) {
for ( ii = 0; ii < nTiles; ++ii ) {
if ( i % BUTTONS_PER_ROW == 0 ) {
if ( ii % BUTTONS_PER_ROW == 0 ) {
hbox = gtk_hbox_new( FALSE, 0 );
}
button = gtk_button_new_with_label( texts[i] );
/* gchar tmp[XP_STRLEN(texts[ii])]; */
/* const XP_UCHAR* src = texts[ii]; */
/* mbstate_t ps = {0}; */
/* wcsrtombs( tmp, &src, sizeof(tmp), &ps ); */
button = gtk_button_new_with_label( texts[ii] );
gtk_box_pack_start( GTK_BOX(hbox), button, FALSE, TRUE, 0 );
g_signal_connect( GTK_OBJECT(button), "clicked",
G_CALLBACK(button_event), &results[i] );
G_CALLBACK(button_event), &results[ii] );
gtk_widget_show( button );
if ( i+1 == nTiles || (i % BUTTONS_PER_ROW == 0) ) {
if ( ii+1 == nTiles || (ii % BUTTONS_PER_ROW == 0) ) {
gtk_widget_show( hbox );
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
}
@ -97,8 +102,8 @@ gtkletterask( XP_Bool forBlank, XP_UCHAR* name,
if ( forBlank ) {
txt = "Choose a letter for your blank.";
} else {
char* fmt = "Choose a tile for %s.";
XP_SNPRINTF( buf, sizeof(buf), fmt, name );
gchar* fmt = "Choose a tile for %ls.";
snprintf( buf, VSIZE(buf), fmt, name );
txt = buf;
}
label = gtk_label_new( txt );
@ -112,16 +117,16 @@ gtkletterask( XP_Bool forBlank, XP_UCHAR* name,
gtk_widget_destroy( dialog );
for ( i = 0; i < nTiles; ++i ) {
if ( results[i] ) {
for ( ii = 0; ii < nTiles; ++ii ) {
if ( results[ii] ) {
break;
}
}
if ( i == nTiles ) {
i = -1;
if ( ii == nTiles ) {
ii = -1;
}
return i;
return ii;
} /* gtkletterask */
#endif /* PLATFORM_GTK */

View file

@ -348,9 +348,17 @@ createOrLoadObjects( GtkAppGlobals* globals )
} else if ( addr.conType == COMMS_CONN_RELAY ) {
addr.u.ip_relay.ipAddr = 0;
addr.u.ip_relay.port = params->connInfo.relay.defaultSendPort;
XP_STRNCPY( addr.u.ip_relay.hostName, params->connInfo.relay.relayName,
/* const char* sp = params->connInfo.relay.relayName; */
/* mbsrtowcs( addr.u.ip_relay.hostName, &sp, */
/* VSIZE(addr.u.ip_relay.hostName), NULL ); */
XP_STRNCPY( addr.u.ip_relay.hostName,
params->connInfo.relay.relayName,
sizeof(addr.u.ip_relay.hostName) - 1 );
XP_STRNCPY( addr.u.ip_relay.cookie, params->connInfo.relay.cookie,
/* sp = params->connInfo.relay.cookie; */
/* mbsrtowcs( addr.u.ip_relay.cookie, &sp, */
/* VSIZE(addr.u.ip_relay.cookie), NULL ); */
XP_STRNCPY( addr.u.ip_relay.cookie,
params->connInfo.relay.cookie,
sizeof(addr.u.ip_relay.cookie) - 1 );
#endif
#ifdef XWFEATURE_BLUETOOTH
@ -362,14 +370,21 @@ createOrLoadObjects( GtkAppGlobals* globals )
#endif
#ifdef XWFEATURE_IP_DIRECT
} else if ( addr.conType == COMMS_CONN_IP_DIRECT ) {
XP_STRNCPY( addr.u.ip.hostName_ip, params->connInfo.ip.hostName,
sizeof(addr.u.ip.hostName_ip) - 1 );
/* const char* sp = params->connInfo.ip.hostName, */
/* mbsrtowcs( addr.u.ip.hostName_ip, &sp, */
/* VSIZE(addr.u.ip.hostName_ip), NULL ); */
XP_STRNCPY( addr.u.ip.hostName,
params->connInfo.ip.hostName,
sizeof(addr.u.ip.hostName) - 1 );
addr.u.ip.port_ip = params->connInfo.ip.port;
#endif
#ifdef XWFEATURE_SMS
} else if ( addr.conType == COMMS_CONN_SMS ) {
XP_STRNCPY( addr.u.sms.phone, params->connInfo.sms.serverPhone,
/* const char* sp = params->connInfo.sms.serverPhone; */
XP_STRNCPY( addr.u.sms.phone,
params->connInfo.sms.serverPhone,
sizeof(addr.u.sms.phone) - 1 );
/* mbsrtowcs( addr.u.sms.phone, &sp, VSIZE(addr.u.sms.phone), NULL ); */
addr.u.sms.port = params->connInfo.sms.port;
#endif
}
@ -622,7 +637,7 @@ final_scores( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
if ( gameOver ) {
printFinalScores( globals );
} else {
if ( gtkask( "Are you sure everybody wants to end the game now?",
if ( gtkask( XP_L(Are you sure everybody wants to end the game now?),
GTK_BUTTONS_YES_NO ) ) {
server_endGame( globals->cGlobals.game.server );
gameOver = TRUE;
@ -1037,14 +1052,14 @@ handle_commit_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
} /* handle_commit_button */
static void
gtkUserError( GtkAppGlobals* XP_UNUSED(globals), const char* format, ... )
gtkUserError( GtkAppGlobals* XP_UNUSED(globals), const XP_UCHAR* format, ... )
{
char buf[512];
XP_UCHAR buf[512];
va_list ap;
va_start( ap, format );
vsprintf( buf, format, ap );
XP_SNPRINTF( buf, VSIZE(buf), format, ap );
(void)gtkask( buf, GTK_BUTTONS_OK );
@ -1319,7 +1334,7 @@ gtk_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, XP_U16 player,
{
XP_Bool result;
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
char buf[300];
XP_UCHAR buf[300];
if ( turnLost ) {
char wordsBuf[256];
@ -1329,7 +1344,7 @@ gtk_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, XP_U16 player,
for ( i = 0, wordsBuf[0] = '\0'; ; ) {
char wordBuf[18];
sprintf( wordBuf, "\"%s\"", bwi->words[i] );
sprintf( wordBuf, "\"" XP_LS "\"", bwi->words[i] );
strcat( wordsBuf, wordBuf );
if ( ++i == bwi->nWords ) {
break;
@ -1337,19 +1352,21 @@ gtk_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi, XP_U16 player,
strcat( wordsBuf, ", " );
}
sprintf( buf, "Player %d (%s) played illegal word[s] %s; loses turn.",
player+1, name, wordsBuf );
XP_SNPRINTF( buf, VSIZE(buf),
"Player %d (%s) played illegal word[s] %s; loses turn.",
player+1, name, wordsBuf );
if ( globals->cGlobals.params->skipWarnings ) {
XP_LOGF( "%s", buf );
XP_LOGF( XP_LS, buf );
} else {
gtkUserError( globals, buf );
}
result = XP_TRUE;
} else {
XP_ASSERT( bwi->nWords == 1 );
sprintf( buf, "Word \"%s\" not in the current dictionary. "
"Use it anyway?", bwi->words[0] );
XP_SNPRINTF( buf, VSIZE(buf),
XP_L(Word ) "\"%s\""
XP_L(not in the current dictionary. Use it anyway?), bwi->words[0] );
result = gtkask( buf, GTK_BUTTONS_YES_NO );
}
@ -1409,7 +1426,7 @@ gtk_util_userError( XW_UtilCtxt* uc, UtilErrID id )
XP_LOGF( "%s(%d)", __func__, id );
if ( silent ) {
XP_LOGF( "%s", message );
XP_LOGF( XP_LS, message );
} else {
gtkUserError( globals, message );
}
@ -1420,7 +1437,7 @@ gtk_util_userQuery( XW_UtilCtxt* XP_UNUSED(uc), UtilQueryID id,
XWStreamCtxt* stream )
{
XP_Bool result;
char* question;
XP_UCHAR* question;
XP_Bool freeMe = XP_FALSE;
GtkButtonsType buttons = GTK_BUTTONS_YES_NO;
@ -1431,7 +1448,7 @@ gtk_util_userQuery( XW_UtilCtxt* XP_UNUSED(uc), UtilQueryID id,
freeMe = XP_TRUE;
break;
case QUERY_COMMIT_TRADE:
question = "Are you sure you want to trade the selected tiles?";
question = XP_L(Are you sure you want to trade the selected tiles?);
break;
case QUERY_ROBOT_MOVE:
case QUERY_ROBOT_TRADE:

View file

@ -326,9 +326,12 @@ makeNewGameDialog( GtkNewGameState* state )
FALSE, TRUE, 0 );
if ( !!gi->dictName ) {
gtk_box_pack_start( GTK_BOX(hbox),
gtk_label_new(gi->dictName),
FALSE, TRUE, 0 );
/* gchar tmp[wcslen(gi->dictName)*sizeof(XP_UCHAR)]; */
/* const XP_UCHAR* src = gi->dictName; */
/* mbstate_t ps = {0}; */
/* wcsrtombs( tmp, &src, sizeof(tmp), &ps ); */
gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new(gi->dictName),
FALSE, TRUE, 0);
}
gtk_widget_show( hbox );
@ -442,10 +445,15 @@ gtk_newgame_col_set( void* closure, XP_U16 player, NewGameColumn col,
switch ( col ) {
case NG_COL_NAME:
case NG_COL_PASSWD:
cp = value.ng_cp? value.ng_cp : "";
case NG_COL_PASSWD: {
cp = value.ng_cp? value.ng_cp : XP_L( );
/* gchar tmp[(sizeof(XP_UCHAR) * wcslen(cp))+6]; */
/* const XP_UCHAR* src = cp; */
/* mbstate_t ps = {0}; */
/* wcsrtombs( tmp, &src, sizeof(tmp), &ps ); */
gtk_entry_set_text( GTK_ENTRY(widget), cp );
break;
}
#ifndef XWFEATURE_STANDALONE_ONLY
case NG_COL_REMOTE:
#endif

View file

@ -30,7 +30,7 @@ button_event( GtkWidget* XP_UNUSED(widget), void* closure )
} /* ok_button_event */
XP_Bool
gtkpasswdask( const char* name, char* outbuf, XP_U16* buflen )
gtkpasswdask( const XP_UCHAR* name, XP_UCHAR* outbuf, XP_U16* buflen )
{
XP_Bool ok = XP_FALSE;
XP_Bool ignore;
@ -49,7 +49,7 @@ gtkpasswdask( const char* name, char* outbuf, XP_U16* buflen )
dialog = gtk_dialog_new();
gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE );
snprintf( buf, sizeof(buf), "Password for player \"%s\"", name );
snprintf( buf, sizeof(buf), "Password for player \"" XP_LS "\"", name );
label = gtk_label_new( buf );
gtk_container_add( GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
@ -83,8 +83,7 @@ gtkpasswdask( const char* name, char* outbuf, XP_U16* buflen )
if ( ok ) {
const char* text = gtk_entry_get_text( GTK_ENTRY(entry) );
strncpy( outbuf, text, *buflen );
*buflen = strlen(outbuf);
*buflen = XP_SNPRINTF( outbuf, *buflen, XP_L(%s), text );
}
gtk_widget_destroy( dialog );

View file

@ -24,7 +24,7 @@
#include "comtypes.h"
XP_Bool gtkpasswdask( const char* name, char* buf, XP_U16* len );
XP_Bool gtkpasswdask( const XP_UCHAR* name, XP_UCHAR* buf, XP_U16* len );
#endif /* _GTKPASSWDASK_H_ */

View file

@ -80,10 +80,10 @@ static XP_U16
countSpecials( LinuxDictionaryCtxt* ctxt )
{
XP_U16 result = 0;
XP_U16 i;
XP_U16 ii;
for ( i = 0; i < ctxt->super.nFaces; ++i ) {
if ( IS_SPECIAL(ctxt->super.faces16[i] ) ) {
for ( ii = 0; ii < ctxt->super.nFaces; ++ii ) {
if ( IS_SPECIAL(ctxt->super.faces[ctxt->super.faceIndices[ii]] ) ) {
++result;
}
}
@ -132,25 +132,28 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
nSpecials * sizeof(*texts) );
bitmaps = (SpecialBitmaps*)XP_MALLOC( ctxt->super.mpool,
nSpecials * sizeof(*bitmaps) );
XP_MEMSET( bitmaps, 0, nSpecials * sizeof(*bitmaps) );
for ( tile = 0; tile < ctxt->super.nFaces; ++tile ) {
XP_CHAR16 face = ctxt->super.faces16[(short)tile];
if ( IS_SPECIAL(face) ) {
XP_UCHAR* facep
= &ctxt->super.faces[ctxt->super.faceIndices[(short)tile]];
if ( IS_SPECIAL(*facep) ) {
XP_U16 asIndex = (XP_U16)*facep;
XP_U8 txtlen;
XP_ASSERT( face < nSpecials );
XP_ASSERT( *facep < nSpecials );
/* get the string */
if ( 1 == fread( &txtlen, sizeof(txtlen), 1, dictF ) ) {
text = (XP_UCHAR*)XP_MALLOC(ctxt->super.mpool, txtlen+1);
if ( 1 == fread( text, txtlen, 1, dictF ) ) {
text[txtlen] = '\0';
texts[face] = text;
texts[(XP_U16)*facep] = text;
XP_DEBUGF( "skipping bitmaps for %s", texts[face] );
XP_DEBUGF( "skipping bitmaps for " XP_LS, texts[asIndex] );
bitmaps[face].largeBM = skipBitmap( ctxt, dictF );
bitmaps[face].smallBM = skipBitmap( ctxt, dictF );
bitmaps[asIndex].largeBM = skipBitmap( ctxt, dictF );
bitmaps[asIndex].smallBM = skipBitmap( ctxt, dictF );
}
}
}
@ -160,11 +163,44 @@ skipBitmaps( LinuxDictionaryCtxt* ctxt, FILE* dictF )
ctxt->super.bitmaps = bitmaps;
} /* skipBitmaps */
static void
splitFaces( LinuxDictionaryCtxt* dctx, XP_UCHAR* bytes,
XP_U16 nFaces, XP_U16 nFaceBytes )
{
XP_UCHAR* faces = XP_MALLOC( dctx->super.mpool,
nFaces + nFaceBytes );
XP_U16* indices = XP_MALLOC( dctx->super.mpool, nFaces * sizeof(indices[0]));
XP_U16 ii;
XP_Bool isUTF8 = dctx->super.isUTF8;
XP_UCHAR* next = faces;
for ( ii = 0; ii < nFaces; ++ii ) {
indices[ii] = next - faces;
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;
} else {
XP_ASSERT( 0 == *bytes );
++bytes; /* skip empty */
*next++ = *bytes++;
}
*next++ = '\0';
}
XP_ASSERT( next == faces + nFaces + nFaceBytes );
XP_ASSERT( !dctx->super.faces );
dctx->super.faces = faces;
XP_ASSERT( !dctx->super.faceIndices );
dctx->super.faceIndices = indices;
} /* splitFaces */
static XP_Bool
initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
{
XP_Bool formatOk = XP_FALSE;
XP_U8 numFaces;
XP_U8 numFaces, numFaceBytes;
long curPos, dictLength;
XP_U32 topOffset;
FILE* dictF = fopen( fileName, "r" );
@ -172,6 +208,7 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
XP_U16 flags;
XP_U16 facesSize;
XP_U16 charSize;
XP_Bool isUTF8 = XP_FALSE;
XP_ASSERT( dictF );
if ( 1 == fread( &flags, sizeof(flags), 1, dictF ) ) {
@ -193,6 +230,18 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
charSize = 2;
dctx->super.is_4_byte = XP_TRUE;
formatOk = XP_TRUE;
} else if ( flags == 0x0004 ) {
dctx->super.nodeSize = 3;
dctx->super.isUTF8 = XP_TRUE;
isUTF8 = XP_TRUE;
dctx->super.is_4_byte = XP_FALSE;
formatOk = XP_TRUE;
} else if ( flags == 0x0005 ) {
dctx->super.nodeSize = 4;
dctx->super.isUTF8 = XP_TRUE;
isUTF8 = XP_TRUE;
dctx->super.is_4_byte = XP_TRUE;
formatOk = XP_TRUE;
} else {
/* case I don't know how to deal with */
XP_ASSERT(0);
@ -205,37 +254,64 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
#endif
if ( formatOk ) {
if ( isUTF8 ) {
if ( 1 != fread( &numFaceBytes, sizeof(numFaceBytes), 1, dictF ) ) {
goto closeAndExit;
}
}
if ( 1 != fread( &numFaces, sizeof(numFaces), 1, dictF ) ) {
goto closeAndExit;
}
if ( !isUTF8 ) {
numFaceBytes = numFaces * charSize;
}
dctx->super.nFaces = numFaces;
dctx->super.countsAndValues = XP_MALLOC( dctx->super.mpool,
numFaces*2 );
facesSize = numFaces * sizeof(dctx->super.faces16[0]);
dctx->super.faces16 = XP_MALLOC( dctx->super.mpool, facesSize );
XP_MEMSET( dctx->super.faces16, 0, facesSize );
facesSize = numFaceBytes;
if ( !isUTF8 ) {
facesSize /= 2;
}
/* dctx->super.faces = XP_MALLOC( dctx->super.mpool, facesSize ); */
/* XP_MEMSET( dctx->super.faces, 0, facesSize ); */
if ( 1 != fread( dctx->super.faces16, numFaces * charSize, 1,
dictF ) ) {
gchar tmp[numFaceBytes];
if ( 1 != fread( tmp, numFaceBytes, 1, dictF ) ) {
goto closeAndExit;
}
if ( charSize == sizeof(dctx->super.faces16[0]) ) {
/* fix endianness */
XP_U16 i;
for ( i = 0; i < numFaces; ++i ) {
XP_CHAR16 tmp = dctx->super.faces16[i];
dctx->super.faces16[i] = ntohs(tmp);
}
} else {
XP_UCHAR* src = ((XP_UCHAR*)(dctx->super.faces16)) + numFaces;
XP_CHAR16* dest = dctx->super.faces16 + numFaces;
while ( src-- <= (XP_UCHAR*)(dest--) ) {
*dest = (XP_CHAR16)*src;
}
}
/* if ( isUTF8 ) { */
/* XP_MEMCPY( dctx->super.faces, tmp, numFaceBytes ); */
/* } else { */
/* XP_U16 ii; */
/* XP_ASSERT( 1 == sizeof(dctx->super.faces[0]) ); */
/* for ( ii = 0; ii < numFaces; ++ii ) { */
/* dctx->super.faces[ii] = tmp[ii*2]; */
/* } */
/* } */
/* XP_ASSERT( !dctx->super.faceIndices ); */
/* dctx->super.faceIndices = */
/* XP_MALLOC( dctx->super.mpool, */
/* numFaces * sizeof(dctx->super.faceIndices[0]) ); */
splitFaces( dctx, tmp, numFaces, numFaceBytes );
/* if ( charSize == sizeof(dctx->super.faces[0]) ) { */
/* /\* fix endianness *\/ */
/* XP_U16 i; */
/* for ( i = 0; i < numFaces; ++i ) { */
/* XP_UCHAR tmp = dctx->super.faces[i]; */
/* dctx->super.faces[i] = ntohs(tmp); */
/* } */
/* } else { */
/* XP_UCHAR* src = ((XP_UCHAR*)(dctx->super.faces)) + numFaces; */
/* XP_UCHAR* dest = dctx->super.faces + numFaces; */
/* while ( src-- <= (XP_UCHAR*)(dest--) ) { */
/* *dest = (XP_UCHAR)*src; */
/* } */
/* } */
if ( (1 != fread( &xloc, 2, 1, dictF ) )/* read in (dump) the xloc
header for now */
@ -286,6 +362,9 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
dctx->super.topEdge = NULL;
}
/* XP_UCHAR tmp[XP_CSTRLEN(fileName) + 1]; */
/* const char* cp = fileName; */
/* (void)mbsrtowcs( tmp, &cp, VSIZE(tmp), NULL ); */
dctx->super.name = copyString( dctx->super.mpool, fileName );
}
goto ok;
@ -294,6 +373,7 @@ initFromDictFile( LinuxDictionaryCtxt* dctx, const char* fileName )
formatOk = XP_FALSE;
ok:
fclose( dictF );
return formatOk;
} /* initFromDictFile */
@ -301,14 +381,14 @@ static void
freeSpecials( LinuxDictionaryCtxt* ctxt )
{
XP_U16 nSpecials = 0;
XP_U16 i;
XP_U16 ii;
for ( i = 0; i < ctxt->super.nFaces; ++i ) {
if ( IS_SPECIAL(ctxt->super.faces16[i]) ) {
for ( ii = 0; ii < ctxt->super.nFaces; ++ii ) {
if ( IS_SPECIAL(ctxt->super.faces[ctxt->super.faceIndices[ii]] ) ) {
if ( !!ctxt->super.bitmaps ) {
XP_Bitmap* bmp = ctxt->super.bitmaps[nSpecials].largeBM;
if ( !!bmp ) {
XP_FREE( ctxt->super.mpool, bmp );
XP_FREE( ctxt->super.mpool, bmp ); /* failing */
}
bmp = ctxt->super.bitmaps[nSpecials].smallBM;
if ( !!bmp ) {
@ -341,7 +421,8 @@ linux_dictionary_destroy( DictionaryCtxt* dict )
}
XP_FREE( dict->mpool, ctxt->super.countsAndValues );
XP_FREE( dict->mpool, ctxt->super.faces16 );
XP_FREE( dict->mpool, ctxt->super.faces );
XP_FREE( dict->mpool, ctxt->super.faceIndices );
XP_FREE( dict->mpool, ctxt->super.name );
XP_FREE( dict->mpool, ctxt );
} /* linux_dictionary_destroy */
@ -350,7 +431,8 @@ static const XP_UCHAR*
linux_dict_getShortName( const DictionaryCtxt* dict )
{
const XP_UCHAR* full = dict_getName( dict );
const char* c = strrchr( full, '/' );
/* const XP_UCHAR* c = wcsrchr( full, '/' ); */
const XP_UCHAR* c = strchr( full, '/' );
if ( !!c ) {
++c;
} else {

View file

@ -113,7 +113,9 @@ writeToFile( XWStreamCtxt* stream, void* closure )
stream_getBytes( stream, buf, len );
file = fopen( cGlobals->params->fileName, "w" );
if ( 1 != fwrite( buf, 1, len, file ) ) {
if ( 1 != fwrite( buf, len, 1, file ) ) {
XP_LOGF( "%s: fwrite failed: %d (%s)", __func__,
errno, strerror(errno) );
XP_ASSERT( 0 );
}
fclose( file );

View file

@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/inotify.h>
#include <unistd.h>
#include "linuxsms.h"
#include "strutils.h"
@ -54,7 +55,7 @@
struct LinSMSData {
XP_UCHAR myPhone[MAX_PHONE_LEN+1];
XP_UCHAR myQueue[256];
char myQueue[256];
FILE* lock;
int wd, fd; /* for inotify */
void* storage;
@ -65,8 +66,11 @@ struct LinSMSData {
static void
makeQueuePath( const XP_UCHAR* phone, XP_U16 port,
XP_UCHAR* path, XP_U16 pathlen )
char* path, XP_U16 pathlen )
{
/* char tmp[XP_STRLEN(phone) + 1]; */
/* (void)wcstombs( tmp, phone, VSIZE(tmp)); */
/* snprintf( path, pathlen, "%s/%s_%d", SMS_DIR, tmp, port ); */
snprintf( path, pathlen, "%s/%s_%d", SMS_DIR, phone, port );
}
@ -104,7 +108,8 @@ linux_sms_init( CommonGlobals* globals, const CommsAddrRec* addr )
XP_STRNCPY( data->myPhone, addr->u.sms.phone,
sizeof(data->myPhone) );
} else {
snprintf( data->myPhone, sizeof(data->myPhone), "%.6d", getpid() );
XP_SNPRINTF( data->myPhone, sizeof(data->myPhone), XP_L(%.6d),
getpid() );
}
makeQueuePath( data->myPhone, addr->u.sms.port,
@ -151,9 +156,9 @@ linux_sms_send( CommonGlobals* globals,
int len = strlen( path );
snprintf( &path[len], sizeof(path)-len, "/%d", ++data->count );
XP_UCHAR sms[buflen*2]; /* more like (buflen*4/3) */
char sms[buflen*2]; /* more like (buflen*4/3) */
XP_U16 smslen = sizeof(sms);
binToSms( sms, &smslen, buf, buflen );
binToSms( (XP_U8*)sms, &smslen, buf, buflen );
XP_ASSERT( smslen == strlen(sms) );
#ifdef DEBUG
@ -162,7 +167,7 @@ linux_sms_send( CommonGlobals* globals,
XP_U8 testout[buflen];
XP_U16 lenout = sizeof( testout );
XP_ASSERT( smsToBin( testout, &lenout, sms, smslen ) );
XP_ASSERT( smsToBin( testout, &lenout, (XP_U8*)sms, smslen ) );
XP_ASSERT( lenout == buflen );
XP_ASSERT( XP_MEMCMP( testout, buf, smslen ) );
#endif
@ -172,7 +177,7 @@ linux_sms_send( CommonGlobals* globals,
(void)fprintf( fp, "from: %s\n", data->myPhone );
(void)fprintf( fp, "%s\n", sms );
fclose( fp );
sync();
/* sync(); */
unlock_queue( data );
@ -199,9 +204,14 @@ decodeAndDelete( LinSMSData* data, const gchar* name,
unlink( path );
if ( 0 == strncmp( "from: ", contents, 6 ) ) {
gchar* eol = strstr( contents, "\n" );
char* eol = strstr( contents, "\n" );
*eol = '\0';
/* const char* sp = &contents[6]; */
/* mbsrtowcs( addr->u.sms.phone, &sp, VSIZE(addr->u.sms.phone), NULL ); */
XP_STRNCPY( addr->u.sms.phone, &contents[6], sizeof(addr->u.sms.phone) );
XP_ASSERT( !*eol );
++eol; /* skip NULL */
*strstr(eol, "\n" ) = '\0';
@ -209,7 +219,7 @@ decodeAndDelete( LinSMSData* data, const gchar* name,
XP_U16 inlen = strlen(eol); /* skip \n */
XP_U8 out[inlen];
XP_U16 outlen = sizeof(out);
XP_Bool valid = smsToBin( out, &outlen, eol, inlen );
XP_Bool valid = smsToBin( out, &outlen, (XP_U8*)eol, inlen );
if ( valid && outlen <= buflen ) {
XP_MEMCPY( buf, out, outlen );

View file

@ -21,6 +21,7 @@
#include <stdarg.h>
#include <sys/time.h>
#include <time.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
@ -33,15 +34,19 @@ linux_debugf( const char* format, ... )
{
char buf[1000];
va_list ap;
struct tm* timp;
struct timeval tv;
struct timezone tz;
/* struct tm* timp; */
/* struct timeval tv; */
/* struct timezone tz; */
gettimeofday( &tv, &tz );
timp = localtime( &tv.tv_sec );
/* gettimeofday( &tv, &tz ); */
struct timespec tp;
clock_gettime( CLOCK_REALTIME, &tp );
struct tm timp;
(void)localtime_r( &tp.tv_sec, &timp );
sprintf( buf, "<%d>%d:%d:%d: ", getpid(),
timp->tm_hour, timp->tm_min, timp->tm_sec );
timp.tm_hour, timp.tm_min, timp.tm_sec );
va_start(ap, format);

View file

@ -27,6 +27,11 @@
#include <unistd.h>
#include <netinet/in.h>
#ifdef XWFEATURE_UNICODE
# include <wchar.h>
#endif
#ifdef PLATFORM_GTK
# include <glib.h>
# include <gdk/gdk.h>
@ -38,7 +43,19 @@
typedef unsigned char XP_U8;
typedef signed char XP_S8;
#ifdef XWFEATURE_UNICODE
/* typedef wchar_t XP_UCHAR; */
typedef gchar XP_UCHAR;
/* typedef gunichar XP_UCHAR; */
/* # define XP_L(s) L##s */
/* # define XP_LS "%ls" */
# define XP_L(s) ""#s
# define XP_LS "%s"
#else
typedef char XP_UCHAR;
# define XP_L(s) ##s
#endif
typedef unsigned short XP_U16;
typedef signed short XP_S16;
@ -55,7 +72,7 @@ typedef guint32 XP_Time;
typedef unsigned long XP_Time;
#endif
#define XP_CR "\n"
#define XP_CR XP_L(\\n)
#define XP_STATUSF XP_DEBUGF
#define XP_LOGF XP_DEBUGF
@ -87,18 +104,45 @@ extern void linux_debugf(const char*, ...)
#define XP_MEMSET(src, val, nbytes) memset( (src), (val), (nbytes) )
#define XP_MEMCPY(d,s,l) memcpy((d),(s),(l))
#define XP_MEMCMP( a1, a2, l ) memcmp((a1),(a2),(l))
#define XP_STRLEN(s) strlen(s)
#define XP_STRCAT(d,s) strcat((d),(s))
#define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len))
#define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len))
#define XP_STRCMP(s1,s2) strcmp((s1),(s2))
#define XP_RANDOM() random()
#define XP_RANDOM() rand()
#ifdef XWFEATURE_UNICODE
/* #define XP_SNPRINTF swprintf */
#define XP_SNPRINTF snprintf
/* #define XP_STRCAT(d,s) wcscat((d),(s)) */
#define XP_STRCAT(d,s) strcat((d),(s))
/* #define XP_STRLEN(s) wcslen(s) */
#define XP_STRLEN(s) strlen(s)
/* #define XP_STRNCMP(s1,s2,len) wcsncmp((s1),(s2),(len)) */
#define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len))
#define XP_CSTRLEN(s) strlen(s)
#define XP_CSNPRINTF snprintf
/* #define XP_STRNCPY(s1,s2,len) wcsncpy((s1),(s2),(len)) */
#define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len))
#else
#define XP_SNPRINTF snprintf
#define XP_STRCAT(d,s) strcat((d),(s))
#define XP_STRLEN(s) strlen(s)
#define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len))
#define XP_CSTRLEN XP_STRLEN
#define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len))
#endif
#define XP_MIN(a,b) ((a)<(b)?(a):(b))
#define XP_MAX(a,b) ((a)>(b)?(a):(b))
#define XP_ABS(a) ((a)>=0?(a):-(a))
#define XP_NARROW_TO_UCHAR( in, out, inlen, outlenp ) \
{ \
memcpy( out, in, inlen ); \
*(outlenp) = inlen; \
}
#define XP_UCHAR_TO_NARROW( in, out, inlen, outlenp ) \
XP_NARROW_TO_UCHAR( in, out, inlen, outlenp )
#ifdef DEBUG
# define XP_ASSERT(b) assert(b)
#else

View file

@ -27,15 +27,15 @@
static void
nameToLabel( HWND hDlg, const XP_UCHAR* name, XP_U16 labelID )
{
wchar_t wideName[128];
/* wchar_t wideName[128]; */
wchar_t wBuf[128];
XP_U16 len;
/* XP_U16 len; */
len = (XP_U16)XP_STRLEN( name );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, name, len + 1,
wideName, len + 1 );
/* len = (XP_U16)XP_STRLEN( name ); */
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, name, len + 1, */
/* wideName, len + 1 ); */
swprintf( wBuf, L"Enter password for %s:", wideName );
swprintf( wBuf, L"Enter password for %ls:", name );
SendDlgItemMessage( hDlg, labelID, WM_SETTEXT, 0, (long)wBuf );
} /* nameToLabel */

View file

@ -33,16 +33,16 @@ loadLettersList( BlankDialogState* bState )
const XP_UCHAR4* texts = bState->texts;
for ( i = 0; i < nTiles; ++i ) {
XP_U16 len;
wchar_t widebuf[4];
/* XP_U16 len; */
/* wchar_t widebuf[4]; */
len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
texts[i], strlen(texts[i]),
widebuf, VSIZE(widebuf) );
widebuf[len] = 0;
/* len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, */
/* texts[i], strlen(texts[i]), */
/* widebuf, VSIZE(widebuf) ); */
/* widebuf[len] = 0; */
SendDlgItemMessage( hDlg, LB_IF_PPC(globals,BLANKFACE_LIST),
ADDSTRING(globals), 0, (long)widebuf );
ADDSTRING(globals), 0, (long)texts[i] );
}
SendDlgItemMessage( hDlg, LB_IF_PPC(globals,BLANKFACE_LIST),
@ -61,28 +61,28 @@ showCurTray( HWND hDlg, BlankDialogState* bState )
XP_U16 lenSoFar = 0;
XP_U16 i;
XP_UCHAR labelBuf[48];
wchar_t widebuf[48];
/* wchar_t widebuf[48]; */
XP_UCHAR* name;
name = bState->dlgHdr.globals->gameInfo.players[bState->playerNum].name;
lenSoFar += XP_SNPRINTF( labelBuf + lenSoFar,
sizeof(labelBuf) - lenSoFar,
"%d of %d for %s" XP_CR "Cur",
VSIZE(labelBuf) - lenSoFar,
XP_L("%d of %d for %s") XP_CR "Cur",
pi->thisPick + 1, pi->nTotal, name );
for ( i = 0; i < pi->nCurTiles; ++i ) {
lenSoFar += XP_SNPRINTF( labelBuf+lenSoFar,
sizeof(labelBuf)-lenSoFar, "%s%s",
VSIZE(labelBuf)-lenSoFar, XP_L("%s%s"),
i==0?": ":", ", pi->curTiles[i] );
}
(void)MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
labelBuf, lenSoFar + 1,
widebuf,
VSIZE(widebuf) + sizeof(widebuf[0]) );
/* (void)MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, */
/* labelBuf, lenSoFar + 1, */
/* widebuf, */
/* VSIZE(widebuf) + VSIZE(widebuf[0]) ); */
SetDlgItemText( hDlg,IDC_PICKMSG, widebuf );
SetDlgItemText( hDlg,IDC_PICKMSG, labelBuf );
}
} /* showCurTray */
#endif

View file

@ -49,32 +49,32 @@ ceControlsToAddrRec( HWND hDlg, CeConnDlgState* state )
if ( state->addrRec.conType == COMMS_CONN_RELAY ) {
#ifdef XWFEATURE_RELAY
len = sizeof(state->addrRec.u.ip_relay.hostName);
len = VSIZE(state->addrRec.u.ip_relay.hostName);
ceGetDlgItemText( hDlg, RELAYNAME_EDIT,
state->addrRec.u.ip_relay.hostName, &len );
state->addrRec.u.ip_relay.port =
(XP_U16)ceGetDlgItemNum( hDlg, RELAYPORT_EDIT );
len = sizeof(state->addrRec.u.ip_relay.cookie);
len = VSIZE(state->addrRec.u.ip_relay.cookie);
ceGetDlgItemText( hDlg, COOKIE_EDIT, state->addrRec.u.ip_relay.cookie,
&len );
#endif
} else if ( state->addrRec.conType == COMMS_CONN_IP_DIRECT ) {
#ifdef XWFEATURE_IP_DIRECT
len = sizeof(state->addrRec.u.ip.hostName_ip);
len = VSIZE(state->addrRec.u.ip.hostName_ip);
ceGetDlgItemText( hDlg, IPNAME_EDIT, state->addrRec.u.ip.hostName_ip,
&len );
#endif
} else if ( state->addrRec.conType == COMMS_CONN_BT ) {
#ifdef XWFEATURE_BLUETOOTH
if ( state->role == SERVER_ISCLIENT ) {
len = sizeof(state->addrRec.u.bt.hostName);
len = VSIZE(state->addrRec.u.bt.hostName);
ceGetDlgItemText( hDlg, IDC_BLUET_ADDR_EDIT,
state->addrRec.u.bt.hostName, &len );
}
#endif
} else if ( state->addrRec.conType == COMMS_CONN_SMS ) {
#ifdef XWFEATURE_SMS
len = sizeof(state->addrRec.u.sms.phone);
len = VSIZE(state->addrRec.u.sms.phone);
ceGetDlgItemText( hDlg, IDC_SMS_PHONE_EDIT, state->addrRec.u.sms.phone,
&len );
state->addrRec.u.sms.port = (XP_U16)ceGetDlgItemNum( hDlg,

View file

@ -97,12 +97,12 @@ messageToStr( UINT message )
} /* messageToStr */
void
XP_LOGW( const XP_UCHAR* prefix, const wchar_t* arg )
XP_LOGW( const char* prefix, const wchar_t* arg )
{
XP_UCHAR buf[512];
char buf[512];
(void)WideCharToMultiByte( CP_ACP, 0, arg, -1,
buf, sizeof(buf), NULL, NULL );
XP_LOGF( "%s: %s", prefix, buf );
XP_LOGF( "%s: %ls", prefix, arg );
}
void
@ -123,8 +123,8 @@ logLastError( const char* comment )
XP_U16 len;
XP_U16 lenSoFar;
snprintf( msg, sizeof(msg), "%s (err: %ld): ", comment, lastErr );
lenSoFar = strlen( msg );
XP_SNPRINTF( msg, VSIZE(msg), XP_L("%s (err: %ld): "), comment, lastErr );
lenSoFar = XP_STRLEN( msg );
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
@ -142,11 +142,11 @@ logLastError( const char* comment )
if ( len >= sizeof(msg)-lenSoFar ) {
len = sizeof(msg) - lenSoFar - 1;
}
WideCharToMultiByte( CP_ACP, 0, lpMsgBuf, len + 1,
msg + lenSoFar, len + 1, NULL, NULL );
LocalFree( lpMsgBuf );
/* WideCharToMultiByte( CP_ACP, 0, lpMsgBuf, len + 1, */
/* msg + lenSoFar, len + 1, NULL, NULL ); */
XP_LOGF( "system error: %s", msg );
XP_LOGF( "system error: %ls", (XP_UCHAR*)lpMsgBuf );
LocalFree( lpMsgBuf );
} /* logLastError */
#endif /* DEBUG */

View file

@ -26,7 +26,7 @@ const char* messageToStr( UINT message );
void logRect( const char* comment, const RECT* rect );
#ifdef DEBUG
void XP_LOGW( const XP_UCHAR* prefix, const wchar_t* arg );
void XP_LOGW( const char* prefix, const wchar_t* arg );
void logLastError( const char* comment );
void messageToBuf( UINT message, char* buf, int bufSize );
#else

View file

@ -57,8 +57,9 @@ static XP_Bool findAlternateDict( CEAppGlobals* globals, wchar_t* dictName );
#define ALIGN_COUNT 2
DictionaryCtxt*
ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
ce_dictionary_make( CEAppGlobals* globals, const XP_UCHAR* dictName )
{
XP_LOGF( "%s(%ls)", __func__, dictName );
CEDictionaryCtxt* ctxt = (CEDictionaryCtxt*)NULL;
HANDLE mappedFile = NULL;
@ -70,15 +71,23 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
XP_ASSERT( !!dictName );
#ifdef UCHAR_IS_WIDE
XP_SNPRINTF( nameBuf, VSIZE(nameBuf), XP_L("%ls"), dictName );
#else
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, dictName, -1,
nameBuf, VSIZE(nameBuf) );
#endif
ptr = openMappedFile( MPPARM(globals->mpool) nameBuf, &mappedFile,
&hFile, &dictLength );
if ( !ptr ) {
if ( findAlternateDict( globals, nameBuf ) ) {
#ifdef UCHAR_IS_WIDE
XP_SNPRINTF( buf, VSIZE(buf), XP_L("%ls"), nameBuf );
#else
(void)WideCharToMultiByte( CP_ACP, 0, nameBuf, -1,
buf, sizeof(buf), NULL, NULL );
#endif
ptr = openMappedFile( MPPARM(globals->mpool) nameBuf, &mappedFile,
&hFile, &dictLength );
if ( !!ptr ) {
@ -89,11 +98,12 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
while( !!ptr ) { /* lets us break.... */
XP_U32 offset;
XP_U16 numFaces;
XP_U16 numFaces, numFaceBytes;
XP_U16 i;
XP_U16 flags;
void* mappedBase = (void*)ptr;
XP_U8 nodeSize;
XP_Bool isUTF8 = XP_FALSE;
flags = n_ptr_tohs( &ptr );
@ -102,6 +112,12 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
nodeSize = 3;
} else if ( flags == 0x0003 ) {
nodeSize = 4;
} else if ( flags == 0x0004 ) {
isUTF8 = XP_TRUE;
nodeSize = 3;
} else if ( flags == 0x0005 ) {
isUTF8 = XP_TRUE;
nodeSize = 4;
} else {
break; /* we want to return NULL */
}
@ -118,21 +134,29 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
ctxt->super.destructor = ce_dict_destroy;
ctxt->super.func_dict_getShortName = ce_dict_getShortName;
if ( isUTF8 ) {
numFaceBytes = (XP_U16)(*ptr++);
}
numFaces = (XP_U16)(*ptr++);
if ( !isUTF8 ) {
numFaceBytes = numFaces * 2;
}
ctxt->super.nFaces = (XP_U8)numFaces;
ctxt->super.faces16 =
XP_MALLOC( globals->mpool,
numFaces * sizeof(ctxt->super.faces16[0]) );
ctxt->super.faces =
XP_MALLOC( globals->mpool,
numFaces * sizeof(ctxt->super.faces[0]) );
#ifdef NODE_CAN_4
ctxt->super.is_4_byte = (ctxt->super.nodeSize == 4);
for ( i = 0; i < numFaces; ++i ) {
ctxt->super.faces16[i] = n_ptr_tohs(&ptr);
}
#else
for ( i = 0; i < numFaces; ++i ) {
ctxt->super.faces16[i] = (XP_CHAR16)*ptr++;
if ( isUTF8 ) {
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, (LPCSTR)ptr, numFaces,
ctxt->super.faces, numFaces );
ptr += numFaceBytes;
} else {
for ( i = 0; i < numFaces; ++i ) {
ctxt->super.faces[i] = n_ptr_tohs(&ptr);
}
}
#endif
@ -215,7 +239,7 @@ ceLoadSpecialData( CEDictionaryCtxt* ctxt, XP_U8** ptrp )
for ( i = 0; i < ctxt->super.nFaces; ++i ) {
XP_CHAR16 face = ctxt->super.faces16[(short)i];
XP_UCHAR face = ctxt->super.faces[(short)i];
if ( IS_SPECIAL(face) ) {
/* get the string */
@ -245,7 +269,7 @@ ceCountSpecials( CEDictionaryCtxt* ctxt )
XP_U16 i;
for ( i = 0; i < ctxt->super.nFaces; ++i ) {
if ( IS_SPECIAL(ctxt->super.faces16[i] ) ) {
if ( IS_SPECIAL(ctxt->super.faces[i] ) ) {
++result;
}
}
@ -410,7 +434,7 @@ ce_dict_destroy( DictionaryCtxt* dict )
XP_FREE( ctxt->super.mpool, ctxt->super.bitmaps );
}
XP_FREE( ctxt->super.mpool, ctxt->super.faces16 );
XP_FREE( ctxt->super.mpool, ctxt->super.faces );
XP_FREE( ctxt->super.mpool, ctxt->super.countsAndValues );
XP_FREE( ctxt->super.mpool, ctxt->super.name );
@ -552,7 +576,7 @@ checkIfDictAndLegal( MPFORMAL wchar_t* path, XP_U16 pathLen,
closeMappedFile( MPPARM(mpool) base, mappedFile );
#ifdef NODE_CAN_4
/* are the flags what we expect */
result = flags == 0x0002 || flags == 0x0003;
result = flags >= 0x0002 && flags <= 0x0005;
#else
result = flags == 0x0001;
#endif
@ -772,9 +796,11 @@ bname( const XP_UCHAR* in )
return out + 1;
} /* bname */
/* WFT does this do, and why not using strrchr? */
wchar_t*
wbname( wchar_t* buf, XP_U16 buflen, const wchar_t* in )
{
XP_LOGF( "%s(%ls)", __func__, in );
wchar_t* result;
_snwprintf( buf, buflen, L"%s", in );

View file

@ -24,13 +24,15 @@
#define CE_MAXDICTS 0x7FFF
/* #define IS_SPECIAL(face) (((XP_UCHAR)(face)) < 0x0020) */
typedef struct CEBitmapInfo {
XP_U8* bits;
XP_U16 nCols;
XP_U16 nRows;
} CEBitmapInfo;
DictionaryCtxt* ce_dictionary_make(CEAppGlobals* globals, XP_UCHAR* name);
DictionaryCtxt* ce_dictionary_make(CEAppGlobals* globals, const XP_UCHAR* name);
DictionaryCtxt* ce_dictionary_make_empty( CEAppGlobals* globals );
/* Callback: return true if done; false to continue */

View file

@ -224,14 +224,15 @@ ceDrawLinesClipped( HDC hdc, const FontCacheEntry* fce, XP_UCHAR* buf,
XP_U16 width = bounds->right - bounds->left;
for ( ; ; ) {
XP_UCHAR* newline = strstr( buf, XP_CR );
XP_U16 len = newline==NULL? strlen(buf): newline - buf;
wchar_t widebuf[len];
XP_UCHAR* newline = XP_STRSTR( buf, XP_CR_L );
XP_U16 len = newline==NULL? XP_STRLEN(buf): newline - buf;
/* wchar_t widebuf[len]; */
#ifndef UCHAR_IS_WIDE
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, buf, len,
widebuf, len );
ceDrawTextClipped( hdc, widebuf, len, clip, fce, bounds->left, top,
#endif
ceDrawTextClipped( hdc, buf, len, clip, fce, bounds->left, top,
width, DT_CENTER );
if ( !newline ) {
break;
@ -296,6 +297,7 @@ ERROR
static void
makeTestBuf( CEDrawCtx* dctx, XP_UCHAR* buf, XP_U16 bufLen, RFIndex index )
{
char* txt = NULL;
switch( index ) {
case RFONTS_TRAY:
case RFONTS_TRAYNOVAL:
@ -321,22 +323,27 @@ makeTestBuf( CEDrawCtx* dctx, XP_UCHAR* buf, XP_U16 bufLen, RFIndex index )
}
break;
case RFONTS_TRAYVAL:
strcpy( buf, "10" ); /* all numbers the same :-) */
txt = "10"; /* all numbers the same */
break;
case RFONTS_REM:
strcpy( buf, "Rem" );
txt = "Rem";
break;
case RFONTS_PTS:
strcpy( buf, "123p" );
txt = "123p";
break;
case RFONTS_SCORE:
case RFONTS_SCORE_BOLD:
strcpy( buf, "0:" );
txt = "0:";
break;
case N_RESIZE_FONTS:
XP_ASSERT(0);
}
XP_LOGF( "%s=>\"%s\"", __func__, buf );
if ( !!txt ) {
XP_SNPRINTF( buf, bufLen, XP_L("%s"), txt );
}
XP_LOGF( "%s=>\"%ls\"", __func__, buf );
} /* makeTestBuf */
static void
@ -492,7 +499,7 @@ ceBestFitFont( CEDrawCtx* dctx, const XP_U16 soughtHeight,
const XP_U16 soughtWidth, /* pass 0 to ignore width */
RFIndex index, FontCacheEntry* fce )
{
wchar_t widebuf[65];
/* wchar_t widebuf[65]; */
XP_U16 len;
XP_U16 hasMinTop, hasMaxBottom;
XP_Bool firstPass;
@ -505,12 +512,13 @@ ceBestFitFont( CEDrawCtx* dctx, const XP_U16 soughtHeight,
XP_U16 nextFromHeight = soughtHeight;
XP_U16 nextFromWidth = soughtWidth; /* starts at 0 if width ignored */
char sample[65];
XP_UCHAR sample[65];
makeTestBuf( dctx, sample, VSIZE(sample), index );
len = 1 + strlen(sample);
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, sample, len, widebuf, len );
len = 1 + XP_STRLEN(sample);
#ifndef UCHAR_IS_WIDE
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, sample, len, widebuf, len ); */
#endif
memBM = CreateCompatibleBitmap( memDC, testHeight, testHeight );
SelectObject( memDC, memBM );
@ -534,15 +542,15 @@ ceBestFitFont( CEDrawCtx* dctx, const XP_U16 soughtHeight,
are calculated. */
if ( nextFromHeight > 0 || nextFromWidth > 0 ) {
if ( firstPass ) {
ceMeasureGlyphs( dctx, memDC, widebuf, &hasMinTop,
ceMeasureGlyphs( dctx, memDC, sample, &hasMinTop,
&hasMaxBottom );
firstPass = XP_FALSE;
}
/* Thereafter, just measure the two we know about */
ceMeasureGlyph( memDC, white, widebuf[hasMinTop], 1000, 0,
ceMeasureGlyph( memDC, white, sample[hasMinTop], 1000, 0,
&top, &bottom );
if ( hasMaxBottom != hasMinTop ) {
ceMeasureGlyph( memDC, white, widebuf[hasMaxBottom],
ceMeasureGlyph( memDC, white, sample[hasMaxBottom],
top, bottom, &top, &bottom );
}
@ -564,7 +572,7 @@ ceBestFitFont( CEDrawCtx* dctx, const XP_U16 soughtHeight,
if ( (soughtWidth > 0) && (nextFromWidth > 0) ) {
SIZE size;
GetTextExtentPoint32( memDC, widebuf, len-1, &size );
GetTextExtentPoint32( memDC, sample, len-1, &size );
if ( size.cx > soughtWidth ) { /* width too big... */
nextFromWidth = 1 + ((testHeight * soughtWidth) / size.cx);
@ -650,7 +658,7 @@ checkBMCache( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* letters,
#ifdef DEBUG
if ( !canCache ) {
XP_WARNF( "%s: unable to cache bitmap for %s", __func__, letters );
XP_WARNF( "%s: unable to cache bitmap for %ls", __func__, letters );
}
#endif
@ -750,8 +758,8 @@ ceMeasureText( CEDrawCtx* dctx, HDC hdc, const FontCacheEntry* fce,
for ( ; ; ) {
wchar_t widebuf[32];
XP_UCHAR* nextStr = strstr( str, XP_CR );
XP_U16 len = nextStr==NULL? strlen(str): nextStr - str;
XP_UCHAR* nextStr = XP_STRSTR( str, XP_CR_L );
XP_U16 len = nextStr==NULL? XP_STRLEN(str): nextStr - str;
SIZE size;
XP_ASSERT( nextStr != str );

View file

@ -127,10 +127,10 @@ addDictsToMenu( GameInfoState* state )
ADDSTRING(globals), 0, (long)shortname );
if ( state->newDictName[0] != 0 && sel == 0 ) {
XP_UCHAR buf[CE_MAX_PATH_LEN+1];
WideCharToMultiByte( CP_ACP, 0, wPath, -1, buf, sizeof(buf),
NULL, NULL );
if ( 0 == XP_STRCMP( buf, state->newDictName ) ) {
/* XP_UCHAR buf[CE_MAX_PATH_LEN+1]; */
/* WideCharToMultiByte( CP_ACP, 0, wPath, -1, buf, sizeof(buf), */
/* NULL, NULL ); */
if ( 0 == XP_STRCMP( wPath, state->newDictName ) ) {
sel = i;
}
}
@ -192,11 +192,11 @@ loadFromGameInfo( GameInfoState* state )
if ( state->isNewGame ) {
(void)ceLocateNDicts( globals, CE_MAXDICTS, addDictToState, state );
} else {
wchar_t wPath[CE_MAX_PATH_LEN+1];
/* wchar_t wPath[CE_MAX_PATH_LEN+1]; */
XP_ASSERT( gi->dictName[0] != '\0' );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, gi->dictName, -1,
wPath, VSIZE(wPath) );
(void)addDictToState( wPath, 0, state );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, gi->dictName, -1, */
/* wPath, VSIZE(wPath) ); */
(void)addDictToState( gi->dictName, 0, state );
}
addDictsToMenu( state );
#endif
@ -222,9 +222,11 @@ stateToGameInfo( GameInfoState* state )
sel = SendDlgItemMessage( hDlg, state->dictListId,
GETCURSEL(globals), 0, 0L );
if ( sel >= 0 ) {
WideCharToMultiByte( CP_ACP, 0, state->menuDicts[sel], -1,
state->newDictName,
sizeof(state->newDictName), NULL, NULL );
/* WideCharToMultiByte( CP_ACP, 0, state->menuDicts[sel], -1, */
/* state->newDictName, */
/* sizeof(state->newDictName), NULL, NULL ); */
XP_SNPRINTF( state->newDictName, VSIZE(state->newDictName),
L"%s", state->menuDicts[sel] );
}
replaceStringIfDifferent( globals->mpool, &gi->dictName,
state->newDictName );
@ -235,10 +237,10 @@ stateToGameInfo( GameInfoState* state )
gi->timerEnabled = timerOn;
if ( timerOn ) {
XP_UCHAR numBuf[10];
XP_U16 len = sizeof(numBuf);
XP_U16 len = VSIZE(numBuf);
ceGetDlgItemText( hDlg, TIMER_EDIT, numBuf, &len );
if ( len > 0 ) {
XP_U16 num = atoi( numBuf );
XP_U16 num = XP_ATOI( numBuf );
gi->gameSeconds = num * 60;
}
}
@ -460,7 +462,7 @@ ceGetColProc( void* closure, XP_U16 player, NewGameColumn col,
break;
case NG_COL_NAME:
case NG_COL_PASSWD:
len = sizeof(txt);
len = VSIZE(txt);
ceGetDlgItemText( state->dlgHdr.hDlg, resID, txt, &len );
value.ng_cp = &txt[0];
break;
@ -486,10 +488,10 @@ ceSetColProc( void* closure, XP_U16 player, NewGameColumn col,
if ( NULL != value.ng_cp ) {
cp = value.ng_cp;
} else if ( col == NG_COL_NAME ) {
snprintf( buf, sizeof(buf), "Player %d", player + 1 );
XP_SNPRINTF( buf, VSIZE(buf), XP_L("Player %d"), player + 1 );
cp = buf;
} else {
cp = "";
cp = XP_L();
}
ceSetDlgItemText( state->dlgHdr.hDlg, resID, cp );
break;

View file

@ -32,6 +32,7 @@
#endif
/* #include <imm.h> */
#include "strutils.h"
/* #include "xwstream.h" */
#include "memstream.h"
@ -783,11 +784,12 @@ ceSetTitleFromName( CEAppGlobals* globals )
LoadString( globals->hInst, IDS_APP_TITLE, widebuf, VSIZE(widebuf) );
} else {
wchar_t* dotPos;
XP_UCHAR* baseStart = 1 + strrchr( gameName, '\\' );
XP_U16 len = (XP_U16)XP_STRLEN( baseStart );
XP_UCHAR* baseStart = 1 + XP_STRRCHR( gameName, '\\' );
/* XP_U16 len = (XP_U16)XP_STRLEN( baseStart ); */
XP_SNPRINTF( widebuf, VSIZE(widebuf), L"%ls", baseStart );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, baseStart, len + 1,
widebuf, len + 1 );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, baseStart, len + 1, */
/* widebuf, len + 1 ); */
/* now get rid of the ".xwg" */
dotPos = wcsrchr( widebuf, '.' );
@ -820,7 +822,7 @@ ceInitAndStartBoard( CEAppGlobals* globals, XP_Bool newGame,
if ( !!dict ) {
const XP_UCHAR* curDictName = dict_getName( dict );
if ( !!newDictName &&
( !curDictName || 0 != strcmp( curDictName, newDictName ) ) ) {
( !curDictName || 0 != XP_STRCMP( curDictName, newDictName ) ) ) {
toBeDestroyed = dict;
dict = NULL;
} else {
@ -836,7 +838,7 @@ ceInitAndStartBoard( CEAppGlobals* globals, XP_Bool newGame,
#else
XP_ASSERT( !!newDictName );
XP_LOGF( "calling ce_dictionary_make" );
dict = ce_dictionary_make( globals, newDictName);
dict = ce_dictionary_make( globals, newDictName );
#endif
XP_ASSERT( !!dict );
model_setDictionary( globals->game.model, dict );
@ -1046,14 +1048,14 @@ fileToStream( const CEAppGlobals* globals, const XP_UCHAR* path )
{
XWStreamCtxt* stream = NULL;
HANDLE fileH;
wchar_t widebuf[257];
/* wchar_t widebuf[257]; */
XP_U16 len;
len = (XP_U16)XP_STRLEN( path );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len + 1,
widebuf, len + 1 );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len + 1, */
/* widebuf, len + 1 ); */
fileH = CreateFile( widebuf, GENERIC_READ, 0, NULL,
fileH = CreateFile( path, GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if ( fileH != INVALID_HANDLE_VALUE ) {
@ -1103,8 +1105,8 @@ ceLoadSavedGame( CEAppGlobals* globals )
success = dict != NULL;
if ( !success ) {
XP_UCHAR buf[128];
snprintf( buf, VSIZE(buf), "Unable to open dictionary: %s",
dictName );
XP_SNPRINTF( buf, VSIZE(buf), XP_L("Unable to open dictionary: %s"),
dictName );
buf[VSIZE(buf)-1] = '\0';
ceOops( globals, buf );
@ -1133,7 +1135,7 @@ ceLoadSavedGame( CEAppGlobals* globals )
if ( !!dict ) {
dict_destroy( dict );
}
ceOops( globals, "Saved game cannot be opened." );
ceOops( globals, XP_L("Saved game cannot be opened.") );
}
}
@ -1306,6 +1308,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow
getOSInfo( globals );
globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(mpool) );
globals->hInst = hInstance;
// Initialize global strings
@ -1640,8 +1643,10 @@ ceChooseAndOpen( CEAppGlobals* globals )
len = wcslen(newName);
name = XP_MALLOC( globals->mpool, len + 1 );
WideCharToMultiByte( CP_ACP, 0, newName, len + 1,
name, len + 1, NULL, NULL );
XP_SNPRINTF( name, len + 1, XP_L("%ls"), newName );
/* WideCharToMultiByte( CP_ACP, 0, newName, len + 1, */
/* name, len + 1, NULL, NULL ); */
if ( globals->curGameName != NULL
&& 0 == XP_STRCMP( name, globals->curGameName ) ){
@ -1662,11 +1667,11 @@ ceChooseAndOpen( CEAppGlobals* globals )
closeGame( globals );
if ( CE_SVGAME_RENAME == choice ) {
XP_U16 len = 1 + XP_STRLEN( oldName );
wchar_t widebuf[len];
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, oldName, len,
widebuf, len );
(void)MoveFile( widebuf, newName );
/* XP_U16 len = 1 + XP_STRLEN( oldName ); */
/* wchar_t widebuf[len]; */
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, oldName, len, */
/* widebuf, len ); */
(void)MoveFile( oldName, newName );
}
globals->curGameName = name;
@ -1738,12 +1743,12 @@ ceWriteToFile( XWStreamCtxt* stream, void* closure )
#endif
XP_UCHAR* path = fwState->path;
XP_U16 len = (XP_U16)XP_STRLEN( path ) + 1; /* 1: null byte */
wchar_t widebuf[len];
/* wchar_t widebuf[len]; */
HANDLE fileH;
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len, widebuf, len );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, path, len, widebuf, len ); */
fileH = CreateFile( widebuf, GENERIC_WRITE, 0, NULL,
fileH = CreateFile( path, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( fileH != INVALID_HANDLE_VALUE ) {
@ -1799,9 +1804,10 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
nameBuf, VSIZE(nameBuf) );
if ( confirmed ) {
XP_U16 len = wcslen(nameBuf);
newName = XP_MALLOC( globals->mpool, len + 1 );
WideCharToMultiByte( CP_ACP, 0, nameBuf, len + 1,
newName, len + 1, NULL, NULL );
newName = XP_MALLOC( globals->mpool, (len + 1) * sizeof(newName[0]) );
XP_SNPRINTF( newName, len*sizeof(newName[0]), L"%ls", nameBuf );
/* WideCharToMultiByte( CP_ACP, 0, nameBuf, len + 1, */
/* newName, len + 1, NULL, NULL ); */
}
}
@ -1821,7 +1827,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
XWStreamCtxt* memStream;
DictionaryCtxt* dict;
FileWriteState fwState;
const char* dictName;
const XP_UCHAR* dictName;
XP_U8 flags;
fwState.path = globals->curGameName;
@ -1844,7 +1850,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
stream_putU8( memStream, flags );
if ( !!dictName ) {
stringToStream( memStream, dictName );
stream_putString( memStream, dictName );
}
ce_draw_toStream( globals->draw, memStream );
@ -2283,8 +2289,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_FILE_NEWGAME:
XP_LOGF( "ID_FILE_NEWGAME" );
if ( ceSaveCurGame( globals, XP_FALSE )
|| queryBoxChar( hWnd, "Do you really want to "
"overwrite the current game?" ) ) {
|| queryBoxChar( hWnd, XP_L("Do you really want to ")
XP_L("overwrite the current game?") ) ) {
draw = ceDoNewGame( globals );
}
break;
@ -2302,8 +2308,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_GAME_FINALSCORES:
if ( server_getGameIsOver( globals->game.server ) ) {
ceDisplayFinalScores( globals );
} else if ( queryBoxChar( hWnd, "Are you sure you want to end "
"the game now?" ) ) {
} else if ( queryBoxChar( hWnd, XP_L("Are you sure you want to end ")
XP_L("the game now?") ) ) {
server_endGame( globals->game.server );
draw = TRUE;
}
@ -2663,14 +2669,14 @@ messageBoxStream( CEAppGlobals* globals, XWStreamCtxt* stream, wchar_t* title,
XP_Bool
queryBoxChar( HWND hWnd, const XP_UCHAR* msg )
{
wchar_t widebuf[128];
/* wchar_t widebuf[128]; */
XP_U16 answer;
XP_U16 len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, msg, -1,
widebuf, VSIZE(widebuf) );
widebuf[len] = 0;
/* XP_U16 len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, msg, -1, */
/* widebuf, VSIZE(widebuf) ); */
/* widebuf[len] = 0; */
answer = MessageBox( hWnd, widebuf, L"Question",
answer = MessageBox( hWnd, msg, L"Question",
MB_YESNO | MB_ICONQUESTION );
return answer == IDOK || answer == IDYES;
} /* queryBoxChar */
@ -2692,7 +2698,7 @@ RECTtoXPR( XP_Rect* dest, const RECT* src )
} /* RECTtoXPR */
void
wince_assert( XP_UCHAR* XP_UNUSED_LOG(s), int XP_UNUSED_LOG(line),
wince_assert( const char* XP_UNUSED_LOG(s), int XP_UNUSED_LOG(line),
const char* XP_UNUSED_LOG(fileName),
const char* XP_UNUSED_LOG(func) )
{
@ -2702,7 +2708,7 @@ wince_assert( XP_UCHAR* XP_UNUSED_LOG(s), int XP_UNUSED_LOG(line),
#ifdef ENABLE_LOGGING
static void
makeTimeStamp( XP_UCHAR* timeStamp, XP_U16 XP_UNUSED_DBG(size) )
makeTimeStamp( char* timeStamp, XP_U16 XP_UNUSED_DBG(len) )
{
SYSTEMTIME st;
DWORD tid;
@ -2712,13 +2718,13 @@ makeTimeStamp( XP_UCHAR* timeStamp, XP_U16 XP_UNUSED_DBG(size) )
GetLocalTime( &st );
sprintf( timeStamp, "<%lx>%d:%.2d:%.2d ", tid, st.wHour, st.wMinute,
st.wSecond );
XP_ASSERT( size > strlen(timeStamp) );
XP_ASSERT( len > XP_STRLEN(timeStamp) );
} /* makeTimeStamp */
void
wince_warnf(const XP_UCHAR* format, ...)
wince_warnf(const char* format, ...)
{
XP_UCHAR buf[256];
char buf[256];
va_list ap;
XP_U16 slen;
@ -2738,13 +2744,13 @@ wince_warnf(const XP_UCHAR* format, ...)
} /* wince_warnf */
void
wince_debugf(const XP_UCHAR* format, ...)
wince_debugf(const char* format, ...)
{
#ifdef XWFEATURE_RELAY
static HANDLE s_logMutex = NULL;
#endif
XP_UCHAR buf[256];
XP_UCHAR timeStamp[32];
char buf[256];
char timeStamp[32];
XP_U16 nBytes;
XP_U32 nWritten;
HANDLE fileH;
@ -2764,7 +2770,7 @@ wince_debugf(const XP_UCHAR* format, ...)
}
if ( WaitForSingleObject( s_logMutex, 200L ) == WAIT_OBJECT_0 ) {
#endif
makeTimeStamp(timeStamp, sizeof(timeStamp));
makeTimeStamp(timeStamp, VSIZE(timeStamp) );
#ifdef _WIN32_WCE
logFileName = L"\\My Documents\\" LCROSSWORDS_DIR L"\\xwDbgLog.txt";
@ -2802,7 +2808,7 @@ wince_snprintf( XP_UCHAR* buf, XP_U16 len, const XP_UCHAR* format, ... )
va_start( ap, format );
_vsnprintf( buf, len, format, ap );
_vsnwprintf( buf, len, format, ap );
/* FormatMessage( */
/* FORMAT_MESSAGE_FROM_STRING, */
@ -2814,7 +2820,7 @@ wince_snprintf( XP_UCHAR* buf, XP_U16 len, const XP_UCHAR* format, ... )
va_end(ap);
return strlen(buf);
return XP_STRLEN(buf);
} /* wince_snprintf */
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
@ -2914,75 +2920,75 @@ ce_util_userError( XW_UtilCtxt* uc, UtilErrID id )
switch( id ) {
case ERR_TILES_NOT_IN_LINE:
message = "All tiles played must be in a line.";
message = XP_L("All tiles played must be in a line.");
break;
case ERR_NO_EMPTIES_IN_TURN:
message = "Empty squares cannot separate tiles played.";
message = XP_L("Empty squares cannot separate tiles played.");
break;
case ERR_TWO_TILES_FIRST_MOVE:
message = "Must play two or more pieces on the first move.";
message = XP_L("Must play two or more pieces on the first move.");
break;
case ERR_TILES_MUST_CONTACT:
message = "New pieces must contact others already in place (or "
"the middle square on the first move).";
message = XP_L("New pieces must contact others already in place (or ")
XP_L("the middle square on the first move.");
break;
case ERR_NOT_YOUR_TURN:
message = "You can't do that; it's not your turn!";
message = XP_L("You can\'t do that; it\'s not your turn!");
break;
case ERR_NO_PEEK_ROBOT_TILES:
message = "No peeking at the robot's tiles!";
message = XP_L("No peeking at the robot's tiles!");
break;
case ERR_CANT_TRADE_MID_MOVE:
message = "Remove played tiles before trading.";
message = XP_L("Remove played tiles before trading.");
break;
case ERR_TOO_FEW_TILES_LEFT_TO_TRADE:
message = "Too few tiles left to trade.";
message = XP_L("Too few tiles left to trade.");
break;
case ERR_CANT_UNDO_TILEASSIGN:
message = "Tile assignment can't be undone.";
message = XP_L("Tile assignment can\'t be undone.");
break;
case ERR_CANT_HINT_WHILE_DISABLED:
message = "The hint feature is disabled for this game. Enable "
"it for a new game using the Preferences dialog.";
message = XP_L("The hint feature is disabled for this game. Enable ")
XP_L("it for a new game using the Preferences dialog.");
break;
#ifndef XWFEATURE_STANDALONE_ONLY
case ERR_NO_PEEK_REMOTE_TILES:
message = "No peeking at remote players' tiles!";
message = XP_L("No peeking at remote players\' tiles!");
break;
case ERR_REG_UNEXPECTED_USER:
message = "Refused attempt to register unexpected user[s].";
message = XP_L("Refused attempt to register unexpected user[s].");
break;
case ERR_SERVER_DICT_WINS:
message = "Conflict between Host and Guest dictionaries; Host wins.";
message = XP_L("Conflict between Host and Guest dictionaries; Host wins.");
XP_WARNF( "GTK may have problems here." );
break;
case ERR_REG_SERVER_SANS_REMOTE:
message = "At least one player must be marked remote for a game "
"started as Host.";
message = XP_L("At least one player must be marked remote for a game ")
XP_L("started as Host.");
break;
#endif
#ifdef XWFEATURE_RELAY
case ERR_RELAY_BASE + XWRELAY_ERROR_TIMEOUT:
message = "The relay timed you out; usually that means "
"the other players didn't show.";
message = XP_L("The relay timed you out; usually that means ")
XP_L("the other players didn\'t show.");
break;
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_YOU:
message = "You were disconnected from relay because it didn't "
"hear from you in too long.";
message = XP_L("You were disconnected from relay because it didn\'t ")
XP_L("hear from you in too long.");
break;
case ERR_RELAY_BASE + XWRELAY_ERROR_HEART_OTHER:
case ERR_RELAY_BASE + XWRELAY_ERROR_LOST_OTHER:
message = "The relay has lost contact with a device in this game.";
message = XP_L("The relay has lost contact with a device in this game.");
break;
#endif
default:
XP_LOGF( "%s(%d)", __func__, id );
message = "unknown errorcode ID!!!";
message = XP_L("unknown errorcode ID!!!");
break;
}
@ -2992,7 +2998,7 @@ ce_util_userError( XW_UtilCtxt* uc, UtilErrID id )
static XP_Bool
ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
{
char* query = NULL;
XP_UCHAR* query = NULL;
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
switch( id ) {
@ -3000,7 +3006,7 @@ ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
return ceQueryFromStream( globals, stream );
case QUERY_COMMIT_TRADE:
query = "Are you sure you want to trade the selected tiles?";
query = XP_L("Are you sure you want to trade the selected tiles?");
assertOnTop( globals->hWnd );
return queryBoxChar( globals->hWnd, query );
@ -3332,14 +3338,14 @@ ce_formatBadWords( BadWordInfo* bwi, XP_UCHAR buf[], XP_U16 bufsiz )
for ( i = 0, buf[0] = '\0'; ; ) {
XP_UCHAR wordBuf[18];
sprintf( wordBuf, "\"%s\"", bwi->words[i] );
XP_ASSERT( strlen(wordBuf) < sizeof(wordBuf)-1 );
strncat( buf, wordBuf, bufsiz - 1 );
XP_SNPRINTF( wordBuf, VSIZE(wordBuf), XP_L("\"%s\""), bwi->words[i] );
XP_ASSERT( XP_STRLEN(wordBuf) < sizeof(wordBuf)-1 );
XP_SNPRINTF( buf, bufsiz - 1, XP_L("%ls"), wordBuf );
if ( ++i == bwi->nWords ) {
break;
}
bufsiz -= strlen( wordBuf );
strncat( buf, ", ", bufsiz - 1 );
bufsiz -= XP_STRLEN( wordBuf );
XP_SNPRINTF( buf, bufsiz - 1, XP_L("%s"), ", " );
bufsiz -= 2;
}
} /* ce_formatBadWords */
@ -3354,14 +3360,14 @@ ce_util_warnIllegalWord( XW_UtilCtxt* uc, BadWordInfo* bwi,
XP_Bool isOk;
ce_formatBadWords( bwi, wordsBuf, sizeof(wordsBuf) );
sprintf( msgBuf, "Word[s] %s not found in dictionary.", wordsBuf );
XP_SNPRINTF( msgBuf, VSIZE(msgBuf), XP_L("Word[s] %s not found in dictionary."), wordsBuf );
if ( turnLost ) {
ceMessageBoxChar( globals, msgBuf, L"Illegal word",
MB_OK | MB_ICONHAND );
isOk = XP_TRUE;
} else {
strcat( msgBuf, " Use it anyway?" );
XP_STRCAT( msgBuf, XP_L(" Use it anyway?") );
assertOnTop( globals->hWnd );
isOk = queryBoxChar( globals->hWnd, msgBuf );
}

View file

@ -333,9 +333,9 @@ PrefsDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
break;
case IDC_CHECKHINTSLIMITS:
if ( IS_SMARTPHONE(globals) ) {
ceMessageBoxChar( globals, "This feature "
ceMessageBoxChar( globals, XP_L("This feature ")
"requires a touch screen.",
L"Sorry", MB_OK | MB_ICONHAND );
XP_L("Sorry"), MB_OK | MB_ICONHAND );
ceSetChecked( hDlg, IDC_CHECKHINTSLIMITS, XP_FALSE );
}
break;

View file

@ -251,12 +251,17 @@ static void
getHostAddr( CeSocketWrapper* self )
{
if ( self->addrRec.u.ip_relay.hostName[0] ) {
XP_LOGF( "%s: calling WSAAsyncGetHostByName(%s)",
__func__, self->addrRec.u.ip_relay.hostName );
XP_UCHAR* hostName = self->addrRec.u.ip_relay.hostName;
XP_U16 len = 1 + XP_STRLEN(hostName);
char tmp[1+VSIZE(self->addrRec.u.ip_relay.hostName)];
WideCharToMultiByte( CP_ACP, 0, hostName, len,
tmp, len + 1, NULL, NULL );
XP_LOGF( "%s: calling WSAAsyncGetHostByName(%s)", __func__, tmp );
self->getHostTask
= WSAAsyncGetHostByName( self->globals->hWnd,
XWWM_HOSTNAME_ARRIVED,
self->addrRec.u.ip_relay.hostName,
XWWM_HOSTNAME_ARRIVED, tmp,
(char*)&self->hostNameUnion,
sizeof(self->hostNameUnion) );
if ( NULL == self->getHostTask ) {

View file

@ -26,7 +26,7 @@ stuffTextInField( HWND hDlg, StrBoxState* state )
{
XP_U16 nBytes = stream_getSize(state->stream);
XP_U16 len, crlen;
XP_UCHAR* sbuf;
char* sbuf;
wchar_t* wbuf;
#ifdef MEM_DEBUG
CEAppGlobals* globals = state->dlgHdr.globals;
@ -36,7 +36,7 @@ stuffTextInField( HWND hDlg, StrBoxState* state )
stream_getBytes( state->stream, sbuf, nBytes );
crlen = strlen(XP_CR);
if ( 0 == strncmp( XP_CR, &sbuf[nBytes-crlen], crlen ) ) {
if ( 0 == XP_STRNCMP( XP_CR, &sbuf[nBytes-crlen], crlen ) ) {
nBytes -= crlen;
}
sbuf[nBytes] = '\0';

View file

@ -361,7 +361,7 @@ deleteSelected( CeSavedGamesState* state )
{
/* confirm first!!!! */
XP_Bool confirmed = queryBoxChar( state->dlgHdr.hDlg,
"Are you certain you want to delete the "
XP_L("Are you certain you want to delete the ")
"selected game? This action cannot be "
"undone.");
if ( confirmed ) {
@ -487,12 +487,12 @@ ceSavedGamesDlg( CEAppGlobals* globals, const XP_UCHAR* curPath,
state.sel = -1;
if ( !!curPath ) {
wchar_t widebuf[MAX_PATH];
XP_U16 len;
len = (XP_U16)XP_STRLEN( curPath );
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, curPath, len + 1,
widebuf, len + 1 );
ceBasename( state.openNameW, widebuf );
/* wchar_t widebuf[MAX_PATH]; */
/* XP_U16 len; */
/* len = (XP_U16)XP_STRLEN( curPath ); */
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, curPath, len + 1, */
/* widebuf, len + 1 ); */
ceBasename( state.openNameW, curPath );
}
for ( ; ; ) {

View file

@ -37,7 +37,7 @@ static void ceDoDlgFocusScroll( CeDlgHdr* dlgHdr, HWND nextCtrl );
void
ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf )
{
wchar_t widebuf[BUF_SIZE];
/* wchar_t widebuf[BUF_SIZE]; */
XP_U16 len;
XP_ASSERT( buf != NULL );
@ -48,9 +48,9 @@ ceSetDlgItemText( HWND hDlg, XP_U16 id, const XP_UCHAR* buf )
len = BUF_SIZE - 1;
}
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, buf, len, widebuf, len );
widebuf[len] = 0;
SendDlgItemMessage( hDlg, id, WM_SETTEXT, 0, (long)widebuf );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, buf, len, widebuf, len ); */
/* widebuf[len] = 0; */
SendDlgItemMessage( hDlg, id, WM_SETTEXT, 0, (long)buf );
} /* ceSetDlgItemText */
void
@ -64,10 +64,10 @@ ceSetDlgItemFileName( HWND hDlg, XP_U16 id, XP_UCHAR* str )
len = BUF_SIZE - 1;
}
XP_MEMCPY( buf, str, len );
XP_SNPRINTF( buf, VSIZE(buf), XP_L("%ls"), str );
buf[len] = '\0';
stripstart = strrchr( (const char*)buf, '.' );
stripstart = XP_STRRCHR( buf, '.' );
if ( !!stripstart ) {
*stripstart = '\0';
}
@ -80,19 +80,21 @@ ceGetDlgItemText( HWND hDlg, XP_U16 id, XP_UCHAR* buf, XP_U16* bLen )
{
XP_U16 len = *bLen;
XP_U16 gotLen;
wchar_t wbuf[BUF_SIZE];
/* wchar_t wbuf[BUF_SIZE]; */
XP_ASSERT( len <= BUF_SIZE );
gotLen = (XP_U16)SendDlgItemMessage( hDlg, id, WM_GETTEXT, len,
(long)wbuf );
(long)buf );
XP_LOGF( "%s: gotLen: %d; len: %d; got: %ls", __func__,
gotLen, len, buf );
if ( gotLen > 0 ) {
XP_ASSERT( gotLen < len );
if ( gotLen >= len ) {
gotLen = len - 1;
}
gotLen = WideCharToMultiByte( CP_ACP, 0, wbuf, gotLen,
buf, len, NULL, NULL );
/* gotLen = WideCharToMultiByte( CP_ACP, 0, wbuf, gotLen, */
/* buf, len, NULL, NULL ); */
*bLen = gotLen;
buf[gotLen] = '\0';
} else {
@ -105,7 +107,7 @@ void
ceSetDlgItemNum( HWND hDlg, XP_U16 id, XP_S32 num )
{
XP_UCHAR buf[20];
XP_SNPRINTF( buf, sizeof(buf), "%ld", num );
XP_SNPRINTF( buf, VSIZE(buf), XP_L("%ld"), num );
ceSetDlgItemText( hDlg, id, buf );
} /* ceSetDlgItemNum */
@ -114,10 +116,10 @@ ceGetDlgItemNum( HWND hDlg, XP_U16 id )
{
XP_S32 result = 0;
XP_UCHAR buf[24];
XP_U16 len = sizeof(buf);
XP_U16 len = VSIZE(buf);
ceGetDlgItemText( hDlg, id, buf, &len );
result = atoi( buf );
result = _wtoi( buf );
return result;
} /* ceGetDlgItemNum */
@ -886,15 +888,15 @@ ceMessageBoxChar( CEAppGlobals* XP_UNUSED(globals), const XP_UCHAR* str,
HWND parent;
/* Get the length required, then alloc and go. This is technically
correct, but everywhere else I assume a 2:1 ratio for wchar_t:char. */
XP_U16 clen = 1 + strlen(str);
XP_U32 wlen = 1 + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str,
clen, NULL, 0 );
wchar_t widebuf[wlen];
/* XP_U16 clen = 1 + XP_STRLEN(str); */
/* XP_U32 wlen = 1 + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, */
/* clen, NULL, 0 ); */
/* wchar_t widebuf[wlen]; */
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, clen, widebuf, wlen );
/* MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, clen, widebuf, wlen ); */
parent = GetForegroundWindow();
return MessageBox( parent, widebuf, title, buttons );
return MessageBox( parent, str, title, buttons );
} /* ceMessageBoxChar */
int
@ -903,3 +905,24 @@ ceOops( CEAppGlobals* globals, const XP_UCHAR* str )
return ceMessageBoxChar( globals, str, L"Oops!",
MB_OK | MB_ICONHAND );
}
XP_U16
wince_narrow_to_wide( const XP_U8* in, XP_UCHAR* out, XP_U16 inLen, XP_U16 outLen )
{
XP_U16 nWritten;
nWritten = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, (const char*)in, inLen,
out, outLen );
out[nWritten++] = 0;
XP_ASSERT( nWritten < outLen );
return nWritten;
}
XP_U16
wince_wide_to_narrow( const XP_UCHAR* in, XP_U8* out, XP_U16 inLen, XP_U16 outLen )
{
XP_U16 nWritten = WideCharToMultiByte( CP_ACP, 0, in, inLen,
(char*)out, outLen, NULL, NULL );
out[nWritten++] = 0;
XP_ASSERT( nWritten <= outLen );
return nWritten;
}

View file

@ -1,6 +1,7 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; -*- */
/*
* Copyright 2002-2004 by Eric House (xwords@eehouse.org). All rights reserved.
* Copyright 2002-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

View file

@ -27,6 +27,8 @@
#include <winuser.h>
#include <winsock2.h>
#define UCHAR_IS_WIDE
typedef unsigned char XP_U8;
typedef signed char XP_S8;
@ -36,7 +38,8 @@ typedef signed short XP_S16;
typedef unsigned long XP_U32;
typedef signed long XP_S32;
typedef char XP_UCHAR;
/* typedef char XP_UCHAR; */
typedef wchar_t XP_UCHAR;
typedef signed short XP_FontCode; /* not sure how I'm using this yet */
typedef BOOL XP_Bool;
@ -45,7 +48,12 @@ typedef XP_U32 XP_Time;
#define XP_TRUE ((XP_Bool)(1==1))
#define XP_FALSE ((XP_Bool)(1==0))
#define XP_CR "\015\012" /* 'Doze expects a carraige return followed by a linefeed */
/* 'Doze expects a carraige return followed by a linefeed */
#define XP_CR "\015\012"
#define XP_CR_L XP_L(XP_CR)
#define XP_L(s) L"" s
#define XP_LS XP_L("%ls")
#ifdef _WIN32_WCE
# define XP_RANDOM() Random()
@ -68,10 +76,24 @@ typedef XP_U32 XP_Time;
#define XP_MEMMOVE(d,s,l) memmove((d),(s),(l))
#define XP_MEMCMP( a1, a2, l ) memcmp((a1),(a2),(l))
#define XP_STRLEN(s) strlen((char*)(s))
#define XP_STRCAT(d,s) strcat((d),(s))
/* #define XP_STRCAT(d,s) strcat((d),(s)) */
#define XP_STRCMP(s1,s2) strcmp((char*)(s1),(char*)(s2))
#define XP_STRNCMP(s1,s2,l) strncmp((char*)(s1),(char*)(s2),(l))
#define XP_SNPRINTF wince_snprintf
#define XP_STRRCHR(s1,c1) wcsrchr(s1,c1)
#define XP_ATOI _wtoi
#define XP_STRCAT wcscat
#define XP_STRSTR wcsstr
XP_U16 wince_narrow_to_wide( const XP_U8* in, XP_UCHAR* out, XP_U16 inLen,
XP_U16 outLen );
XP_U16 wince_wide_to_narrow( const XP_UCHAR* in, XP_U8* out, XP_U16 inLen,
XP_U16 outLen );
#define XP_NARROW_TO_UCHAR( bytes, where, len, wlenp ) \
wince_narrow_to_wide( (bytes), (where), (len), (wlenp) )
#define XP_UCHAR_TO_NARROW( whence, bytes, wlen, lenp ) \
wince_wide_narrow_to( (whence), (bytes), (wlen), (lenp) )
#define XP_MIN(a,b) ((a)<(b)?(a):(b))
#define XP_MAX(a,b) ((a)>(b)?(a):(b))
@ -100,10 +122,11 @@ typedef XP_U32 XP_Time;
extern "C" {
#endif
void wince_assert(XP_UCHAR* s, int line, const char* fileName, const char* func );
void wince_debugf(const XP_UCHAR*, ...)
void wince_assert(const char* s, int line, const char* fileName,
const char* func );
void wince_debugf(const char*, ...)
__attribute__ ((format (printf, 1, 2)));
void wince_warnf(const XP_UCHAR*, ...)
void wince_warnf(const char*, ...)
__attribute__ ((format (printf, 1, 2)));
void p_ignore(XP_UCHAR*, ...);
XP_U16 wince_snprintf( XP_UCHAR* buf, XP_U16 len,