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
+100 -51
View File
@@ -67,14 +67,33 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
uio_Stream *fp; uio_Stream *fp;
unsigned long dataLen; unsigned long dataLen;
void *result; void *result;
int n, path_len, num_data_sets; int n;
DWORD opos, int path_len;
slen[MAX_STRINGS], StringOffs, tot_string_size, int num_data_sets;
clen[MAX_STRINGS], ClipOffs, tot_clip_size, DWORD opos;
tslen[MAX_STRINGS], TSOffs; 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; DWORD tot_ts_size = 0;
char CurrentLine[1024], paths[1024], *clip_path, *ts_path, char CurrentLine[1024];
*strdata, *clipdata, *ts_data; 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; uio_Stream *timestamp_fp = NULL;
/* Parse out the conversation components. */ /* Parse out the conversation components. */
@@ -107,7 +126,8 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
} }
dataLen = LengthResFile (fp); 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) if (clip_path)
log_add (log_Info, "\t'%s' -- voice clip directory", clip_path); log_add (log_Info, "\t'%s' -- voice clip directory", clip_path);
else else
@@ -117,41 +137,51 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
else else
log_add (log_Info, "\tNo associated timestamp file"); log_add (log_Info, "\tNo associated timestamp file");
if (dataLen == 0) 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; 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; goto err;
if ((clipdata = HMalloc (tot_clip_size = POOL_SIZE)) == 0) tot_clip_size = POOL_SIZE;
{ clipdata = HMalloc (tot_clip_size);
HFree (strdata); if (clipdata == 0)
goto err; goto err;
}
ts_data = NULL; ts_data = NULL;
path_len = clip_path ? strlen (clip_path) : 0; path_len = clip_path ? strlen (clip_path) : 0;
if (ts_path && (timestamp_fp = uio_fopen (contentDir, ts_path, if (ts_path)
"rb")))
{ {
if ((ts_data = HMalloc (tot_ts_size = POOL_SIZE)) == 0) timestamp_fp = uio_fopen (contentDir, ts_path, "rb");
goto err; 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); opos = uio_ftell (fp);
n = -1; n = -1;
StringOffs = ClipOffs = TSOffs = 0; StringOffs = 0;
ClipOffs = 0;
TSOffs = 0;
while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && n < MAX_STRINGS - 1) while (uio_fgets (CurrentLine, sizeof (CurrentLine), fp) && n < MAX_STRINGS - 1)
{ {
int l; int l;
if (CurrentLine[0] == '#') if (CurrentLine[0] == '#')
{ {
// String header, of the following form:
// #(GLAD_WHEN_YOU_COME_BACK) commander-000.ogg
char CopyLine[1024]; char CopyLine[1024];
char *s; char *s;
@@ -172,32 +202,38 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
} }
slen[++n] = 0; slen[++n] = 0;
// now lets check for timestamp data // now lets check for timestamp data
if (timestamp_fp) if (timestamp_fp)
{ {
char TimeStampLine[1024], *tsptr; // We have a time stamp file.
char TimeStampLine[1024];
char *tsptr;
BOOLEAN ts_ok = FALSE; BOOLEAN ts_ok = FALSE;
uio_fgets (TimeStampLine, sizeof (TimeStampLine), timestamp_fp); uio_fgets (TimeStampLine, sizeof (TimeStampLine), timestamp_fp);
if (TimeStampLine[0] == '#') if (TimeStampLine[0] == '#')
{ {
// Line is of the following form:
// #(GIVE_FUEL_AGAIN) 3304,3255
tslen[n] = 0; tslen[n] = 0;
if ((tsptr = strstr (TimeStampLine,s)) tsptr = strstr (TimeStampLine, s);
&& (tsptr += strlen(s)) if (tsptr)
&& (++tsptr))
{ {
tsptr += strlen(s) + 1;
ts_ok = TRUE; ts_ok = TRUE;
while (! strcspn(tsptr," \t\r\n") && *tsptr) while (! strcspn(tsptr," \t\r\n") && *tsptr)
tsptr++; tsptr++;
if (*tsptr) if (*tsptr)
{ {
l = strlen (tsptr) + 1; l = strlen (tsptr) + 1;
if (TSOffs + l > tot_ts_size if (TSOffs + l > tot_ts_size)
&& (ts_data = HRealloc (ts_data,
tot_ts_size += POOL_SIZE)) == 0)
{ {
HFree (strdata); tot_ts_size += POOL_SIZE;
goto err; ts_data = HRealloc (ts_data, tot_ts_size);
if (ts_data == 0)
goto err; // BUG: old ts_data leaks
} }
strcpy (&ts_data[TSOffs], tsptr); strcpy (&ts_data[TSOffs], tsptr);
TSOffs += l; TSOffs += l;
tslen[n] = l; tslen[n] = l;
@@ -221,12 +257,12 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
if (s) if (s)
{ {
l = path_len + strlen (s) + 1; l = path_len + strlen (s) + 1;
if (ClipOffs + l > tot_clip_size if (ClipOffs + l > tot_clip_size)
&& (clipdata = HRealloc (clipdata,
tot_clip_size += POOL_SIZE)) == 0)
{ {
HFree (strdata); tot_clip_size += POOL_SIZE;
goto err; clipdata = HRealloc (clipdata, tot_clip_size);
if (clipdata == 0)
goto err; // BUG: old clipdata leaks
} }
if (clip_path) if (clip_path)
@@ -241,12 +277,12 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
{ {
char *s; char *s;
l = strlen (CurrentLine) + 1; l = strlen (CurrentLine) + 1;
if (StringOffs + l > tot_string_size if (StringOffs + l > tot_string_size)
&& (strdata = HRealloc (strdata,
tot_string_size += POOL_SIZE)) == 0)
{ {
HFree (clipdata); tot_string_size += POOL_SIZE;
goto err; strdata = HRealloc (strdata, tot_string_size);
if (strdata == 0)
goto err; // BUG: old strdata leaks
} }
if (slen[n]) if (slen[n])
@@ -287,10 +323,13 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
flags |= HAS_SOUND_CLIPS; flags |= HAS_SOUND_CLIPS;
if (TSOffs) if (TSOffs)
flags |= HAS_TIMESTAMP; flags |= HAS_TIMESTAMP;
result = AllocStringTable (n, flags); result = AllocStringTable (n, flags);
if (result) if (result)
{ {
int StringIndex, ClipIndex, TSIndex; int StringIndex;
int ClipIndex;
int TSIndex;
STRING_TABLE_DESC *lpST; STRING_TABLE_DESC *lpST;
lpST = (STRING_TABLE) result; lpST = (STRING_TABLE) result;
@@ -299,7 +338,9 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
ClipIndex = n; ClipIndex = n;
TSIndex = n * ((flags & HAS_SOUND_CLIPS) ? 2 : 1); 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; for (n = 0; n < (int)lpST->size;
++n, ++StringIndex, ++ClipIndex, ++TSIndex) ++n, ++StringIndex, ++ClipIndex, ++TSIndex)
@@ -328,9 +369,14 @@ _GetConversationData (const char *path, RESOURCE_DATA *resdata)
return; return;
err: err:
if (ts_data != NULL)
HFree (ts_data);
if (clipdata != NULL)
HFree (clipdata);
if (strdata != NULL)
HFree (strdata);
res_CloseResFile (fp); res_CloseResFile (fp);
resdata->ptr = NULL; resdata->ptr = NULL;
} }
void * void *
@@ -342,8 +388,10 @@ _GetStringData (uio_Stream *fp, DWORD length)
DWORD opos, slen[MAX_STRINGS], StringOffs, tot_string_size; DWORD opos, slen[MAX_STRINGS], StringOffs, tot_string_size;
char CurrentLine[1024], *strdata; char CurrentLine[1024], *strdata;
if ((strdata = HMalloc (tot_string_size = POOL_SIZE)) == 0) tot_string_size = POOL_SIZE;
return (0); strdata = HMalloc (tot_string_size);
if (strdata == 0)
return 0;
opos = uio_ftell (fp); opos = uio_ftell (fp);
n = -1; n = -1;
@@ -380,11 +428,12 @@ _GetStringData (uio_Stream *fp, DWORD length)
{ {
char *s; char *s;
l = strlen (CurrentLine) + 1; l = strlen (CurrentLine) + 1;
if (StringOffs + l > tot_string_size if (StringOffs + l > tot_string_size)
&& (strdata = HRealloc (strdata,
tot_string_size += POOL_SIZE)) == 0)
{ {
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]) if (slen[n])
@@ -439,7 +488,7 @@ _GetStringData (uio_Stream *fp, DWORD length)
} }
HFree (strdata); HFree (strdata);
return (result); return result;
} }
@@ -478,6 +527,6 @@ _GetBinaryTableData (uio_Stream *fp, DWORD length)
result = lpST; result = lpST;
} }
return (result); return result;
} }