* Specialized parser for lists of addresses. */
| 287 | * Specialized parser for lists of addresses. |
| 288 | */ |
| 289 | void 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. |