From e891a26756268396d66756173c1d2cb4868b87e1 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 26 May 2007 14:03:07 +0000 Subject: [PATCH] substitute macro for common sizeof(x)/sizeof(x[0]) pattern; no generated code change --- common/comtypes.h | 2 ++ common/engine.c | 2 +- common/server.c | 2 +- linux/cursesletterask.c | 2 +- linux/gtknewgame.c | 2 +- palm/connsdlg.c | 2 +- palm/fnavgen.c | 2 +- palm/palmmain.c | 9 +++++---- wince/ceblank.c | 6 ++---- wince/cecondlg.c | 4 ++-- wince/cedict.c | 12 ++++++------ wince/cedraw.c | 12 ++++++------ wince/ceginfo.c | 4 ++-- wince/cemain.c | 14 +++++++------- wince/ceprefs.c | 18 +++++------------- wince/ceutil.c | 4 ++-- 16 files changed, 45 insertions(+), 52 deletions(-) diff --git a/common/comtypes.h b/common/comtypes.h index 1642e5634..0fd714229 100644 --- a/common/comtypes.h +++ b/common/comtypes.h @@ -39,6 +39,8 @@ # endif #endif +#define VSIZE(arr) (sizeof(arr)/sizeof(arr[0])) + typedef struct XP_Rect { XP_S16 left; XP_S16 top; diff --git a/common/engine.c b/common/engine.c index 8194d8050..a4d107e03 100644 --- a/common/engine.c +++ b/common/engine.c @@ -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)); } diff --git a/common/server.c b/common/server.c index 78483bbd8..69d9d210e 100644 --- a/common/server.c +++ b/common/server.c @@ -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 ); diff --git a/linux/cursesletterask.c b/linux/cursesletterask.c index bee2a2596..6e0f065c9 100644 --- a/linux/cursesletterask.c +++ b/linux/cursesletterask.c @@ -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 ); diff --git a/linux/gtknewgame.c b/linux/gtknewgame.c index daa859b73..5ae4d678a 100644 --- a/linux/gtknewgame.c +++ b/linux/gtknewgame.c @@ -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", diff --git a/palm/connsdlg.c b/palm/connsdlg.c index 522e3be52..5a0c8d415 100644 --- a/palm/connsdlg.c +++ b/palm/connsdlg.c @@ -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 ); diff --git a/palm/fnavgen.c b/palm/fnavgen.c index 899291027..07f53ee9b 100644 --- a/palm/fnavgen.c +++ b/palm/fnavgen.c @@ -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]) ); */ diff --git a/palm/palmmain.c b/palm/palmmain.c index e7ff351d3..843841416 100644 --- a/palm/palmmain.c +++ b/palm/palmmain.c @@ -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; diff --git a/wince/ceblank.c b/wince/ceblank.c index 989c9c3bb..2e0367d44 100755 --- a/wince/ceblank.c +++ b/wince/ceblank.c @@ -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 ); } diff --git a/wince/cecondlg.c b/wince/cecondlg.c index 86bca0f9a..080f873b2 100755 --- a/wince/cecondlg.c +++ b/wince/cecondlg.c @@ -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] ); } diff --git a/wince/cedict.c b/wince/cedict.c index a9ef673d5..e553c7651 100755 --- a/wince/cedict.c +++ b/wince/cedict.c @@ -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 ); } diff --git a/wince/cedraw.c b/wince/cedraw.c index 96e76227c..6c21149e5 100755 --- a/wince/cedraw.c +++ b/wince/cedraw.c @@ -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); diff --git a/wince/ceginfo.c b/wince/ceginfo.c index a56fed37e..82bde8a05 100755 --- a/wince/ceginfo.c +++ b/wince/ceginfo.c @@ -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 ); diff --git a/wince/cemain.c b/wince/cemain.c index f9c091029..42bfde26c 100755 --- a/wince/cemain.c +++ b/wince/cemain.c @@ -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 ); diff --git a/wince/ceprefs.c b/wince/ceprefs.c index d78858f2a..fc2051733 100755 --- a/wince/ceprefs.c +++ b/wince/ceprefs.c @@ -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 ); } } diff --git a/wince/ceutil.c b/wince/ceutil.c index 6b64fdeee..67cb59ef6 100755 --- a/wince/ceutil.c +++ b/wince/ceutil.c @@ -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,