Read in the Messages
| 212 | |
| 213 | // Read in the Messages |
| 214 | int ReadMessageFile(const char *filename) { |
| 215 | void *infile; |
| 216 | char filebuffer[MAX_MSG_FILEBUF_LEN + 1]; |
| 217 | char *line, *msg_start; |
| 218 | int line_num; |
| 219 | bool next_msgid_found; |
| 220 | |
| 221 | // Try to open the file for loading |
| 222 | infile = File_Open(filename, "rt"); |
| 223 | if (!infile) |
| 224 | return false; |
| 225 | |
| 226 | line_num = 0; |
| 227 | next_msgid_found = true; |
| 228 | |
| 229 | // Clear the message list |
| 230 | ClearMessageList(); |
| 231 | |
| 232 | // Read in and parse each line of the file |
| 233 | while (!File_eof(infile)) { |
| 234 | |
| 235 | // Clear the buffer |
| 236 | strcpy(filebuffer, ""); |
| 237 | |
| 238 | // Read in a line from the file |
| 239 | File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile); |
| 240 | line_num++; |
| 241 | |
| 242 | // Remove whitespace padding at start and end of line |
| 243 | RemoveTrailingWhitespace(filebuffer); |
| 244 | line = SkipInitialWhitespace(filebuffer); |
| 245 | |
| 246 | // If line is a comment, or empty, discard it |
| 247 | if (strlen(line) == 0 || strncmp(line, "//", 2) == 0) |
| 248 | continue; |
| 249 | |
| 250 | if (!next_msgid_found) { // Parse out the last message ID number |
| 251 | |
| 252 | // Grab the first keyword, make sure it's valid |
| 253 | line = strtok(line, WHITESPACE_CHARS); |
| 254 | if (line == NULL) |
| 255 | continue; |
| 256 | |
| 257 | // Grab the second keyword, and assign it as the next message ID |
| 258 | line = strtok(NULL, WHITESPACE_CHARS); |
| 259 | if (line == NULL) |
| 260 | continue; |
| 261 | |
| 262 | next_msgid_found = true; |
| 263 | } else { // Parse line as a message line |
| 264 | |
| 265 | // Find the start of message, and mark it |
| 266 | msg_start = strchr(line, '='); |
| 267 | if (msg_start == NULL) |
| 268 | continue; |
| 269 | msg_start[0] = '\0'; |
| 270 | msg_start++; |
| 271 |
no test coverage detected