MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ReadMessageFile

Function ReadMessageFile

scripts/Geodomes.cpp:255–320  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

253
254// Read in the Messages
255int ReadMessageFile(const char *filename) {
256 void *infile;
257 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
258 char *line, *msg_start;
259 int line_num;
260 bool next_msgid_found;
261
262 // Try to open the file for loading
263 infile = File_Open(filename, "rt");
264 if (!infile)
265 return false;
266
267 line_num = 0;
268 next_msgid_found = true;
269
270 // Clear the message list
271 ClearMessageList();
272
273 // Read in and parse each line of the file
274 while (!File_eof(infile)) {
275
276 // Clear the buffer
277 strcpy(filebuffer, "");
278
279 // Read in a line from the file
280 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
281 line_num++;
282
283 // Remove whitespace padding at start and end of line
284 RemoveTrailingWhitespace(filebuffer);
285 line = SkipInitialWhitespace(filebuffer);
286
287 // If line is a comment, or empty, discard it
288 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
289 continue;
290
291 if (!next_msgid_found) { // Parse out the last message ID number
292
293 // Grab the first keyword, make sure it's valid
294 line = strtok(line, WHITESPACE_CHARS);
295 if (line == NULL)
296 continue;
297
298 // Grab the second keyword, and assign it as the next message ID
299 line = strtok(NULL, WHITESPACE_CHARS);
300 if (line == NULL)
301 continue;
302
303 next_msgid_found = true;
304 } else { // Parse line as a message line
305
306 // Find the start of message, and mark it
307 msg_start = strchr(line, '=');
308 if (msg_start == NULL)
309 continue;
310 msg_start[0] = '\0';
311 msg_start++;
312

Callers 1

InitializeDLLFunction · 0.70

Calls 4

ClearMessageListFunction · 0.70
RemoveTrailingWhitespaceFunction · 0.70
SkipInitialWhitespaceFunction · 0.70
AddMessageToListFunction · 0.70

Tested by

no test coverage detected