Small step towards cleaning up this mess.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3710 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2011-12-26 01:35:07 +00:00
parent 5fd7d584ce
commit 41680a3e99
+101 -52
View File
@@ -67,14 +67,33 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
uio_Stream *fp;
unsigned long dataLen;
void *result;
int n, path_len, num_data_sets;
DWORD opos,
slen[MAX_STRINGS], StringOffs, tot_string_size,
clen[MAX_STRINGS], ClipOffs, tot_clip_size,
tslen[MAX_STRINGS], TSOffs;
int n;
int path_len;
int num_data_sets;
DWORD opos;
DWORD slen[MAX_STRINGS];
// Length of each of the dialog strings.
DWORD StringOffs;
DWORD tot_string_size;
DWORD clen[MAX_STRINGS];
// Length of each of the speech file names.
DWORD ClipOffs;
DWORD tot_clip_size;
DWORD tslen[MAX_STRINGS];
// Length of each of the timestamp strings.
DWORD TSOffs;
DWORD tot_ts_size = 0;
char CurrentLine[1024], paths[1024], *clip_path, *ts_path,
*strdata, *clipdata, *ts_data;
char CurrentLine[1024];
char paths[1024];
char *clip_path;
char *ts_path;
char *strdata = NULL;
// Contains the dialog strings.
char *clipdata = NULL;
// Contains the file names of the speech files.
char *ts_data = NULL;
// Contains the timestamp data for synching the text with the
// speech.
uio_Stream *timestamp_fp = NULL;
/* Parse out the conversation components. */
@@ -107,7 +126,8 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
}
dataLen = LengthResFile (fp);
log_add (log_Info, "\t'%s' -- conversation phrases -- %lu bytes", paths, dataLen);
log_add (log_Info, "\t'%s' -- conversation phrases -- %lu bytes", paths,
dataLen);
if (clip_path)
log_add (log_Info, "\t'%s' -- voice clip directory", clip_path);
else
@@ -117,41 +137,51 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
else
log_add (log_Info, "\tNo associated timestamp file");
if (dataLen == 0)
{
log_add (log_Warning, "Warning: Trying to load empty file '%s'.", path);
log_add (log_Warning, "Warning: Trying to load empty file '%s'.",
path);
goto err;
}
if ((strdata = HMalloc (tot_string_size = POOL_SIZE)) == 0)
tot_string_size = POOL_SIZE;
strdata = HMalloc (tot_string_size);
if (strdata == 0)
goto err;
if ((clipdata = HMalloc (tot_clip_size = POOL_SIZE)) == 0)
{
HFree (strdata);
tot_clip_size = POOL_SIZE;
clipdata = HMalloc (tot_clip_size);
if (clipdata == 0)
goto err;
}
ts_data = NULL;
path_len = clip_path ? strlen (clip_path) : 0;
if (ts_path && (timestamp_fp = uio_fopen (contentDir, ts_path,
"rb")))
if (ts_path)
{
if ((ts_data = HMalloc (tot_ts_size = POOL_SIZE)) == 0)
goto err;
timestamp_fp = uio_fopen (contentDir, ts_path, "rb");
if (timestamp_fp != NULL)
{
tot_ts_size = POOL_SIZE;
ts_data = HMalloc (tot_ts_size);
if (ts_data == 0)
goto err;
}
}
opos = uio_ftell (fp);
n = -1;
StringOffs = ClipOffs = TSOffs = 0;
StringOffs = 0;
ClipOffs = 0;
TSOffs = 0;
while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && n < MAX_STRINGS - 1)
{
int l;
if (CurrentLine[0] == '#')
{
// String header, of the following form:
// #(GLAD_WHEN_YOU_COME_BACK) commander-000.ogg
char CopyLine[1024];
char *s;
@@ -161,7 +191,7 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
{
if (n >= 0)
{
while (slen[n] > 1 &&
while (slen[n] > 1 &&
(strdata[StringOffs - 2] == '\n' ||
strdata[StringOffs - 2] == '\r'))
{
@@ -172,32 +202,38 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
}
slen[++n] = 0;
// now lets check for timestamp data
if (timestamp_fp)
{
char TimeStampLine[1024], *tsptr;
// We have a time stamp file.
char TimeStampLine[1024];
char *tsptr;
BOOLEAN ts_ok = FALSE;
uio_fgets (TimeStampLine, sizeof (TimeStampLine), timestamp_fp);
if (TimeStampLine[0] == '#')
{
// Line is of the following form:
// #(GIVE_FUEL_AGAIN) 3304,3255
tslen[n] = 0;
if ((tsptr = strstr (TimeStampLine,s))
&& (tsptr += strlen(s))
&& (++tsptr))
tsptr = strstr (TimeStampLine, s);
if (tsptr)
{
tsptr += strlen(s) + 1;
ts_ok = TRUE;
while (! strcspn(tsptr," \t\r\n") && *tsptr)
tsptr++;
if (*tsptr)
{
l = strlen (tsptr) + 1;
if (TSOffs + l > tot_ts_size
&& (ts_data = HRealloc (ts_data,
tot_ts_size += POOL_SIZE)) == 0)
l = strlen (tsptr) + 1;
if (TSOffs + l > tot_ts_size)
{
HFree (strdata);
goto err;
tot_ts_size += POOL_SIZE;
ts_data = HRealloc (ts_data, tot_ts_size);
if (ts_data == 0)
goto err; // BUG: old ts_data leaks
}
strcpy (&ts_data[TSOffs], tsptr);
TSOffs += l;
tslen[n] = l;
@@ -221,12 +257,12 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
if (s)
{
l = path_len + strlen (s) + 1;
if (ClipOffs + l > tot_clip_size
&& (clipdata = HRealloc (clipdata,
tot_clip_size += POOL_SIZE)) == 0)
if (ClipOffs + l > tot_clip_size)
{
HFree (strdata);
goto err;
tot_clip_size += POOL_SIZE;
clipdata = HRealloc (clipdata, tot_clip_size);
if (clipdata == 0)
goto err; // BUG: old clipdata leaks
}
if (clip_path)
@@ -241,12 +277,12 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
{
char *s;
l = strlen (CurrentLine) + 1;
if (StringOffs + l > tot_string_size
&& (strdata = HRealloc (strdata,
tot_string_size += POOL_SIZE)) == 0)
if (StringOffs + l > tot_string_size)
{
HFree (clipdata);
goto err;
tot_string_size += POOL_SIZE;
strdata = HRealloc (strdata, tot_string_size);
if (strdata == 0)
goto err; // BUG: old strdata leaks
}
if (slen[n])
@@ -287,10 +323,13 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
flags |= HAS_SOUND_CLIPS;
if (TSOffs)
flags |= HAS_TIMESTAMP;
result = AllocStringTable (n, flags);
if (result)
{
int StringIndex, ClipIndex, TSIndex;
int StringIndex;
int ClipIndex;
int TSIndex;
STRING_TABLE_DESC *lpST;
lpST = (STRING_TABLE) result;
@@ -299,7 +338,9 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
ClipIndex = n;
TSIndex = n * ((flags & HAS_SOUND_CLIPS) ? 2 : 1);
StringOffs = ClipOffs = TSOffs = 0;
StringOffs = 0;
ClipOffs = 0;
TSOffs = 0;
for (n = 0; n < (int)lpST->size;
++n, ++StringIndex, ++ClipIndex, ++TSIndex)
@@ -328,9 +369,14 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
return;
err:
if (ts_data != NULL)
HFree (ts_data);
if (clipdata != NULL)
HFree (clipdata);
if (strdata != NULL)
HFree (strdata);
res_CloseResFile (fp);
resdata->ptr = NULL;
}
void *
@@ -342,8 +388,10 @@ _GetStringData (uio_Stream *fp, DWORD length)
DWORD opos, slen[MAX_STRINGS], StringOffs, tot_string_size;
char CurrentLine[1024], *strdata;
if ((strdata = HMalloc (tot_string_size = POOL_SIZE)) == 0)
return (0);
tot_string_size = POOL_SIZE;
strdata = HMalloc (tot_string_size);
if (strdata == 0)
return 0;
opos = uio_ftell (fp);
n = -1;
@@ -380,11 +428,12 @@ _GetStringData (uio_Stream *fp, DWORD length)
{
char *s;
l = strlen (CurrentLine) + 1;
if (StringOffs + l > tot_string_size
&& (strdata = HRealloc (strdata,
tot_string_size += POOL_SIZE)) == 0)
if (StringOffs + l > tot_string_size)
{
return (0);
tot_string_size += POOL_SIZE;
strdata = HRealloc (strdata, tot_string_size);
if (strdata == 0)
return 0; // BUG: old strdata leaks
}
if (slen[n])
@@ -439,7 +488,7 @@ _GetStringData (uio_Stream *fp, DWORD length)
}
HFree (strdata);
return (result);
return result;
}
@@ -478,6 +527,6 @@ _GetBinaryTableData (uio_Stream *fp, DWORD length)
result = lpST;
}
return (result);
return result;
}