From 507a30e01b3a1a4557f46210edad722d17258518 Mon Sep 17 00:00:00 2001 From: meep-eep Date: Fri, 20 Jan 2006 05:53:33 +0000 Subject: [PATCH] Fixed places which expected GetStringLength() to return the amount of memory used instead of the number of chars. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2211 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/gfxlib.h | 2 +- sc2/src/sc2code/libs/reslib.h | 2 +- sc2/src/sc2code/libs/strings/strings.c | 28 +++++++++++++++++++++++++- sc2/src/sc2code/libs/strlib.h | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/sc2/src/sc2code/libs/gfxlib.h b/sc2/src/sc2code/libs/gfxlib.h index b9506c7b5..104fb290b 100644 --- a/sc2/src/sc2code/libs/gfxlib.h +++ b/sc2/src/sc2code/libs/gfxlib.h @@ -261,7 +261,7 @@ extern void FlushColorXForms (void); #define GetColorMapIndex GetStringTableIndex #define SetAbsColorMapIndex SetAbsStringTableIndex #define SetRelColorMapIndex SetRelStringTableIndex -#define GetColorMapLength GetStringLength +#define GetColorMapLength GetStringLengthBin #define GetColorMapAddress GetStringAddress #define GetColorMapContents GetStringContents diff --git a/sc2/src/sc2code/libs/reslib.h b/sc2/src/sc2code/libs/reslib.h index 7052620f3..97b71a8b8 100644 --- a/sc2/src/sc2code/libs/reslib.h +++ b/sc2/src/sc2code/libs/reslib.h @@ -115,7 +115,7 @@ extern DIRENTRY_REF LoadDirEntryTable (uio_DirHandle *dirHandle, #define GetDirEntryTableIndex GetStringTableIndex #define SetAbsDirEntryTableIndex SetAbsStringTableIndex #define SetRelDirEntryTableIndex SetRelStringTableIndex -#define GetDirEntryLength GetStringLength +#define GetDirEntryLength GetStringLengthBin #define GetDirEntryAddress GetStringAddress #define GetDirEntryContents GetStringContents diff --git a/sc2/src/sc2code/libs/strings/strings.c b/sc2/src/sc2code/libs/strings/strings.c index 179f0e4da..45b0f3078 100644 --- a/sc2/src/sc2code/libs/strings/strings.c +++ b/sc2/src/sc2code/libs/strings/strings.c @@ -172,6 +172,32 @@ GetStringLength (STRING String) return (StringLength); } +COUNT +GetStringLengthBin (STRING String) +{ + COUNT StringLength; + STRING_TABLE StringTable; + + StringTable = GetStringTable (String); + if (StringTable == 0) + StringLength = 0; + else + { + COUNT StringIndex; + STRING_TABLEPTR StringTablePtr; + + StringIndex = STRING_INDEX (String); + LockStringTable (StringTable, &StringTablePtr); + + StringLength = (COUNT)( + StringTablePtr->StringOffsets[StringIndex + 1] + - StringTablePtr->StringOffsets[StringIndex]); + UnlockStringTable (StringTable); + } + + return (StringLength); +} + STRINGPTR GetStringSoundClip (STRING String) { @@ -270,7 +296,7 @@ GetStringContents (STRING String, STRINGPTR StringBuf, BOOLEAN COUNT StringLength; if ((StringAddr = GetStringAddress (String)) != 0 && - (StringLength = GetStringLength (String)) != 0) + (StringLength = GetDirEntryLength (String)) != 0) { memcpy (StringBuf, StringAddr, StringLength); if (AppendSpace) diff --git a/sc2/src/sc2code/libs/strlib.h b/sc2/src/sc2code/libs/strlib.h index 82ef7152b..e72d1df13 100644 --- a/sc2/src/sc2code/libs/strlib.h +++ b/sc2/src/sc2code/libs/strlib.h @@ -44,6 +44,7 @@ extern STRING SetAbsStringTableIndex (STRING String, COUNT extern STRING SetRelStringTableIndex (STRING String, SIZE StringTableOffs); extern COUNT GetStringLength (STRING String); +extern COUNT GetStringLengthBin (STRING String); extern STRINGPTR GetStringAddress (STRING String); extern STRINGPTR GetStringSoundClip (STRING String); extern STRINGPTR GetStringTimeStamp (STRING String);