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

Function ReadFullLine

Descent3/BriefingParse.cpp:230–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228 } while (0)
229
230static int ReadFullLine(char **data, CFILE *ifile) {
231 int counter, readin;
232 char buffer[512];
233 bool done;
234
235 counter = 0;
236 done = false;
237 readin = 0;
238 *data = NULL;
239 char c;
240
241 while (!done) {
242
243 // read in a byte
244 c = cfgetc(ifile);
245
246 if ((c == EOF) || (!(ifile->flags & CFF_TEXT) && (c == 0)) || ((ifile->flags & CFF_TEXT) && (c == '\n'))) {
247 // we've hit the end of the line
248 done = true;
249 } else {
250 buffer[readin] = c;
251 readin++;
252 }
253
254 // check if we have a full temp buffer
255 if (readin == sizeof(buffer)) {
256 // we have a full temp buffer
257 char *temp_buffer;
258 temp_buffer = (char *)mem_malloc(counter + sizeof(buffer)); // allocate another buffer full
259 if (*data) {
260 // copy over existing data
261 memcpy(temp_buffer, *data, counter);
262 // free it
263 mem_free(*data);
264 }
265 // copy over new data
266 memcpy(&temp_buffer[counter], buffer, sizeof(buffer));
267
268 // reset our buffer for the temp buffer
269 counter += readin;
270 readin = 0;
271
272 *data = temp_buffer;
273 }
274 }
275
276 // append all the data thats in the tempbuffer into the final buffer
277 char *temp_buffer;
278 temp_buffer = (char *)mem_malloc(counter + readin + 1); // allocate what we need (plus for NULL term)
279 if (*data) {
280 // copy over existing data
281 memcpy(temp_buffer, *data, counter);
282 // free it
283 mem_free(*data);
284 }
285 // copy over new data
286 memcpy(&temp_buffer[counter], buffer, readin);
287

Callers 1

ParseBriefingMethod · 0.85

Calls 1

cfgetcFunction · 0.85

Tested by

no test coverage detected