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

Function ReadMessageFile

scripts/ChrisTest.cpp:229–294  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

227
228// Read in the Messages
229int ReadMessageFile(const char *filename) {
230 void *infile;
231 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
232 char *line, *msg_start;
233 int line_num;
234 bool next_msgid_found;
235
236 // Try to open the file for loading
237 infile = File_Open(filename, "rt");
238 if (!infile)
239 return false;
240
241 line_num = 0;
242 next_msgid_found = true;
243
244 // Clear the message list
245 ClearMessageList();
246
247 // Read in and parse each line of the file
248 while (!File_eof(infile)) {
249
250 // Clear the buffer
251 strcpy(filebuffer, "");
252
253 // Read in a line from the file
254 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
255 line_num++;
256
257 // Remove whitespace padding at start and end of line
258 RemoveTrailingWhitespace(filebuffer);
259 line = SkipInitialWhitespace(filebuffer);
260
261 // If line is a comment, or empty, discard it
262 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
263 continue;
264
265 if (!next_msgid_found) { // Parse out the last message ID number
266
267 // Grab the first keyword, make sure it's valid
268 line = strtok(line, WHITESPACE_CHARS);
269 if (line == NULL)
270 continue;
271
272 // Grab the second keyword, and assign it as the next message ID
273 line = strtok(NULL, WHITESPACE_CHARS);
274 if (line == NULL)
275 continue;
276
277 next_msgid_found = true;
278 } else { // Parse line as a message line
279
280 // Find the start of message, and mark it
281 msg_start = strchr(line, '=');
282 if (msg_start == NULL)
283 continue;
284 msg_start[0] = '\0';
285 msg_start++;
286

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