mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-26 09:58:20 +01:00
Add, and use, stream_putString. Saves 500 bytes on win32.
This commit is contained in:
parent
1c4f0a47b7
commit
4e2b080be5
9 changed files with 44 additions and 27 deletions
|
@ -221,13 +221,13 @@ mpool_stats( MemPoolCtx* mpool, XWStreamCtxt* stream )
|
|||
"Number of free blocks: %d\n"
|
||||
"Total number of blocks allocated: %d\n",
|
||||
mpool->nUsed, mpool->nFree, mpool->nAllocs );
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
|
||||
for ( entry = mpool->usedList; !!entry; entry = entry->next ) {
|
||||
XP_SNPRINTF( buf, sizeof(buf),
|
||||
(XP_UCHAR*)"%ld byte block allocated %s: line %ld\n",
|
||||
entry->size, entry->fileName, entry->lineNo );
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
}
|
||||
} /* mpool_stats */
|
||||
|
||||
|
|
|
@ -212,6 +212,13 @@ mem_stream_putBytes( XWStreamCtxt* p_sctx, void* whence, XP_U16 count )
|
|||
stream->curWritePos += count;
|
||||
} /* mem_stream_putBytes */
|
||||
|
||||
static void
|
||||
mem_stream_putString( XWStreamCtxt* p_sctx, const char* whence )
|
||||
{
|
||||
XP_U16 len = XP_STRLEN( whence );
|
||||
mem_stream_putBytes( p_sctx, (void*)whence, len );
|
||||
}
|
||||
|
||||
static void
|
||||
mem_stream_putU8( XWStreamCtxt* p_sctx, XP_U8 data )
|
||||
{
|
||||
|
@ -413,6 +420,7 @@ make_vtable( MemStreamCtxt* stream )
|
|||
|
||||
SET_VTABLE_ENTRY( vtable, stream_putU8, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putBytes, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putString, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putU16, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putU32, mem );
|
||||
SET_VTABLE_ENTRY( vtable, stream_putBits, mem );
|
||||
|
|
|
@ -1370,7 +1370,7 @@ notifyTrayListeners( ModelCtxt* model, XP_U16 turn, TileBit bits )
|
|||
static void
|
||||
printString( XWStreamCtxt* stream, XP_UCHAR* str )
|
||||
{
|
||||
stream_putBytes( stream, str, (XP_U16)XP_STRLEN((char*)str) );
|
||||
stream_putString( stream, str );
|
||||
} /* printString */
|
||||
|
||||
static XP_UCHAR*
|
||||
|
|
|
@ -516,7 +516,7 @@ figureMoveScore( ModelCtxt* model, MoveInfo* moveInfo, EngineCtxt* engine,
|
|||
if ( !!stream ) {
|
||||
XP_UCHAR* bstr = util_getUserString( model->vol.util,
|
||||
STR_BONUS_ALL );
|
||||
stream_putBytes( stream, bstr, (XP_U8)XP_STRLEN(bstr) );
|
||||
stream_putString( stream, bstr );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -832,7 +832,7 @@ formatWordScore( XWStreamCtxt* stream, XP_U16 wordScore,
|
|||
}
|
||||
XP_ASSERT( XP_STRLEN(tmpBuf) < sizeof(tmpBuf) );
|
||||
|
||||
stream_putBytes( stream, tmpBuf, (XP_U16)XP_STRLEN(tmpBuf) );
|
||||
stream_putString( stream, tmpBuf );
|
||||
}
|
||||
} /* formatWordScore */
|
||||
|
||||
|
@ -844,7 +844,7 @@ formatSummary( XWStreamCtxt* stream, ModelCtxt* model, XP_U16 score )
|
|||
util_getUserString(model->vol.util, STRD_TURN_SCORE),
|
||||
score);
|
||||
XP_ASSERT( XP_STRLEN(buf) < sizeof(buf) );
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
} /* formatSummary */
|
||||
|
||||
#ifdef CPLUS
|
||||
|
|
|
@ -658,7 +658,7 @@ makeRobotMove( ServerCtxt* server )
|
|||
str = util_getUserString(util, STRD_ROBOT_TRADED);
|
||||
XP_SNPRINTF( buf, sizeof(buf), str, MAX_TRAY_TILES );
|
||||
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
XP_ASSERT( !server->vol.prevMoveStream );
|
||||
server->vol.prevMoveStream = stream;
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ showPrevScore( ServerCtxt* server )
|
|||
stream = mkServerStream( server );
|
||||
|
||||
str = util_getUserString( util, strCode );
|
||||
stream_putBytes( stream, str, (XP_U16)XP_STRLEN(str) );
|
||||
stream_putString( stream, str );
|
||||
|
||||
if ( !!server->vol.prevMoveStream ) {
|
||||
XWStreamCtxt* prevStream = server->vol.prevMoveStream;
|
||||
|
@ -1762,7 +1762,7 @@ reflectMoveAndInform( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
XP_SNPRINTF( tradeBuf, sizeof(tradeBuf),
|
||||
tradeStr, tradedTiles.nTiles );
|
||||
mvStream = mkServerStream( server );
|
||||
stream_putBytes( mvStream, tradeBuf, XP_STRLEN(tradeBuf) );
|
||||
stream_putString( mvStream, tradeBuf );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -2343,7 +2343,7 @@ server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
|||
dict = model_getDictionary( server->vol.model );
|
||||
dname = dict_getShortName( dict );
|
||||
XP_SNPRINTF( buf, sizeof(buf), fmt, dname );
|
||||
stream_putBytes( stream, buf, XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
|
||||
nChars = dict_numTileFaces( dict );
|
||||
|
||||
|
@ -2360,16 +2360,16 @@ server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
|||
|
||||
XP_SNPRINTF( buf, sizeof(buf), (XP_UCHAR*)"%s: %d/%d",
|
||||
face, count, value );
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
}
|
||||
|
||||
if ( ++tile >= nChars ) {
|
||||
break;
|
||||
} else if ( count > 0 ) {
|
||||
if ( ++nPrinted % nCols == 0 ) {
|
||||
stream_putBytes( stream, XP_CR, (XP_U16)XP_STRLEN(XP_CR) );
|
||||
stream_putString( stream, XP_CR );
|
||||
} else {
|
||||
stream_putBytes( stream, (void*)" ", 3 );
|
||||
stream_putString( stream, (void*)" " );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2429,13 +2429,13 @@ server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
|
|||
buf[0] = '\0';
|
||||
putNTiles( buf, face, count );
|
||||
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
}
|
||||
|
||||
if ( ++tile >= nChars ) {
|
||||
break;
|
||||
} else if ( count > 0 ) {
|
||||
stream_putBytes( stream, (void*)" ", 3 );
|
||||
stream_putString( stream, (void*)" " );
|
||||
}
|
||||
}
|
||||
} /* server_formatRemainingTiles */
|
||||
|
@ -2483,7 +2483,7 @@ server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
if ( highestIndex == -1 ) {
|
||||
break; /* we're done */
|
||||
} else if ( place > 1 ) {
|
||||
stream_putBytes( stream, XP_CR, (XP_U16)XP_STRLEN(XP_CR) );
|
||||
stream_putString( stream, XP_CR );
|
||||
}
|
||||
scores[highestIndex] = IMPOSSIBLY_LOW_SCORE;
|
||||
|
||||
|
@ -2514,7 +2514,7 @@ server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
place,
|
||||
emptyStringIfNull(gi->players[highestIndex].name),
|
||||
highestScore, curScore, tmpbuf, timeStr );
|
||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||
stream_putString( stream, buf );
|
||||
}
|
||||
} /* server_writeFinalScores */
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ typedef struct StreamCtxVTable {
|
|||
void (*m_stream_putU8)( XWStreamCtxt* dctx, XP_U8 byt );
|
||||
void (*m_stream_putBytes)( XWStreamCtxt* dctx, void* whence,
|
||||
XP_U16 count );
|
||||
void (*m_stream_putString)( XWStreamCtxt* dctx, const char* 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 );
|
||||
|
@ -103,6 +104,9 @@ struct XWStreamCtxt {
|
|||
#define stream_putBytes( sc, w, c ) \
|
||||
(sc)->vtable->m_stream_putBytes((sc), (w), (c))
|
||||
|
||||
#define stream_putString( sc, w ) \
|
||||
(sc)->vtable->m_stream_putString((sc), (w))
|
||||
|
||||
#define stream_putU16(sc, d) \
|
||||
(sc)->vtable->m_stream_putU16((sc), (d))
|
||||
|
||||
|
|
|
@ -90,6 +90,12 @@ linux_file_stream_putBytes( XWStreamCtxt* p_sctx, void* where,
|
|||
XP_ASSERT( written != 0 );
|
||||
} /* linux_file_stream_putBytes */
|
||||
|
||||
static void
|
||||
linux_file_stream_putString( XWStreamCtxt* p_sctx, const char* where )
|
||||
{
|
||||
linux_file_stream_putBytes( p_sctx, (void*)where, XP_STRLEN(where) );
|
||||
}
|
||||
|
||||
static void
|
||||
linux_file_stream_putU8( XWStreamCtxt* p_sctx, XP_U8 data )
|
||||
{
|
||||
|
@ -152,6 +158,7 @@ make_vtable( LinuxFileStreamCtxt* stream )
|
|||
|
||||
SET_VTABLE_ENTRY( stream, stream_putU8, linux_file );
|
||||
SET_VTABLE_ENTRY( stream, stream_putBytes, linux_file );
|
||||
SET_VTABLE_ENTRY( stream, stream_putString, linux_file );
|
||||
SET_VTABLE_ENTRY( stream, stream_putU16, linux_file );
|
||||
SET_VTABLE_ENTRY( stream, stream_putU32, linux_file );
|
||||
|
||||
|
|
|
@ -706,7 +706,7 @@ formatDirsCB( wchar_t* dir, void* ctxt )
|
|||
int len;
|
||||
|
||||
if ( datap->firstPassDone ) {
|
||||
stream_putBytes( datap->stream, ", ", 2 );
|
||||
stream_putString( datap->stream, ", " );
|
||||
} else {
|
||||
datap->firstPassDone = XP_TRUE;
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ formatDirsCB( wchar_t* dir, void* ctxt )
|
|||
len = WideCharToMultiByte( CP_ACP, 0, dir, -1,
|
||||
narrow, sizeof(narrow)/sizeof(narrow[0]),
|
||||
NULL, NULL );
|
||||
stream_putBytes( datap->stream, narrow, len-1 ); /* skip null */
|
||||
stream_putString( datap->stream, narrow );
|
||||
return XP_FALSE;
|
||||
} /* formatDirsCB */
|
||||
|
||||
|
@ -770,12 +770,12 @@ ceFormatDictDirs( XWStreamCtxt* stream, HINSTANCE hInstance )
|
|||
}
|
||||
|
||||
if ( id != IDS_DICTDIRS ) {
|
||||
stream_putBytes( stream, ", ", 2 );
|
||||
stream_putString( stream, ", " );
|
||||
}
|
||||
len = WideCharToMultiByte( CP_ACP, 0, wide, -1,
|
||||
narrow, sizeof(narrow)/sizeof(narrow[0]),
|
||||
NULL, NULL );
|
||||
stream_putBytes( stream, narrow, len-1 ); /* skip null */
|
||||
stream_putString( stream, narrow );
|
||||
}
|
||||
}
|
||||
#endif /* USE_FOREACH */
|
||||
|
|
|
@ -975,13 +975,11 @@ InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|||
globals );
|
||||
if ( !result ) {
|
||||
XWStreamCtxt* stream = make_generic_stream( globals );
|
||||
char* str = "Please install a Crosswords dictionary "
|
||||
"in one of these directories: ";
|
||||
stream_putBytes( stream, str, XP_STRLEN(str) );
|
||||
stream_putString( stream, "Please install a Crosswords dictionary "
|
||||
"in one of these directories: " );
|
||||
ceFormatDictDirs( stream, hInstance );
|
||||
str = ". Download dictionaries from http://xwords.sf.net.";
|
||||
stream_putBytes( stream, str, XP_STRLEN(str) );
|
||||
|
||||
stream_putString( stream, ". Download dictionaries from "
|
||||
"http://xwords.sf.net." );
|
||||
messageBoxStream( globals, stream, L"Dictionary Not Found" );
|
||||
stream_destroy( stream );
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue