From f0af98b0a7146875f150271dd2778af3ecced107 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 17 Jun 2012 20:15:04 -0400 Subject: [PATCH] Toss lots of custom CString code We already have a C standard library, so let's not reimplement it. --- Sources/Plasma/Apps/plClient/plClient.cpp | 4 +- Sources/Plasma/Apps/plFileEncrypt/main.cpp | 11 +- Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp | 6 +- Sources/Plasma/CoreLib/HeadSpin.cpp | 128 +----------------- Sources/Plasma/CoreLib/HeadSpin.h | 14 -- Sources/Plasma/CoreLib/hsStream.cpp | 12 +- .../pfConsoleCore/pfConsoleCommandsCore.cpp | 24 ++-- .../FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp | 4 +- .../FeatureLib/pfSurface/plLayerMovie.cpp | 2 +- .../NucleusLib/pnKeyedObject/plKeyImp.cpp | 4 +- .../Plasma/NucleusLib/pnMessage/plMessage.cpp | 7 +- .../NucleusLib/pnNetCommon/plSynchedValue.cpp | 6 +- Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp | 10 +- .../PubUtilLib/plFile/plEncryptedStream.cpp | 3 +- .../PubUtilLib/plFile/plSecureStream.cpp | 4 +- .../PubUtilLib/plMessage/plLoadAgeMsg.cpp | 2 +- .../plPipeline/hsG3DDeviceSelector.cpp | 8 +- .../PubUtilLib/plResMgr/plResManager.cpp | 8 +- .../PubUtilLib/plSDL/plStateVariable.cpp | 4 +- .../plStatGather/plProfileManagerFull.cpp | 4 +- Sources/Tools/MaxComponent/plAnimCompProc.cpp | 2 +- .../Tools/MaxComponent/plAnimComponent.cpp | 4 +- .../Tools/MaxComponent/plMultistageStage.cpp | 45 +----- .../Tools/MaxComponent/plResponderLink.cpp | 4 +- Sources/Tools/MaxComponent/plResponderMtl.cpp | 4 +- .../Tools/MaxConvert/hsMaterialConverter.cpp | 4 +- Sources/Tools/MaxMain/plMaxNode.cpp | 2 +- Sources/Tools/MaxMain/plPluginResManager.cpp | 8 +- .../Materials/plAnimStealthNode.cpp | 4 +- 29 files changed, 91 insertions(+), 251 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 4d33c02e..035efb51 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -1015,7 +1015,7 @@ void plClient::IQueueRoomLoad(const std::vector& locs, bool hold) fLoadRooms.push_back(new LoadRequest(loc, hold)); - if (!lastAgeName || hsStrEQ(info->GetAge(), lastAgeName)) + if (!lastAgeName || strcmp(info->GetAge(), lastAgeName) == 0) lastAgeName = info->GetAge(); else allSameAge = false; @@ -1208,7 +1208,7 @@ void plClient::IRoomLoaded(plSceneNode* node, bool hold) int numMsgs = 0; for (int i = 0; i < sizeof(ageMsgCount)/sizeof(AgeMsgCount); i++) { - if (hsStrEQ(ageMsgCount[i].AgeName, name)) + if (strcmp(ageMsgCount[i].AgeName, name) == 0) { numMsgs = ageMsgCount[i].NumMsgs; break; diff --git a/Sources/Plasma/Apps/plFileEncrypt/main.cpp b/Sources/Plasma/Apps/plFileEncrypt/main.cpp index d821433d..2a52b1b1 100644 --- a/Sources/Plasma/Apps/plFileEncrypt/main.cpp +++ b/Sources/Plasma/Apps/plFileEncrypt/main.cpp @@ -62,37 +62,38 @@ void print_help() { printf("\t-v|--version\t - Prints build version information\n"); } - int main(int argc, char *argv[]) { bool encrypt = true; const char* dir = "."; +#define ARGCMP(y) (strcmp(argv[1], y) == 0) if (argc > 1) { - if (hsStrEQ(argv[1], "encrypt") || hsStrEQ(argv[1], "-e") ) + if (ARGCMP("encrypt") || ARGCMP("-e") ) { if (argc > 2) dir = argv[2]; encrypt = true; } - else if (hsStrEQ(argv[1], "decrypt") || hsStrEQ(argv[1], "-d")) + else if (ARGCMP("decrypt") || ARGCMP("-d")) { if (argc > 2) dir = argv[2]; encrypt = false; } - else if(hsStrEQ(argv[1], "--help") || hsStrEQ(argv[1], "-h") || hsStrEQ(argv[1], "-?") || hsStrEQ(argv[1], "/?")) + else if(ARGCMP("--help") || ARGCMP("-h") || ARGCMP("-?") || ARGCMP("/?")) { print_help(); return 0; } - else if (hsStrEQ(argv[1], "-v") || hsStrEQ(argv[1], "--version")) + else if (ARGCMP("-v") || ARGCMP("--version")) { print_version(); return 0; } } +#undef ARGCMP EncryptFiles(dir, ".age", encrypt); EncryptFiles(dir, ".fni", encrypt); diff --git a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp index 299b1bc1..e995fd23 100644 --- a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp +++ b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp @@ -95,7 +95,7 @@ int PrintHelp( void ) int main(int argc, char* argv[]) { - if (argc >= 1 && hsStrEQ(argv[1], "-v")) + if (argc >= 1 && strcmp(argv[1], "-v") == 0) { PrintVersion(); return 0; @@ -110,9 +110,9 @@ int main(int argc, char* argv[]) int arg = 1; for (arg = 1; arg < argc; arg++) { - if (hsStrEQ(argv[arg], "-s")) + if (strcmp(argv[arg], "-s") == 0) sounds = true; - else if (hsStrEQ(argv[arg], "-i")) + else if (strcmp(argv[arg], "-i") == 0) stats = true; else break; diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 7aeba571..caff9906 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -377,12 +377,6 @@ int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int return hsMessageBoxWithOwner((hsWindowHndl)nil,message,caption,kind,icon); } -inline hsBool hsCompare(float a, float b, float delta) -{ - return (fabs(a - b) < delta); -} - - /* Generic psuedo RNG used in ANSI C. */ static unsigned long SEED = 1; int hsRand() @@ -398,24 +392,13 @@ void hsRandSeed(int seed) SEED = seed; } /**************************************/ -int hsStrlen(const char src[]) -{ - if (src==nil) - return 0; - - int i = 0; - while (src[i]) - i++; - return i; -} - char* hsStrcpy(char dst[], const char src[]) { if (src) { if (dst == nil) { - int count = hsStrlen(src); + int count = strlen(src); dst = (char *)malloc(count + 1); memcpy(dst, src, count); dst[count] = 0; @@ -431,75 +414,16 @@ char* hsStrcpy(char dst[], const char src[]) return dst; } -bool hsStrEQ(const char s1[], const char s2[]) -{ - if (s1 && s2) - { - while (*s1) - if(*s1++ != *s2++) - return false; - return *s2 == 0; - } - - return (!s1 && !s2); -} - -bool hsStrCaseEQ(const char* s1, const char* s2) -{ - if (s1 && s2) - { - while (*s1) - if(tolower(*s1++) != tolower(*s2++)) - return false; - return *s2 == 0; - } - - return (!s1 && !s2); -} - -void hsStrcat(char dst[], const char src[]) -{ - if (src && dst) - { - dst += hsStrlen(dst); - while(*src) - *dst++ = *src++; - *dst = 0; - } -} - void hsStrLower(char *s) { if (s) { int i; - for (i = 0; i < hsStrlen(s); i++) + for (i = 0; i < strlen(s); i++) s[i] = tolower(s[i]); } } -char* hsP2CString(const uint8_t pstring[], char cstring[]) -{ - char* cstr = cstring; - const uint8_t* stop = &pstring[1] + pstring[0]; - - pstring += 1; // skip length byte - while (pstring < stop) - *cstr++ = *pstring++; - *cstr = 0; - return cstring; -} - -uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]) -{ - int i; - - for (i = 1; *cstring; i++) - pstring[i] = *cstring++; - pstring[0] = i - 1; - return pstring; -} - //// IStringToWString ///////////////////////////////////////////////////////// // Converts a char * string to a wchar_t * string @@ -540,54 +464,6 @@ char *hsWStringToString( const wchar_t *str ) return sStr; } -void hsCPathToMacPath(char* dst, char* fname) -{ - int i; - - int offset = 0; - hsBool prefix = 1; // Assume it's a relative path. - - // KLUDGE: this determines whether a PC path is - // relative or absolute. True if relative, therefore - // we prefix the pathname with a colon. - - hsStrcpy(dst, ""); - - if(strstr(fname, ":")) - { - prefix = 0; - } - else if(strstr(fname, "\\\\")) - { - prefix = 0; - offset = 2; // copy fname from 2-Bytes in. This removes - // the first two chars... - } - - if(prefix) - { - hsStrcpy(dst, ":"); - } - - hsStrcat(dst, &fname[offset]); - - // No more slashes? We're done. (Optimization? Not really I guess.) - if(!strstr(dst, "\\") && !strstr(dst, "/")) return; - - for(i =0; i < hsStrlen(dst); i++) - { - if(dst[i] == '\\' || dst[i] == '/') - { - dst[i] = ':'; - } - } -} - -int hsRemove(const char * fname) -{ - return remove(fname); -} - // // Microsoft SAMPLE CODE // returns array of allocated version info strings or nil diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 5aec902b..c5d13732 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -401,14 +401,7 @@ void SWAP (T & a, T & b) { void hsStatusMessageF(const char * fmt, ...); #endif // PLASMA_EXTERNAL_RELEASE -int hsStrlen(const char src[]); char* hsStrcpy(char dstOrNil[], const char src[]); -void hsStrcat(char dst[], const char src[]); -bool hsStrEQ(const char s1[], const char s2[]); -bool hsStrCaseEQ(const char* s1, const char* s2); -char* hsScalarToStr(float); -int hsRemove(const char* filename); -void hsCPathToMacPath(char* dst, char* fname); void hsStrLower(char *s); char * hsFormatStr(const char * fmt, ...); // You are responsible for returned memory. char * hsFormatStrV(const char * fmt, va_list args); // You are responsible for returned memory. @@ -428,11 +421,6 @@ char * hsFormatStrV(const char * fmt, va_list args); // You are responsible f # define strlwr hsStrLower #endif - -// A pstring has a length uint8_t at the beginning, and no trailing 0 -char* hsP2CString(const uint8_t pstring[], char cstring[]); -uint8_t* hsC2PString(const char cstring[], uint8_t pstring[]); - inline char* hsStrcpy(const char src[]) { return hsStrcpy(nil, src); @@ -480,8 +468,6 @@ int hsMessageBox(const wchar_t message[], const wchar_t caption[], int kind, int int hsMessageBoxWithOwner(hsWindowHndl owner, const char message[], const char caption[], int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t message[], const wchar_t caption[], int kind, int icon=hsMessageBoxIconAsterisk); -inline hsBool hsCompare(float a, float b, float delta=0.0001); - // flag testing / clearing #define hsCheckBits(f,c) ((f & c)==c) #define hsTestBits(f,b) ( (f) & (b) ) diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 257511bf..835c1742 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -118,7 +118,9 @@ hsStream::~hsStream() uint32_t hsStream::WriteString(const char cstring[]) { - return Write(hsStrlen(cstring), cstring); + if (cstring) + return Write(strlen(cstring), cstring); + return 0; } uint32_t hsStream::WriteFmt(const char * fmt, ...) @@ -139,7 +141,9 @@ uint32_t hsStream::WriteFmtV(const char * fmt, va_list av) uint32_t hsStream::WriteSafeStringLong(const char *string) { - uint32_t len = hsStrlen(string); + uint32_t len = 0; + if (string) + len = strlen(string); WriteLE32(len); if (len > 0) { @@ -222,7 +226,9 @@ wchar_t *hsStream::ReadSafeWStringLong() uint32_t hsStream::WriteSafeString(const char *string) { - int len = hsStrlen(string); + int len = 0; + if (string) + len = strlen(string); hsAssert(len<0xf000, xtl::format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong", string, len).c_str() ); diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp index 36d16c3c..601993db 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp @@ -149,14 +149,14 @@ PF_CONSOLE_CMD( "string base64Key", "Set the Auth Server N key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kAuthDhNData); } @@ -167,14 +167,14 @@ PF_CONSOLE_CMD( "string base64Key", "Set the Auth Server X key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kAuthDhXData); } @@ -190,14 +190,14 @@ PF_CONSOLE_CMD( "string base64Key", "Set the Game Server N key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kGameDhNData); } @@ -208,14 +208,14 @@ PF_CONSOLE_CMD( "string base64Key", "Set the Game Server X key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kGameDhXData); } @@ -241,14 +241,14 @@ PF_CONSOLE_CMD( "string base64Key", "Set the GateKeeper Server N key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kGateKeeperDhNData); } @@ -259,13 +259,13 @@ PF_CONSOLE_CMD( "string base64Key", "Set the GateKeeper Server X key" ) { - int baseLength = hsStrlen((const char *)params[0]); + int baseLength = strlen((const char *)params[0]); if ((kNetDiffieHellmanKeyBits / 8) != Base64DecodeSize(baseLength, (const char *)params[0])) { PrintStringF(PrintString, "Invalid key: should be exactly %u bytes", kNetDiffieHellmanKeyBits / 8); return; } - Base64Decode(hsStrlen((const char *)params[0]), (const char *)params[0], + Base64Decode(strlen((const char *)params[0]), (const char *)params[0], kNetDiffieHellmanKeyBits / 8, kGateKeeperDhXData); } diff --git a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp index 19010b66..5ce7795b 100644 --- a/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGameGUIMgr.cpp @@ -235,7 +235,7 @@ void pfGameGUIMgr::IAddDlgToList( hsKeyedObject *obj ) // check to see if it is the dialog we are waiting for to be loaded for ( i=0 ; iGetName(), mod->GetName()) ) + if ( strcmp(fDialogToSetKeyOf[i]->GetName(), mod->GetName()) == 0 ) { SetDialogToNotify(mod,fDialogToSetKeyOf[i]->GetKey()); // now remove this entry... we did it @@ -316,7 +316,7 @@ void pfGameGUIMgr::LoadDialog( const char *name, plKey recvrKey, const char * int i; for ( i=0 ; iGetName(), name) ) + if ( strcmp(fDialogToSetKeyOf[i]->GetName(), name) == 0 ) { alreadyLoaded = true; break; diff --git a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp b/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp index 8a003f4b..f5553787 100644 --- a/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp +++ b/Sources/Plasma/FeatureLib/pfSurface/plLayerMovie.cpp @@ -202,7 +202,7 @@ void plLayerMovie::Write(hsStream* s, hsResMgr* mgr) { plLayerAnimation::Write(s, mgr); - int len = hsStrlen(fMovieName); + int len = (fMovieName) ? strlen(fMovieName) : 0; s->WriteLE32(len); if( len ) s->Write(len, fMovieName); diff --git a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp index 7400f8a3..78037f6f 100644 --- a/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp +++ b/Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp @@ -68,7 +68,9 @@ static uint16_t kClassType = CLASS_INDEX_SCOPED(plSceneNode); static uint32_t kCloneID = 0; hsBool IsTrackedKey(const plKeyImp* key) { - return hsStrEQ(key->GetName(), kObjName) && key->GetUoid().GetClassType() == kClassType && key->GetUoid().GetCloneID() == kCloneID; + return (strcmp(key->GetName(), kObjName) == 0) && + key->GetUoid().GetClassType() == kClassType && + key->GetUoid().GetCloneID() == kCloneID; } #endif diff --git a/Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp b/Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp index 5796fe6a..c0de62e8 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp +++ b/Sources/Plasma/NucleusLib/pnMessage/plMessage.cpp @@ -367,11 +367,10 @@ int plMsgXtlStringHelper::Peek(xtl::istring & stringref, hsStream* stream, const // STATIC int plMsgCStringHelper::Poke(const char * str, hsStream* stream, const uint32_t peekOptions) { - plMessage::plStrLen strlen; - strlen = (str)?hsStrlen(str):0; - stream->WriteLE(strlen); + plMessage::plStrLen len = (str) ? strlen(str) : 0; + stream->WriteLE(len); if (strlen) - stream->Write(strlen,str); + stream->Write(len,str); return stream->GetPosition(); } diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.cpp index c5aca9c1..c29a63be 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plSynchedValue.cpp @@ -100,9 +100,9 @@ const plKey plSynchedValueBase::ISaveOrLoad(const plKey key, hsBool32 save, hsSt stream->WriteByte(1); // I need to write a key to MY stream... #if 0 // DEBUG - int32_t len = hsStrlen(key->GetName()); - stream->WriteLE32(len); - stream->Write(len, key->GetName()); + plStringBuffer buf = key->GetName()->ToIso8859_1(); + stream->WriteLE32(buf.GetSize()); + stream->Write(buf.GetSize(), buf.GetData()); #endif key->GetUoid().Write(stream); } diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp b/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp index d7b7e1e9..ef898ad9 100644 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/hsFiles.cpp @@ -153,18 +153,20 @@ hsBool hsFolderIterator::NextFileSuffix(const char suffix[]) int hsFolderIterator::GetPathAndName(char pathandname[]) { + hsAssert(pathandname, "NULL path string"); const char* name = this->GetFileName(); - int pathLen = hsStrlen(fPath); + int pathLen = strlen(fPath); // add 1 for null terminator - int totalLen = pathLen + sizeof(kDirChar) + hsStrlen(name) + 1; + int totalLen = pathLen + sizeof(kDirChar) + strlen(name) + 1; hsAssert(totalLen <= kFolderIterator_MaxPath, "Overrun kFolderIterator_MaxPath"); if (pathandname) - { hsStrcpy(pathandname, fPath); + { + strcpy(pathandname, fPath); if (pathLen > 0 && pathandname[pathLen - 1] != kDirChar) pathandname[pathLen++] = kDirChar; - hsStrcpy(pathandname + pathLen, name); + strcpy(pathandname + pathLen, name); } return totalLen; } diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index 8350bc87..b0ce0509 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp @@ -518,7 +518,8 @@ bool plEncryptedStream::ICheckMagicString(FILE* fp) char magicString[kMagicStringLen+1]; fread(&magicString, kMagicStringLen, 1, fp); magicString[kMagicStringLen] = '\0'; - return (hsStrEQ(magicString, kMagicString) || hsStrEQ(magicString, kOldMagicString)); + return strcmp(magicString, kMagicString) == 0 || + strcmp(magicString, kOldMagicString) == 0; } bool plEncryptedStream::IsEncryptedFile(const char* fileName) diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index dabb390c..2f1f4390 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -652,7 +652,7 @@ bool plSecureStream::ICheckMagicString(hsStream* s) char magicString[kMagicStringLen+1]; s->Read(kMagicStringLen, &magicString); magicString[kMagicStringLen] = '\0'; - return (hsStrEQ(magicString, kMagicString) != 0); + return (strcmp(magicString, kMagicString) == 0); } bool plSecureStream::ICheckMagicString(hsFD fp) @@ -665,7 +665,7 @@ bool plSecureStream::ICheckMagicString(hsFD fp) fread(&magicString, kMagicStringLen, 1, fp); #endif magicString[kMagicStringLen] = '\0'; - return (hsStrEQ(magicString, kMagicString) != 0); + return (strcmp(magicString, kMagicString) == 0); } bool plSecureStream::IsSecureFile(const char* fileName) diff --git a/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp index 3d51511b..2ab7722c 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plLoadAgeMsg.cpp @@ -70,7 +70,7 @@ void plLoadAgeMsg::Write(hsStream* stream, hsResMgr* mgr) plMessage::IMsgWrite(stream, mgr); // write agename - uint8_t len=fAgeFilename?hsStrlen(fAgeFilename):0; + uint8_t len = fAgeFilename ? strlen(fAgeFilename) : 0; stream->WriteLE(len); if (len) { diff --git a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp index c053443d..e911e592 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/hsG3DDeviceSelector.cpp @@ -415,19 +415,19 @@ void hsG3DDeviceRecord::Write(hsStream* s) const int len; - len = hsStrlen(fG3DDriverDesc); + len = strlen(fG3DDriverDesc); s->WriteLE32(len); s->Write(len, fG3DDriverDesc); - len = hsStrlen(fG3DDriverName); + len = strlen(fG3DDriverName); s->WriteLE32(len); s->Write(len, fG3DDriverName); - len = hsStrlen(fG3DDriverVersion); + len = strlen(fG3DDriverVersion); s->WriteLE32(len); s->Write(len, fG3DDriverVersion); - len = hsStrlen(fG3DDeviceDesc); + len = strlen(fG3DDeviceDesc); s->WriteLE32(len); s->Write(len, fG3DDeviceDesc); diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index f6558235..844e2e5d 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -244,7 +244,7 @@ plRegistryPageNode* plResManager::FindSinglePage(const char* path) const PageMap::const_iterator it; for (it = fAllPages.begin(); it != fAllPages.end(); it++) { - if (hsStrCaseEQ((it->second)->GetPagePath(), path)) + if (strcmpi((it->second)->GetPagePath(), path) == 0) return it->second; } @@ -1651,8 +1651,8 @@ plRegistryPageNode* plResManager::FindPage(const char* age, const char* page) co for (it = fAllPages.begin(); it != fAllPages.end(); ++it) { const plPageInfo& info = (it->second)->GetPageInfo(); - if (hsStrCaseEQ(info.GetAge(), age) && - hsStrCaseEQ(info.GetPage(), page)) + if (strcmpi(info.GetAge(), age) == 0 && + strcmpi(info.GetPage(), page) == 0) return it->second; } @@ -1766,7 +1766,7 @@ hsBool plResManager::IteratePages(plRegistryPageIterator* iterator, const char* if (page->GetPageInfo().GetLocation() == plLocation::kGlobalFixedLoc) continue; - if (!ageToRestrictTo || hsStrCaseEQ(page->GetPageInfo().GetAge(), ageToRestrictTo)) + if (!ageToRestrictTo || strcmpi(page->GetPageInfo().GetAge(), ageToRestrictTo) == 0) { if (!iterator->EatPage(page)) { diff --git a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp index 899bf977..c759362c 100644 --- a/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp +++ b/Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp @@ -1468,8 +1468,8 @@ bool plSimpleStateVariable::Set(const char* v, int idx) if (v && fVar.GetType()==plVarDescriptor::kString32) { - hsAssert(hsStrlen(v)<32, "string length overflow"); - hsStrncpy(fS32[idx], v, 32); + hsAssert(strlen(v)<32, "string length overflow"); + strncpy(fS32[idx], v, 32); IVarSet(); return true; } diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 484d7b0f..28922a0f 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -310,7 +310,7 @@ void plProfileManagerFull::Update() std::vector group; for (int i = 0; i < fVars.size(); i++) - if (hsStrEQ(fVars[i]->GetGroup(), groupName)) + if (strcmp(fVars[i]->GetGroup(), groupName) == 0) group.push_back(fVars[i]); int x = 10; @@ -405,7 +405,7 @@ void plProfileManagerFull::IPrintGroup(hsStream* s, const char* groupName, bool for (int i = 0; i < fVars.size(); i++) { plProfileVar* var = fVars[i]; - if (hsStrEQ(var->GetGroup(), groupName)) + if (strcmp(var->GetGroup(), groupName) == 0) { if (printTitle) sprintf(buf, "%s:%s", var->GetGroup(), var->GetName()); diff --git a/Sources/Tools/MaxComponent/plAnimCompProc.cpp b/Sources/Tools/MaxComponent/plAnimCompProc.cpp index c1e65fdc..6fd7cb31 100644 --- a/Sources/Tools/MaxComponent/plAnimCompProc.cpp +++ b/Sources/Tools/MaxComponent/plAnimCompProc.cpp @@ -412,7 +412,7 @@ protected: void ISetUserType(plMaxNode* node, const char* userType) { - if (hsStrEQ(userType, kUserTypeAll)) + if (strcmp(userType, kUserTypeAll) == 0) ISetNodeValue(nil); } diff --git a/Sources/Tools/MaxComponent/plAnimComponent.cpp b/Sources/Tools/MaxComponent/plAnimComponent.cpp index ab44d51a..18d35a6d 100644 --- a/Sources/Tools/MaxComponent/plAnimComponent.cpp +++ b/Sources/Tools/MaxComponent/plAnimComponent.cpp @@ -963,12 +963,12 @@ protected: void ISetUserType(plMaxNode* node, const char* userType) { - if (hsStrEQ(userType, kUseParamBlockNodeString)) + if (strcmp(userType, kUseParamBlockNodeString) == 0) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, plAnimObjInterface::kUseParamBlockNode); } - else if (hsStrEQ(userType, kUseOwnerNodeString)) + else if (strcmp(userType, kUseOwnerNodeString) == 0) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, plAnimObjInterface::kUseOwnerNode); diff --git a/Sources/Tools/MaxComponent/plMultistageStage.cpp b/Sources/Tools/MaxComponent/plMultistageStage.cpp index d8cabea1..c7c6f550 100644 --- a/Sources/Tools/MaxComponent/plMultistageStage.cpp +++ b/Sources/Tools/MaxComponent/plMultistageStage.cpp @@ -48,39 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plAvatar/plAnimStage.h" -// We don't want to be subject to any changes to ReadSafeString, so we just keep -// our own version now. Unfortunately, some files were saved with a modified -// version of it, so we need to keep all the backwards compatability BS -char* MyReadSafeString(hsStream* s) -{ - char *name = nil; - uint16_t numChars = s->ReadLE16(); - - bool oldFormat = !(numChars & 0xf000); - if (oldFormat) - s->ReadLE16(); - - numChars &= ~0xf000; - hsAssert(numChars <= s->GetSizeLeft(), "Bad string"); - if (numChars > 0) - { - name = new char[numChars+1]; - s->Read(numChars, name); - name[numChars] = '\0'; - } - - return name; -} - -void MyWriteSafeString(hsStream* s, const char* str) -{ - int len = hsStrlen(str); - hsAssert(len<0xf000, "String too long"); - s->WriteLE16(len | 0xf000); - if (len > 0) - s->Write(len, str); -} - plBaseStage::plBaseStage() { fName = nil; @@ -139,15 +106,15 @@ void plBaseStage::SetName(const char* name) void plBaseStage::Read(hsStream *stream) { - int version = stream->ReadLE16(); + stream->ReadLE16(); delete [] fName; - fName = MyReadSafeString(stream); + fName = stream->ReadSafeString(); } void plBaseStage::Write(hsStream *stream) { stream->WriteLE16(1); - MyWriteSafeString(stream, fName); + stream->WriteSafeString(fName); } void plBaseStage::IBaseClone(plBaseStage* clone) @@ -189,7 +156,7 @@ void plStandardStage::Read(hsStream *stream) uint16_t version = stream->ReadLE16(); delete [] fAnimName; - fAnimName = MyReadSafeString(stream); + fAnimName = stream->ReadSafeString(); fNumLoops = stream->ReadLE32(); fLoopForever = stream->Readbool(); fForward = stream->ReadByte(); @@ -214,7 +181,7 @@ void plStandardStage::Write(hsStream *stream) stream->WriteLE16(2); - MyWriteSafeString(stream, fAnimName); + stream->WriteSafeString(fAnimName); stream->WriteLE32(fNumLoops); stream->Writebool(fLoopForever); stream->WriteByte(fForward); @@ -357,7 +324,7 @@ void plStandardStage::IGetAnimName() char buf[256]; edit->GetText(buf, sizeof(buf)); - if (!hsStrEQ(buf, fAnimName)) + if (strcmp(buf, fAnimName) != 0) { delete [] fAnimName; fAnimName = hsStrcpy(buf); diff --git a/Sources/Tools/MaxComponent/plResponderLink.cpp b/Sources/Tools/MaxComponent/plResponderLink.cpp index 4ca2db98..b9826ecc 100644 --- a/Sources/Tools/MaxComponent/plResponderLink.cpp +++ b/Sources/Tools/MaxComponent/plResponderLink.cpp @@ -332,7 +332,7 @@ void plResponderLinkProc::ILoadAgeFilenamesCombo(HWND hWnd, IParamBlock2 *pb) int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)name); - if (hsStrEQ(name, savedName)) + if (strcmp(name, savedName) == 0) SendMessage(hAge, CB_SETCURSEL, idx, 0); } } @@ -369,7 +369,7 @@ void plResponderLinkProc::ILoadParentAgeFilenamesCombo(HWND hWnd, IParamBlock2 * int idx = SendMessage(hAge, CB_ADDSTRING, 0, (LPARAM)name); - if (hsStrEQ(name, savedName)) + if (strcmp(name, savedName) == 0) SendMessage(hAge, CB_SETCURSEL, idx, 0); } } diff --git a/Sources/Tools/MaxComponent/plResponderMtl.cpp b/Sources/Tools/MaxComponent/plResponderMtl.cpp index 494d42e2..5c1e323b 100644 --- a/Sources/Tools/MaxComponent/plResponderMtl.cpp +++ b/Sources/Tools/MaxComponent/plResponderMtl.cpp @@ -607,12 +607,12 @@ protected: void ISetUserType(plMaxNode* node, const char* userType) { - if (hsStrEQ(userType, kUserTypeAll)) + if (strcmp(userType, kUserTypeAll) == 0) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, kNodePB); } - else if (hsStrEQ(userType, kResponderNodeName)) + else if (strcmp(userType, kResponderNodeName) == 0) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, kNodeResponder); diff --git a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp index dd06c718..5e24133c 100644 --- a/Sources/Tools/MaxConvert/hsMaterialConverter.cpp +++ b/Sources/Tools/MaxConvert/hsMaterialConverter.cpp @@ -5020,7 +5020,7 @@ void hsMaterialConverter::IPrintDoneMaterials(const char* path, hsTArrayGetPageInfo().GetPage())) + if (strcmpi(plAgeDescription::GetCommonPage(i), pageNode->GetPageInfo().GetPage()) == 0) { common = true; break; @@ -327,7 +327,7 @@ plLocation plPluginResManager::ICreateLocation(const char* age, const char* page plLocation plPluginResManager::ICreateLocation(const char* age, const char* page, int32_t seqNum, hsBool itinerant) { - hsBool willBeReserved = hsStrCaseEQ(age, "global"); + bool willBeReserved = strcmpi(age, "global") == 0; int32_t oldNum = seqNum; seqNum = VerifySeqNumber(seqNum, age, page); @@ -351,7 +351,7 @@ plLocation plPluginResManager::ICreateLocation(const char* age, const char* page // Flag common pages for (int i = 0; i < plAgeDescription::kNumCommonPages; i++) { - if (hsStrEQ(plAgeDescription::GetCommonPage(i), page)) + if (strcmp(plAgeDescription::GetCommonPage(i), page) == 0) { newLoc.SetFlags(plLocation::kBuiltIn); break; @@ -428,7 +428,7 @@ void plPluginResManager::AddLooseEnd(plKey key) // Verifies that the given sequence number belongs to the given string combo and ONLY that combo. Returns a new, unique sequenceNumber if not int32_t plPluginResManager::VerifySeqNumber(int32_t sequenceNumber, const char* age, const char* page) { - hsBool negated = false, willBeReserved = hsStrCaseEQ(age, "global"); + bool negated = false, willBeReserved = strcmpi(age, "global") == 0; if (sequenceNumber < 0) { sequenceNumber = -sequenceNumber; diff --git a/Sources/Tools/MaxPlasmaMtls/Materials/plAnimStealthNode.cpp b/Sources/Tools/MaxPlasmaMtls/Materials/plAnimStealthNode.cpp index 9b34aca8..97708d71 100644 --- a/Sources/Tools/MaxPlasmaMtls/Materials/plAnimStealthNode.cpp +++ b/Sources/Tools/MaxPlasmaMtls/Materials/plAnimStealthNode.cpp @@ -849,12 +849,12 @@ protected: void ISetUserType(plMaxNode* node, const char* userType) { - if( hsStrEQ( userType, kUseParamBlockNodeString ) ) + if( strcmp( userType, kUseParamBlockNodeString ) == 0 ) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, plAnimObjInterface::kUseParamBlockNode); } - else if( hsStrEQ(userType, kUseOwnerNodeString ) ) + else if( strcmp(userType, kUseOwnerNodeString ) == 0 ) { ISetNodeValue(nil); fPB->SetValue(fTypeID, 0, plAnimObjInterface::kUseOwnerNode);