changeset 8445:cfc312cfe346 draft

(svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
author peter1138 <peter1138@openttd.org>
date Tue, 29 Jan 2008 17:09:00 +0000
parents 370882fad6c6
children 4abab4c394c2
files src/newgrf_text.cpp src/newgrf_text.h src/strings.cpp src/strings_func.h
diffstat 4 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -405,7 +405,7 @@
 }
 
 
-char *GetGRFString(char *buff, uint16 stringid, const char* last)
+const char *GetGRFStringPtr(uint16 stringid)
 {
 	const GRFText *default_text = NULL;
 	const GRFText *search_text;
@@ -418,7 +418,7 @@
 	/*Search the list of lang-strings of this stringid for current lang */
 	for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
 		if (search_text->langid == _currentLangID) {
-			return strecpy(buff, search_text->text, last);
+			return search_text->text;
 		}
 
 		/* If the current string is English or American, set it as the
@@ -429,10 +429,10 @@
 	}
 
 	/* If there is a fallback string, return that */
-	if (default_text != NULL) return strecpy(buff, default_text->text, last);
+	if (default_text != NULL) return default_text->text;
 
 	/* Use the default string ID if the fallback string isn't available */
-	return GetString(buff, _grf_text[stringid].def_string, last);
+	return GetStringPtr(_grf_text[stringid].def_string);
 }
 
 /**
--- a/src/newgrf_text.h
+++ b/src/newgrf_text.h
@@ -8,7 +8,7 @@
 
 StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add, StringID def_string);
 StringID GetGRFStringID(uint32 grfid, uint16 stringid);
-char *GetGRFString(char *buff, uint16 stringid, const char* last);
+const char *GetGRFStringPtr(uint16 stringid);
 void CleanUpStrings();
 void SetCurrentGrfLangID(const char *iso_name);
 char *TranslateTTDPatchCodes(const char *str);
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -104,9 +104,14 @@
  * the indices will be reused. */
 static int _bind_index;
 
-static const char *GetStringPtr(StringID string)
+const char *GetStringPtr(StringID string)
 {
-	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
+	switch (GB(string, 11, 5)) {
+		case 28: return GetGRFStringPtr(GB(string, 0, 11));
+		case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
+		case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
+		default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
+	}
 }
 
 /** The highest 8 bits of string contain the "case index".
@@ -125,7 +130,6 @@
 
 	uint index = GB(string,  0, 11);
 	uint tab   = GB(string, 11,  5);
-	char buff[512];
 
 	switch (tab) {
 		case 4:
@@ -139,7 +143,8 @@
 			break;
 
 		case 15:
-			error("Boo!");
+			/* Old table for custom names. This is no longer used */
+			error("Incorrect conversion of custom name string.");
 
 		case 26:
 			/* Include string within newgrf text (format code 81) */
@@ -150,16 +155,13 @@
 			break;
 
 		case 28:
-			GetGRFString(buff, index, lastof(buff));
-			return FormatString(buffr, buff, argv, 0, last);
+			return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last);
 
 		case 29:
-			GetGRFString(buff, index + 0x800, lastof(buff));
-			return FormatString(buffr, buff, argv, 0, last);
+			return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last);
 
 		case 30:
-			GetGRFString(buff, index + 0x1000, lastof(buff));
-			return FormatString(buffr, buff, argv, 0, last);
+			return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last);
 
 		case 31:
 			/* dynamic strings. These are NOT to be passed through the formatter,
@@ -695,8 +697,7 @@
 			}
 
 			case SCC_GENDER_LIST: { // {G 0 Der Die Das}
-				char buffr[512];
-				const char *s = GetStringWithArgs(buffr, argv_orig[(byte)*str++], argv, last); // contains the string that determines gender.
+				const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
 				int len;
 				int gender = 0;
 				if (s != NULL) {
--- a/src/strings_func.h
+++ b/src/strings_func.h
@@ -9,6 +9,7 @@
 
 char *InlineString(char *buf, StringID string);
 char *GetString(char *buffr, StringID string, const char *last);
+const char *GetStringPtr(StringID string);
 
 extern char _userstring[128];