mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-13 08:01:33 +01:00
substitute macro for common sizeof(x)/sizeof(x[0]) pattern; no generated code change
This commit is contained in:
parent
41b81f463e
commit
e891a26756
16 changed files with 45 additions and 52 deletions
|
@ -39,6 +39,8 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
|
||||
typedef struct XP_Rect {
|
||||
XP_S16 left;
|
||||
XP_S16 top;
|
||||
|
|
|
@ -689,7 +689,7 @@ figureCrosschecks( EngineCtxt* engine, XP_U16 x, XP_U16 y, XP_U16* scoreP,
|
|||
tiles[0] = tile;
|
||||
if ( lookup( dict, in_edge, tiles, 0, tilesAfter ) ) {
|
||||
XP_ASSERT( (tile >> 5)
|
||||
< (sizeof(check->bits)/sizeof(check->bits[0])) );
|
||||
< (VSIZE(check->bits)) );
|
||||
check->bits[tile>>5] |= (1L << (tile & 0x1F));
|
||||
}
|
||||
|
||||
|
|
|
@ -350,7 +350,7 @@ static void
|
|||
cleanupServer( ServerCtxt* server )
|
||||
{
|
||||
XP_U16 i;
|
||||
for ( i = 0; i < sizeof(server->players)/sizeof(server->players[0]); ++i ){
|
||||
for ( i = 0; i < VSIZE(server->players); ++i ){
|
||||
ServerPlayer* player = &server->players[i];
|
||||
if ( player->engine != NULL ) {
|
||||
engine_destroy( player->engine );
|
||||
|
|
|
@ -72,7 +72,7 @@ curses_askLetter( CursesAppGlobals* globals, XP_UCHAR* query,
|
|||
getmaxyx(globals->boardWin, y, x);
|
||||
XP_DEBUGF( "getmaxyx=>x=%d,y=%d", x, y );
|
||||
|
||||
numCtlButtons = sizeof(ctlButtons) / sizeof(ctlButtons[0]);
|
||||
numCtlButtons = VSIZE(ctlButtons);
|
||||
|
||||
measureAskText( query, &fi );
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame )
|
|||
roleCombo = gtk_combo_box_new_text();
|
||||
state->roleCombo = roleCombo;
|
||||
|
||||
for ( i = 0; i < sizeof(roles)/sizeof(roles[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(roles); ++i ) {
|
||||
gtk_combo_box_append_text( GTK_COMBO_BOX(roleCombo), roles[i] );
|
||||
}
|
||||
g_signal_connect( GTK_OBJECT(roleCombo), "changed",
|
||||
|
|
|
@ -158,7 +158,7 @@ updateFormCtls( FormPtr form, ConnsDlgState* state )
|
|||
on = NULL;
|
||||
}
|
||||
|
||||
for ( i = 0; i < sizeof(allCtls)/sizeof(allCtls[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(allCtls); ++i ) {
|
||||
const XP_U16* cur = allCtls[i];
|
||||
if ( cur != on ) {
|
||||
disOrEnableSet( form, cur, XP_FALSE );
|
||||
|
|
|
@ -179,7 +179,7 @@ main( int argc, char** argv )
|
|||
}
|
||||
|
||||
write_fnav( &gamesHeader, gamesElemsShort, NULL,
|
||||
sizeof(gamesElemsShort)/sizeof(gamesElemsShort[0]) );
|
||||
VSIZE(gamesElemsShort) );
|
||||
/* sizeof(gamesElems)/sizeof(gamesElems[0]) ); */
|
||||
|
||||
|
||||
|
|
|
@ -918,7 +918,7 @@ doCallbackReg( PalmAppGlobals* globals, XP_Bool reg )
|
|||
};
|
||||
|
||||
|
||||
for ( i = 0; i < sizeof(notifyTypes) / sizeof(notifyTypes[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(notifyTypes); ++i ) {
|
||||
UInt32 notifyType = notifyTypes[i];
|
||||
|
||||
if ( reg ) {
|
||||
|
@ -2421,10 +2421,10 @@ handleKeyEvent( PalmAppGlobals* globals, const EventType* event,
|
|||
BoardObjectType nxt = board_getFocusOwner( board );
|
||||
XP_U16 indx = 0;
|
||||
if ( nxt != OBJ_NONE ) {
|
||||
for ( ; indx < sizeof(typs)/sizeof(typs[0]); ++indx ){
|
||||
for ( ; indx < VSIZE(typs); ++indx ){
|
||||
if ( nxt == typs[indx] ) {
|
||||
indx = (indx + (sizeof(typs)/sizeof(typs[0]) + incr));
|
||||
indx %= sizeof(typs)/sizeof(typs[0]);
|
||||
indx = (indx + (VSIZE(typs) + incr));
|
||||
indx %= VSIZE(typs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3787,6 +3787,7 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
|
|||
XP_ASSERT( 0 );
|
||||
}
|
||||
|
||||
XP_ASSERT( why < VSIZE(globals->timerProcs) );
|
||||
globals->timerProcs[why] = proc;
|
||||
globals->timerClosures[why] = closure;
|
||||
globals->timerFireAt[why] = now;
|
||||
|
|
|
@ -34,8 +34,7 @@ loadLettersList( HWND hDlg, BlankDialogState* bState )
|
|||
|
||||
len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
|
||||
texts[i], strlen(texts[i]),
|
||||
widebuf,
|
||||
sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
widebuf[len] = 0;
|
||||
|
||||
SendDlgItemMessage( hDlg, BLANKFACE_LIST, LB_ADDSTRING,
|
||||
|
@ -72,8 +71,7 @@ showCurTray( HWND hDlg, BlankDialogState* bState )
|
|||
(void)MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
|
||||
labelBuf, lenSoFar + 1,
|
||||
widebuf,
|
||||
(sizeof(widebuf)/sizeof(widebuf[0]))
|
||||
+ sizeof(widebuf[0]) );
|
||||
VSIZE(widebuf) + sizeof(widebuf[0]) );
|
||||
|
||||
SetDlgItemText( hDlg,IDC_PICKMSG, widebuf );
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ adjustForConnType( HWND hDlg, const CeConnDlgState* cState )
|
|||
btIds; /* we want the "disabled" message */
|
||||
}
|
||||
|
||||
for ( i = 0; i < sizeof(allIDs)/sizeof(allIDs[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(allIDs); ++i ) {
|
||||
XP_U16* ids = allIDs[i];
|
||||
XP_Bool enable = ids == on;
|
||||
while ( *ids != 0 ) {
|
||||
|
@ -132,7 +132,7 @@ ceControlsFromAddrRec( HWND hDlg, const CeConnDlgState* cState )
|
|||
, L"WiFi/Cellular data"
|
||||
};
|
||||
|
||||
for ( i = 0; i < sizeof(strs)/sizeof(strs[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(strs); ++i ) {
|
||||
SendDlgItemMessage( hDlg, IDC_CONNECTCOMBO, CB_ADDSTRING,
|
||||
0, (LPARAM)strs[i] );
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ ce_dictionary_make( CEAppGlobals* globals, XP_UCHAR* dictName )
|
|||
XP_DEBUGF( "looking for dict %s", dictName );
|
||||
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, dictName, -1,
|
||||
nameBuf, sizeof(nameBuf)/sizeof(nameBuf[0]) );
|
||||
nameBuf, VSIZE(nameBuf) );
|
||||
|
||||
ptr = openMappedFile( MPPARM(globals->mpool) nameBuf, &mappedFile,
|
||||
&hFile, &dictLength );
|
||||
|
@ -650,7 +650,7 @@ forEachDictDir( HINSTANCE hInstance, ForEachCB cb, void* ctxt )
|
|||
for ( id = IDS_DICTDIRS; ; ++id ) {
|
||||
wchar_t pathBuf[CE_MAX_PATH_LEN+1];
|
||||
if ( 0 >= LoadString( hInstance, id, pathBuf,
|
||||
sizeof(pathBuf)/sizeof(pathBuf[0]) ) ) {
|
||||
VSIZE(pathBuf) ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -716,7 +716,7 @@ formatDirsCB( wchar_t* dir, void* ctxt )
|
|||
}
|
||||
|
||||
len = WideCharToMultiByte( CP_ACP, 0, dir, -1,
|
||||
narrow, sizeof(narrow)/sizeof(narrow[0]),
|
||||
narrow, VSIZE(narrow),
|
||||
NULL, NULL );
|
||||
stream_putString( datap->stream, narrow );
|
||||
return XP_FALSE;
|
||||
|
@ -744,7 +744,7 @@ ceLocateNDicts( MPFORMAL HINSTANCE hInstance, XP_U16 nSought,
|
|||
for ( id = IDS_DICTDIRS; ; ++id ) {
|
||||
wchar_t pathBuf[CE_MAX_PATH_LEN+1];
|
||||
if ( 0 >= LoadString( hInstance, id, pathBuf,
|
||||
sizeof(pathBuf)/sizeof(pathBuf[0]) ) ) {
|
||||
VSIZE(pathBuf) ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -769,7 +769,7 @@ ceFormatDictDirs( XWStreamCtxt* stream, HINSTANCE hInstance )
|
|||
XP_U16 len;
|
||||
|
||||
if ( 0 >= LoadString( hInstance, id, wide,
|
||||
sizeof(wide)/sizeof(wide[0]) ) ) {
|
||||
VSIZE(wide) ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -777,7 +777,7 @@ ceFormatDictDirs( XWStreamCtxt* stream, HINSTANCE hInstance )
|
|||
stream_putString( stream, ", " );
|
||||
}
|
||||
len = WideCharToMultiByte( CP_ACP, 0, wide, -1,
|
||||
narrow, sizeof(narrow)/sizeof(narrow[0]),
|
||||
narrow, VSIZE(narrow),
|
||||
NULL, NULL );
|
||||
stream_putString( stream, narrow );
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ measureText( CEDrawCtx* dctx, const XP_UCHAR* str, XP_S16 padding,
|
|||
XP_ASSERT( nextStr != str );
|
||||
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, len,
|
||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
GetTextExtentPoint32( hdc, widebuf, len, &size );
|
||||
|
||||
maxWidth = (XP_U16)XP_MAX( maxWidth, size.cx );
|
||||
|
@ -167,7 +167,7 @@ drawLines( CEDrawCtx* dctx, HDC hdc, const XP_UCHAR* text, XP_S16 padding,
|
|||
}
|
||||
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, text, len,
|
||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
|
||||
textRt.bottom = textRt.top + dctx->miniLineHt;
|
||||
|
||||
|
@ -329,12 +329,12 @@ DRAW_FUNC_NAME(drawCell)( DrawCtx* p_dctx, const XP_Rect* xprect,
|
|||
XP_MEMSET( widebuf, 0, sizeof(widebuf) );
|
||||
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, cp, -1,
|
||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
|
||||
SetTextColor( hdc, foreColorRef );
|
||||
#ifdef TARGET_OS_WIN32
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, letters, -1,
|
||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
#endif
|
||||
DrawText( hdc, widebuf, -1, &textRect,
|
||||
DT_SINGLELINE | DT_VCENTER | DT_CENTER);
|
||||
|
@ -442,7 +442,7 @@ drawDrawTileGuts( DrawCtx* p_dctx, const XP_Rect* xprect,
|
|||
HFONT oldFont = SelectObject( hdc, dctx->trayFont );
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, letters, -1,
|
||||
widebuf,
|
||||
sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
VSIZE(widebuf) );
|
||||
DrawText( hdc, widebuf, -1, &rt,
|
||||
DT_SINGLELINE | DT_TOP | DT_LEFT );
|
||||
SelectObject( hdc, oldFont );
|
||||
|
@ -800,7 +800,7 @@ DRAW_FUNC_NAME(score_pendingScore)( DrawCtx* p_dctx, const XP_Rect* rect,
|
|||
}
|
||||
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, buf, -1,
|
||||
widebuf, sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
widebuf, VSIZE(widebuf) );
|
||||
DrawText(hdc, widebuf, -1, &rt, DT_SINGLELINE | DT_BOTTOM | DT_CENTER);
|
||||
DrawText(hdc, L"Pts", -1, &rt, DT_SINGLELINE | DT_TOP | DT_CENTER);
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
|||
|
||||
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH
|
||||
wchar_t* roles[] = { L"Standalone", L"Host", L"Guest" };
|
||||
for ( i = 0; i < (sizeof(roles)/sizeof(roles[0])); ++i ) {
|
||||
for ( i = 0; i < VSIZE(roles); ++i ) {
|
||||
SendDlgItemMessage( hDlg, IDC_ROLECOMBO, CB_ADDSTRING, 0,
|
||||
(long)roles[i] );
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState )
|
|||
wchar_t wPath[CE_MAX_PATH_LEN+1];
|
||||
XP_ASSERT( gi->dictName[0] != '\0' );
|
||||
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, gi->dictName, -1,
|
||||
wPath, sizeof(wPath)/sizeof(wPath[0]) );
|
||||
wPath, VSIZE(wPath) );
|
||||
(void)addDictToState( wPath, 0, giState );
|
||||
}
|
||||
addDictsToMenu( giState );
|
||||
|
|
|
@ -174,7 +174,7 @@ doCmd( const char* cmd )
|
|||
};
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < sizeof(params)/sizeof(params[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(params); ++i ) {
|
||||
char* p = params[i].p;
|
||||
int len = strlen(p);
|
||||
if ( 0 == strncmp( p, cmd, len ) ) {
|
||||
|
@ -187,7 +187,7 @@ doCmd( const char* cmd )
|
|||
}
|
||||
}
|
||||
|
||||
if ( i == sizeof(params)/sizeof(params[0]) ) {
|
||||
if ( i == VSIZE(params) ) {
|
||||
XP_LOGF( "failed to match cmdline arg \"%s\"", cmd );
|
||||
}
|
||||
} /* doCmd */
|
||||
|
@ -324,7 +324,7 @@ addButtonsToCmdBar( CEAppGlobals* globals )
|
|||
int resIDs[] = { IDB_FLIPBUTTON, IDB_VALUESBUTTON,
|
||||
IDB_HINTBUTTON, IDB_JUGGLEBUTTON };
|
||||
|
||||
for ( i = 0; i < sizeof(cmds)/sizeof(cmds[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(cmds); ++i ) {
|
||||
TBBUTTON buttData;
|
||||
|
||||
index = CommandBar_AddBitmap(globals->hwndCB, globals->hInst,
|
||||
|
@ -1416,7 +1416,7 @@ ceChooseAndOpen( CEAppGlobals* globals )
|
|||
| OFN_PATHMUSTEXIST;
|
||||
|
||||
openFileStruct.lpstrFile = path;
|
||||
openFileStruct.nMaxFile = sizeof(path)/sizeof(path[0]);
|
||||
openFileStruct.nMaxFile = VSIZE(path);
|
||||
|
||||
if ( GetOpenFileName( &openFileStruct ) ) {
|
||||
XP_UCHAR* name;
|
||||
|
@ -1575,13 +1575,13 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave )
|
|||
XP_MEMSET( &sfs, 0, sizeof(sfs) );
|
||||
XP_MEMSET( nameBuf, 0, sizeof(nameBuf) );
|
||||
|
||||
makeUniqueName( nameBuf, sizeof(nameBuf)/sizeof(nameBuf[0]) );
|
||||
makeUniqueName( nameBuf, VSIZE(nameBuf) );
|
||||
|
||||
sfs.lStructSize = sizeof(sfs);
|
||||
sfs.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
|
||||
sfs.hwndOwner = globals->hWnd;
|
||||
sfs.lpstrFile = nameBuf;
|
||||
sfs.nMaxFile = sizeof(nameBuf)/sizeof(nameBuf[0]);
|
||||
sfs.nMaxFile = VSIZE(nameBuf);
|
||||
|
||||
sfs.lpstrDefExt = L"xwg";
|
||||
|
||||
|
@ -2273,7 +2273,7 @@ queryBoxChar( CEAppGlobals* globals, XP_UCHAR* msg )
|
|||
|
||||
XP_U16 len = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, msg, strlen(msg),
|
||||
widebuf,
|
||||
sizeof(widebuf)/sizeof(widebuf[0]) );
|
||||
VSIZE(widebuf) );
|
||||
widebuf[len] = 0;
|
||||
|
||||
answer = MessageBox( globals->hWnd, widebuf, L"Question", MB_YESNO );
|
||||
|
|
|
@ -82,19 +82,11 @@ adjustForChoice( HWND hDlg, CePrefsDlgState* state )
|
|||
SendDlgItemMessage( hDlg, resID, BM_SETCHECK, BST_CHECKED, 0L );
|
||||
|
||||
if ( doGlobalPrefs ) {
|
||||
turnOnOff( hDlg, goesWithLocal,
|
||||
sizeof(goesWithLocal)/sizeof(goesWithLocal[0]),
|
||||
XP_FALSE );
|
||||
turnOnOff( hDlg, goesWithGlobal,
|
||||
sizeof(goesWithGlobal)/sizeof(goesWithGlobal[0]),
|
||||
XP_TRUE);
|
||||
turnOnOff( hDlg, goesWithLocal, VSIZE(goesWithLocal), XP_FALSE );
|
||||
turnOnOff( hDlg, goesWithGlobal, VSIZE(goesWithGlobal), XP_TRUE);
|
||||
} else {
|
||||
turnOnOff( hDlg, goesWithGlobal,
|
||||
sizeof(goesWithGlobal)/sizeof(goesWithGlobal[0]),
|
||||
XP_FALSE );
|
||||
turnOnOff( hDlg, goesWithLocal,
|
||||
sizeof(goesWithLocal)/sizeof(goesWithLocal[0]),
|
||||
XP_TRUE);
|
||||
turnOnOff( hDlg, goesWithGlobal, VSIZE(goesWithGlobal), XP_FALSE );
|
||||
turnOnOff( hDlg, goesWithLocal, VSIZE(goesWithLocal), XP_TRUE);
|
||||
}
|
||||
|
||||
if ( !doGlobalPrefs ) {
|
||||
|
@ -204,7 +196,7 @@ loadControlsFromState( HWND hDlg, CePrefsDlgState* pState )
|
|||
#endif
|
||||
};
|
||||
XP_U16 i;
|
||||
for ( i = 0; i < sizeof(unavail)/sizeof(unavail[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(unavail); ++i ) {
|
||||
ceEnOrDisable( hDlg, unavail[i], XP_FALSE );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg )
|
|||
butHeight = 0;
|
||||
butWidth = 0;
|
||||
nButtons = 0;
|
||||
for ( i = 0; i < sizeof(resIDs)/sizeof(resIDs[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(resIDs); ++i ) {
|
||||
HWND itemH = GetDlgItem( hDlg, resIDs[i] );
|
||||
if ( ceIsVisible( itemH ) ) {
|
||||
RECT buttonRect;
|
||||
|
@ -296,7 +296,7 @@ ceStackButtonsRight( CEAppGlobals* globals, HWND hDlg )
|
|||
top = spacing - (butHeight / 2) + VPADDING;
|
||||
left = crect.right + HPADDING_L;
|
||||
|
||||
for ( i = 0; i < sizeof(resIDs)/sizeof(resIDs[0]); ++i ) {
|
||||
for ( i = 0; i < VSIZE(resIDs); ++i ) {
|
||||
HWND itemH = GetDlgItem( hDlg, resIDs[i] );
|
||||
if ( ceIsVisible( itemH ) ) {
|
||||
(void)MoveWindow( itemH, left, top, butWidth, butHeight,
|
||||
|
|
Loading…
Reference in a new issue