From: <Mee...@us...> - 2011-12-26 01:35:13
|
Revision: 3710 http://sc2.svn.sourceforge.net/sc2/?rev=3710&view=rev Author: Meep-Eep Date: 2011-12-26 01:35:07 +0000 (Mon, 26 Dec 2011) Log Message: ----------- Small step towards cleaning up this mess. Modified Paths: -------------- trunk/sc2/src/libs/strings/getstr.c Modified: trunk/sc2/src/libs/strings/getstr.c =================================================================== --- trunk/sc2/src/libs/strings/getstr.c 2011-12-21 18:03:45 UTC (rev 3709) +++ trunk/sc2/src/libs/strings/getstr.c 2011-12-26 01:35:07 UTC (rev 3710) @@ -67,14 +67,33 @@ 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 @@ } 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 @@ 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 @@ { if (n >= 0) { - while (slen[n] > 1 && + while (slen[n] > 1 && (strdata[StringOffs - 2] == '\n' || strdata[StringOffs - 2] == '\r')) { @@ -172,32 +202,38 @@ } 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 @@ 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ } HFree (strdata); - return (result); + return result; } @@ -478,6 +527,6 @@ result = lpST; } - return (result); + return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |