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

Function ReadMessageFile

scripts/barney.cpp:202–267  ·  view source on GitHub ↗

Read in the Messages

Source from the content-addressed store, hash-verified

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

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