MCPcopy Create free account
hub / github.com/GJDuck/e9patch / parseAddrs

Function parseAddrs

src/e9tool/e9csv.cpp:289–322  ·  view source on GitHub ↗

* Specialized parser for lists of addresses. */

Source from the content-addressed store, hash-verified

287 * Specialized parser for lists of addresses.
288 */
289void parseAddrs(const char *filename, std::vector<intptr_t> &As)
290{
291 FILE *stream = fopen(filename, "r");
292 if (stream == nullptr)
293 error("failed to open CSV file \"%s\" for reading: %s",
294 filename, strerror(errno));
295
296 Record record;
297 CSV csv = {stream, filename, -1, 0};
298 for (size_t i = 0; ; i++)
299 {
300 if (!parseRecord(csv, record))
301 break;
302 if ((unsigned)record.size() < 1)
303 error("failed to parse CSV file \"%s\" at line %u; record with "
304 "empty length", csv.filename, csv.lineno);
305 MatchVal &addr = record[0];
306 if (addr.type != MATCH_TYPE_INTEGER)
307 {
308 record.clear();
309 if (i == 0)
310 continue; // Skip presumed header
311 error("failed to parse CSV file \"%s\" at line %u; first record "
312 "entry must be an address", csv.filename, csv.lineno);
313 }
314 As.push_back(addr.i);
315 record.clear();
316 }
317
318 fclose(stream);
319 std::sort(As.begin(), As.end());
320 std::unique(As.begin(), As.end());
321 As.shrink_to_fit();
322}
323
324/*
325 * Specialized parser for targets.

Callers 1

main_2Function · 0.85

Calls 8

fopenFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85
parseRecordFunction · 0.85
fcloseFunction · 0.85
beginMethod · 0.80
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected