Read in the Messages
| 289 | |
| 290 | // Read in the Messages |
| 291 | int ReadMessageFile(const char *filename) { |
| 292 | void *infile; |
| 293 | char filebuffer[MAX_MSG_FILEBUF_LEN + 1]; |
| 294 | char *line, *msg_start; |
| 295 | int line_num; |
| 296 | bool next_msgid_found; |
| 297 | |
| 298 | // Try to open the file for loading |
| 299 | infile = File_Open(filename, "rt"); |
| 300 | if (!infile) |
| 301 | return false; |
| 302 | |
| 303 | line_num = 0; |
| 304 | next_msgid_found = true; |
| 305 | |
| 306 | // Clear the message list |
| 307 | ClearMessageList(); |
| 308 | |
| 309 | // Read in and parse each line of the file |
| 310 | while (!File_eof(infile)) { |
| 311 | |
| 312 | // Clear the buffer |
| 313 | strcpy(filebuffer, ""); |
| 314 | |
| 315 | // Read in a line from the file |
| 316 | File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile); |
| 317 | line_num++; |
| 318 | |
| 319 | // Remove whitespace padding at start and end of line |
| 320 | RemoveTrailingWhitespace(filebuffer); |
| 321 | line = SkipInitialWhitespace(filebuffer); |
| 322 | |
| 323 | // If line is a comment, or empty, discard it |
| 324 | if (strlen(line) == 0 || strncmp(line, "//", 2) == 0) |
| 325 | continue; |
| 326 | |
| 327 | if (!next_msgid_found) { // Parse out the last message ID number |
| 328 | |
| 329 | // Grab the first keyword, make sure it's valid |
| 330 | line = strtok(line, WHITESPACE_CHARS); |
| 331 | if (line == NULL) |
| 332 | continue; |
| 333 | |
| 334 | // Grab the second keyword, and assign it as the next message ID |
| 335 | line = strtok(NULL, WHITESPACE_CHARS); |
| 336 | if (line == NULL) |
| 337 | continue; |
| 338 | |
| 339 | next_msgid_found = true; |
| 340 | } else { // Parse line as a message line |
| 341 | |
| 342 | // Find the start of message, and mark it |
| 343 | msg_start = strchr(line, '='); |
| 344 | if (msg_start == NULL) |
| 345 | continue; |
| 346 | msg_start[0] = '\0'; |
| 347 | msg_start++; |
| 348 |
no test coverage detected