Refactored STRING to operate more like FRAME.
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2895 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
Changes towards version 0.7:
|
||||
- Normalized all loaded resources to be flat MEM_HANDLEs - Michael
|
||||
- Prevent overflow for planet weight when scanning a planet (bug #1025)
|
||||
- from Benjamin Alan Weaver
|
||||
- Don't set _POSIX_THREAD_SAFE_FUNCTIONS - SvdB
|
||||
@@ -20,7 +21,7 @@ Changes towards version 0.7:
|
||||
- The current directory is now among the locations searched for the content
|
||||
when no explicit location has been specified. (bug fix) - from Nic
|
||||
- Non-3DO Shipspin anims now use Presentations - Michael
|
||||
- Added presentaion commands TEXT, TE (text effect), MOVIE - Alex
|
||||
- Added presentation commands TEXT, TE (text effect), MOVIE - Alex
|
||||
- Increased the size of display queue (elements were sometimes missing
|
||||
in e.g. Nemesis vs. Nemesis battles with many marines out) - Alex
|
||||
- ShowPresentation() no longer clears the screen by force; presentations
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "libs/strings/strintrn.h"
|
||||
#include "misc.h"
|
||||
#include "port.h"
|
||||
#include "libs/uio.h"
|
||||
#include <sys/stat.h>
|
||||
@@ -26,21 +27,18 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
|
||||
const char *pattern, match_MatchType matchType)
|
||||
{
|
||||
uio_DirList *dirList;
|
||||
COUNT num_entries, length;
|
||||
COUNT num_entries;
|
||||
COUNT i;
|
||||
COUNT slen;
|
||||
uio_DirHandle *dir;
|
||||
STRING_TABLE StringTable;
|
||||
STRING_TABLEPTR lpST;
|
||||
char *lpStr;
|
||||
DWORD *lpLastOffs;
|
||||
STRING_TABLE_DESC *lpST;
|
||||
STRING lpLastString;
|
||||
|
||||
dir = uio_openDirRelative (dirHandle, path, 0);
|
||||
assert(dir != NULL);
|
||||
dirList = uio_getDirList (dir, "", pattern, matchType);
|
||||
assert(dirList != NULL);
|
||||
num_entries = 0;
|
||||
length = 0;
|
||||
|
||||
// First, count the amount of space needed
|
||||
for (i = 0; i < dirList->numNames; i++)
|
||||
@@ -62,7 +60,6 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
|
||||
dirList->names[i] = NULL;
|
||||
continue;
|
||||
}
|
||||
length += strlen (dirList->names[i]) + 1;
|
||||
num_entries++;
|
||||
}
|
||||
uio_closeDir (dir);
|
||||
@@ -72,9 +69,7 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
|
||||
return ((DIRENTRY_REF) 0);
|
||||
}
|
||||
|
||||
slen = sizeof (STRING_TABLE_DESC)
|
||||
+ (num_entries * sizeof (DWORD));
|
||||
StringTable = AllocResourceData (slen + length, 0);
|
||||
StringTable = AllocStringTable (num_entries, 0);
|
||||
LockStringTable (StringTable, &lpST);
|
||||
if (lpST == 0)
|
||||
{
|
||||
@@ -82,21 +77,21 @@ LoadDirEntryTable (uio_DirHandle *dirHandle, const char *path,
|
||||
uio_DirList_free(dirList);
|
||||
return ((DIRENTRY_REF) 0);
|
||||
}
|
||||
lpST->StringCount = num_entries;
|
||||
lpLastOffs = &lpST->StringOffsets[0];
|
||||
*lpLastOffs = slen;
|
||||
lpStr = (BYTE*)lpST + slen;
|
||||
lpST->size = num_entries;
|
||||
lpLastString = lpST->strings;
|
||||
|
||||
for (i = 0; i < dirList->numNames; i++)
|
||||
{
|
||||
int size;
|
||||
STRINGPTR target;
|
||||
if (dirList->names[i] == NULL)
|
||||
continue;
|
||||
size = strlen (dirList->names[i]) + 1;
|
||||
memcpy (lpStr, dirList->names[i], size);
|
||||
lpLastOffs[1] = lpLastOffs[0] + size;
|
||||
lpLastOffs++;
|
||||
lpStr += size;
|
||||
target = HMalloc (size);
|
||||
memcpy (target, dirList->names[i], size);
|
||||
lpLastString->data = target;
|
||||
lpLastString->length = size;
|
||||
lpLastString++;
|
||||
}
|
||||
|
||||
uio_DirList_free(dirList);
|
||||
|
||||
@@ -254,13 +254,9 @@ _GetSoundBankData (uio_Stream *fp, DWORD length)
|
||||
}
|
||||
|
||||
Snd = 0;
|
||||
if (snd_ct && (Snd = AllocStringTable (
|
||||
sizeof (STRING_TABLE_DESC)
|
||||
+ (sizeof (DWORD) * snd_ct)
|
||||
+ (sizeof (sndfx[0]) * snd_ct)
|
||||
)))
|
||||
if (snd_ct && (Snd = AllocStringTable (snd_ct, 0)))
|
||||
{
|
||||
STRING_TABLEPTR fxTab;
|
||||
STRING_TABLE_DESC *fxTab;
|
||||
|
||||
LockStringTable (Snd, &fxTab);
|
||||
if (fxTab == 0)
|
||||
@@ -277,18 +273,18 @@ _GetSoundBankData (uio_Stream *fp, DWORD length)
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD *offs, StringOffs;
|
||||
STRING str;
|
||||
int i;
|
||||
|
||||
fxTab->StringCount = snd_ct;
|
||||
fxTab->flags = 0;
|
||||
offs = fxTab->StringOffsets;
|
||||
StringOffs = sizeof (STRING_TABLE_DESC) + (sizeof (DWORD) * snd_ct);
|
||||
memcpy ((BYTE *)fxTab + StringOffs, sndfx, sizeof (sndfx[0]) * snd_ct);
|
||||
do
|
||||
str = fxTab->strings;
|
||||
for (i = 0; i < snd_ct; i++)
|
||||
{
|
||||
*offs++ = StringOffs;
|
||||
StringOffs += sizeof (sndfx[0]);
|
||||
} while (snd_ct--);
|
||||
TFB_SoundSample **target = HMalloc (sizeof (sndfx[0]));
|
||||
*target = sndfx[i];
|
||||
str->data = (STRINGPTR)target;
|
||||
str->length = sizeof (sndfx[0]);
|
||||
str++;
|
||||
}
|
||||
UnlockStringTable (Snd);
|
||||
}
|
||||
}
|
||||
@@ -299,20 +295,22 @@ _GetSoundBankData (uio_Stream *fp, DWORD length)
|
||||
BOOLEAN
|
||||
_ReleaseSoundBankData (MEM_HANDLE Snd)
|
||||
{
|
||||
STRING_TABLEPTR fxTab;
|
||||
STRING_TABLE_DESC *fxTab;
|
||||
|
||||
LockStringTable (Snd, &fxTab);
|
||||
if (fxTab)
|
||||
{
|
||||
int snd_ct;
|
||||
int snd_ct, index;
|
||||
TFB_SoundSample **sptr;
|
||||
|
||||
snd_ct = fxTab->StringCount;
|
||||
sptr = (TFB_SoundSample **)((BYTE *)fxTab + fxTab->StringOffsets[0]);
|
||||
snd_ct = fxTab->size;
|
||||
index = 0;
|
||||
while (snd_ct--)
|
||||
{
|
||||
int i;
|
||||
|
||||
sptr = (TFB_SoundSample **)(fxTab->strings[index].data);
|
||||
|
||||
for (i = 0; i < NUM_SOUNDSOURCES; ++i)
|
||||
{
|
||||
if (soundSource[i].sample == (*sptr))
|
||||
@@ -329,7 +327,8 @@ _ReleaseSoundBankData (MEM_HANDLE Snd)
|
||||
if ((*sptr)->buffer_tag)
|
||||
HFree ((*sptr)->buffer_tag);
|
||||
HFree (*sptr);
|
||||
*sptr++ = 0;
|
||||
*sptr = 0;
|
||||
index++;
|
||||
}
|
||||
UnlockStringTable (Snd);
|
||||
FreeStringTable (Snd);
|
||||
|
||||
@@ -38,6 +38,25 @@ dword_convert (DWORD *dword_array, COUNT num_dwords)
|
||||
} while (--num_dwords);
|
||||
}
|
||||
|
||||
static void
|
||||
set_strtab_entry (STRING_TABLE_DESC *strtab, int index, const char *value, int len)
|
||||
{
|
||||
STRING str = &strtab->strings[index];
|
||||
|
||||
if (str->data)
|
||||
{
|
||||
HFree (str->data);
|
||||
str->data = NULL;
|
||||
str->length = 0;
|
||||
}
|
||||
if (len)
|
||||
{
|
||||
str->data = HMalloc (len);
|
||||
str->length = len;
|
||||
memcpy (str->data, value, len);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_HANDLE
|
||||
_GetStringData (uio_Stream *fp, DWORD length)
|
||||
{
|
||||
@@ -238,67 +257,47 @@ _GetStringData (uio_Stream *fp, DWORD length)
|
||||
|
||||
hData = 0;
|
||||
num_data_sets = (ClipOffs ? 1 : 0) + (TSOffs ? 1 : 0) + 1;
|
||||
if (++n && (hData = AllocStringTable (
|
||||
(sizeof (STRING_TABLE_DESC) - sizeof (DWORD))
|
||||
+ (sizeof (DWORD) * ((n + 1) * num_data_sets))
|
||||
+ StringOffs + ClipOffs + TSOffs)))
|
||||
if (++n)
|
||||
{
|
||||
DWORD *lpStringOffs;
|
||||
DWORD *lpClipOffs;
|
||||
DWORD *lpTSOffs;
|
||||
STRING_TABLEPTR lpST;
|
||||
|
||||
LockStringTable (hData, &lpST);
|
||||
lpST->StringCount = n;
|
||||
lpST->flags = 0;
|
||||
int flags = 0;
|
||||
if (ClipOffs)
|
||||
lpST->flags |= HAS_SOUND_CLIPS;
|
||||
flags |= HAS_SOUND_CLIPS;
|
||||
if (TSOffs)
|
||||
lpST->flags |= HAS_TIMESTAMP;
|
||||
|
||||
memcpy (&lpST->StringOffsets[(n + 1) * num_data_sets],
|
||||
strdata, StringOffs);
|
||||
memcpy ((BYTE *)&lpST->StringOffsets[(n + 1) * num_data_sets]
|
||||
+ StringOffs, clipdata, ClipOffs);
|
||||
if (TSOffs)
|
||||
memcpy ((BYTE *)&lpST->StringOffsets[
|
||||
(n + 1) * num_data_sets] + StringOffs + ClipOffs,
|
||||
ts_data, TSOffs);
|
||||
TSOffs = ((BYTE *)&lpST->StringOffsets[(n + 1) * num_data_sets]
|
||||
- (BYTE *)lpST) + StringOffs + ClipOffs;
|
||||
ClipOffs = TSOffs - ClipOffs;
|
||||
StringOffs = ClipOffs - StringOffs;
|
||||
|
||||
lpStringOffs = lpST->StringOffsets;
|
||||
lpClipOffs = &lpST->StringOffsets[lpST->StringCount + 1];
|
||||
lpTSOffs = &lpST->StringOffsets[(lpST->StringCount + 1)
|
||||
<< ((lpST->flags & HAS_SOUND_CLIPS) ? 1 : 0)];
|
||||
for (n = 0; n < (int)lpST->StringCount;
|
||||
++n, ++lpStringOffs, ++lpClipOffs, ++lpTSOffs)
|
||||
flags |= HAS_TIMESTAMP;
|
||||
hData = AllocStringTable (n, flags);
|
||||
if (hData)
|
||||
{
|
||||
*lpStringOffs = StringOffs;
|
||||
StringOffs += slen[n];
|
||||
if (lpST->flags & HAS_SOUND_CLIPS)
|
||||
int StringIndex, ClipIndex, TSIndex;
|
||||
STRING_TABLE_DESC *lpST;
|
||||
|
||||
LockStringTable (hData, &lpST);
|
||||
|
||||
StringIndex = 0;
|
||||
ClipIndex = n;
|
||||
TSIndex = n * ((flags & HAS_SOUND_CLIPS) ? 2 : 1);
|
||||
|
||||
StringOffs = ClipOffs = TSOffs = 0;
|
||||
|
||||
for (n = 0; n < (int)lpST->size;
|
||||
++n, ++StringIndex, ++ClipIndex, ++TSIndex)
|
||||
{
|
||||
*lpClipOffs = ClipOffs;
|
||||
ClipOffs += clen[n];
|
||||
}
|
||||
if (lpST->flags & HAS_TIMESTAMP)
|
||||
{
|
||||
*lpTSOffs = TSOffs;
|
||||
TSOffs += tslen[n];
|
||||
set_strtab_entry(lpST, StringIndex, strdata + StringOffs, slen[n]);
|
||||
StringOffs += slen[n];
|
||||
if (lpST->flags & HAS_SOUND_CLIPS)
|
||||
{
|
||||
set_strtab_entry(lpST, ClipIndex, clipdata + ClipOffs, clen[n]);
|
||||
ClipOffs += clen[n];
|
||||
}
|
||||
if (lpST->flags & HAS_TIMESTAMP)
|
||||
{
|
||||
set_strtab_entry(lpST, TSIndex, ts_data + TSOffs, tslen[n]);
|
||||
TSOffs += tslen[n];
|
||||
}
|
||||
}
|
||||
|
||||
UnlockStringTable (hData);
|
||||
}
|
||||
*lpStringOffs = StringOffs;
|
||||
if (lpST->flags & HAS_SOUND_CLIPS)
|
||||
*lpClipOffs = ClipOffs;
|
||||
if (lpST->flags & HAS_TIMESTAMP)
|
||||
*lpTSOffs = TSOffs;
|
||||
|
||||
UnlockStringTable (hData);
|
||||
}
|
||||
|
||||
HFree (strdata);
|
||||
HFree (clipdata);
|
||||
if (ts_data)
|
||||
@@ -308,32 +307,39 @@ _GetStringData (uio_Stream *fp, DWORD length)
|
||||
}
|
||||
}
|
||||
|
||||
/* We don't end in .txt, so, we're a color table of some kind. */
|
||||
hData = GetResourceData (fp, length, MEM_SOUND);
|
||||
if (hData)
|
||||
{
|
||||
COUNT StringCount;
|
||||
DWORD StringOffs;
|
||||
DWORD *lpStringOffs;
|
||||
STRING_TABLEPTR lpST;
|
||||
DWORD *fileData;
|
||||
MEM_HANDLE hStrTab;
|
||||
|
||||
LockStringTable (hData, &lpST);
|
||||
length = *(DWORD *)&lpST->StringCount;
|
||||
dword_convert (&length, 1);
|
||||
lpST->StringCount = (unsigned short)length;
|
||||
StringCount = lpST->StringCount;
|
||||
lpST->flags = 0;
|
||||
fileData = mem_lock (hData);
|
||||
|
||||
lpStringOffs = lpST->StringOffsets;
|
||||
dword_convert (lpStringOffs, StringCount + 1);
|
||||
StringOffs = sizeof (STRING_TABLE_DESC)
|
||||
+ (sizeof (DWORD) * StringCount);
|
||||
do
|
||||
dword_convert (fileData, 1); /* Length */
|
||||
|
||||
hStrTab = AllocStringTable (fileData[0], 0);
|
||||
if (hStrTab)
|
||||
{
|
||||
StringOffs += *lpStringOffs;
|
||||
*lpStringOffs++ = StringOffs;
|
||||
} while (StringCount--);
|
||||
STRING_TABLE_DESC *lpST;
|
||||
int i, size;
|
||||
BYTE *stringptr;
|
||||
|
||||
UnlockStringTable (hData);
|
||||
LockStringTable (hStrTab, &lpST);
|
||||
size = lpST->size;
|
||||
|
||||
dword_convert (fileData+2, size);
|
||||
stringptr = (BYTE *)(fileData + 2 + size);
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
set_strtab_entry (lpST, i, stringptr, fileData[2+i]);
|
||||
stringptr += fileData[2+i];
|
||||
}
|
||||
UnlockStringTable (hStrTab);
|
||||
}
|
||||
mem_unlock (hData);
|
||||
mem_release (hData);
|
||||
hData = hStrTab;
|
||||
}
|
||||
|
||||
return (hData);
|
||||
|
||||
@@ -17,11 +17,78 @@
|
||||
*/
|
||||
|
||||
#include "strintrn.h"
|
||||
#include "misc.h"
|
||||
|
||||
STRING_TABLE
|
||||
AllocStringTable (int num_entries, int flags)
|
||||
{
|
||||
MEM_HANDLE hData = mem_allocate (sizeof (STRING_TABLE_DESC), MEM_SOUND);
|
||||
STRING_TABLE_DESC *strtab = mem_lock (hData);
|
||||
int i, multiplier = 1;
|
||||
|
||||
if (flags & HAS_SOUND_CLIPS)
|
||||
{
|
||||
multiplier++;
|
||||
}
|
||||
if (flags & HAS_TIMESTAMP)
|
||||
{
|
||||
multiplier++;
|
||||
}
|
||||
strtab->handle = hData;
|
||||
strtab->flags = flags;
|
||||
strtab->size = num_entries;
|
||||
num_entries *= multiplier;
|
||||
strtab->strings = HMalloc (sizeof (STRING_TABLE_ENTRY_DESC) * num_entries);
|
||||
for (i = 0; i < num_entries; i++)
|
||||
{
|
||||
strtab->strings[i].data = NULL;
|
||||
strtab->strings[i].length = 0;
|
||||
strtab->strings[i].parent = strtab;
|
||||
strtab->strings[i].index = i;
|
||||
}
|
||||
return hData;
|
||||
}
|
||||
|
||||
void
|
||||
FreeStringTable (STRING_TABLE StringTable)
|
||||
{
|
||||
STRING_TABLE_DESC *strtab;
|
||||
int i, multiplier = 1;
|
||||
|
||||
strtab = mem_lock (StringTable);
|
||||
|
||||
if (strtab == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (strtab->flags & HAS_SOUND_CLIPS)
|
||||
{
|
||||
multiplier++;
|
||||
}
|
||||
if (strtab->flags & HAS_TIMESTAMP)
|
||||
{
|
||||
multiplier++;
|
||||
}
|
||||
|
||||
for (i = 0; i < strtab->size * multiplier; i++)
|
||||
{
|
||||
if (strtab->strings[i].data != NULL)
|
||||
{
|
||||
HFree (strtab->strings[i].data);
|
||||
}
|
||||
}
|
||||
|
||||
HFree (strtab->strings);
|
||||
mem_unlock (StringTable);
|
||||
mem_release (StringTable);
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
DestroyStringTable (STRING_TABLE StringTable)
|
||||
{
|
||||
return (FreeStringTable (StringTable));
|
||||
FreeStringTable (StringTable);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STRING
|
||||
@@ -29,15 +96,21 @@ CaptureStringTable (STRING_TABLE StringTable)
|
||||
{
|
||||
if (StringTable != 0)
|
||||
{
|
||||
COUNT StringTableIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
STRING_TABLE_DESC *StringTablePtr;
|
||||
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
StringTableIndex = GetStringTableIndex (StringTable);
|
||||
return (BUILD_STRING (StringTable, StringTableIndex));
|
||||
if (StringTablePtr->size > 0)
|
||||
{
|
||||
return StringTablePtr->strings;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnlockStringTable (StringTable);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ((STRING)NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STRING_TABLE
|
||||
@@ -55,53 +128,51 @@ ReleaseStringTable (STRING String)
|
||||
STRING_TABLE
|
||||
GetStringTable (STRING String)
|
||||
{
|
||||
return ((STRING_TABLE)LOWORD (String));
|
||||
if (String && String->parent)
|
||||
{
|
||||
return String->parent->handle;
|
||||
}
|
||||
return NULL_HANDLE;
|
||||
}
|
||||
|
||||
COUNT
|
||||
GetStringTableCount (STRING String)
|
||||
{
|
||||
COUNT StringCount;
|
||||
STRING_TABLE StringTable;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringCount = 0;
|
||||
else
|
||||
if (String && String->parent)
|
||||
{
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
StringCount = StringTablePtr->StringCount;
|
||||
UnlockStringTable (StringTable);
|
||||
return String->parent->size;
|
||||
}
|
||||
|
||||
return (StringCount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
COUNT
|
||||
GetStringTableIndex (STRING String)
|
||||
{
|
||||
return (STRING_INDEX (String));
|
||||
if (String)
|
||||
{
|
||||
return String->index;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
STRING
|
||||
SetAbsStringTableIndex (STRING String, COUNT StringTableIndex)
|
||||
{
|
||||
STRING_TABLE StringTable;
|
||||
STRING_TABLE_DESC *StringTablePtr;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
String = 0;
|
||||
if (!String)
|
||||
return NULL;
|
||||
|
||||
StringTablePtr = String->parent;
|
||||
|
||||
if (StringTablePtr == NULL)
|
||||
{
|
||||
String = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
StringTableIndex = StringTableIndex % StringTablePtr->StringCount;
|
||||
UnlockStringTable (StringTable);
|
||||
|
||||
String = BUILD_STRING (StringTable, StringTableIndex);
|
||||
StringTableIndex = StringTableIndex % StringTablePtr->size;
|
||||
String = &StringTablePtr->strings[StringTableIndex];
|
||||
}
|
||||
|
||||
return (String);
|
||||
@@ -110,24 +181,27 @@ SetAbsStringTableIndex (STRING String, COUNT StringTableIndex)
|
||||
STRING
|
||||
SetRelStringTableIndex (STRING String, SIZE StringTableOffs)
|
||||
{
|
||||
STRING_TABLE StringTable;
|
||||
STRING_TABLE_DESC *StringTablePtr;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
String = 0;
|
||||
if (!String)
|
||||
return NULL;
|
||||
|
||||
StringTablePtr = String->parent;
|
||||
|
||||
if (StringTablePtr == NULL)
|
||||
{
|
||||
String = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
COUNT StringTableIndex;
|
||||
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
while (StringTableOffs < 0)
|
||||
StringTableOffs += StringTablePtr->StringCount;
|
||||
StringTableIndex = (STRING_INDEX (String) + StringTableOffs)
|
||||
% StringTablePtr->StringCount;
|
||||
UnlockStringTable (StringTable);
|
||||
StringTableOffs += StringTablePtr->size;
|
||||
StringTableIndex = (String->index + StringTableOffs)
|
||||
% StringTablePtr->size;
|
||||
|
||||
String = BUILD_STRING (StringTable, StringTableIndex);
|
||||
String = &StringTablePtr->strings[StringTableIndex];
|
||||
}
|
||||
|
||||
return (String);
|
||||
@@ -136,156 +210,99 @@ SetRelStringTableIndex (STRING String, SIZE StringTableOffs)
|
||||
COUNT
|
||||
GetStringLength (STRING String)
|
||||
{
|
||||
COUNT StringLength;
|
||||
STRING_TABLE StringTable;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringLength = 0;
|
||||
else
|
||||
if (String == NULL)
|
||||
{
|
||||
COUNT StringIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
StringIndex = STRING_INDEX (String);
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
|
||||
{
|
||||
STRINGPTR start;
|
||||
STRINGPTR end;
|
||||
|
||||
start = (STRINGPTR) ((BYTE *) StringTablePtr +
|
||||
StringTablePtr->StringOffsets[StringIndex]);
|
||||
end = (STRINGPTR) ((BYTE *) StringTablePtr +
|
||||
StringTablePtr->StringOffsets[StringIndex + 1]);
|
||||
StringLength = utf8StringCountN(start, end);
|
||||
}
|
||||
|
||||
#if 0
|
||||
StringLength = (COUNT)(
|
||||
StringTablePtr->StringOffsets[StringIndex + 1]
|
||||
- StringTablePtr->StringOffsets[StringIndex]);
|
||||
#endif
|
||||
UnlockStringTable (StringTable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (StringLength);
|
||||
return utf8StringCountN(String->data, String->data + String->length);
|
||||
}
|
||||
|
||||
COUNT
|
||||
GetStringLengthBin (STRING String)
|
||||
{
|
||||
COUNT StringLength;
|
||||
STRING_TABLE StringTable;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringLength = 0;
|
||||
else
|
||||
if (String == NULL)
|
||||
{
|
||||
COUNT StringIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
StringIndex = STRING_INDEX (String);
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
|
||||
StringLength = (COUNT)(
|
||||
StringTablePtr->StringOffsets[StringIndex + 1]
|
||||
- StringTablePtr->StringOffsets[StringIndex]);
|
||||
UnlockStringTable (StringTable);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (StringLength);
|
||||
return String->length;
|
||||
}
|
||||
|
||||
STRINGPTR
|
||||
GetStringSoundClip (STRING String)
|
||||
{
|
||||
STRINGPTR StringAddr;
|
||||
STRING_TABLE StringTable;
|
||||
STRING_TABLE_DESC *StringTablePtr;
|
||||
COUNT StringIndex;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringAddr = 0;
|
||||
else
|
||||
if (String == NULL)
|
||||
{
|
||||
COUNT StringIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
StringIndex = STRING_INDEX (String);
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
if (!(StringTablePtr->flags & HAS_SOUND_CLIPS)
|
||||
|| ((StringIndex += StringTablePtr->StringCount + 1),
|
||||
StringTablePtr->StringOffsets[StringIndex + 1]
|
||||
== StringTablePtr->StringOffsets[StringIndex]))
|
||||
StringAddr = 0;
|
||||
else
|
||||
{
|
||||
StringAddr = (STRINGPTR) ((BYTE *) StringTablePtr +
|
||||
StringTablePtr->StringOffsets[StringIndex]);
|
||||
}
|
||||
UnlockStringTable (StringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (StringAddr);
|
||||
StringTablePtr = String->parent;
|
||||
if (StringTablePtr == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringIndex = String->index;
|
||||
if (!(StringTablePtr->flags & HAS_SOUND_CLIPS))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringIndex += StringTablePtr->size;
|
||||
String = &StringTablePtr->strings[StringIndex];
|
||||
if (String->length == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return String->data;
|
||||
}
|
||||
|
||||
STRINGPTR
|
||||
GetStringTimeStamp (STRING String)
|
||||
{
|
||||
STRINGPTR StringAddr;
|
||||
STRING_TABLE StringTable;
|
||||
STRING_TABLE_DESC *StringTablePtr;
|
||||
COUNT StringIndex;
|
||||
int offset;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringAddr = 0;
|
||||
else
|
||||
if (String == NULL)
|
||||
{
|
||||
COUNT StringIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
int offset;
|
||||
|
||||
StringIndex = STRING_INDEX (String);
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
offset = (StringTablePtr->flags & HAS_SOUND_CLIPS) ? 1 : 0;
|
||||
if (!(StringTablePtr->flags & HAS_TIMESTAMP)
|
||||
|| ((StringIndex += (StringTablePtr->StringCount + 1) << offset),
|
||||
StringTablePtr->StringOffsets[StringIndex + 1]
|
||||
== StringTablePtr->StringOffsets[StringIndex]))
|
||||
StringAddr = 0;
|
||||
else
|
||||
{
|
||||
StringAddr = (STRINGPTR) ((BYTE *) StringTablePtr +
|
||||
StringTablePtr->StringOffsets[StringIndex]);
|
||||
}
|
||||
UnlockStringTable (StringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (StringAddr);
|
||||
StringTablePtr = String->parent;
|
||||
if (StringTablePtr == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringIndex = String->index;
|
||||
if (!(StringTablePtr->flags & HAS_SOUND_CLIPS))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
offset = (StringTablePtr->flags & HAS_SOUND_CLIPS) ? 1 : 0;
|
||||
StringIndex += StringTablePtr->size << offset;
|
||||
String = &StringTablePtr->strings[StringIndex];
|
||||
if (String->length == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return String->data;
|
||||
}
|
||||
|
||||
STRINGPTR
|
||||
GetStringAddress (STRING String)
|
||||
{
|
||||
STRINGPTR StringAddr;
|
||||
STRING_TABLE StringTable;
|
||||
|
||||
StringTable = GetStringTable (String);
|
||||
if (StringTable == 0)
|
||||
StringAddr = 0;
|
||||
else
|
||||
if (String == NULL)
|
||||
{
|
||||
COUNT StringIndex;
|
||||
STRING_TABLEPTR StringTablePtr;
|
||||
|
||||
StringIndex = STRING_INDEX (String);
|
||||
LockStringTable (StringTable, &StringTablePtr);
|
||||
StringAddr = (STRINGPTR) ((BYTE *) StringTablePtr +
|
||||
StringTablePtr->StringOffsets[StringIndex]);
|
||||
UnlockStringTable (StringTable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (StringAddr);
|
||||
return String->data;
|
||||
}
|
||||
|
||||
BOOLEAN
|
||||
@@ -309,4 +326,3 @@ GetStringContents (STRING String, STRINGPTR StringBuf, BOOLEAN
|
||||
*StringBuf = '\0';
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,27 +25,33 @@
|
||||
#include "memlib.h"
|
||||
#include "reslib.h"
|
||||
|
||||
typedef struct string_table_entry
|
||||
{
|
||||
STRINGPTR data;
|
||||
int length; /* Internal NULs are allowed */
|
||||
int index;
|
||||
struct string_table *parent;
|
||||
} STRING_TABLE_ENTRY_DESC;
|
||||
|
||||
typedef struct string_table
|
||||
{
|
||||
unsigned short StringCount;
|
||||
MEM_HANDLE handle;
|
||||
unsigned short flags;
|
||||
DWORD StringOffsets[1];
|
||||
int size;
|
||||
STRING_TABLE_ENTRY_DESC *strings;
|
||||
} STRING_TABLE_DESC;
|
||||
typedef STRING_TABLE_DESC *PSTRING_TABLE_DESC;
|
||||
|
||||
#define HAS_SOUND_CLIPS (1 << 0)
|
||||
#define HAS_TIMESTAMP (1 << 1)
|
||||
#define STRING_TABLEPTR PSTRING_TABLE_DESC
|
||||
|
||||
#define AllocStringTable(s) AllocResourceData((s),MEM_SOUND)
|
||||
#define LockStringTable LockResourceData
|
||||
#define UnlockStringTable UnlockResourceData
|
||||
#define FreeStringTable FreeResourceData
|
||||
|
||||
#define STRING_INDEX(S) ((COUNT)HIWORD (S))
|
||||
#define BUILD_STRING(h,i) ((STRING)MAKE_DWORD(h,i))
|
||||
STRING_TABLE AllocStringTable (int num_entries, int flags);
|
||||
void FreeStringTable (STRING_TABLE strtab);
|
||||
|
||||
extern MEM_HANDLE _GetStringData (uio_Stream *fp, DWORD length);
|
||||
MEM_HANDLE _GetStringData (uio_Stream *fp, DWORD length);
|
||||
|
||||
#endif /* _STRINTRN_H */
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct string_table_entry STRING_TABLE_ENTRY_DESC;
|
||||
|
||||
typedef MEM_HANDLE STRING_TABLE;
|
||||
typedef DWORD STRING;
|
||||
typedef BYTE* STRINGPTR;
|
||||
typedef STRING_TABLE_ENTRY_DESC *STRING;
|
||||
typedef BYTE *STRINGPTR;
|
||||
|
||||
extern BOOLEAN InstallStringTableResType (COUNT string_type);
|
||||
extern STRING_TABLE LoadStringTableInstance (DWORD res);
|
||||
|
||||
Reference in New Issue
Block a user