| 12 | } |
| 13 | |
| 14 | BRD2File::BRD2File(std::vector<char> &buf) { |
| 15 | auto buffer_size = buf.size(); |
| 16 | std::unordered_map<int, char *> nets; // Map between net id and net name |
| 17 | unsigned int num_nets = 0; |
| 18 | BRDPoint max{0, 0}; // Top-right board boundary |
| 19 | |
| 20 | ENSURE_OR_FAIL(buffer_size > 4, error_msg, return); |
| 21 | size_t file_buf_size = 3 * (1 + buffer_size); |
| 22 | file_buf = (char *)calloc(1, file_buf_size); |
| 23 | ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return); |
| 24 | |
| 25 | std::copy(buf.begin(), buf.end(), file_buf); |
| 26 | file_buf[buffer_size] = 0; |
| 27 | // This is for fixing degenerate utf8 |
| 28 | char *arena = &file_buf[buffer_size + 1]; |
| 29 | char *arena_end = file_buf + file_buf_size - 1; |
| 30 | *arena_end = 0; |
| 31 | |
| 32 | int current_block = 0; |
| 33 | |
| 34 | std::vector<char *> lines; |
| 35 | stringfile(file_buf, lines); |
| 36 | |
| 37 | for (char *line : lines) { |
| 38 | while (isspace((uint8_t)*line)) line++; |
| 39 | if (!line[0]) continue; |
| 40 | |
| 41 | char *p = line; |
| 42 | char *s; |
| 43 | |
| 44 | if (strstr(line, "BRDOUT:") == line) { |
| 45 | current_block = 1; |
| 46 | p += 7; // Skip "BRDOUT:" |
| 47 | num_format = READ_UINT(); |
| 48 | max.x = READ_INT(); |
| 49 | max.y = READ_INT(); |
| 50 | continue; |
| 51 | } |
| 52 | if (strstr(line, "NETS:") == line) { |
| 53 | current_block = 2; |
| 54 | p += 5; // Skip "NETS:" |
| 55 | num_nets = READ_UINT(); |
| 56 | continue; |
| 57 | } |
| 58 | if (strstr(line, "PARTS:") == line) { |
| 59 | current_block = 3; |
| 60 | p += 6; // Skip "PARTS:" |
| 61 | num_parts = READ_UINT(); |
| 62 | continue; |
| 63 | } |
| 64 | if (strstr(line, "PINS:") == line) { |
| 65 | current_block = 4; |
| 66 | p += 5; // Skip "PINS:" |
| 67 | num_pins = READ_UINT(); |
| 68 | continue; |
| 69 | } |
| 70 | if (strstr(line, "NAILS:") == line) { |
| 71 | current_block = 5; |
nothing calls this directly
no test coverage detected