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

Function ReadMessageFile

scripts/myPowerHouse.cpp:211–276  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

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

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