Given a filename, pointer to a char * array and a pointer to an int, it will load the string table and fill in the information returns true on success
| 262 | // it will load the string table and fill in the information |
| 263 | // returns true on success |
| 264 | bool CreateStringTable(const char *filename, char ***table, int *size) { |
| 265 | ASSERT(filename); |
| 266 | ASSERT(Localization_language != -1); |
| 267 | if (!filename) { |
| 268 | if (table) |
| 269 | *table = NULL; |
| 270 | if (size) |
| 271 | *size = 0; |
| 272 | return false; |
| 273 | } |
| 274 | CFILE *file; |
| 275 | |
| 276 | char fname[_MAX_PATH]; |
| 277 | FixFilenameCase(filename, fname); |
| 278 | file = cfopen(fname, "rt"); |
| 279 | if (!file) { |
| 280 | if (table) |
| 281 | *table = NULL; |
| 282 | if (size) |
| 283 | *size = 0; |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | int old_language, scount; |
| 288 | char tempbuffer[MAX_STRING_LENGTH]; |
| 289 | |
| 290 | old_language = Localization_language; |
| 291 | |
| 292 | try_english: |
| 293 | |
| 294 | // first found out how many strings total in the file |
| 295 | scount = 0; |
| 296 | |
| 297 | while (!cfeof(file)) { |
| 298 | cf_ReadString(tempbuffer, MAX_LINE_LENGTH + 1, file); |
| 299 | if (_parse_line_information(tempbuffer) == Localization_language) |
| 300 | scount++; |
| 301 | } |
| 302 | cfclose(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_language != LANGUAGE_ENGLISH) { |
| 308 | Localization_language = LANGUAGE_ENGLISH; |
| 309 | // open the file again |
| 310 | file = cfopen(fname, "rt"); |
| 311 | goto try_english; |
| 312 | } |
| 313 | |
| 314 | // no strings found |
| 315 | Localization_language = old_language; |
| 316 | mprintf(0, "Localization: Warning, 0 strings found in %s\n", filename); |
| 317 | *table = NULL; |
| 318 | *size = 0; |
| 319 | return true; |
| 320 | } |
| 321 |
no test coverage detected