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

Function ReadMessageFile

scripts/LEVEL15.cpp:1541–1606  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

1539
1540// Read in the Messages
1541int ReadMessageFile(const char *filename) {
1542 void *infile;
1543 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
1544 char *line, *msg_start;
1545 int line_num;
1546 bool next_msgid_found;
1547
1548 // Try to open the file for loading
1549 infile = File_Open(filename, "rt");
1550 if (!infile)
1551 return false;
1552
1553 line_num = 0;
1554 next_msgid_found = true;
1555
1556 // Clear the message list
1557 ClearMessageList();
1558
1559 // Read in and parse each line of the file
1560 while (!File_eof(infile)) {
1561
1562 // Clear the buffer
1563 strcpy(filebuffer, "");
1564
1565 // Read in a line from the file
1566 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
1567 line_num++;
1568
1569 // Remove whitespace padding at start and end of line
1570 RemoveTrailingWhitespace(filebuffer);
1571 line = SkipInitialWhitespace(filebuffer);
1572
1573 // If line is a comment, or empty, discard it
1574 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
1575 continue;
1576
1577 if (!next_msgid_found) { // Parse out the last message ID number
1578
1579 // Grab the first keyword, make sure it's valid
1580 line = strtok(line, WHITESPACE_CHARS);
1581 if (line == NULL)
1582 continue;
1583
1584 // Grab the second keyword, and assign it as the next message ID
1585 line = strtok(NULL, WHITESPACE_CHARS);
1586 if (line == NULL)
1587 continue;
1588
1589 next_msgid_found = true;
1590 } else { // Parse line as a message line
1591
1592 // Find the start of message, and mark it
1593 msg_start = strchr(line, '=');
1594 if (msg_start == NULL)
1595 continue;
1596 msg_start[0] = '\0';
1597 msg_start++;
1598

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