mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Toss lots of custom CString code
We already have a C standard library, so let's not reimplement it.
This commit is contained in:
@ -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
|
||||
|
@ -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) )
|
||||
|
@ -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() );
|
||||
|
||||
|
Reference in New Issue
Block a user