From ef11f9d0c53cbdd9d88a99143de6f43f34d7e24d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 15:59:26 +0200 Subject: WINTERMUTE: Run Astyle with add-braces to break one-line statements into easier-to-read-code. --- engines/wintermute/utils/path_util.cpp | 14 +++-- engines/wintermute/utils/string_util.cpp | 22 ++++--- engines/wintermute/utils/utils.cpp | 102 ++++++++++++++++++++++--------- 3 files changed, 97 insertions(+), 41 deletions(-) (limited to 'engines/wintermute/utils') diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp index 27b2b0b727..51f0f5817e 100644 --- a/engines/wintermute/utils/path_util.cpp +++ b/engines/wintermute/utils/path_util.cpp @@ -37,8 +37,9 @@ AnsiString PathUtil::unifySeparators(const AnsiString &path) { AnsiString newPath = path; for (uint32 i = 0; i < newPath.size(); i++) { - if (newPath[i] == '\\') + if (newPath[i] == '\\') { newPath.setChar('/', i); + } } return newPath; @@ -56,8 +57,9 @@ AnsiString PathUtil::combine(const AnsiString &path1, const AnsiString &path2) { AnsiString newPath1 = unifySeparators(path1); AnsiString newPath2 = unifySeparators(path2); - if (!StringUtil::endsWith(newPath1, "/", true) && !StringUtil::startsWith(newPath2, "/", true)) + if (!StringUtil::endsWith(newPath1, "/", true) && !StringUtil::startsWith(newPath2, "/", true)) { newPath1 += "/"; + } return newPath1 + newPath2; } @@ -79,10 +81,11 @@ AnsiString PathUtil::getFileName(const AnsiString &path) { //size_t pos = newPath.find_last_of(L'/'); TODO REMOVE. Common::String lastPart = Common::lastPathComponent(newPath, '/'); - if (lastPart[lastPart.size() - 1 ] != '/') + if (lastPart[lastPart.size() - 1 ] != '/') { return lastPart; - else + } else { return path; + } //if (pos == AnsiString::npos) return path; //else return newPath.substr(pos + 1); } @@ -183,8 +186,9 @@ AnsiString PathUtil::getUserDirectory() { if (error == noErr) { char buffer[MAX_PATH_LENGTH]; error = FSRefMakePath(&fileRef, (UInt8 *)buffer, sizeof(buffer)); - if (error == noErr) + if (error == noErr) { userDir = buffer; + } } #elif __IPHONEOS__ diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp index 748016d9c4..f864a8480a 100644 --- a/engines/wintermute/utils/string_util.cpp +++ b/engines/wintermute/utils/string_util.cpp @@ -215,14 +215,15 @@ bool StringUtil::startsWith(const AnsiString &str, const AnsiString &pattern, bo if (ignoreCase) return CompareNoCase(startPart, pattern); else return (startPart == pattern);*/ - if (!ignoreCase) + if (!ignoreCase) { return str.hasPrefix(pattern); - else { + } else { size_t strLength = str.size(); size_t patternLength = pattern.size(); - if (strLength < patternLength || patternLength == 0) + if (strLength < patternLength || patternLength == 0) { return false; + } AnsiString startPart(str.c_str(), patternLength); uint32 likeness = startPart.compareToIgnoreCase(pattern.c_str()); @@ -248,8 +249,9 @@ bool StringUtil::endsWith(const AnsiString &str, const AnsiString &pattern, bool size_t strLength = str.size(); size_t patternLength = pattern.size(); - if (strLength < patternLength || patternLength == 0) + if (strLength < patternLength || patternLength == 0) { return false; + } Common::String endPart(str.c_str() + (strLength - patternLength), patternLength); uint32 likeness = str.compareToIgnoreCase(pattern.c_str()); @@ -259,8 +261,11 @@ bool StringUtil::endsWith(const AnsiString &str, const AnsiString &pattern, bool ////////////////////////////////////////////////////////////////////////// bool StringUtil::isUtf8BOM(const byte *Buffer, uint32 BufferSize) { - if (BufferSize > 3 && Buffer[0] == 0xEF && Buffer[1] == 0xBB && Buffer[2] == 0xBF) return true; - else return false; + if (BufferSize > 3 && Buffer[0] == 0xEF && Buffer[1] == 0xBB && Buffer[2] == 0xBF) { + return true; + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// @@ -269,10 +274,11 @@ int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t if (pos == str.npos) return -1; else return pos;*/ const char *index = strstr(str.c_str(), toFind.c_str()); - if (index == NULL) + if (index == NULL) { return -1; - else + } else { return index - str.c_str(); + } } diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index a4751ef11b..39bb1d7137 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -48,8 +48,12 @@ void BaseUtils::swap(int *a, int *b) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { - while (angle > 360) angle -= 360; - while (angle < 0) angle += 360; + while (angle > 360) { + angle -= 360; + } + while (angle < 0) { + angle += 360; + } return angle; } @@ -81,7 +85,9 @@ void BaseUtils::debugMessage(const char *text) { char *BaseUtils::setString(char **string, const char *value) { delete[] *string; *string = new char[strlen(value) + 1]; - if (*string) strcpy(*string, value); + if (*string) { + strcpy(*string, value); + } return *string; } @@ -89,7 +95,9 @@ char *BaseUtils::setString(char **string, const char *value) { int BaseUtils::strNumEntries(const char *str, const char delim) { int numEntries = 1; for (uint32 i = 0; i < strlen(str); i++) { - if (str[i] == delim) numEntries++; + if (str[i] == delim) { + numEntries++; + } } return numEntries; } @@ -104,8 +112,11 @@ char *BaseUtils::strEntry(int entry, const char *str, const char delim) { for (uint32 i = 0; i <= strlen(str); i++) { if (numEntries == entry) { - if (!start) start = str + i; - else len++; + if (!start) { + start = str + i; + } else { + len++; + } } if (str[i] == delim || str[i] == '\0') { numEntries++; @@ -159,35 +170,46 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { return (stringc == 0); case '?': - if (stringc == 0) return false; + if (stringc == 0) { + return false; + } break; case '*': - if (!*pattern) return true; + if (!*pattern) { + return true; + } if (*pattern == '.') { char *dot; - if (pattern[1] == '*' && pattern[2] == 0) return true; + if (pattern[1] == '*' && pattern[2] == 0) { + return true; + } dot = (char *)strchr(string, '.'); - if (pattern[1] == 0) return (dot == NULL || dot[1] == 0); + if (pattern[1] == 0) { + return (dot == NULL || dot[1] == 0); + } if (dot != NULL) { string = dot; - if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) + if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) { return(scumm_stricmp(pattern + 1, string + 1) == 0); + } } } while (*string) - if (BaseUtils::matchesPattern(pattern, string++)) + if (BaseUtils::matchesPattern(pattern, string++)) { return true; + } return false; default: if (patternc != stringc) - if (patternc == '.' && stringc == 0) + if (patternc == '.' && stringc == 0) { return(BaseUtils::matchesPattern(pattern, string)); - else + } else { return false; + } break; } } @@ -222,19 +244,30 @@ void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { } //Chromatic data... else { - if (L < 0.5f) S = delMax / (varMax + varMin); - else S = delMax / (2.0f - varMax - varMin); + if (L < 0.5f) { + S = delMax / (varMax + varMin); + } else { + S = delMax / (2.0f - varMax - varMin); + } float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; - if (varR == varMax) H = delB - delG; - else if (varG == varMax) H = (1.0f / 3.0f) + delR - delB; - else if (varB == varMax) H = (2.0f / 3.0f) + delG - delR; + if (varR == varMax) { + H = delB - delG; + } else if (varG == varMax) { + H = (1.0f / 3.0f) + delR - delB; + } else if (varB == varMax) { + H = (2.0f / 3.0f) + delG - delR; + } - if (H < 0) H += 1; - if (H > 1) H -= 1; + if (H < 0) { + H += 1; + } + if (H > 1) { + H -= 1; + } } *outH = (byte)(H * 255); @@ -259,8 +292,11 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { } else { float var_1, var_2; - if (L < 0.5) var_2 = L * (1.0 + S); - else var_2 = (L + S) - (S * L); + if (L < 0.5) { + var_2 = L * (1.0 + S); + } else { + var_2 = (L + S) - (S * L); + } var_1 = 2.0f * L - var_2; @@ -274,11 +310,21 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::Hue2RGB(float v1, float v2, float vH) { - if (vH < 0.0f) vH += 1.0f; - if (vH > 1.0f) vH -= 1.0f; - if ((6.0f * vH) < 1.0f) return (v1 + (v2 - v1) * 6.0f * vH); - if ((2.0f * vH) < 1.0f) return (v2); - if ((3.0f * vH) < 2.0f) return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + if (vH < 0.0f) { + vH += 1.0f; + } + if (vH > 1.0f) { + vH -= 1.0f; + } + if ((6.0f * vH) < 1.0f) { + return (v1 + (v2 - v1) * 6.0f * vH); + } + if ((2.0f * vH) < 1.0f) { + return (v2); + } + if ((3.0f * vH) < 2.0f) { + return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + } return (v1); } -- cgit v1.2.3