diff options
author | Strangerke | 2012-08-29 00:30:07 +0200 |
---|---|---|
committer | Strangerke | 2012-08-29 00:30:07 +0200 |
commit | b12ccad9943c99ecfc4edc6f4a46e4d88db609cf (patch) | |
tree | ed8abe9f66100e1a90d5418edf5cef78343a36e8 | |
parent | d2b33ca4cce2794e7b4fcf3ccb3f00dc74fff68d (diff) | |
download | scummvm-rg350-b12ccad9943c99ecfc4edc6f4a46e4d88db609cf.tar.gz scummvm-rg350-b12ccad9943c99ecfc4edc6f4a46e4d88db609cf.tar.bz2 scummvm-rg350-b12ccad9943c99ecfc4edc6f4a46e4d88db609cf.zip |
TONY: Reduce scope of some variables
-rw-r--r-- | engines/tony/mpal/expr.cpp | 30 | ||||
-rw-r--r-- | engines/tony/mpal/loadmpc.cpp | 88 | ||||
-rw-r--r-- | engines/tony/mpal/mpal.cpp | 121 | ||||
-rw-r--r-- | engines/tony/utils.cpp | 13 | ||||
-rw-r--r-- | engines/tony/window.cpp | 2 |
5 files changed, 107 insertions, 147 deletions
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp index ef58208d3f..2b2dbf2529 100644 --- a/engines/tony/mpal/expr.cpp +++ b/engines/tony/mpal/expr.cpp @@ -109,13 +109,12 @@ typedef EXPRESSION *LPEXPRESSION; * @retruns Pointer to the cloned expression */ static byte *duplicateExpression(HGLOBAL h) { - int i, num; byte *orig, *clone; LPEXPRESSION one, two; orig = (byte *)globalLock(h); - num = *(byte *)orig; + int num = *(byte *)orig; one = (LPEXPRESSION)(orig+1); clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(EXPRESSION) * num + 1); @@ -123,7 +122,7 @@ static byte *duplicateExpression(HGLOBAL h) { memcpy(clone, orig, sizeof(EXPRESSION) * num + 1); - for (i = 0; i < num; i++) { + for (int i = 0; i < num; i++) { if (one->type == ELT_PARENTH) { two->type = ELT_PARENTH2; two->val.pson = duplicateExpression(two->val.son); @@ -218,14 +217,14 @@ static void solve(LPEXPRESSION one, int num) { * @returns Value */ static int evaluateAndFreeExpression(byte *expr) { - int i,num,val; - LPEXPRESSION one,cur; + LPEXPRESSION one, cur; - num = *expr; + int num = *expr; one = (LPEXPRESSION)(expr + 1); // 1) Sostituzioni delle variabili - for (i = 0, cur = one; i < num; i++, cur++) { + cur = one; + for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_VAR) { cur->type = ELT_NUMBER; cur->val.num = varGetValue(cur->val.name); @@ -233,7 +232,8 @@ static int evaluateAndFreeExpression(byte *expr) { } // 2) Sostituzioni delle parentesi (tramite ricorsione) - for (i = 0, cur = one; i < num; i++, cur++) { + cur = one; + for (int i = 0; i < num; i++, cur++) { if (cur->type == ELT_PARENTH2) { cur->type = ELT_NUMBER; cur->val.num = evaluateAndFreeExpression(cur->val.pson); @@ -242,7 +242,7 @@ static int evaluateAndFreeExpression(byte *expr) { // 3) Risoluzione algebrica solve(one, num); - val = one->val.num; + int val = one->val.num; globalDestroy(expr); return val; @@ -260,9 +260,8 @@ static int evaluateAndFreeExpression(byte *expr) { const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { LPEXPRESSION cur; byte *start; - uint32 num, i; - num = *lpBuf; + uint32 num = *lpBuf; lpBuf++; if (num == 0) @@ -277,7 +276,7 @@ const byte *parseExpression(const byte *lpBuf, HGLOBAL *h) { cur = (LPEXPRESSION)(start + 1); - for (i = 0;i < num; i++) { + for (uint32 i = 0;i < num; i++) { cur->type = *(lpBuf); cur->unary = *(lpBuf + 1); lpBuf += 2; @@ -343,15 +342,14 @@ int evaluateExpression(HGLOBAL h) { * @param h2 Expression to be compared */ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { - int i, num1, num2; byte *e1, *e2; LPEXPRESSION one, two; e1 = (byte *)globalLock(h1); e2 = (byte *)globalLock(h2); - num1 = *(byte *)e1; - num2 = *(byte *)e2; + int num1 = *(byte *)e1; + int num2 = *(byte *)e2; if (num1 != num2) { globalUnlock(h1); @@ -362,7 +360,7 @@ bool compareExpressions(HGLOBAL h1, HGLOBAL h2) { one = (LPEXPRESSION)(e1 + 1); two = (LPEXPRESSION)(e2 + 1); - for (i = 0; i < num1; i++) { + for (int i = 0; i < num1; i++) { if (one->type != two->type || (i != num1 - 1 && one->symbol != two->symbol)) { globalUnlock(h1); globalUnlock(h2); diff --git a/engines/tony/mpal/loadmpc.cpp b/engines/tony/mpal/loadmpc.cpp index 9da2cc121e..790d8d4903 100644 --- a/engines/tony/mpal/loadmpc.cpp +++ b/engines/tony/mpal/loadmpc.cpp @@ -62,24 +62,21 @@ static bool compareCommands(struct command *cmd1, struct command *cmd2) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { - int curCmd, j, len; - uint i; - lpmsScript->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; lpmsScript->nMoments = READ_LE_UINT16(lpBuf); lpBuf += 2; - curCmd = 0; + int curCmd = 0; - for (i = 0; i < lpmsScript->nMoments; i++) { + for (uint i = 0; i < lpmsScript->nMoments; i++) { lpmsScript->Moment[i].dwTime = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; lpmsScript->Moment[i].nCmds = *lpBuf; lpBuf++; - for (j = 0; j < lpmsScript->Moment[i].nCmds; j++) { + for (int j = 0; j < lpmsScript->Moment[i].nCmds; j++) { lpmsScript->_command[curCmd].type = *lpBuf; lpBuf++; switch (lpmsScript->_command[curCmd].type) { @@ -96,8 +93,8 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { lpBuf += 4; break; - case 2: // Variable assign - len = *lpBuf; + case 2: { // Variable assign + int len = *lpBuf; lpBuf++; lpmsScript->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmsScript->_command[curCmd].lpszVarName == NULL) @@ -109,7 +106,7 @@ static const byte *ParseScript(const byte *lpBuf, LPMPALSCRIPT lpmsScript) { if (lpBuf == NULL) return NULL; break; - + } default: return NULL; } @@ -145,22 +142,20 @@ static void FreeScript(LPMPALSCRIPT lpmsScript) { * @returns Pointer to the buffer after the item, or NULL on failure. */ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { - uint32 i, j, z, kk; - uint32 num, num2, num3; + uint32 num2, num3; byte *lpLock; - uint32 curCmd; - uint32 len; lpmdDialog->nObj = READ_LE_UINT32(lpBuf); lpBuf += 4; /* Periodi */ - num = READ_LE_UINT16(lpBuf); + uint32 num = READ_LE_UINT16(lpBuf); lpBuf += 2; if (num >= MAX_PERIODS_PER_DIALOG - 1) error("Too much periods in dialog #%d", lpmdDialog->nObj); + uint32 i; for (i = 0; i < num; i++) { lpmdDialog->_periodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; @@ -177,7 +172,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { /* Gruppi */ num = READ_LE_UINT16(lpBuf); lpBuf += 2; - curCmd = 0; + uint32 curCmd = 0; if (num >= MAX_GROUPS_PER_DIALOG) error("Too much groups in dialog #%d", lpmdDialog->nObj); @@ -190,7 +185,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (lpmdDialog->_group[i].nCmds >= MAX_COMMANDS_PER_GROUP) error("Too much commands in group #%d in dialog #%d",lpmdDialog->_group[i].num,lpmdDialog->nObj); - for (j = 0; j < lpmdDialog->_group[i].nCmds; j++) { + for (uint32 j = 0; j < lpmdDialog->_group[i].nCmds; j++) { lpmdDialog->_command[curCmd].type = *lpBuf; lpBuf++; @@ -210,8 +205,8 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { break; // Variable assign - case 2: - len = *lpBuf; + case 2: { + uint32 len = *lpBuf; lpBuf++; lpmdDialog->_command[curCmd].lpszVarName = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, len + 1); if (lpmdDialog->_command[curCmd].lpszVarName == NULL) @@ -224,7 +219,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (lpBuf == NULL) return NULL; break; - + } // Do Choice case 3: lpmdDialog->_command[curCmd].nChoice = READ_LE_UINT16(lpBuf); @@ -235,6 +230,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { return NULL; } + uint32 kk; for (kk = 0;kk < curCmd; kk++) { if (compareCommands(&lpmdDialog->_command[kk], &lpmdDialog->_command[curCmd])) { lpmdDialog->_group[i].CmdNum[j] = kk; @@ -278,7 +274,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (num2 >= MAX_SELECTS_PER_CHOICE) error("Too much selects in choice #%d in dialog #%d", lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); - for (j = 0; j < num2; j++) { + for (uint32 j = 0; j < num2; j++) { // When switch (*lpBuf++) { case 0: @@ -308,7 +304,7 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { if (num3 >= MAX_PLAYGROUPS_PER_SELECT) error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->_choice[i].nChoice, lpmdDialog->nObj); - for (z = 0; z < num3; z++) { + for (uint32 z = 0; z < num3; z++) { lpmdDialog->_choice[i]._select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; } @@ -337,14 +333,10 @@ static const byte *parseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) { * completely initialized to 0 beforehand. */ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { - byte len; - uint32 i, j, kk; - uint32 curCmd; - lpmiItem->nObj = (int32)READ_LE_UINT32(lpBuf); lpBuf += 4; - len = *lpBuf; + byte len = *lpBuf; lpBuf++; memcpy(lpmiItem->lpszDescribe, lpBuf, MIN((byte)127, len)); lpBuf += len; @@ -359,9 +351,9 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { if (lpmiItem->nActions > 0) lpmiItem->Action = (ItemAction *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(struct ItemAction) * (int)lpmiItem->nActions); - curCmd = 0; + uint32 curCmd = 0; - for (i = 0; i < lpmiItem->nActions; i++) { + for (uint32 i = 0; i < lpmiItem->nActions; i++) { lpmiItem->Action[i].num = *lpBuf; lpBuf++; @@ -393,7 +385,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); - for (j = 0; j < lpmiItem->Action[i].nCmds; j++) { + for (uint32 j = 0; j < lpmiItem->Action[i].nCmds; j++) { lpmiItem->_command[curCmd].type = *lpBuf; lpBuf++; switch (lpmiItem->_command[curCmd].type) { @@ -428,6 +420,7 @@ static const byte *parseItem(const byte *lpBuf, LPMPALITEM lpmiItem) { return NULL; } + uint32 kk; for (kk = 0; kk < curCmd; kk++) { if (compareCommands(&lpmiItem->_command[kk], &lpmiItem->_command[curCmd])) { lpmiItem->Action[i].CmdNum[j] = kk; @@ -527,8 +520,6 @@ static const byte *ParseLocation(const byte *lpBuf, LPMPALLOCATION lpmlLocation) * @returns True if succeeded OK, false if failure. */ bool ParseMpc(const byte *lpBuf) { - uint16 i, j; - uint16 wLen; byte *lpTemp; /* 1. Variables */ @@ -545,8 +536,8 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmvVars = (LPMPALVAR)globalLock(GLOBALS._hVars); - for (i = 0; i < GLOBALS._nVars; i++) { - wLen = *(const byte *)lpBuf; + for (uint16 i = 0; i < GLOBALS._nVars; i++) { + uint16 wLen = *(const byte *)lpBuf; lpBuf++; memcpy(GLOBALS._lpmvVars->lpszVarName, lpBuf, MIN(wLen, (uint16)32)); lpBuf += wLen; @@ -579,10 +570,11 @@ bool ParseMpc(const byte *lpBuf) { return false; #endif - for (i = 0; i < GLOBALS._nMsgs; i++) { + for (uint16 i = 0; i < GLOBALS._nMsgs; i++) { GLOBALS._lpmmMsgs->_wNum = READ_LE_UINT16(lpBuf); lpBuf += 2; + uint16 j; for (j = 0; lpBuf[j] != 0;) j += lpBuf[j] + 1; @@ -628,7 +620,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0;i < GLOBALS._nDialogs; i++) { + for (uint16 i = 0; i < GLOBALS._nDialogs; i++) { if ((lpBuf = parseDialog(lpBuf + 7, &GLOBALS._lpmdDialogs[i])) == NULL) return false; } @@ -650,7 +642,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS._nItems; i++) { + for (uint16 i = 0; i < GLOBALS._nItems; i++) { if ((lpBuf = parseItem(lpBuf + 5, &GLOBALS._lpmiItems[i])) == NULL) return false; } @@ -672,7 +664,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmlLocations = (LPMPALLOCATION)globalLock(GLOBALS._hLocations); - for (i = 0; i < GLOBALS._nLocations; i++) { + for (uint16 i = 0; i < GLOBALS._nLocations; i++) { if ((lpBuf = ParseLocation(lpBuf + 9, &GLOBALS._lpmlLocations[i])) == NULL) return false; } @@ -694,7 +686,7 @@ bool ParseMpc(const byte *lpBuf) { GLOBALS._lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS._nScripts; i++) { + for (uint16 i = 0; i < GLOBALS._nScripts; i++) { if ((lpBuf = ParseScript(lpBuf + 7, &GLOBALS._lpmsScripts[i])) == NULL) return false; @@ -721,12 +713,10 @@ bool ParseMpc(const byte *lpBuf) { */ static void freeDialog(LPMPALDIALOG lpmdDialog) { // Free the periods - int i, j; - - for (i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) + for (int i = 0; i < MAX_PERIODS_PER_DIALOG && (lpmdDialog->_periods[i]); ++i) globalFree(lpmdDialog->_periods[i]); - for (i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { + for (int i = 0; i < MAX_COMMANDS_PER_DIALOG && (lpmdDialog->_command[i].type); i++) { if (lpmdDialog->_command[i].type == 2) { // Variable assign globalDestroy(lpmdDialog->_command[i].lpszVarName); @@ -735,8 +725,8 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { } // Free the choices - for (i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { - for (j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { + for (int i = 0; i < MAX_CHOICES_PER_DIALOG; ++i) { + for (int j = 0; j < MAX_SELECTS_PER_CHOICE; j++) { if (lpmdDialog->_choice[i]._select[j].when) freeExpression(lpmdDialog->_choice[i]._select[j].when); } @@ -747,14 +737,12 @@ static void freeDialog(LPMPALDIALOG lpmdDialog) { * Frees any data allocated from the parsing of the MPC file */ void FreeMpc() { - int i; - // Free variables globalFree(GLOBALS._hVars); // Free messages LPMPALMSG lpmmMsgs = (LPMPALMSG)globalLock(GLOBALS._hMsgs); - for (i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) + for (int i = 0; i < GLOBALS._nMsgs; i++, ++lpmmMsgs) globalFree(lpmmMsgs->_hText); globalUnlock(GLOBALS._hMsgs); @@ -764,7 +752,7 @@ void FreeMpc() { if (GLOBALS._hDialogs) { LPMPALDIALOG lpmdDialogs = (LPMPALDIALOG)globalLock(GLOBALS._hDialogs); - for (i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) + for (int i = 0; i < GLOBALS._nDialogs; i++, ++lpmdDialogs) freeDialog(lpmdDialogs); globalFree(GLOBALS._hDialogs); @@ -774,7 +762,7 @@ void FreeMpc() { if (GLOBALS._hItems) { LPMPALITEM lpmiItems = (LPMPALITEM)globalLock(GLOBALS._hItems); - for (i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) + for (int i = 0; i < GLOBALS._nItems; ++i, ++lpmiItems) freeItem(lpmiItems); globalUnlock(GLOBALS._hItems); @@ -790,7 +778,7 @@ void FreeMpc() { if (GLOBALS._hScripts) { LPMPALSCRIPT lpmsScripts = (LPMPALSCRIPT)globalLock(GLOBALS._hScripts); - for (i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { + for (int i = 0; i < GLOBALS._nScripts; ++i, ++lpmsScripts) { FreeScript(lpmsScripts); } diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp index be2f6db43f..540dee664f 100644 --- a/engines/tony/mpal/mpal.cpp +++ b/engines/tony/mpal/mpal.cpp @@ -154,10 +154,9 @@ static void unlockScripts() { * need to remember to call UnlockVar() */ int32 varGetValue(const char *lpszVarName) { - int i; LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS._nVars; v++, i++) + for (int i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) return v->dwVal; @@ -171,10 +170,9 @@ int32 varGetValue(const char *lpszVarName) { * @param val Value to set */ void varSetValue(const char *lpszVarName, int32 val) { - uint i; LPMPALVAR v = GLOBALS._lpmvVars; - for (i = 0; i < GLOBALS._nVars; v++, i++) + for (uint i = 0; i < GLOBALS._nVars; v++, i++) if (strcmp(lpszVarName, v->lpszVarName) == 0) { v->dwVal = val; if (GLOBALS._lpiifCustom != NULL && strncmp(v->lpszVarName, "Pattern.", 8) == 0) { @@ -202,10 +200,9 @@ void varSetValue(const char *lpszVarName, int32 val) { * first been locked with a call to LockLoc(). */ static int locGetOrderFromNum(uint32 nLoc) { - int i; LPMPALLOCATION loc = GLOBALS._lpmlLocations; - for (i = 0; i < GLOBALS._nLocations; i++, loc++) + for (int i = 0; i < GLOBALS._nLocations; i++, loc++) if (loc->nObj == nLoc) return i; @@ -221,10 +218,9 @@ static int locGetOrderFromNum(uint32 nLoc) { * first been locked with a call to LockMsg() */ static int msgGetOrderFromNum(uint32 nMsg) { - int i; LPMPALMSG msg = GLOBALS._lpmmMsgs; - for (i = 0; i < GLOBALS._nMsgs; i++, msg++) { + for (int i = 0; i < GLOBALS._nMsgs; i++, msg++) { if (msg->_wNum == nMsg) return i; } @@ -240,10 +236,9 @@ static int msgGetOrderFromNum(uint32 nMsg) { * first been locked with a call to LockItems() */ static int itemGetOrderFromNum(uint32 nItem) { - int i; LPMPALITEM item = GLOBALS._lpmiItems; - for (i = 0; i < GLOBALS._nItems; i++, item++) { + for (int i = 0; i < GLOBALS._nItems; i++, item++) { if (item->nObj == nItem) return i; } @@ -260,10 +255,9 @@ static int itemGetOrderFromNum(uint32 nItem) { * first been locked with a call to LockScripts() */ static int scriptGetOrderFromNum(uint32 nScript) { - int i; LPMPALSCRIPT script = GLOBALS._lpmsScripts; - for (i = 0; i < GLOBALS._nScripts; i++, script++) { + for (int i = 0; i < GLOBALS._nScripts; i++, script++) { if (script->nObj == nScript) return i; } @@ -280,10 +274,9 @@ static int scriptGetOrderFromNum(uint32 nScript) { * first been locked with a call to LockDialogs() */ static int dialogGetOrderFromNum(uint32 nDialog) { - int i; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs; - for (i = 0; i < GLOBALS._nDialogs; i++, dialog++) { + for (int i = 0; i < GLOBALS._nDialogs; i++, dialog++) { if (dialog->nObj == nDialog) return i; } @@ -301,14 +294,13 @@ static int dialogGetOrderFromNum(uint32 nDialog) { static char *DuplicateMessage(uint32 nMsgOrd) { const char *origmsg; char *clonemsg; - int j; if (nMsgOrd == (uint32)-1) return NULL; origmsg = (const char *)globalLock(GLOBALS._lpmmMsgs[nMsgOrd]._hText); - j = 0; + int j = 0; while (origmsg[j] != '\0' || origmsg[j + 1] != '\0') j++; j += 2; @@ -335,15 +327,14 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { const char *origmsg; char *clonemsg; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; - int i, j; - for (j = 0; dialog->_periods[j] != NULL; j++) { + for (int j = 0; dialog->_periods[j] != NULL; j++) { if (dialog->_periodNums[j] == nPeriod) { /* Found the phrase, it should be duplicated */ origmsg = (const char *)globalLock(dialog->_periods[j]); /* Calculate the length and allocate memory */ - i = 0; + int i = 0; while (origmsg[i] != '\0') i++; @@ -370,14 +361,13 @@ static char *duplicateDialogPeriod(uint32 nPeriod) { * @returns Handle to the loaded resource */ HGLOBAL resLoad(uint32 dwId) { - int i; HGLOBAL h; char head[4]; uint32 nBytesRead; uint32 nSizeComp, nSizeDecomp; byte *temp, *buf; - for (i = 0; i < GLOBALS._nResources; i++) + for (int i = 0; i < GLOBALS._nResources; i++) if (GLOBALS._lpResources[i * 2] == dwId) { GLOBALS._hMpr.seek(GLOBALS._lpResources[i * 2 + 1]); nBytesRead = GLOBALS._hMpr.read(head, 4); @@ -416,12 +406,11 @@ HGLOBAL resLoad(uint32 dwId) { static uint32 *getSelectList(uint32 i) { uint32 *sl; - int j, k, num; LPMPALDIALOG dialog = GLOBALS._lpmdDialogs + GLOBALS._nExecutingDialog; /* Count how many are active selects */ - num = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { + int num = 0; + for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) num++; } @@ -430,13 +419,13 @@ static uint32 *getSelectList(uint32 i) { if (num == 0) return NULL; - sl= (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); + sl = (uint32 *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(uint32) * (num + 1)); if (sl == NULL) return NULL; /* Copy all the data inside the active select list */ - k = 0; - for (j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { + int k = 0; + for (int j = 0; dialog->_choice[i]._select[j].dwData != 0; j++) { if (dialog->_choice[i]._select[j].curActive) sl[k++] = dialog->_choice[i]._select[j].dwData; } @@ -447,11 +436,10 @@ static uint32 *getSelectList(uint32 i) { static uint32 *GetItemList(uint32 nLoc) { uint32 *il; - uint32 num,i,j; LPMPALVAR v = GLOBALS._lpmvVars; - num = 0; - for (i = 0; i < GLOBALS._nVars; i++, v++) { + uint32 num = 0; + for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName,"Location",8) == 0 && v->dwVal == nLoc) num++; } @@ -461,8 +449,8 @@ static uint32 *GetItemList(uint32 nLoc) { return NULL; v = GLOBALS._lpmvVars; - j = 0; - for (i = 0; i < GLOBALS._nVars; i++, v++) { + uint32 j = 0; + for (uint32 i = 0; i < GLOBALS._nVars; i++, v++) { if (strncmp(v->lpszVarName, "Location", 8) == 0 && v->dwVal == nLoc) { sscanf(v->lpszVarName, "Location.%u", &il[j]); j++; @@ -478,9 +466,7 @@ static LPITEM getItemData(uint32 nOrdItem) { LPITEM ret; HGLOBAL hDat; char *dat; - int i, j; char *patlength; - uint32 dim; // Zeroing out the allocated memory is required!!! ret = (LPITEM)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(ITEM)); @@ -492,7 +478,7 @@ static LPITEM getItemData(uint32 nOrdItem) { dat = (char *)globalLock(hDat); if (dat[0] == 'D' && dat[1] == 'A' && dat[2] == 'T') { - i = dat[3]; // For version 1.0!! + int i = dat[3]; // For version 1.0!! dat += 4; if (i >= 0x10) { // From 1.0, there's a destination point for each object @@ -513,21 +499,21 @@ static LPITEM getItemData(uint32 nOrdItem) { ret->_destZ = *dat++; // Upload the left & top co-ordinates of each frame - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_frameslocations[i].left = (int16)READ_LE_UINT16(dat); ret->_frameslocations[i].top = (int16)READ_LE_UINT16(dat + 2); dat += 4; } // Upload the size of each frame and calculate the right & bottom - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_frameslocations[i].right = (int16)READ_LE_UINT16(dat) + ret->_frameslocations[i].left; ret->_frameslocations[i].bottom = (int16)READ_LE_UINT16(dat + 2) + ret->_frameslocations[i].top; dat += 4; } // Upload the bounding boxes of each frame - for (i = 0; i < ret->_numframe; i++) { + for (int i = 0; i < ret->_numframe; i++) { ret->_bbox[i].left = (int16)READ_LE_UINT16(dat); ret->_bbox[i].top = (int16)READ_LE_UINT16(dat + 2); ret->_bbox[i].right = (int16)READ_LE_UINT16(dat + 4); @@ -539,16 +525,16 @@ static LPITEM getItemData(uint32 nOrdItem) { patlength = dat; dat += ret->_numpattern; - for (i = 1; i < ret->_numpattern; i++) { - for (j = 0; j < patlength[i]; j++) + for (int i = 1; i < ret->_numpattern; i++) { + for (int j = 0; j < patlength[i]; j++) ret->_pattern[i][j] = dat[j]; ret->_pattern[i][(int)patlength[i]] = 255; // Terminate pattern dat += patlength[i]; } // Upload the individual frames of animations - for (i = 1; i < ret->_numframe; i++) { - dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * + for (int i = 1; i < ret->_numframe; i++) { + uint32 dim = (uint32)(ret->_frameslocations[i].right - ret->_frameslocations[i].left) * (uint32)(ret->_frameslocations[i].bottom - ret->_frameslocations[i].top); ret->_frames[i] = (char *)globalAlloc(GMEM_FIXED,dim); @@ -559,7 +545,7 @@ static LPITEM getItemData(uint32 nOrdItem) { } // Check if we've got to the end of the file - i = READ_LE_UINT16(dat); + int i = READ_LE_UINT16(dat); if (i != 0xABCD) return NULL; @@ -1288,16 +1274,14 @@ void doChoice(CORO_PARAM, uint32 nChoice) { */ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { LPMPALITEM item = GLOBALS._lpmiItems; - int i; LPMPALITEM newitem; - uint32 h; item+=ordItem; Common::String buf = Common::String::format("Status.%u", item->nObj); if (varGetValue(buf.c_str()) <= 0) return CORO_INVALID_PID_VALUE; - for (i = 0; i < item->nActions; i++) { + for (int i = 0; i < item->nActions; i++) { if (item->Action[i].num != nAction) continue; @@ -1326,6 +1310,7 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { // and a second process to free up the memory when the action is finished. // !!! New process management + uint32 h; if ((h = CoroScheduler.createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; @@ -1353,8 +1338,6 @@ static uint32 doAction(uint32 nAction, uint32 ordItem, uint32 dwParam) { * The data on the choices may be obtained through various queries. */ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { - uint32 h; - // Store the running dialog in a global variable GLOBALS._nExecutingDialog = nDlgOrd; @@ -1367,6 +1350,7 @@ static uint32 doDialog(uint32 nDlgOrd, uint32 nGroup) { // Create a thread that performs the dialogue group // Create the process + uint32 h; if ((h = CoroScheduler.createProcess(GroupThread, &nGroup, sizeof(uint32))) == CORO_INVALID_PID_VALUE) return CORO_INVALID_PID_VALUE; @@ -1589,7 +1573,6 @@ void mpalFree() { * method that returns numeric results. */ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { - int x, y; Common::String buf; uint32 dwRet = 0; char *n; @@ -1635,8 +1618,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord); */ lockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); + int x = locGetOrderFromNum(GETARG(uint32)); + int y = GETARG(uint32); if (x != -1) { if (y == MPQ_X) dwRet = GLOBALS._lpmlLocations[x].dwXlen; @@ -1678,7 +1661,7 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) dwRet = (uint32)false; @@ -1692,14 +1675,14 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0]='\0'; else { lockItems(); - y = itemGetOrderFromNum(x); + int y = itemGetOrderFromNum(x); memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1729,8 +1712,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData); */ lockDialogs(); - x = GETARG(uint32); - y = GETARG(uint32); + int x = GETARG(uint32); + int y = GETARG(uint32); dwRet = (uint32)doSelection(x, y); unlockDialogs(); @@ -1741,9 +1724,9 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { */ lockItems(); lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); int z = GETARG(uint32); - y = itemGetOrderFromNum(z); + int y = itemGetOrderFromNum(z); if (y != -1) { dwRet = doAction(x, y, GETARG(uint32)); } else { @@ -1761,8 +1744,8 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { if (!GLOBALS._bExecutingDialog) { lockDialogs(); - x = dialogGetOrderFromNum(GETARG(uint32)); - y = GETARG(uint32); + int x = dialogGetOrderFromNum(GETARG(uint32)); + int y = GETARG(uint32); dwRet = doDialog(x, y); unlockDialogs(); } @@ -1787,7 +1770,6 @@ uint32 mpalQueryDWORD(uint16 wQueryType, ...) { * method that returns a pointer or handle. */ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { - int x, y; char *n; Common::String buf; va_list v; @@ -1833,7 +1815,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc); */ lockLocations(); - x = locGetOrderFromNum(GETARG(uint32)); + int x = locGetOrderFromNum(GETARG(uint32)); hRet = resLoad(GLOBALS._lpmlLocations[x].dwPicRes); unlockLocations(); @@ -1870,14 +1852,14 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char *lpszName); */ lockVar(); - x = GETARG(uint32); + int x = GETARG(uint32); n = GETARG(char *); buf = Common::String::format("Status.%u", x); if (varGetValue(buf.c_str()) <= 0) n[0] = '\0'; else { lockItems(); - y = itemGetOrderFromNum(x); + int y = itemGetOrderFromNum(x); memcpy(n, (char *)(GLOBALS._lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE); unlockItems(); } @@ -1889,7 +1871,7 @@ HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) { * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod); */ lockDialogs(); - y = GETARG(uint32); + int y = GETARG(uint32); hRet = duplicateDialogPeriod(y); unlockDialogs(); @@ -1998,11 +1980,10 @@ uint32 mpalGetError() { * @returns TRUE if the script 'was launched, FALSE on failure */ bool mpalExecuteScript(int nScript) { - int n; LPMPALSCRIPT s; LockScripts(); - n = scriptGetOrderFromNum(nScript); + int n = scriptGetOrderFromNum(nScript); s = (LPMPALSCRIPT)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALSCRIPT)); if (s == NULL) return false; @@ -2039,14 +2020,12 @@ void mpalInstallItemIrq(LPITEMIRQFUNCTION lpiifCus) { * simultaneously is defined defined by MAXPOLLINGFUNCIONS */ bool mpalStartIdlePoll(int nLoc) { - uint32 i; - - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { + for (uint32 i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == (uint32)nLoc) return false; } - for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { + for (uint32 i = 0; i < MAXPOLLINGLOCATIONS; i++) { if (GLOBALS._nPollingLocations[i] == 0) { GLOBALS._nPollingLocations[i] = nLoc; diff --git a/engines/tony/utils.cpp b/engines/tony/utils.cpp index 70c33e71ee..db83c2910b 100644 --- a/engines/tony/utils.cpp +++ b/engines/tony/utils.cpp @@ -38,12 +38,9 @@ namespace Tony { */ Common::String readString(Common::ReadStream &df) { Common::String var; - uint8 len; - int i; + uint8 len = df.readByte(); - len = df.readByte(); - - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { char c; c = df.readByte(); var += c; @@ -356,16 +353,14 @@ void RMResUpdate::init(const Common::String &fileName) { // It doesn't exist, so exit immediately return; - uint8 version; - uint32 i; + uint8 version = _hFile.readByte(); - version = _hFile.readByte(); _numUpd = _hFile.readUint32LE(); _infos = new ResUpdInfo[_numUpd]; // Load the index of the resources in the file - for (i = 0; i < _numUpd; ++i) { + for (uint32 i = 0; i < _numUpd; ++i) { ResUpdInfo &info = _infos[i]; info._dwRes = _hFile.readUint32LE(); diff --git a/engines/tony/window.cpp b/engines/tony/window.cpp index 9385db27c7..0746b267bd 100644 --- a/engines/tony/window.cpp +++ b/engines/tony/window.cpp @@ -265,7 +265,6 @@ void RMSnapshot::grabScreenshot(byte *lpBuf, int dezoom, uint16 *lpDestBuf) { int dimx = RM_SX / dezoom; int dimy = RM_SY / dezoom; - uint32 k = 0; uint16 *cursrc; if (lpDestBuf == NULL) @@ -292,6 +291,7 @@ void RMSnapshot::grabScreenshot(byte *lpBuf, int dezoom, uint16 *lpDestBuf) { src += RM_BBX; } } else { + uint32 k = 0; for (int y = 0; y < dimy; y++) { for (int x = 0; x < dimx; x++) { cursrc = &src[RM_SKIPX + x * dezoom]; |