Debian Codegraph @

Descent3/localization.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/localization.cpp $
21 * $Revision: 18 $
22 * $Date: 11/05/99 4:05p $
23 * $Author: Jeff $
24 *
25 * Localization implementation
26 *
27 * $Log: /DescentIII/main/localization.cpp $
28 *
29 * 18 11/05/99 4:05p Jeff
30 * fixed bug with 'retry english' closing the file and then trying to read
31 * it
32 *
33 * 17 10/12/99 11:04a Jeff
34 * load english string table if foreign strings are not found
35 *
36 * 16 5/05/99 4:33p Jeff
37 * fixed Linux filename fix when opening file for second time
38 *
39 * 15 5/04/99 8:50p Jeff
40 * safety precautions
41 *
42 * 14 4/26/99 5:17p Jeff
43 * loading string tables is filename friendly (for Linux)...filename must
44 * be all lowercase
45 *
46 * 13 4/14/99 2:51a Jeff
47 * fixed some case mismatched #includes
48 *
49 * 12 2/22/99 3:19p Jeff
50 * added function to get current language
51 *
52 * 11 2/11/99 11:02p Jeff
53 * fixed bug with aux string table loading
54 *
55 * 10 2/11/99 10:35p Jeff
56 * added support for multiple languages in string table files
57 *
58 * 9 1/19/99 1:26p Jeff
59 * handled \r
60 *
61 * 8 1/18/99 12:03p Jeff
62 * return true if 0 strings are loaded from a correct string table, not
63 * false
64 *
65 * 7 1/13/99 4:05p Jeff
66 * when loading a script dll, a string table is looked for and
67 * automatically loaded and passed to the newly loaded dll on init for
68 * use.
69 *
70 * 6 6/26/98 4:52p Jeff
71 * fixed stupid
72 *
73 * 5 6/26/98 4:00p Jeff
74 * added parsing of escape characters for CreateStringTable()
75 *
76 * 4 6/17/98 3:28p Jeff
77 *
78 * 3 6/16/98 10:37a Jeff
79 * fixed bug in growstring class, parse escape chars
80 *
81 * 2 6/12/98 5:55p Jeff
82 * initial creation
83 *
84 * $NoKeywords: $
85 */
86
87 #include <stdlib.h>
88 #include <string.h>
89 #include <stdio.h>
90 #include <ctype.h>
91 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
92 #include "descent.h"cxx . . $ `<file>/Descent3/descent.h`/
93 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
94 #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/
95 #include "localization.h"cxx . . $ `<file>/Descent3/localization.h`/
96 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
97 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
98
99 struct tLangTagcxx . . $ tLangTag# {
100 const char *tagcxx . . $ tLangTag#tag.;
101 int lengthcxx . . $ tLangTag#length.;
102 };
103
104 tLangTagcxx . . $ tLangTag# Language_tagscxx . . $ Language_tags.[] = {
105 {"!=!", -1}, // English
106 {"!G!", -1}, // German
107 {"!S!", -1}, // Spanish
108 {"!I!", -1}, // Italian
109 {"!F!", -1}, // French
110 };
111 int Num_languagescxx . . $ Num_languages. = sizeof(Language_tagscxx . . $ Language_tags.) / sizeof(tLangTagcxx . . $ tLangTag#);
112
113 // The following data, in the anonymous namespace, are static to this file
114 namespacecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/ {
115 int Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = -1;
116
117 int String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size. = 0;
118 char **String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
119
120 // list of the string table files, they will be loaded in the order they are listed
121 const char *String_table_listcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_list.[] = {"D3.STR", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!};
122
123 const char *_Error_stringcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/_Error_string. = "!!ERROR MISSING STRING!!";
124 const char *_Empty_stringcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/_Empty_string. = "\0";
125 } // namespace
126
127 void Localization_SetLanguagecxx . . $ Localization_SetLanguage(d4f767463ce0a6b3).(int type) {
128 ASSERTcxx . . $ `misc/pserror.h:246:9`!(type >= 0 && type < Num_languages);
129 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = type;
130 }
131
132 int Localization_GetLanguagecxx . . $ Localization_GetLanguage(b126dc7c1de90089).(void) { return Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.; }
133
134 #define COMMENT_TAGcxx . . $ `Descent3/localization.cpp:134:9`! "!/!" // This line is to be ignored
135
136 #define STAG_CONTINUEcxx . . $ `Descent3/localization.cpp:136:9`! -1 // this line is just a continuation of the last line
137 #define STAG_EMPTYcxx . . $ `Descent3/localization.cpp:137:9`! -2 // empty line
138 #define STAG_COMMENTcxx . . $ `Descent3/localization.cpp:138:9`! -3 // comment line
139 // 0 -> Num_languages means it's the start of a string that begins with that language
140
141 #define MAX_LINE_LENGTHcxx . . $ `Descent3/localization.cpp:141:9`! 1024
142 #define MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`! 8 * MAX_LINE_LENGTHcxx . . $ `Descent3/localization.cpp:141:9`!
143 #define MAX_TAG_LENGTHcxx . . $ `Descent3/localization.cpp:143:9`! 3
144
145 int GetTotalStringCountcxx . . $ GetTotalStringCount(b126dc7c1de90089).(void);
146 int LoadStringFilecxx . . $ LoadStringFile(cb7559238bb26814).(const char *filename, int starting_offset);
147 int8_t _parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(char *line);
148 char *_parse_string_tagcxx . . $ _parse_string_tag(7a9722d75b371431).(char *buffer);
149 char *_parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(char *buffer);
150
151 // Call this to load up the string tables into memory
152 // Returns the number of strings loaded, if this is 0, then the program MUST not continue
153 int LoadStringTablescxx . . $ LoadStringTables(b126dc7c1de90089).(void) {
154 static bool called = false;
155 int old_language;
156
157 if (called) {
158 // Only call this guy once
159 Int3cxx . . $ `misc/pserror.h:247:9`!();
160 return 0;
161 }
162 called = true;
163
164 old_language = Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.;
165
166 int string_count = GetTotalStringCountcxx . . $ GetTotalStringCount(b126dc7c1de90089).();
167 if (string_count == 0) {
168 // attempt to load english version of language, so there is something
169 if (Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. != LANGUAGE_ENGLISHcxx . . $ `Descent3/localization.h:44:9`!) {
170 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = LANGUAGE_ENGLISHcxx . . $ `Descent3/localization.h:44:9`!;
171 string_count = GetTotalStringCountcxx . . $ GetTotalStringCount(b126dc7c1de90089).();
172 }
173
174 if (string_count == 0) {
175 return 0;
176 }
177 }
178
179 String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size. = 0;
180
181 // malloc our array of char *
182 String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table. = (char **)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(char *) * string_count);
183 if (!String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.) {
184 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
185 return 0;
186 }
187
188 for (int tcount = 0; tcount < string_count; tcount++)
189 String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[tcount] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
190
191 int runcount = 0;
192 int temp;
193 int index = 0;
194 while (String_table_listcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_list.[index]) {
195 temp = LoadStringFilecxx . . $ LoadStringFile(cb7559238bb26814).(String_table_listcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_list.[index], runcount);
196 if (temp == 0) {
197 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
198 return 0;
199 }
200 if (runcount + temp > string_count) {
201 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
202 return 0;
203 }
204 runcount += temp;
205 index++;
206 }
207
208 if (runcount == 0) {
209 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
210 return 0;
211 }
212
213 String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size. = runcount;
214 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
215
216 atexitcxx . . $ atexit(cc8c495369588262).(FreeStringTablescxx . . $ FreeStringTables(49f6e7a06ebc5aa8).);
217 return String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size.;
218 }
219
220 // Deallocates all the memory used for the string tables
221 void FreeStringTablescxx . . $ FreeStringTables(49f6e7a06ebc5aa8).(void) {
222 DestroyStringTablecxx . . $ DestroyStringTable(a50bc8ce1fe710a2).(String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table., String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size.);
223 String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
224 }
225
226 const char *GetStringFromTablecxx . . $ GetStringFromTable(f7ae7e56280f18ae).(int index) {
227 if ((index < 0) || (index >= String_table_sizecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_size.))
228 return _Error_stringcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/_Error_string.;
229
230 if (!String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[index])
231 return _Empty_stringcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/_Empty_string.;
232
233 return String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[index];
234 }
235
236 void FixFilenameCasecxx . . $ FixFilenameCase(611124a97efc52dd).(const char *filename, char *newfile) {
237 char path[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`!], file[_MAX_FNAMEcxx . . $ `linux/linux_fix.h:35:9`!], ext[_MAX_EXTcxx . . $ `linux/linux_fix.h:36:9`!];
238 ddio_SplitPathcxx . . $ ddio_SplitPath(b05ba7ab99603c07).(filename, path, file, ext);
239
240 char *p;
241
242 p = file;
243 while (*p) {
244 *p = tolower(*p);
245 p++;
246 };
247 p = ext;
248 while (*p) {
249 *p = tolower(*p);
250 p++;
251 };
252
253 strcat(file, ext);
254
255 if (strlen(path) > 0)
256 ddio_MakePathcxx . . $ ddio_MakePath(9ad4b0815420a85).(newfile, path, file, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
257 else
258 strcpy(newfile, file);
259 }
260
261 // Given a filename, pointer to a char * array and a pointer to an int,
262 // it will load the string table and fill in the information
263 // returns true on success
264 bool CreateStringTablecxx . . $ CreateStringTable(c1b497ce97e7b78).(const char *filename, char ***table, int *size) {
265 ASSERTcxx . . $ `misc/pserror.h:246:9`!(filename);
266 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Localization_language != -1);
267 if (!filename) {
268 if (table)
269 *table = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
270 if (size)
271 *size = 0;
272 return false;
273 }
274 CFILEcxx . . $ CFILE# *file;
275
276 char fname[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`!];
277 FixFilenameCasecxx . . $ FixFilenameCase(611124a97efc52dd).(filename, fname);
278 file = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(fnamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
279 if (!file) {
280 if (table)
281 *table = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
282 if (size)
283 *size = 0;
284 return false;
285 }
286
287 int old_language, scount;
288 char tempbuffer[MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`!];
289
290 old_language = Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.;
291
292 try_english:
293
294 // first found out how many strings total in the file
295 scount = 0;
296
297 while (!cfeofcxx . . $ cfeof(413716a422df0036).(file)) {
298 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(tempbuffer, MAX_LINE_LENGTHcxx . . $ `Descent3/localization.cpp:141:9`! + 1, file);
299 if (_parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(tempbuffer) == Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.)
300 scount++;
301 }
302 cfclosecxx . . $ cfclose(3639e799710acb68).(file);
303
304 if (scount == 0) {
305 // no strings found, if we are searching a non-English version, then
306 // load english versions
307 if (Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. != LANGUAGE_ENGLISHcxx . . $ `Descent3/localization.h:44:9`!) {
308 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = LANGUAGE_ENGLISHcxx . . $ `Descent3/localization.h:44:9`!;
309 // open the file again
310 file = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(fnamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
311 goto try_english;
312 }
313
314 // no strings found
315 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
316 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Localization: Warning, 0 strings found in %s\n", filename);
317 *table = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
318 *size = 0;
319 return true;
320 }
321
322 *size = scount;
323 char **strtable;
324
325 // malloc our array of char *
326 *table = (char **)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(char *) * scount);
327 if (!*table) {
328 if (table)
329 *table = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
330 if (size)
331 *size = 0;
332 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
333 return false;
334 }
335
336 strtable = *table;
337 for (int tcount = 0; tcount < scount; tcount++)
338 strtable[tcount] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
339
340 // now load the strings
341 file = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(fnamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
342 if (!file) {
343 if (table)
344 *table = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
345 if (size)
346 *size = 0;
347 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
348 return false;
349 }
350
351 bool reading_string = false;
352 scount = 0;
353
354 GrowStringcxx . . $ GrowString# stringcxx . . $ GrowString#GrowString(49f6e7a06ebc5aa8).;
355
356 int line_info;
357
358 while (!cfeofcxx . . $ cfeof(413716a422df0036).(file)) {
359 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(tempbuffer, MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`!, file);
360 if (scount >= 198)
361 scount = scount;
362
363 line_info = _parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(tempbuffer);
364
365 switch (line_info) {
366 case STAG_CONTINUEcxx . . $ `Descent3/localization.cpp:136:9`!:
367 if (reading_string) {
368 // we need to add on to the working buffer
369 string +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). _parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(tempbuffer);
370 }
371 break;
372 case STAG_EMPTYcxx . . $ `Descent3/localization.cpp:137:9`!:
373 // empty line !ACK! What should I do...do a new line char or skip?...skip for now
374 break;
375 case STAG_COMMENTcxx . . $ `Descent3/localization.cpp:138:9`!:
376 // ignore this line
377 if (reading_string) {
378 // ok we're done with the string, finish it and put it in the string table
379 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&strtable[scount]);
380 scount++;
381 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
382 }
383 reading_string = false;
384 break;
385 default: {
386 if (line_info >= 0 && line_info < Num_languagescxx . . $ Num_languages.) {
387 if (reading_string) {
388 // ok we're done with the string, finish it and put it in the string table
389 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&strtable[scount]);
390 scount++;
391 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
392 reading_string = false;
393 }
394
395 // see if we should read this string
396 if (line_info == Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.) {
397 reading_string = true;
398 // start filling in the buffer
399 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
400 string =cxx . . $ GrowString#`operator=`(fda57c8427c60377). _parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(_parse_string_tagcxx . . $ _parse_string_tag(7a9722d75b371431).(tempbuffer));
401 }
402
403 } else {
404 Int3cxx . . $ `misc/pserror.h:247:9`!(); // get Jeff
405 reading_string = false;
406 }
407 } break;
408 } // end switch
409 } // end while
410
411 if (reading_string) {
412 // we're at the end of the file and we're reading, so but it in the string table
413 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&strtable[scount]);
414 scount++;
415 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
416 reading_string = false;
417 }
418
419 cfclosecxx . . $ cfclose(3639e799710acb68).(file);
420
421 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "String Table (%s) loaded with %d strings\n", filename, *size);
422 Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language. = old_language;
423
424 return (scount == (*size));
425 }
426
427 // Given a string table and it's count of strings, it will free up it's memory
428 void DestroyStringTablecxx . . $ DestroyStringTable(a50bc8ce1fe710a2).(char **table, int size) {
429 if ((size > 0) && (table)) {
430 for (int i = 0; i < size; i++) {
431 if (table[i])
432 mem_freecxx . . $ `mem/mem.h:80:9`!(table[i]);
433 }
434 }
435
436 if (table)
437 mem_freecxx . . $ `mem/mem.h:80:9`!(table);
438 }
439
440 // returns the total number of strings in all the string table files
441 // returns 0 on error
442 int GetTotalStringCountcxx . . $ GetTotalStringCount(b126dc7c1de90089).(void) {
443 int scount = 0;
444 int findex = 0;
445 CFILEcxx . . $ CFILE# *file;
446 char tempbuffer[MAX_LINE_LENGTHcxx . . $ `Descent3/localization.cpp:141:9`! + 1];
447 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Localization_language != -1);
448
449 while (String_table_listcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_list.[findex]) {
450 // open the file up
451 char fname[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`!];
452 FixFilenameCasecxx . . $ FixFilenameCase(611124a97efc52dd).(String_table_listcxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table_list.[findex], fname);
453 file = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(fnamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
454 if (!file)
455 return 0;
456
457 while (!cfeofcxx . . $ cfeof(413716a422df0036).(file)) {
458 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(tempbuffer, MAX_LINE_LENGTHcxx . . $ `Descent3/localization.cpp:141:9`! + 1, file);
459 if (_parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(tempbuffer) == Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.)
460 scount++;
461 }
462
463 cfclosecxx . . $ cfclose(3639e799710acb68).(file);
464 findex++;
465 }
466 return scount;
467 }
468
469 // Loads a string table file, returns number of strings read if everything went ok,else 0
470 int LoadStringFilecxx . . $ LoadStringFile(cb7559238bb26814).(const char *filename, int starting_offset) {
471 ASSERTcxx . . $ `misc/pserror.h:246:9`!(filename);
472 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Localization_language != -1);
473 if (!filename)
474 return 0;
475
476 CFILEcxx . . $ CFILE# *file;
477 char fname[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`!];
478 FixFilenameCasecxx . . $ FixFilenameCase(611124a97efc52dd).(filename, fname);
479 file = cfopencxx . . $ cfopen(7c7b94e455f1ae56).(fnamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "rt");
480 if (!file)
481 return 0;
482
483 int scount = 0;
484 char buffer[MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`!];
485
486 bool reading_string = false;
487
488 GrowStringcxx . . $ GrowString# stringcxx . . $ GrowString#GrowString(49f6e7a06ebc5aa8).;
489 int line_info;
490
491 while (!cfeofcxx . . $ cfeof(413716a422df0036).(file)) {
492 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(buffer, MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`!, file);
493 if (scount >= 198)
494 scount = scount;
495
496 line_info = _parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(buffer);
497
498 switch (line_info) {
499 case STAG_CONTINUEcxx . . $ `Descent3/localization.cpp:136:9`!:
500 if (reading_string) {
501 // we need to add on to the working buffer
502 string +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). _parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(buffer);
503 }
504 break;
505 case STAG_EMPTYcxx . . $ `Descent3/localization.cpp:137:9`!:
506 // empty line !ACK! What should I do...do a new line char or skip?...skip for now
507 break;
508 case STAG_COMMENTcxx . . $ `Descent3/localization.cpp:138:9`!:
509 // ignore this line
510 if (reading_string) {
511 // ok we're done with the string, finish it and put it in the string table
512 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[scount + starting_offset]);
513 scount++;
514 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
515 }
516 reading_string = false;
517 break;
518 default: {
519 if (line_info >= 0 && line_info < Num_languagescxx . . $ Num_languages.) {
520 if (reading_string) {
521 // ok we're done with the string, finish it and put it in the string table
522 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[scount + starting_offset]);
523 scount++;
524 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
525 reading_string = false;
526 }
527
528 // see if we should read this string
529 if (line_info == Localization_languagecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/Localization_language.) {
530 reading_string = true;
531 // start filling in the buffer
532 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
533 string =cxx . . $ GrowString#`operator=`(fda57c8427c60377). _parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(_parse_string_tagcxx . . $ _parse_string_tag(7a9722d75b371431).(buffer));
534 }
535
536 } else {
537 Int3cxx . . $ `misc/pserror.h:247:9`!(); // get Jeff
538 reading_string = false;
539 }
540 } break;
541 } // end switch
542 } // end while
543
544 if (reading_string) {
545 // we're at the end of the file and we're reading, so but it in the string table
546 string.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&String_tablecxx . . $ `$anonymous_namespace_Descent3/localization.cpp`/String_table.[scount + starting_offset]);
547 scount++;
548 string.Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
549 reading_string = false;
550 }
551
552 cfclosecxx . . $ cfclose(3639e799710acb68).(file);
553 return scount;
554 }
555
556 // returns STAG_* information about the line
557 int8_t _parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(char *line) {
558 for (int i = 0; i < Num_languagescxx . . $ Num_languages.; i++) {
559 if (Language_tagscxx . . $ Language_tags.[i].lengthcxx . . $ tLangTag#length. == -1)
560 Language_tagscxx . . $ Language_tags.[i].lengthcxx . . $ tLangTag#length. = strlen(Language_tagscxx . . $ Language_tags.[i].tagcxx . . $ tLangTag#tag.);
561
562 if (!strncmp(line, Language_tagscxx . . $ Language_tags.[i].tagcxx . . $ tLangTag#tag., Language_tagscxx . . $ Language_tags.[i].lengthcxx . . $ tLangTag#length.))
563 return i;
564 }
565
566 if (!strncmp(line, COMMENT_TAGcxx . . $ `Descent3/localization.cpp:134:9`!, strlen(COMMENT_TAGcxx . . $ `Descent3/localization.cpp:134:9`!)))
567 return STAG_COMMENTcxx . . $ `Descent3/localization.cpp:138:9`!;
568 if (strlen(line) == 0)
569 return STAG_EMPTYcxx . . $ `Descent3/localization.cpp:137:9`!;
570 return STAG_CONTINUEcxx . . $ `Descent3/localization.cpp:136:9`!;
571 }
572
573 // parses a string_tag out
574 char *_parse_string_tagcxx . . $ _parse_string_tag(7a9722d75b371431).(char *buffer) {
575 int8_t i = _parse_line_informationcxx . . $ _parse_line_information(497767f01c66eb20).(buffer);
576
577 switch (i) {
578 case STAG_CONTINUEcxx . . $ `Descent3/localization.cpp:136:9`!:
579 case STAG_EMPTYcxx . . $ `Descent3/localization.cpp:137:9`!:
580 return buffer;
581 break;
582 case STAG_COMMENTcxx . . $ `Descent3/localization.cpp:138:9`!:
583 return buffer + (strlen(COMMENT_TAGcxx . . $ `Descent3/localization.cpp:134:9`!));
584 break;
585 default:
586 if (i >= 0 && i < Num_languagescxx . . $ Num_languages.) {
587 // we have a specific language...
588 return buffer + (Language_tagscxx . . $ Language_tags.[i].lengthcxx . . $ tLangTag#length.);
589 }
590 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jeff
591 break;
592 }
593 return buffer;
594 }
595
596 // parses out escape chars...like /t,/n
597 char *_parse_escape_charscxx . . $ _parse_escape_chars(7a9722d75b371431).(char *buffer) {
598 char tempbuffer[MAX_STRING_LENGTHcxx . . $ `Descent3/localization.cpp:142:9`!];
599 int t_index, b_index;
600
601 t_index = 0;
602 b_index = 0;
603
604 // search for a /
605 while (buffer[b_index] != '\0') {
606 // see if we are at a backslash
607 if (buffer[b_index] != '\\') {
608 tempbuffer[t_index] = buffer[b_index];
609 t_index++;
610 b_index++;
611 } else {
612 // we are at a backslash, so determine what to do
613 b_index++;
614 switch (toupper(buffer[b_index])) {
615 case 'T':
616 tempbuffer[t_index] = '\t';
617 break;
618 case 'N':
619 tempbuffer[t_index] = '\n';
620 break;
621 case 'R':
622 tempbuffer[t_index] = '\r';
623 break;
624 case '\"':
625 tempbuffer[t_index] = '\"';
626 break;
627 case '\\':
628 tempbuffer[t_index] = '\\';
629 break;
630 default:
631 // see if we have a number
632 if ((buffer[b_index] >= '0') && (buffer[b_index] <= '9')) {
633 // we have a number, so parse the value
634 uint8_tcxx . . $ uint8_t# value = 0;
635 while ((buffer[b_index] >= '0') && (buffer[b_index] <= '9')) {
636 value = (value * 10) + buffer[b_index] - '0';
637 b_index++;
638 }
639 // adjust b_index
640 b_index--;
641 tempbuffer[t_index] = value;
642 }
643 break;
644 }
645 b_index++;
646 t_index++;
647 }
648 }
649 tempbuffer[t_index] = '\0';
650 strcpy(buffer, tempbuffer);
651 return buffer;
652 }
653
654 GrowStringcxx . . $ GrowString#::GrowStringcxx . . $ GrowString#GrowString(49f6e7a06ebc5aa8).() {
655 rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
656 rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
657 currcxx . . $ GrowString#curr. = &rootcxx . . $ GrowString#root.;
658 }
659 GrowStringcxx . . $ GrowString#::~cxx . . $ GrowString#`~GrowString`(ced63f7c635d850d).GrowStringcxx . . $ GrowString#() { Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).(); }
660
661 void GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#`operator+=`(fda57c8427c60377).+=(char *str) {
662 if (!str)
663 return;
664 if (rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.) {
665 tbufferinfocxx . . $ tbufferinfo# *node;
666 node = (tbufferinfocxx . . $ tbufferinfo# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(tbufferinfo));
667 if (!node)
668 return;
669 node->string_datacxx . . $ tbufferinfo#string_data. = (char *)mem_malloccxx . . $ `mem/mem.h:79:9`!(strlen(str) + 2);
670 if (!node->string_datacxx . . $ tbufferinfo#string_data.) {
671 mem_freecxx . . $ `mem/mem.h:80:9`!(node);
672 return;
673 }
674 sprintf(node->string_datacxx . . $ tbufferinfo#string_data., "\n%s", str);
675 currcxx . . $ GrowString#curr.->nextcxx . . $ tbufferinfo#next. = node;
676 node->nextcxx . . $ tbufferinfo#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
677 currcxx . . $ GrowString#curr. = node;
678 } else {
679 rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data. = (char *)mem_malloccxx . . $ `mem/mem.h:79:9`!(strlen(str) + 1);
680 if (!rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.)
681 return;
682 strcpy(rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data., str);
683 rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
684 }
685 }
686
687 void GrowStringcxx . . $ GrowString#::Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).(void) {
688 if (rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.)
689 mem_freecxx . . $ `mem/mem.h:80:9`!(root.string_data);
690 rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
691
692 tbufferinfocxx . . $ tbufferinfo# *c, *next;
693 c = next = rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next.;
694 while (c) {
695 next = c->nextcxx . . $ tbufferinfo#next.;
696 if (c->string_datacxx . . $ tbufferinfo#string_data.)
697 mem_freecxx . . $ `mem/mem.h:80:9`!(c->string_data);
698 mem_freecxx . . $ `mem/mem.h:80:9`!(c);
699 c = next;
700 }
701 rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
702 rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
703 currcxx . . $ GrowString#curr. = &rootcxx . . $ GrowString#root.;
704 }
705
706 GrowStringcxx . . $ GrowString# GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#operator+(cfed376955f0f75f).+(char *str) {
707 *this +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). str;
708 return *this;
709 }
710
711 GrowStringcxx . . $ GrowString# GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#operator+(40432a41a67ae3e9).+(GrowStringcxx . . $ GrowString# &gs) {
712 char *str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
713 gs.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&str);
714 *this +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). str;
715 if (str)
716 mem_freecxx . . $ `mem/mem.h:80:9`!(str);
717 return *this;
718 }
719
720 void GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#`operator+=`(a92de8bf1fe4f3e2).+=(GrowStringcxx . . $ GrowString# &gs) {
721 char *str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
722 gs.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&str);
723 *this +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). str;
724 if (str)
725 mem_freecxx . . $ `mem/mem.h:80:9`!(str);
726 }
727
728 void GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#`operator=`(fda57c8427c60377).=(char *str) {
729 Destroycxx . . $ GrowString#Destroy(49f6e7a06ebc5aa8).();
730 *this +=cxx . . $ GrowString#`operator+=`(fda57c8427c60377). str;
731 }
732
733 void GrowStringcxx . . $ GrowString#::operatorcxx . . $ GrowString#`operator=`(a92de8bf1fe4f3e2).=(GrowStringcxx . . $ GrowString# &gs) {
734 char *str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
735 gs.GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(&str);
736 *this =cxx . . $ GrowString#`operator=`(fda57c8427c60377). str;
737 if (str)
738 mem_freecxx . . $ `mem/mem.h:80:9`!(str);
739 }
740
741 void GrowStringcxx . . $ GrowString#::GetStringcxx . . $ GrowString#GetString(3ed91490e421178f).(char **str) {
742 *str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
743 int size = Lengthcxx . . $ GrowString#Length(b126dc7c1de90089).();
744 if (size == -1)
745 return;
746
747 tbufferinfocxx . . $ tbufferinfo# *next;
748 next = rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next.;
749
750 *str = (char *)mem_malloccxx . . $ `mem/mem.h:79:9`!(size + 1);
751
752 strcpy(*str, rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.);
753 next = rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next.;
754 while (next) {
755 if (next->string_datacxx . . $ tbufferinfo#string_data.) {
756 strcat(*str, next->string_datacxx . . $ tbufferinfo#string_data.);
757 }
758 next = next->nextcxx . . $ tbufferinfo#next.;
759 }
760 }
761
762 int GrowStringcxx . . $ GrowString#::Lengthcxx . . $ GrowString#Length(b126dc7c1de90089).(void) {
763 if (!rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.)
764 return -1;
765
766 tbufferinfocxx . . $ tbufferinfo# *next;
767 next = rootcxx . . $ GrowString#root..nextcxx . . $ tbufferinfo#next.;
768 int size = strlen(rootcxx . . $ GrowString#root..string_datacxx . . $ tbufferinfo#string_data.);
769 while (next) {
770 if (next->string_datacxx . . $ tbufferinfo#string_data.)
771 size += strlen(next->string_datacxx . . $ tbufferinfo#string_data.);
772 next = next->nextcxx . . $ tbufferinfo#next.;
773 }
774 return size;
775 }