equal
deleted
inserted
replaced
18 #include "macros.h" |
18 #include "macros.h" |
19 #include "table/strings.h" |
19 #include "table/strings.h" |
20 #include "newgrf.h" |
20 #include "newgrf.h" |
21 #include "newgrf_text.h" |
21 #include "newgrf_text.h" |
22 #include "table/control_codes.h" |
22 #include "table/control_codes.h" |
|
23 #include "helpers.hpp" |
23 |
24 |
24 #define GRFTAB 28 |
25 #define GRFTAB 28 |
25 #define TABSIZE 11 |
26 #define TABSIZE 11 |
26 |
27 |
27 /** |
28 /** |
155 static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used. |
156 static byte _currentLangID = GRFLX_ENGLISH; //by default, english is used. |
156 |
157 |
157 |
158 |
158 char *TranslateTTDPatchCodes(const char *str) |
159 char *TranslateTTDPatchCodes(const char *str) |
159 { |
160 { |
160 char *tmp = malloc(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */ |
161 char *tmp; |
|
162 MallocT(&tmp, strlen(str) * 10 + 1); /* Allocate space to allow for expansion */ |
161 char *d = tmp; |
163 char *d = tmp; |
162 bool unicode = false; |
164 bool unicode = false; |
163 WChar c; |
165 WChar c; |
164 size_t len = Utf8Decode(&c, str); |
166 size_t len = Utf8Decode(&c, str); |
165 |
167 |
251 break; |
253 break; |
252 } |
254 } |
253 } |
255 } |
254 |
256 |
255 *d = '\0'; |
257 *d = '\0'; |
256 return realloc(tmp, strlen(tmp) + 1); |
258 ReallocT(&tmp, strlen(tmp) + 1); |
|
259 return tmp; |
257 } |
260 } |
258 |
261 |
259 |
262 |
260 /** |
263 /** |
261 * Add the new read string into our structure. |
264 * Add the new read string into our structure. |
293 /* Too many strings allocated, return empty */ |
296 /* Too many strings allocated, return empty */ |
294 if (id == lengthof(_grf_text)) return STR_EMPTY; |
297 if (id == lengthof(_grf_text)) return STR_EMPTY; |
295 |
298 |
296 translatedtext = TranslateTTDPatchCodes(text_to_add); |
299 translatedtext = TranslateTTDPatchCodes(text_to_add); |
297 |
300 |
298 newtext = malloc(sizeof(*newtext) + strlen(translatedtext) + 1); |
301 newtext = (GRFText*)malloc(sizeof(*newtext) + strlen(translatedtext) + 1); |
299 newtext->next = NULL; |
302 newtext->next = NULL; |
300 newtext->langid = langid_to_add; |
303 newtext->langid = langid_to_add; |
301 strcpy(newtext->text, translatedtext); |
304 strcpy(newtext->text, translatedtext); |
302 |
305 |
303 free(translatedtext); |
306 free(translatedtext); |