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

Function ReadMessageFile

scripts/level13.cpp:1393–1458  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

1391
1392// Read in the Messages
1393int ReadMessageFile(const char *filename) {
1394 void *infile;
1395 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
1396 char *line, *msg_start;
1397 int line_num;
1398 bool next_msgid_found;
1399
1400 // Try to open the file for loading
1401 infile = File_Open(filename, "rt");
1402 if (!infile)
1403 return false;
1404
1405 line_num = 0;
1406 next_msgid_found = true;
1407
1408 // Clear the message list
1409 ClearMessageList();
1410
1411 // Read in and parse each line of the file
1412 while (!File_eof(infile)) {
1413
1414 // Clear the buffer
1415 strcpy(filebuffer, "");
1416
1417 // Read in a line from the file
1418 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
1419 line_num++;
1420
1421 // Remove whitespace padding at start and end of line
1422 RemoveTrailingWhitespace(filebuffer);
1423 line = SkipInitialWhitespace(filebuffer);
1424
1425 // If line is a comment, or empty, discard it
1426 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
1427 continue;
1428
1429 if (!next_msgid_found) { // Parse out the last message ID number
1430
1431 // Grab the first keyword, make sure it's valid
1432 line = strtok(line, WHITESPACE_CHARS);
1433 if (line == NULL)
1434 continue;
1435
1436 // Grab the second keyword, and assign it as the next message ID
1437 line = strtok(NULL, WHITESPACE_CHARS);
1438 if (line == NULL)
1439 continue;
1440
1441 next_msgid_found = true;
1442 } else { // Parse line as a message line
1443
1444 // Find the start of message, and mark it
1445 msg_start = strchr(line, '=');
1446 if (msg_start == NULL)
1447 continue;
1448 msg_start[0] = '\0';
1449 msg_start++;
1450

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