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

Function ReadMessageFile

scripts/CellTestLevel.cpp:204–269  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

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

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