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