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

Function ReadMessageFile

scripts/merc5.cpp:1089–1154  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

1087
1088// Read in the Messages
1089int ReadMessageFile(const char *filename) {
1090 void *infile;
1091 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
1092 char *line, *msg_start;
1093 int line_num;
1094 bool next_msgid_found;
1095
1096 // Try to open the file for loading
1097 infile = File_Open(filename, "rt");
1098 if (!infile)
1099 return false;
1100
1101 line_num = 0;
1102 next_msgid_found = true;
1103
1104 // Clear the message list
1105 ClearMessageList();
1106
1107 // Read in and parse each line of the file
1108 while (!File_eof(infile)) {
1109
1110 // Clear the buffer
1111 strcpy(filebuffer, "");
1112
1113 // Read in a line from the file
1114 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
1115 line_num++;
1116
1117 // Remove whitespace padding at start and end of line
1118 RemoveTrailingWhitespace(filebuffer);
1119 line = SkipInitialWhitespace(filebuffer);
1120
1121 // If line is a comment, or empty, discard it
1122 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
1123 continue;
1124
1125 if (!next_msgid_found) { // Parse out the last message ID number
1126
1127 // Grab the first keyword, make sure it's valid
1128 line = strtok(line, WHITESPACE_CHARS);
1129 if (line == NULL)
1130 continue;
1131
1132 // Grab the second keyword, and assign it as the next message ID
1133 line = strtok(NULL, WHITESPACE_CHARS);
1134 if (line == NULL)
1135 continue;
1136
1137 next_msgid_found = true;
1138 } else { // Parse line as a message line
1139
1140 // Find the start of message, and mark it
1141 msg_start = strchr(line, '=');
1142 if (msg_start == NULL)
1143 continue;
1144 msg_start[0] = '\0';
1145 msg_start++;
1146

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