From a28119ae30bccb60c82778a75dfe56064052eb21 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 20 Sep 2019 08:52:29 +0200 Subject: [PATCH] Fix Linux compilation - replaced stricmp with strcasecmp and strncasecmp https://linux.die.net/man/3/strcasecmp - replaced all Microsoft specific types with standard ones - replaced all instances of MAX_PATH with BMAX_PATH --- source/blood/src/barf.cpp | 32 ++++++++++++++++---------------- source/blood/src/resource.cpp | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/source/blood/src/barf.cpp b/source/blood/src/barf.cpp index f548dafc9..890f4d589 100644 --- a/source/blood/src/barf.cpp +++ b/source/blood/src/barf.cpp @@ -116,7 +116,7 @@ const int kTagCount = sizeof(tags) / sizeof(tag_t); int qsort_compar(const void *a, const void *b) { - return stricmp((const char*)a, (const char*)b); + return strcasecmp((const char*)a, (const char*)b); } void SortTags() @@ -171,7 +171,7 @@ void RFS::Open(const char *fileName) ThrowError("Error opening file %s", _fileName); } - int fileSize = filelength(hFile); + int fileSize = kfilelength(hFile); _ptr = (char*)Resource::Alloc(fileSize); if (_ptr == NULL) { ThrowError("Not enough memory to read %s", _fileName); @@ -314,14 +314,14 @@ uint8_t RFS::GetNextTag() else { scriptValue = 0; - BOOL isNegative = FALSE; // or 'isSigned' ? + bool isNegative = false; // or 'isSigned' ? // is it a negative number? if (_curChar == '-') { Increment(); - isNegative = TRUE; + isNegative = true; if (!isdigit(_curChar)) { UnsetMark(); @@ -407,7 +407,7 @@ uint8_t RFS::GetNextTag() } // eax = strnicmp(tags[i]._value, scriptBuffer, ebp); - eax = strnicmp(scriptBuffer, tags[i]._value, ebp); + eax = strncasecmp(scriptBuffer, tags[i]._value, ebp); //if (eax >= 0) { if (eax == 0) { @@ -468,7 +468,7 @@ void ParseScript(char *scriptFileName) gParseLevel = 0; dword_44CE0[0] = 0; - BOOL parsing = TRUE; + bool parsing = true; while (parsing) { @@ -485,7 +485,7 @@ void ParseScript(char *scriptFileName) } case kTagEnd: { - parsing = FALSE; + parsing = true; break; } case kTagComment: @@ -539,7 +539,7 @@ void ParseScript(char *scriptFileName) strcpy(inp, scriptBuffer); char nFlags = 0; int ID = 0; - BOOL isDefine = FALSE; + bool isDefine = false; tag = rfs.GetNextTag(); if (tag == kTagAs) @@ -556,7 +556,7 @@ void ParseScript(char *scriptFileName) break; } - isDefine = TRUE; + isDefine = true; tag = rfs.GetNextTag(); } @@ -626,13 +626,13 @@ void ParseScript(char *scriptFileName) rfs.SetMark(); strcpy(char256_1, scriptBuffer); - BOOL bGotDefine = FALSE; + bool bGotDefine = false; // check if this was defined via command prompt arguments for (int i = 0; i < nCmdDefines; i++) { - if (stricmp(gCmdDefines[i]._text, char256_1) == 0) { // string is equivalent - bGotDefine = TRUE; + if (strcasecmp(gCmdDefines[i]._text, char256_1) == 0) { // string is equivalent + bGotDefine = true; break; } } @@ -719,7 +719,7 @@ void ParseScript(char *scriptFileName) char nFlags = 0; int ID = 0; - BOOL isDefine = FALSE; + bool isDefine = false; tag = rfs.GetNextTag(); @@ -738,7 +738,7 @@ void ParseScript(char *scriptFileName) break; } - isDefine = TRUE; + isDefine = true; tag = rfs.GetNextTag(); } @@ -888,7 +888,7 @@ void sub_11C10(char *pzScriptDir, char *fileName, char flags, int ID) dirr = Bopendir("./"); if (dirr) { - while (dirent = Breaddir(dirr)) + while ((dirent = Breaddir(dirr))) { if (!Bwildmatch(dirent->name, fileName)) continue; @@ -905,7 +905,7 @@ void sub_11C10(char *pzScriptDir, char *fileName, char flags, int ID) dirr = Bopendir(pzScriptDir); if (dirr) { - while (dirent = Breaddir(dirr)) + while ((dirent = Breaddir(dirr))) { if (!Bwildmatch(dirent->name, fileName)) continue; diff --git a/source/blood/src/resource.cpp b/source/blood/src/resource.cpp index 71ae279f4..e319c8624 100644 --- a/source/blood/src/resource.cpp +++ b/source/blood/src/resource.cpp @@ -578,7 +578,7 @@ void Resource::Read(DICTNODE *n, void *p) if (n->path) Bstrncpy(filename, n->path, BMAX_PATH-1); else - Bsnprintf(filename, MAX_PATH-1, "%s.%s", n->name, n->type); + Bsnprintf(filename, BMAX_PATH-1, "%s.%s", n->name, n->type); int fhandle = kopen4loadfrommod(filename, 0); if (fhandle == -1 || (uint32_t)kread(fhandle, p, n->size) != n->size) {