2 * $Logfile: /Freespace2/code/Localization/localize.cpp $
9 * Revision 1.1 2002/05/03 03:28:09 root
13 * 91 6/16/00 3:16p Jefff
14 * sim of the year dvd version changes, a few german soty localization
17 * 90 11/02/99 8:20p Jefff
18 * more translation changes/additions
20 * 89 11/02/99 3:24p Jefff
21 * added translation functions for a few key instances where english was
24 * 88 10/29/99 10:40p Jefff
27 * 87 10/28/99 2:05a Jefff
28 * safety fix in localization stuff
30 * 86 10/26/99 10:53a Jefff
31 * German builds now correctly default to German on first run
33 * 85 10/25/99 11:22p Jefff
34 * mo' strings (launcher)
36 * 84 10/25/99 5:46p Jefff
37 * Many localization fixes/changes for German builds
39 * 83 10/14/99 3:25p Jefff
40 * soo...many....xstrs....
42 * 82 10/14/99 2:52p Jefff
43 * localization fixes. added support for hi-res specific xstr offsets
45 * 81 10/13/99 3:58p Jefff
46 * added a bunch of missed XSTRs
48 * 80 9/13/99 11:30a Dave
49 * Added checkboxes and functionality for disabling PXO banners as well as
50 * disabling d3d zbuffer biasing.
52 * 79 9/08/99 9:59a Jefff
54 * 78 9/07/99 4:01p Dave
55 * Fixed up a string.tbl paroblem (self destruct message). Make sure IPX
56 * does everything properly (setting up address when binding). Remove
57 * black rectangle background from UI_INPUTBOX.
59 * 77 9/07/99 1:54p Jefff
60 * skip mission strings added
62 * 76 9/03/99 10:55a Jefff
65 * 75 9/03/99 1:31a Dave
66 * CD checking by act. Added support to play 2 cutscenes in a row
67 * seamlessly. Fixed super low level cfile bug related to files in the
68 * root directory of a CD. Added cheat code to set campaign mission # in
71 * 74 8/27/99 12:04a Dave
72 * Campaign loop screen.
74 * 73 8/26/99 12:48p Jefff
76 * 72 8/22/99 5:53p Dave
77 * Scoring fixes. Added self destruct key. Put callsigns in the logfile
78 * instead of ship designations for multiplayer players.
80 * 71 8/22/99 1:55p Dave
81 * Cleaned up host/team-captain leaving code.
83 * 70 8/17/99 7:32p Jefff
86 * 69 8/16/99 5:15p Dave
89 * 68 8/16/99 4:04p Dave
90 * Big honking checkin.
92 * 67 8/11/99 2:09p Jefff
93 * ill give you three guesses.
95 * 66 8/10/99 7:57p Jefff
98 * 65 8/05/99 2:40p Jefff
101 * 64 8/02/99 9:13p Dave
104 * 63 8/02/99 12:01p Jefff
107 * 62 7/29/99 10:47p Dave
108 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
110 * 61 7/29/99 9:44a Jefff
111 * added some strings for ingame objectives screen
113 * 60 7/27/99 7:15p Jefff
114 * 3 new interface strings
116 * 59 7/27/99 6:53p Dave
117 * Hi-res main hall support.
119 * 58 7/24/99 1:54p Dave
120 * Hud text flash gauge. Reworked dead popup to use 4 buttons in red-alert
123 * 57 7/22/99 4:08p Jefff
126 * 56 7/19/99 7:20p Dave
127 * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
130 * 55 7/19/99 2:13p Dave
131 * Added some new strings for Heiko.
133 * 54 7/15/99 2:37p Jefff
135 * 53 7/13/99 6:07p Jefff
136 * Added support for localization string offsets.
138 * 52 7/09/99 10:32p Dave
139 * Command brief and red alert screens.
141 * 51 6/25/99 2:51p Jasons
144 * 50 6/25/99 11:59a Dave
145 * Multi options screen.
147 * 49 6/24/99 12:34a Dave
148 * Main options screen.
150 * 48 6/19/99 3:58p Dave
153 * 47 6/14/99 5:19p Dave
155 * 46 6/04/99 11:32a Dave
156 * Added reset text to ship select screen. Fixed minor xstr bug in ui
159 * 45 6/01/99 6:07p Dave
160 * New loading/pause/please wait bar.
162 * 44 6/01/99 4:03p Dave
163 * Changed some popup flag #defines. Upped string count to 1336
165 * 43 5/26/99 11:46a Dave
166 * Added ship-blasting lighting and made the randomization of lighting
167 * much more customizable.
169 * 42 5/22/99 6:05p Dave
170 * Fixed a few localization # problems.
172 * 41 5/21/99 6:45p Dave
173 * Sped up ui loading a bit. Sped up localization disk access stuff. Multi
174 * start game screen, multi password, and multi pxo-help screen.
176 * 40 5/17/99 2:52p Dave
177 * Fixed dumb localization problem.
179 * 39 5/17/99 10:07a Dave
180 * Updated string count.
182 * 38 5/04/99 6:38p Dave
183 * Finished multi join-wait screen.
185 * 37 5/04/99 5:20p Dave
186 * Fixed up multiplayer join screen and host options screen. Should both
189 * 36 5/03/99 11:04p Dave
190 * Most of the way done with the multi join screen.
192 * 35 5/03/99 8:32p Dave
193 * New version of multi host options screen.
195 * 34 4/09/99 2:28p Dave
196 * Upped Xstring count.
198 * 33 4/09/99 2:21p Dave
199 * Multiplayer beta stuff. CD checking.
201 * 32 4/08/99 12:50p Neilk
202 * changed number of xstr constant
204 * 31 4/07/99 5:54p Dave
205 * Fixes for encryption in updatelauncher.
207 * 30 3/24/99 4:05p Dave
208 * Put in support for assigning the player to a specific squadron with a
209 * specific logo. Preliminary work for doing pos/orient checksumming in
210 * multiplayer to reduce bandwidth.
212 * 29 3/23/99 3:35p Andsager
213 * Add error check for duplicate string indices
215 * 28 3/22/99 2:56p Andsager
216 * Localize Launcher Updater
218 * 27 2/23/99 11:18a Andsager
219 * Localize launcher using strings.tbl
221 * 26 2/22/99 9:35p Andsager
222 * Add lcl_get_language_name() returns string with current lang. Added
223 * localization for launcher.
225 * 25 2/21/99 6:02p Dave
226 * Fixed standalone WSS packets.
228 * 24 2/17/99 2:11p Dave
229 * First full run of squad war. All freespace and tracker side stuff
232 * 23 2/12/99 6:15p Dave
233 * Pre-mission Squad War code is 95% done.
235 * 22 2/02/99 7:27p Neilk
236 * implemented lc_close() to free up some string memory when shutting down
238 * 21 1/30/99 1:29a Dave
239 * Fixed nebula thumbnail problem. Full support for 1024x768 choose pilot
240 * screen. Fixed beam weapon death messages.
242 * 20 1/29/99 7:56p Neilk
243 * Added new mission log interface
245 * 19 1/29/99 4:17p Dave
246 * New interface screens.
248 * 18 1/29/99 12:47a Dave
249 * Put in sounds for beam weapon. A bunch of interface screens (tech
252 * 17 1/13/99 2:10p Andsager
255 * 16 12/14/98 12:13p Dave
256 * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
259 * 15 12/03/98 5:22p Dave
260 * Ported over Freespace 1 multiplayer ships.tbl and weapons.tbl
263 * 14 12/02/98 5:47p Dave
264 * Put in interface xstr code. Converted barracks screen to new format.
266 * 13 12/01/98 4:46p Dave
267 * Put in targa bitmap support (16 bit).
275 #include "localize.h"
277 #include "osregistry.h"
281 // ------------------------------------------------------------------------------------------------------------
282 // LOCALIZE DEFINES/VARS
285 // general language/localization data ---------------------
288 int Lcl_current_lang = LCL_ENGLISH;
290 // language info table
291 typedef struct lang_info {
292 char lang_name[LCL_LANG_NAME_LEN + 1]; // literal name of the language
293 char lang_ext[LCL_LANG_NAME_LEN + 1]; // for adding to names on disk access
296 lang_info Lcl_languages[LCL_NUM_LANGUAGES] = {
297 { "English", "" }, // english
298 { "German", "gr" }, // german
299 { "French", "fr" }, // french
302 //#if defined(GERMAN_BUILD)
303 //#define DEFAULT_LANGUAGE "German"
305 #define DEFAULT_LANGUAGE "English"
308 // following is the offset where special characters start in our font
309 #define LCL_SPECIAL_CHARS_FR 164
310 #define LCL_SPECIAL_CHARS_GR 164
311 #define LCL_SPECIAL_CHARS 127
312 int Lcl_special_chars;
314 // use these to replace *_BUILD, values before
315 // only 1 will be active at a time
321 // executable string localization data --------------------
323 // XSTR_SIZE is the total count of unique XSTR index numbers. An index is used to
324 // reference an entry in strings.tbl. This is used for translation of strings from
325 // the english version (in the code) to a foreign version (in the table). Thus, if you
326 // add a new string to the code, you must assign it a new index. Use the number below for
327 // that index and increase the number below by one.
328 #define XSTR_SIZE 1570
331 // struct to allow for strings.tbl-determined x offset
332 // offset is 0 for english, by default
335 int offset_x; // string offset in 640
336 int offset_x_hi; // string offset in 1024
339 //char *Xstr_table[XSTR_SIZE];
340 lcl_xstr Xstr_table[XSTR_SIZE];
344 // table/mission externalization stuff --------------------
346 #define TABLE_STRING_FILENAME "tstrings.tbl"
347 // filename of the file to use when localizing table strings
348 char *Lcl_ext_filename = NULL;
349 CFILE *Lcl_ext_file = NULL;
351 // for scanning/parsing tstrings.tbl (from ExStr)
352 #define PARSE_TEXT_STRING_LEN 2048
353 #define PARSE_ID_STRING_LEN 128
354 #define TS_SCANNING 0 // scanning for a line of text
355 #define TS_ID_STRING 1 // reading in an id string
356 #define TS_OPEN_QUOTE 2 // looking for an open quote
357 #define TS_STRING 3 // reading in the text string itself
358 int Ts_current_state = 0;
359 char Ts_text[PARSE_TEXT_STRING_LEN]; // string we're currently working with
360 char Ts_id_text[PARSE_ID_STRING_LEN]; // id string we're currently working with
364 // file pointers for optimized string lookups
365 // some example times for Freespace2 startup with granularities (mostly .tbl files, ~500 strings in the table file, many looked up more than once)
366 // granularity 20 : 13 secs
367 // granularity 10 : 11 secs
368 // granularity 5 : 9 secs
369 // granularity 2 : 7-8 secs
370 #define LCL_GRANULARITY 1 // how many strings between each pointer (lower granularities should give faster lookup times)
371 #define LCL_MAX_POINTERS 4500 // max # of pointers
372 #define LCL_MAX_STRINGS (LCL_GRANULARITY * LCL_MAX_POINTERS)
373 int Lcl_pointers[LCL_MAX_POINTERS];
374 int Lcl_pointer_count = 0;
377 // ------------------------------------------------------------------------------------------------------------
378 // LOCALIZE FORWARD DECLARATIONS
381 // associate table file externalization with the specified input file
382 void lcl_ext_associate(char *filename);
384 // given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success
385 int lcl_ext_get_text(char *xstr, char *out);
387 // given a valid XSTR() tag piece of text, extract the id# portion, return the value in out, nonzero on success
388 int lcl_ext_get_id(char *xstr, int *out);
390 // given a valid XSTR() id#, lookup the string in tstrings.tbl, filling in out if found, nonzero on success
391 int lcl_ext_lookup(char *out, int id);
393 // if the char is a valid char for a signed integer value string
394 int lcl_is_valid_numeric_char(char c);
396 // sub-parse function for individual lines of tstrings.tbl (from Exstr)
397 // returns : integer with the low bits having the following values :
398 // 0 on fail, 1 on success, 2 if found a matching id/string pair, 3 if end of language has been found
399 // for cases 1 and 2 : the high bit (1<<31) will be set if the parser detected the beginning of a new string id on this line
400 // so be sure to mask this value out to get the low portion of the return value
402 int lcl_ext_lookup_sub(char *text, char *out, int id);
404 // initialize the pointer array into tstrings.tbl (call from lcl_ext_open() ONLY)
405 void lcl_ext_setup_pointers();
408 // ------------------------------------------------------------------------------------------------------------
409 // LOCALIZE FUNCTIONS
412 // initialize localization, if no language is passed - use the language specified in the registry
413 void lcl_init(int lang_init)
415 char lang_string[128];
419 // initialize encryption
422 // read the language from the registry
424 memset(lang_string, 0, 128);
425 #if defined(GERMAN_BUILD)
426 // defualt lang to German, mein herr
427 ret = os_config_read_string(NULL, "Language", "German");
429 // default to DEFAULT_LANGUAGE (which should be english so we dont have to put German text
430 // in tstrings in the #default section
431 ret = os_config_read_string(NULL, "Language", DEFAULT_LANGUAGE);
435 strcpy(lang_string, DEFAULT_LANGUAGE);
437 strcpy(lang_string, ret);
442 for(idx=0; idx<LCL_NUM_LANGUAGES; idx++){
443 if(!stricmp(Lcl_languages[idx].lang_name, lang_string)){
452 Assert((lang_init >= 0) && (lang_init < LCL_NUM_LANGUAGES));
457 Lcl_pointer_count = 0;
459 // associate the table string file
460 lcl_ext_associate(TABLE_STRING_FILENAME);
462 // set the language (this function takes care of setting up file pointers)
463 lcl_set_language(lang);
466 // added 2.2.99 by NeilK to take care of fs2 launcher memory leaks
467 // shutdown localization
470 // if the filename exists, free it up
471 if(Lcl_ext_filename != NULL){
472 free(Lcl_ext_filename);
476 // determine what language we're running in, see LCL_* defines above
477 int lcl_get_language()
479 return Lcl_current_lang;
482 // initialize the xstr table
486 char language_tag[512];
487 int i, z, index, rval;
488 char *p_offset = NULL;
489 int offset_lo = 0, offset_hi = 0;
491 for (i=0; i<XSTR_SIZE; i++){
492 Xstr_table[i].str = NULL;
495 if ((rval = setjmp(parse_abort)) != 0) {
496 mprintf(("Error parsing 'strings.tbl'\nError code = %i.\n", rval));
498 // make sure localization is NOT running
501 read_file_text("strings.tbl");
504 // move down to the proper section
505 memset(language_tag, 0, 512);
506 strcpy(language_tag, "#");
507 strcat(language_tag, Lcl_languages[Lcl_current_lang].lang_name);
508 if(skip_to_string(language_tag) != 1){
509 Error(LOCATION, NOX("Strings.tbl is corrupt"));
512 // parse all the strings in this section of the table
513 while (!check_for_string("#")) {
514 int num_offsets_on_this_line = 0;
517 stuff_string(buf, F_NAME, NULL, 4096);
520 if (!isspace(buf[i])) {
525 // trim unneccesary end of string
527 // Assert(buf[i] == '"');
529 // probably an offset on this entry
530 buf[i+1] = 0; // drop down a null terminator (prolly unnecessary)
531 while(!is_white_space(buf[i])) i--; // back up over the potential offset
532 while(is_white_space(buf[i])) i--; // now back up over intervening spaces
533 num_offsets_on_this_line = 1;
535 // could have a 2nd offset value (one for 640, one for 1024)
537 while(!is_white_space(buf[i])) i--; // back up over the 2nd offset
538 while(is_white_space(buf[i])) i--; // now back up over intervening spaces
539 num_offsets_on_this_line = 2;
542 p_offset = &buf[i+1]; // get ptr to string section with offset in it
544 Error(LOCATION, NOX("Strings.tbl is corrupt")); // now its an error
551 // copy string into buf
553 for (i=1; buf[i]; i++) {
559 } else if (chr == 'r') {
568 // null terminator on buf
571 // write into Xstr_table
572 if (index >= 0 && index < XSTR_SIZE) {
573 if (Xstr_table[index].str != NULL) {
574 Warning(LOCATION, "Strings table index %d used more than once", index);
576 Xstr_table[index].str = strdup(buf);
579 // read offset information, assume 0 if nonexistant
580 if (p_offset != NULL) {
581 if (sscanf(p_offset, "%d%d", &offset_lo, &offset_hi) < num_offsets_on_this_line) {
582 // whatever is in the file ain't a proper offset
583 Error(LOCATION, NOX("Strings.tbl is corrupt"));
586 Xstr_table[index].offset_x = offset_lo;
587 if (num_offsets_on_this_line == 2) {
588 Xstr_table[index].offset_x_hi = offset_hi;
590 Xstr_table[index].offset_x_hi = offset_lo;
593 // clear out our vars
597 num_offsets_on_this_line = 0;
606 void lcl_xstr_close()
608 for (int i=0; i<XSTR_SIZE; i++){
609 if (Xstr_table[i].str != NULL) {
610 free(Xstr_table[i].str);
611 Xstr_table[i].str = NULL;
617 // set our current language
618 void lcl_set_language(int lang)
620 Lcl_current_lang = lang;
622 nprintf(("General", "Setting language to %s\n", Lcl_languages[lang].lang_name));
624 // flag the proper language as being active
631 Lcl_special_chars = LCL_SPECIAL_CHARS;
635 Lcl_special_chars = LCL_SPECIAL_CHARS_FR;
639 Lcl_special_chars = LCL_SPECIAL_CHARS_GR;
643 // set to 0, so lcl_ext_open() knows to reset file pointers
644 Lcl_pointer_count = 0;
646 // reset file pointers to the proper language-section
647 if(Lcl_current_lang != LCL_DEFAULT_LANGUAGE){
648 lcl_ext_setup_pointers();
652 // maybe add on an appropriate subdirectory when opening a localized file
653 void lcl_add_dir(char *current_path)
658 // if the disk extension is 0 length, don't add enything
659 if (strlen(Lcl_languages[Lcl_current_lang].lang_ext) <= 0) {
663 // get the length of the string so far
664 path_len = strlen(current_path);
669 // get the current last char
670 last_char = current_path[path_len - 1];
672 // if the last char is a slash, just copy in the disk extension
673 if (last_char == '\\') {
674 strcat(current_path, Lcl_languages[Lcl_current_lang].lang_ext);
675 strcat(current_path, "\\");
677 // otherwise add a slash, then copy in the disk extension
679 strcat(current_path, "\\");
680 strcat(current_path, Lcl_languages[Lcl_current_lang].lang_ext);
684 // maybe add localized directory to full path with file name when opening a localized file
685 void lcl_add_dir_to_path_with_filename(char *current_path)
687 char temp[MAX_PATH_LEN];
689 // if the disk extension is 0 length, don't add enything
690 if (strlen(Lcl_languages[Lcl_current_lang].lang_ext) <= 0) {
694 // find position of last slash and copy rest of filename (not counting slash) to temp
695 // mark end of current path with '\0', so strcat will work
696 char *last_slash = strrchr(current_path, '\\');
697 if (last_slash == NULL) {
698 strcpy(temp, current_path);
699 current_path[0] = '\0';
701 strcpy(temp, last_slash+1);
702 last_slash[1] = '\0';
706 strcat(current_path, Lcl_languages[Lcl_current_lang].lang_ext);
707 strcat(current_path, "\\");
709 // copy rest of filename from temp
710 strcat(current_path, temp);
714 // externalization of table/mission files -----------------------
716 // open the externalization file for use during parsing (call before parsing a given file)
719 // if the file is already open, do nothing
720 Assert(Lcl_ext_file == NULL);
722 // if we're running in the default language, do nothing
723 if(Lcl_current_lang == LCL_DEFAULT_LANGUAGE){
727 // otherwise open the file
728 Lcl_ext_file = cfopen(Lcl_ext_filename, "rt");
729 if(Lcl_ext_file == NULL){
734 // close the externalization file (call after parsing a given file)
737 // if the file is not open, do nothing
738 if(Lcl_ext_file == NULL){
742 // if we're running in the default language, do nothing
743 if(Lcl_current_lang == LCL_DEFAULT_LANGUAGE){
747 // otherwise close it
748 cfclose(Lcl_ext_file);
752 // get the localized version of the string. if none exists, return the original string
753 // valid input to this function includes :
754 // "this is some text"
755 // XSTR("wheeee", -1)
757 // and these should cover all the externalized string cases
758 // fills in id if non-NULL. a value of -2 indicates it is not an external string
759 void lcl_ext_localize(char *in, char *out, int max_len, int *id)
762 char text_str[2048]="";
763 char lookup_str[2048]="";
770 // default (non-external string) value
775 str_len = strlen(in);
777 // if the string is < 9 chars, it can't be an XSTR("",) tag, so just copy it
779 if(str_len > max_len){
780 error_display(0, "Token too long: [%s]. Length = %i. Max is %i.\n", in, str_len, max_len);
790 // otherwise, check to see if it's an XSTR() tag
791 memset(first_four, 0, 5);
792 strncpy(first_four, in, 4);
793 if(stricmp(first_four, "XSTR")){
795 if(str_len > max_len){
796 error_display(0, "Token too long: [%s]. Length = %i. Max is %i.\n", in, str_len, max_len);
806 // at this point we _know_ its an XSTR() tag, so split off the strings and id sections
807 if(!lcl_ext_get_text(in, text_str)){
815 if(!lcl_ext_get_id(in, &str_id)){
823 // if the localization file is not open, or we're running in the default language, return the original string
824 if((Lcl_ext_file == NULL) || (str_id < 0) || (Lcl_current_lang == LCL_DEFAULT_LANGUAGE)){
825 strcpy(out, text_str);
832 // attempt to find the string
833 if(lcl_ext_lookup(lookup_str, str_id)){
834 // copy to the outgoing string
835 Assert(strlen(lookup_str) <= (unsigned int)(max_len - 1));
837 if (strlen(lookup_str) > (unsigned int)(max_len-1)) {
838 // be safe and truncate string to fit
839 strncpy(out, lookup_str, (size_t) (max_len-1));
840 out[max_len-1] = '\0'; // ensure null terminator, since strncpy(...) doesnt.
842 strcpy(out, lookup_str);
846 // otherwise use what we have - probably should Int3() or assert here
848 strcpy(out, text_str);
857 // translate the specified string based upon the current language
858 char *XSTR(char *str, int index)
865 if (index >= 0 && index < XSTR_SIZE) {
866 if (Xstr_table[index].str){
867 return Xstr_table[index].str; // return translation of string
871 // can't translate, return original english string
875 // retrieve the offset for a localized string
876 int lcl_get_xstr_offset(int index, int res)
879 return Xstr_table[index].offset_x;
881 return Xstr_table[index].offset_x_hi;
886 // ------------------------------------------------------------------------------------------------------------
887 // LOCALIZE FORWARD DEFINITIONS
890 // associate table file externalization with the specified input file
891 void lcl_ext_associate(char *filename)
893 // if the filename already exists, free it up
894 if(Lcl_ext_filename != NULL){
895 free(Lcl_ext_filename);
898 // set the new filename
899 Lcl_ext_filename = strdup(filename);
902 // given a valid XSTR() tag piece of text, extract the string portion, return it in out, nonzero on success
903 int lcl_ext_get_text(char *xstr, char *out)
905 int str_start, str_end;
909 Assert(xstr != NULL);
911 str_len = strlen(xstr);
913 // this is some crazy wack-ass code.
914 // look for the open quote
915 str_start = str_end = 0;
916 p = strstr(xstr, "\"");
918 error_display(0, "Error parsing XSTR() tag %s\n", xstr);
921 str_start = p - xstr + 1;
923 // make sure we're not about to walk past the end of the string
924 if((p - xstr) >= str_len){
925 error_display(0, "Error parsing XSTR() tag %s\n", xstr);
929 // look for the close quote
930 p2 = strstr(p+1, "\"");
932 error_display(0, "Error parsing XSTR() tag %s\n", xstr);
938 // now that we know the boundaries of the actual string in the XSTR() tag. copy it
939 memcpy(out, xstr + str_start, str_end - str_start);
945 // given a valid XSTR() tag piece of text, extract the id# portion, return the value in out, nonzero on success
946 int lcl_ext_get_id(char *xstr, int *out)
951 Assert(xstr != NULL);
954 str_len = strlen(xstr);
956 // find the first quote
957 p = strstr(xstr, "\"");
959 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
962 // make sure we're not about to walk off the end of the string
963 if((p - xstr) >= str_len){
964 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
969 // continue searching until we find the close quote
971 pnext = strstr(p, "\"");
973 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
977 // if the previous char is a \, we know its not the "end-of-string" quote
978 if(*(pnext - 1) != '\\'){
987 // search until we find a ,
988 pnext = strstr(p, ",");
990 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
993 // make sure we're not about to walk off the end of the string
994 if((pnext - xstr) >= str_len){
995 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
1000 // now get the id string
1002 pnext = strtok(p, ")");
1004 error_display(0, "Error parsing id# in XSTR() tag %s\n", xstr);
1008 // get the value and we're done
1015 // given a valid XSTR() id#, lookup the string in tstrings.tbl, filling in out if found, nonzero on success
1016 int lcl_ext_lookup(char *out, int id)
1022 Assert(Lcl_pointer_count >= 0);
1023 Assert(Lcl_pointers[0] >= 0);
1024 Assert(Lcl_pointers[Lcl_pointer_count - 1] >= 0);
1025 Assert(Lcl_ext_file != NULL);
1028 // seek to the closest pointer <= the id# we're looking for
1029 pointer = id / LCL_GRANULARITY;
1030 cfseek(Lcl_ext_file, Lcl_pointers[pointer], CF_SEEK_SET);
1032 // reset parsing vars and go to town
1033 Ts_current_state = TS_SCANNING;
1034 Ts_id_text_size = 0;
1036 memset(Ts_text, 0, PARSE_TEXT_STRING_LEN);
1037 memset(Ts_id_text, 0, PARSE_ID_STRING_LEN);
1038 while((cftell(Lcl_ext_file) < Lcl_pointers[Lcl_pointer_count - 1]) && cfgets(text, 1024, Lcl_ext_file)){
1039 ret = lcl_ext_lookup_sub(text, out, id);
1041 // run the line parse function
1042 switch(ret & 0x0fffffff){
1045 Int3(); // should never get here - it means the string doens't exist in the table!!
1048 // success parsing the line - please continue
1052 // found a matching string/id pair
1055 #if defined(GERMAN_BUILD)
1056 // this is because tstrings.tbl reads in as ANSI for some reason
1057 // opening tstrings with "rb" mode didnt seem to help, so its now still "rt" like before
1058 lcl_fix_umlauts(out, LCL_TO_ASCII);
1062 // end of language found
1064 Int3(); // should never get here - it means the string doens't exist in the table!!
1069 Int3(); // should never get here - it means the string doens't exist in the table!!
1073 // sub-parse function for individual lines of tstrings.tbl (from Exstr)
1074 // returns : integer with the low bits having the following values :
1075 // 0 on fail, 1 on success, 2 if found a matching id/string pair, 3 if end of language has been found
1076 // for cases 1 and 2 : the high bit (1<<31) will be set if the parser detected the beginning of a new string id on this line
1078 int lcl_ext_lookup_sub(char *text, char *out, int id)
1080 char *front; // front of the line
1081 char *p; // current ptr
1082 int len = strlen(text);
1084 char text_copy[1024];
1086 int found_new_string_id = 0;
1092 // do something useful
1093 switch(Ts_current_state){
1094 // scanning for a line of text
1096 // if the first word is #end, we're done with the file altogether
1097 strcpy(text_copy, text);
1098 tok = strtok(text_copy, " \n");
1099 if((tok != NULL) && !stricmp(tok, "#end")){
1102 // if its a commented line, skip it
1103 else if((text[0] == ';') || (text[0] == ' ') || (text[0] == '\n')){
1106 // otherwise we should have an ID #, so stuff it and move to the proper state
1108 if(lcl_is_valid_numeric_char(*p)){
1109 memset(Ts_id_text, 0, PARSE_ID_STRING_LEN);
1110 Ts_id_text_size = 0;
1111 Ts_id_text[Ts_id_text_size++] = *p;
1112 Ts_current_state = TS_ID_STRING;
1114 found_new_string_id = 1;
1124 // scanning in an id string
1126 // if we have another valid char
1127 if(lcl_is_valid_numeric_char(*p)){
1128 Ts_id_text[Ts_id_text_size++] = *p;
1130 // if we found a comma, our id# is finished, look for the open quote
1132 Ts_current_state = TS_OPEN_QUOTE;
1140 // valid space or an open quote
1141 if((*p == ' ') || (*p == '\"')){
1143 memset(Ts_text, 0, PARSE_TEXT_STRING_LEN);
1145 Ts_current_state = TS_STRING;
1154 // if we have an end quote, we need to look for a comma
1155 if((*p == '\"') /*&& (Ts_text_size > 0)*/ && (Ts_text[Ts_text_size - 1] != '\\')){
1156 // we're now done - we have a string
1157 Ts_current_state = TS_SCANNING;
1159 // if the id#'s match, copy the string and return "string found"
1160 if((atoi(Ts_id_text) == id) && (out != NULL)){
1161 strcpy(out, Ts_text);
1163 return found_new_string_id ? (1<<1) | (1<<31) : (1<<1);
1166 // otherwise, just continue parsing
1167 return found_new_string_id ? (1<<0) | (1<<31) : (1<<0);
1169 // otherwise add to the string
1171 Ts_text[Ts_text_size++] = *p;
1176 // if we have a newline, return success, we're done with this line
1178 return found_new_string_id ? (1<<0) | (1<<31) : (1<<0);
1181 // next char in the line
1187 return found_new_string_id ? (1<<0) | (1<<31) : (1<<0);
1190 // if the char is a valid char for a signed integer value
1191 int lcl_is_valid_numeric_char(char c)
1193 return ( (c == '-') || (c == '0') || (c == '1') || (c == '2') || (c == '3') || (c == '4') ||
1194 (c == '5') || (c == '6') || (c == '7') || (c == '8') || (c == '9') ) ? 1 : 0;
1197 // initialize the pointer array into tstrings.tbl (call from lcl_ext_open() ONLY)
1198 void lcl_ext_setup_pointers()
1200 char language_string[128];
1205 int found_start = 0;
1207 // open the localization file
1209 if(Lcl_ext_file == NULL){
1210 error_display(0, "Error opening externalization file! File likely does not exist or could not be found");
1214 // seek to the currently active language
1215 memset(language_string, 0, 128);
1216 strcpy(language_string, "#");
1217 if(!stricmp(DEFAULT_LANGUAGE, Lcl_languages[Lcl_current_lang].lang_name)){
1218 strcat(language_string, "default");
1220 strcat(language_string, Lcl_languages[Lcl_current_lang].lang_name);
1222 memset(line, 0, 1024);
1224 // reset seek variables and begin
1225 Lcl_pointer_count = 0;
1226 while(cfgets(line, 1024, Lcl_ext_file)){
1227 tok = strtok(line, " \n");
1232 // if the language matches, we're good to start parsing strings
1233 if(!stricmp(language_string, tok)){
1239 // if we didn't find the language specified, error
1240 if(found_start <= 0){
1241 error_display(0, "Could not find specified langauge in tstrings.tbl!\n");
1247 while(cfgets(line, 1024, Lcl_ext_file)){
1248 ret = lcl_ext_lookup_sub(line, NULL, -1);
1251 switch(ret & 0x0fffffff){
1257 // end of language found
1259 // mark one final pointer
1260 Lcl_pointers[Lcl_pointer_count++] = cftell(Lcl_ext_file) - strlen(line) - 1;
1265 // the only other case we care about is the beginning of a new id#
1267 if((string_count % LCL_GRANULARITY) == 0){
1268 // mark the pointer down
1269 Lcl_pointers[Lcl_pointer_count++] = cftell(Lcl_ext_file) - strlen(line) - 1;
1271 // if we're out of pointer slots
1272 if(Lcl_pointer_count >= LCL_MAX_POINTERS){
1273 error_display(0, "Out of pointer for tstrings.tbl lookup. Please increment LCL_MAX_POINTERS in localize.cpp");
1278 // increment string count
1283 // should never get here. we should always be exiting through case 3 (end of language section) of the above switch
1289 void lcl_get_language_name(char *lang_name)
1291 Assert(LCL_NUM_LANGUAGES == 3);
1293 strcpy(lang_name, Lcl_languages[Lcl_current_lang].lang_name);
1296 // converts german umlauted chars from ASCII to ANSI
1297 // so they appear in the launcher
1298 // how friggin lame is this
1299 // pass in a null terminated string, foo!
1300 // returns ptr to string you sent in
1301 char* lcl_fix_umlauts(char *str, int which_way)
1305 if (which_way == LCL_TO_ANSI) {
1306 // moving to ANSI charset
1307 // run thru string and perform appropriate conversions
1308 while (str[i] != '\0') {
1335 // beta-lookin thing that means "ss"
1343 // moving to ASCII charset
1344 // run thru string and perform appropriate conversions
1345 while (str[i] != '\0') {
1372 // beta-lookin thing that means "ss"
1384 // ------------------------------------------------------------------
1385 // lcl_translate_wep_name()
1387 // For displaying weapon names in german version
1388 // since we cant actually just change them outright.
1390 void lcl_translate_wep_name(char *name)
1392 if (!strcmp(name, "Morning Star")) {
1393 strcpy(name, "Morgenstern");
1394 } else if (!strcmp(name, "MorningStar")) {
1395 strcpy(name, "Morgenstern D");
1396 } else if (!strcmp(name, "UD-8 Kayser")) {
1397 strcpy(name, "Kayserstrahl");
1398 } else if (!strcmp(name, "UD-D Kayser")) {
1399 strcpy(name, "Kayserstrahl");
1403 // ------------------------------------------------------------------
1404 // lcl_translate_brief_icon_name()
1406 // For displaying ship names in german version
1407 // since we cant actually just change them outright.
1409 void lcl_translate_brief_icon_name(char *name)
1414 if (!stricmp(name, "Subspace Portal")) {
1415 strcpy(name, "Subraum Portal");
1417 } else if (!stricmp(name, "Alpha Wing")) {
1418 strcpy(name, "Alpha");
1420 } else if (!stricmp(name, "Beta Wing")) {
1421 strcpy(name, "Beta");
1423 } else if (!stricmp(name, "Zeta Wing")) {
1424 strcpy(name, "Zeta");
1426 } else if (!stricmp(name, "Capella Node")) {
1427 strcpy(name, "Capella");
1429 } else if (!stricmp(name, "Hostile")) {
1430 strcpy(name, "Gegner");
1432 } else if (!stricmp(name, "Hostile Craft")) {
1433 strcpy(name, "Gegner");
1435 } else if (!stricmp(name, "Rebel Wing")) {
1436 strcpy(name, "Rebellen");
1438 } else if (!stricmp(name, "Rebel Fleet")) {
1439 strcpy(name, "Rebellenflotte");
1441 } else if (!stricmp(name, "Sentry Gun")) {
1442 strcpy(name, "Gesch\x81tz");
1444 } else if (!stricmp(name, "Cargo")) {
1445 strcpy(name, "Fracht");
1447 } else if (!stricmp(name, "Knossos Device")) {
1448 strcpy(name, "Knossosger\x84t");
1450 } else if (!stricmp(name, "Support")) {
1451 strcpy(name, "Versorger");
1453 } else if (!stricmp(name, "Unknown")) {
1454 strcpy(name, "Unbekannt");
1456 } else if (!stricmp(name, "Instructor")) {
1457 strcpy(name, "Ausbilder");
1459 } else if (!stricmp(name, "Jump Node")) {
1460 strcpy(name, "Sprungknoten");
1462 } else if (!stricmp(name, "Escort")) {
1463 strcpy(name, "Geleitschutz");
1465 } else if (!stricmp(name, "Asteroid Field")) {
1466 strcpy(name, "Asteroidenfeld");
1468 } else if (!stricmp(name, "Enif Station")) {
1469 strcpy(name, "Station Enif");
1471 } else if (!stricmp(name, "Rally Point")) {
1472 strcpy(name, "Sammelpunkt");
1474 } else if ((pos = strstr(name, "Transport")) != NULL) {
1475 pos += 9; // strlen of "transport"
1476 strcpy(buf, "Transporter");
1480 } else if ((pos = strstr(name, "Jump Node")) != NULL) {
1481 pos += 9; // strlen of "jump node"
1482 strcpy(buf, "Sprungknoten");
1486 } else if (!stricmp(name, "Orion under repair")) {
1487 strcpy(name, "Orion wird repariert");
1489 // SOTY-specific ones below!
1491 } else if (!stricmp(name, "Wayfarer Station")) {
1492 strcpy(name, "Station Wayfarer");
1493 } else if (!stricmp(name, "Enemy")) {
1494 strcpy(name, "Gegner");
1495 } else if (!stricmp(name, "Supply Depot")) {
1496 strcpy(name, "Nachschubdepot");
1497 } else if (!stricmp(name, "Fighter Escort")) {
1498 strcpy(name, "Jagdschutz");
1499 } else if (!stricmp(name, "Shivans")) {
1500 strcpy(name, "Shivaner");
1501 } else if (!stricmp(name, "NTF Base of Operations")) {
1502 strcpy(name, "NTF-Operationsbasis");
1503 } else if (!stricmp(name, "NTF Bombers")) {
1504 strcpy(name, "NTF-Bomber");
1505 } else if (!stricmp(name, "NTF Fighters")) {
1506 strcpy(name, "NTF-J\x84ger");
1507 } else if (!stricmp(name, "Sentry")) {
1508 strcpy(name, "Sperrgesch\x81tz");
1509 } else if (!stricmp(name, "Cargo Containers")) {
1510 strcpy(name, "Frachtbeh\x84lter");
1511 } else if (!stricmp(name, "NTF Reinforcements")) {
1512 strcpy(name, "NTF-Verst\x84rkungen");
1513 } else if (!stricmp(name, "NTF Base")) {
1514 strcpy(name, "NTF-St\x81tzpunkt");
1515 } else if (!stricmp(name, "Refugee Convoy")) {
1516 strcpy(name, "Fl\x81""chtlingskonvoi");
1517 } else if (!stricmp(name, "Food Convoy")) {
1518 strcpy(name, "Nachschubkonvoi");
1519 } else if (!stricmp(name, "Governor's Shuttle")) {
1520 strcpy(name, "F\x84hre des Gouverneurs");
1521 } else if (!stricmp(name, "GTVA Patrol")) {
1522 strcpy(name, "GTVA-Patrouille");
1523 } else if (!stricmp(name, "Escort fighters")) {
1524 strcpy(name, "Geleitschutz");
1525 } else if (!stricmp(name, "Nagada Outpost")) {
1526 strcpy(name, "Nagada-Aussenposten");
1527 } else if (!stricmp(name, "Fighters")) {
1528 strcpy(name, "J\x84ger");
1529 } else if (!stricmp(name, "Bombers")) {
1530 strcpy(name, "Bomber");
1531 } else if (!stricmp(name, "Enemy Destroyers")) {
1532 strcpy(name, "Feindliche Zerst\x94rer");
1533 } else if (!stricmp(name, "Ross 128 System")) {
1534 strcpy(name, "System Ross 128");
1535 } else if (!stricmp(name, "Knossos Station")) {
1536 strcpy(name, "Knossos-Station");
1537 } else if (!stricmp(name, "Transporters")) {
1538 strcpy(name, "Transporter");
1539 } else if (!stricmp(name, "Pirates?")) {
1540 strcpy(name, "Piraten?");
1541 } else if (!stricmp(name, "Escorts")) {
1542 strcpy(name, "Geleitschutz");
1543 } else if (!stricmp(name, "Shivan Fighters")) {
1544 strcpy(name, "J\x84ger");
1545 } else if (!stricmp(name, "Shivan Territory")) {
1546 strcpy(name, "Shivaner");
1551 // ------------------------------------------------------------------
1552 // lcl_translate_ship_name()
1554 // For displaying ship names in german version in the briefing
1555 // since we cant actually just change them outright.
1557 void lcl_translate_ship_name(char *name)
1559 if (!strcmp(name, "GTDR Amazon Advanced")) {
1560 strcpy(name, "GTDR Amazon VII");
1564 // ------------------------------------------------------------------
1565 // lcl_translate_targetbox_name()
1567 // For displaying ship names in german version in the targetbox
1568 // since we cant actually just change them outright.
1570 void lcl_translate_targetbox_name(char *name)
1575 if ((pos = strstr(name, "Sentry")) != NULL) {
1576 pos += 6; // strlen of "sentry"
1577 strcpy(buf, "Sperrgesch\x81tz");
1581 } else if ((pos = strstr(name, "Support")) != NULL) {
1582 pos += 7; // strlen of "support"
1583 strcpy(buf, "Versorger");
1587 } else if ((pos = strstr(name, "Unknown")) != NULL) {
1588 pos += 7; // strlen of "unknown"
1589 strcpy(buf, "Unbekannt");
1593 } else if ((pos = strstr(name, "Drone")) != NULL) {
1594 pos += 5; // strlen of "drone"
1595 strcpy(buf, "Drohne");
1599 } else if ((pos = strstr(name, "Jump Node")) != NULL) {
1600 pos += 9; // strlen of "jump node"
1601 strcpy(buf, "Sprungknoten");
1605 } else if (!stricmp(name, "Instructor")) {
1606 strcpy(name, "Ausbilder");
1608 } else if (!stricmp(name, "NTF Vessel")) {
1609 strcpy(name, "NTF-Schiff");
1611 } else if (!stricmp(name, "Enif Station")) {
1612 strcpy(name, "Station Enif");