switch for loop to using C99-style variable declarations; no other change

This commit is contained in:
Eric House 2014-11-25 06:09:18 -08:00
parent 53bfe9812d
commit 938756a34f
5 changed files with 36 additions and 63 deletions

View file

@ -92,9 +92,8 @@ static XP_U16
andCountSpecials( AndDictionaryCtxt* ctxt )
{
XP_U16 result = 0;
XP_U16 ii;
for ( ii = 0; ii < ctxt->super.nFaces; ++ii ) {
for ( int ii = 0; ii < ctxt->super.nFaces; ++ii ) {
if ( IS_SPECIAL( ctxt->super.facePtrs[ii][0] ) ) {
++result;
}
@ -121,14 +120,13 @@ andMakeBitmap( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp,
#else
XP_U8 srcByte = 0;
XP_U8 nBits;
XP_U16 ii;
jboolean* colors = (jboolean*)XP_CALLOC( ctxt->super.mpool,
nCols * nRows * sizeof(*colors) );
jboolean* next = colors;
nBits = nRows * nCols;
for ( ii = 0; ii < nBits; ++ii ) {
for ( int ii = 0; ii < nBits; ++ii ) {
XP_U8 srcBitIndex = ii % 8;
XP_U8 srcMask;
@ -164,7 +162,6 @@ andLoadSpecialData( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp,
XP_Bool success = XP_TRUE;
XP_U16 nSpecials = andCountSpecials( ctxt );
XP_U8 const* ptr = *ptrp;
Tile ii;
XP_UCHAR** texts;
XP_UCHAR** textEnds;
SpecialBitmaps* bitmaps;
@ -177,7 +174,7 @@ andLoadSpecialData( AndDictionaryCtxt* ctxt, XP_U8 const** ptrp,
bitmaps = (SpecialBitmaps*)
XP_CALLOC( ctxt->super.mpool, nSpecials * sizeof(*bitmaps) );
for ( ii = 0; ii < ctxt->super.nFaces; ++ii ) {
for ( Tile ii = 0; ii < ctxt->super.nFaces; ++ii ) {
const XP_UCHAR* facep = ctxt->super.facePtrs[(short)ii];
if ( IS_SPECIAL(*facep) ) {
@ -239,17 +236,16 @@ splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr,
int indx = 0;
int offsets[nFaces];
int nBytes;
int ii, jj;
jobject jstrarr = and_util_splitFaces( ctxt->jniutil, ptr, nFaceBytes,
isUTF8 );
XP_ASSERT( (*env)->GetArrayLength( env, jstrarr ) == nFaces );
for ( ii = 0; ii < nFaces; ++ii ) {
for ( int ii = 0; ii < nFaces; ++ii ) {
jobject jstrs = (*env)->GetObjectArrayElement( env, jstrarr, ii );
offsets[ii] = indx;
int nAlternates = (*env)->GetArrayLength( env, jstrs );
for ( jj = 0; jj < nAlternates; ++jj ) {
for ( int jj = 0; jj < nAlternates; ++jj ) {
jobject jstr = (*env)->GetObjectArrayElement( env, jstrs, jj );
nBytes = (*env)->GetStringUTFLength( env, jstr );
@ -280,7 +276,7 @@ splitFaces_via_java( JNIEnv* env, AndDictionaryCtxt* ctxt, const XP_U8* ptr,
XP_CALLOC( ctxt->super.mpool, nFaces * sizeof(ptrs[0]));
XP_MEMCPY( faces, facesBuf, indx );
for ( ii = 0; ii < nFaces; ++ii ) {
for ( int ii = 0; ii < nFaces; ++ii ) {
ptrs[ii] = &faces[offsets[ii]];
}
@ -312,7 +308,6 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength,
const XP_U8 const* end = ptr + dictLength;
XP_U32 offset;
XP_U16 nFaces, numFaceBytes = 0;
XP_U16 i;
XP_U16 flags;
void* mappedBase = (void*)ptr;
XP_U8 nodeSize;
@ -420,10 +415,9 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength,
} else {
XP_U8 tmp[nFaces*4]; /* should be enough... */
XP_U16 nBytes = 0;
XP_U16 ii;
/* Need to translate from iso-8859-n to utf8 */
CHECK_PTR( ptr, 2 * nFaces, end );
for ( ii = 0; ii < nFaces; ++ii ) {
for ( int ii = 0; ii < nFaces; ++ii ) {
XP_UCHAR ch = ptr[1];
ptr += 2;
@ -445,9 +439,9 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8 const* ptr, XP_U32 dictLength,
ctxt->super.langCode = ptr[0] & 0x7F;
ptr += 2; /* skip xloc header */
CHECK_PTR( ptr, 2 * nFaces, end );
for ( i = 0; i < nFaces*2; i += 2 ) {
ctxt->super.countsAndValues[i] = *ptr++;
ctxt->super.countsAndValues[i+1] = *ptr++;
for ( int ii = 0; ii < nFaces*2; ii += 2 ) {
ctxt->super.countsAndValues[ii] = *ptr++;
ctxt->super.countsAndValues[ii+1] = *ptr++;
}
if ( !andLoadSpecialData( ctxt, &ptr, end ) ) {
@ -492,11 +486,10 @@ and_dictionary_destroy( DictionaryCtxt* dict )
AndDictionaryCtxt* ctxt = (AndDictionaryCtxt*)dict;
XP_LOGF( "%s(dict=%p); code=%x", __func__, ctxt, ctxt->dbgid );
XP_U16 nSpecials = andCountSpecials( ctxt );
XP_U16 ii;
JNIEnv* env = ctxt->env;
if ( !!ctxt->super.chars ) {
for ( ii = 0; ii < nSpecials; ++ii ) {
for ( int ii = 0; ii < nSpecials; ++ii ) {
XP_UCHAR* text = ctxt->super.chars[ii];
if ( !!text ) {
XP_FREE( ctxt->super.mpool, text );
@ -507,7 +500,7 @@ and_dictionary_destroy( DictionaryCtxt* dict )
XP_FREEP( ctxt->super.mpool, &ctxt->super.charEnds );
if ( !!ctxt->super.bitmaps ) {
for ( ii = 0; ii < nSpecials; ++ii ) {
for ( int ii = 0; ii < nSpecials; ++ii ) {
jobject bitmap = ctxt->super.bitmaps[ii].largeBM;
if ( !!bitmap ) {
(*env)->DeleteGlobalRef( env, bitmap );
@ -576,11 +569,10 @@ makeDicts( MPFORMAL JNIEnv *env, DictMgrCtxt* dictMgr, JNIUtilCtxt* jniutil,
jobjectArray jnames, jobjectArray jdicts, jobjectArray jpaths,
jstring jlang )
{
int ii;
jsize len = (*env)->GetArrayLength( env, jdicts );
XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) );
for ( ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) {
for ( int ii = 0; ii <= VSIZE(dicts->dicts); ++ii ) {
DictionaryCtxt* dict = NULL;
if ( ii < len ) {
jobject jdict = (*env)->GetObjectArrayElement( env, jdicts, ii );

View file

@ -41,8 +41,7 @@ XP_U32
and_ntohl(XP_U32 ll)
{
XP_U32 result = 0L;
int ii;
for ( ii = 0; ii < 4; ++ii ) {
for ( int ii = 0; ii < 4; ++ii ) {
result <<= 8;
result |= ll & 0x000000FF;
ll >>= 8;
@ -91,8 +90,7 @@ getInt( JNIEnv* env, jobject obj, const char* name )
void
getInts( JNIEnv* env, void* cobj, jobject jobj, const SetInfo* sis, XP_U16 nSis )
{
int ii;
for ( ii = 0; ii < nSis; ++ii ) {
for ( int ii = 0; ii < nSis; ++ii ) {
const SetInfo* si = &sis[ii];
uint8_t* ptr = ((uint8_t*)cobj) + si->offset;
int val = getInt( env, jobj, si->name );
@ -126,8 +124,7 @@ setInt( JNIEnv* env, jobject obj, const char* name, int value )
void
setInts( JNIEnv* env, jobject jobj, void* cobj, const SetInfo* sis, XP_U16 nSis )
{
int ii;
for ( ii = 0; ii < nSis; ++ii ) {
for ( int ii = 0; ii < nSis; ++ii ) {
const SetInfo* si = &sis[ii];
uint8_t* ptr = ((uint8_t*)cobj) + si->offset;
int val;
@ -169,8 +166,7 @@ setBool( JNIEnv* env, jobject obj, const char* name, bool value )
void
setBools( JNIEnv* env, jobject jobj, void* cobj, const SetInfo* sis, XP_U16 nSis )
{
int ii;
for ( ii = 0; ii < nSis; ++ii ) {
for ( int ii = 0; ii < nSis; ++ii ) {
const SetInfo* si = &sis[ii];
XP_Bool val = *(XP_Bool*)(((uint8_t*)cobj)+si->offset);
setBool( env, jobj, si->name, val );
@ -278,8 +274,7 @@ getBool( JNIEnv* env, jobject obj, const char* name )
void
getBools( JNIEnv* env, void* cobj, jobject jobj, const SetInfo* sis, XP_U16 nSis )
{
int ii;
for ( ii = 0; ii < nSis; ++ii ) {
for ( int ii = 0; ii < nSis; ++ii ) {
const SetInfo* si = &sis[ii];
XP_Bool val = getBool( env, jobj, si->name );
*(XP_Bool*)(((uint8_t*)cobj)+si->offset) = val;
@ -380,8 +375,7 @@ makeStringArray( JNIEnv *env, int siz, const XP_UCHAR** vals )
jobjectArray jarray = (*env)->NewObjectArray( env, siz, clas, empty );
deleteLocalRefs( env, clas, empty, DELETE_NO_REF );
int ii;
for ( ii = 0; !!vals && ii < siz; ++ii ) {
for ( int ii = 0; !!vals && ii < siz; ++ii ) {
jstring jstr = (*env)->NewStringUTF( env, vals[ii] );
(*env)->SetObjectArrayElement( env, jarray, ii, jstr );
deleteLocalRef( env, jstr );

View file

@ -86,7 +86,6 @@ readJRect( JNIEnv* env, XP_Rect* rect, jobject jrect )
static jobject
makeJRects( AndDraw* draw, int indx, XP_U16 nPlayers, const XP_Rect rects[] )
{
XP_U16 ii;
JNIEnv* env = ENVFORME( draw->ti );
jobject jrects = draw->jCache[indx];
if ( !jrects ) {
@ -98,7 +97,7 @@ makeJRects( AndDraw* draw, int indx, XP_U16 nPlayers, const XP_Rect rects[] )
jmethodID initId = (*env)->GetMethodID( env, rclass, "<init>",
"()V" );
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jobject jrect = (*env)->NewObject( env, rclass, initId );
(*env)->SetObjectArrayElement( env, jrects, ii, jrect );
deleteLocalRef( env, jrect );
@ -121,7 +120,6 @@ makeJRects( AndDraw* draw, int indx, XP_U16 nPlayers, const XP_Rect rects[] )
static jobject
makeDSIs( AndDraw* draw, int indx, XP_U16 nPlayers, const DrawScoreInfo dsis[] )
{
XP_U16 ii;
JNIEnv* env = ENVFORME( draw->ti );
jobject dsiobjs = draw->jCache[indx];
@ -133,7 +131,7 @@ makeDSIs( AndDraw* draw, int indx, XP_U16 nPlayers, const DrawScoreInfo dsis[] )
dsiobjs = draw->jCache[indx];
jmethodID initId = (*env)->GetMethodID( env, clas, "<init>", "()V" );
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jobject dsiobj = (*env)->NewObject( env, clas, initId );
(*env)->SetObjectArrayElement( env, dsiobjs, ii, dsiobj );
deleteLocalRef( env, dsiobj );
@ -142,7 +140,7 @@ makeDSIs( AndDraw* draw, int indx, XP_U16 nPlayers, const DrawScoreInfo dsis[] )
deleteLocalRef( env, clas );
}
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jobject dsiobj = (*env)->GetObjectArrayElement( env, dsiobjs, ii );
const DrawScoreInfo* dsi = &dsis[ii];
@ -206,8 +204,8 @@ and_draw_scoreBegin( DrawCtx* dctx, const XP_Rect* rect,
DRAW_CBK_HEADER("scoreBegin", "(Landroid/graphics/Rect;I[II)Z" );
jint jarr[numPlayers];
int ii;
for ( ii = 0; ii < numPlayers; ++ii ) {
for ( int ii = 0; ii < numPlayers; ++ii ) {
jarr[ii] = scores[ii];
}
jintArray jscores = makeIntArray( env, numPlayers, jarr );
@ -241,7 +239,6 @@ and_draw_score_drawPlayers( DrawCtx* dctx, const XP_Rect* scoreRect,
XP_U16 nPlayers, DrawScoreInfo playerData[],
XP_Rect playerRects[] )
{
XP_U16 ii;
DRAW_CBK_HEADER("score_drawPlayers", "(Landroid/graphics/Rect;"
"[L" PKG_PATH("jni/DrawScoreInfo;")
"[Landroid/graphics/Rect;)V" );
@ -251,7 +248,7 @@ and_draw_score_drawPlayers( DrawCtx* dctx, const XP_Rect* scoreRect,
jobject jrects = makeJRects( draw, JCACHE_RECTS, nPlayers, NULL );
(*env)->CallVoidMethod( env, draw->jdraw, mid, jrect, jdsis, jrects );
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jobject jrect = (*env)->GetObjectArrayElement( env, jrects, ii );
readJRect( env, &playerRects[ii], jrect );
}
@ -611,8 +608,7 @@ makeDraw( MPFORMAL EnvThreadInfo* ti, jobject jdraw )
draw->ti = ti;
MPASSIGN( draw->mpool, mpool );
int ii;
for ( ii = 0; ii < sizeof(*draw->vtable)/4; ++ii ) {
for ( int ii = 0; ii < sizeof(*draw->vtable)/4; ++ii ) {
((void**)(draw->vtable))[ii] = draw_doNothing;
}
@ -664,8 +660,7 @@ destroyDraw( DrawCtx** dctx )
(*env)->DeleteGlobalRef( env, draw->jdraw );
}
int ii;
for ( ii = 0; ii < JCACHE_COUNT; ++ii ) {
for ( int ii = 0; ii < JCACHE_COUNT; ++ii ) {
jobject jobj = draw->jCache[ii];
if ( !!jobj ) {
(*env)->DeleteGlobalRef( env, jobj );

View file

@ -745,8 +745,7 @@ destroyUtil( XW_UtilCtxt** utilc )
AndUtil* util = (AndUtil*)*utilc;
JNIEnv* env = ENVFORME( util->ti );
int ii;
for ( ii = 0; ii < VSIZE(util->userStrings); ++ii ) {
for ( int ii = 0; ii < VSIZE(util->userStrings); ++ii ) {
XP_UCHAR* ptr = util->userStrings[ii];
if ( NULL != ptr ) {
XP_FREE( util->util.mpool, ptr );

View file

@ -241,8 +241,7 @@ makeGI( MPFORMAL JNIEnv* env, jobject jgi )
jobject jplayers;
if ( getObject( env, jgi, "players", "[L" PKG_PATH("jni/LocalPlayer") ";",
&jplayers ) ) {
int ii;
for ( ii = 0; ii < gi->nPlayers; ++ii ) {
for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
LocalPlayer* lp = &gi->players[ii];
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
@ -288,8 +287,7 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
if ( getObject( env, jgi, "players",
"[L" PKG_PATH("jni/LocalPlayer") ";",
&jplayers ) ) {
int ii;
for ( ii = 0; ii < gi->nPlayers; ++ii ) {
for ( int ii = 0; ii < gi->nPlayers; ++ii ) {
const LocalPlayer* lp = &gi->players[ii];
jobject jlp = (*env)->GetObjectArrayElement( env, jplayers, ii );
@ -1345,7 +1343,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
( JNIEnv* env, jclass C, jint gamePtr )
{
jobjectArray result = NULL;
XP_U16 ii;
XWJNI_START();
XP_ASSERT( state->game.comms );
CommsAddrRec addrs[MAX_NUM_PLAYERS];
@ -1356,7 +1353,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getAddrs
result = (*env)->NewObjectArray( env, count, clas, NULL );
jmethodID initId = (*env)->GetMethodID( env, clas, "<init>", "()V" );
for ( ii = 0; ii < count; ++ii ) {
for ( int ii = 0; ii < count; ++ii ) {
jobject jaddr = (*env)->NewObject( env, clas, initId );
setJAddrRec( env, jaddr, &addrs[ii] );
(*env)->SetObjectArrayElement( env, result, ii, jaddr );
@ -1411,8 +1408,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1receiveMessage
I'm a robot. Only one server_do and I'll never make that first
robot move. That's because comms can't detect a duplicate initial
packet (in validateInitialMessage()). */
int ii;
for ( ii = 0; ii < 5; ++ii ) {
for ( int ii = 0; ii < 5; ++ii ) {
(void)server_do( server );
}
}
@ -1471,9 +1467,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
XP_U16 count = VSIZE(addrs);
comms_getAddrs( comms, addrs, &count );
int ii;
const XP_UCHAR* addrps[count];
for ( ii = 0; ii < count; ++ii ) {
for ( int ii = 0; ii < count; ++ii ) {
addrps[ii] = isBT ? (XP_UCHAR*)&addrs[ii].u.bt.btAddr :
(XP_UCHAR*)&addrs[ii].u.sms.phone;
XP_LOGF( "%s: adding btaddr/phone %s", __func__, addrps[ii] );
@ -1493,15 +1488,14 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1summarize
XP_U16 nPlayers = model_getNPlayers( model );
jint jvals[nPlayers];
int ii;
if ( gameOver ) {
ScoresArray scores;
model_figureFinalScores( model, &scores, NULL );
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jvals[ii] = scores.arr[ii];
}
} else {
for ( ii = 0; ii < nPlayers; ++ii ) {
for ( int ii = 0; ii < nPlayers; ++ii ) {
jvals[ii] = model_getPlayerScore( model, ii );
}
}
@ -1906,9 +1900,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1getPrefixes
if ( NULL != data && NULL != data->idata.prefixes ) {
result = makeStringArray( env, data->idata.count, NULL );
int ii;
XP_U16 depth = data->depth;
for ( ii = 0; ii < data->idata.count; ++ii ) {
for ( int ii = 0; ii < data->idata.count; ++ii ) {
XP_UCHAR buf[16];
(void)dict_tilesToString( data->dict,
&data->idata.prefixes[depth*ii],