| 18 | } |
| 19 | |
| 20 | BVR3File::BVR3File(std::vector<char> &buf) { |
| 21 | auto buffer_size = buf.size(); |
| 22 | |
| 23 | char *saved_locale = setlocale(LC_NUMERIC, "C"); // Use '.' as delimiter for strtod |
| 24 | |
| 25 | ENSURE_OR_FAIL(buffer_size > 4, error_msg, return); |
| 26 | size_t file_buf_size = 3 * (1 + buffer_size); |
| 27 | file_buf = (char *)calloc(1, file_buf_size); |
| 28 | ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return); |
| 29 | |
| 30 | std::copy(buf.begin(), buf.end(), file_buf); |
| 31 | file_buf[buffer_size] = 0; |
| 32 | // This is for fixing degenerate utf8 |
| 33 | char *arena = &file_buf[buffer_size + 1]; |
| 34 | char *arena_end = file_buf + file_buf_size - 1; |
| 35 | *arena_end = 0; |
| 36 | |
| 37 | BRDPin blank_pin; |
| 38 | BVR3Part part; |
| 39 | BRDPin pin; |
| 40 | std::list<std::pair<BRDPoint, BRDPoint>> outline_segments; |
| 41 | |
| 42 | std::vector<char *> lines; |
| 43 | stringfile(file_buf, lines); |
| 44 | |
| 45 | for (char *line : lines) { |
| 46 | while (isspace((uint8_t)*line)) line++; |
| 47 | if (!line[0]) continue; |
| 48 | |
| 49 | char *p = line; |
| 50 | char *s; |
| 51 | |
| 52 | if (!strncmp(line, "PART_NAME ", 10)) { |
| 53 | p += 10; |
| 54 | part.name = READ_STR(); |
| 55 | } else if (!strncmp(line, "PART_SIDE ", 10)) { |
| 56 | p += 10; |
| 57 | char *side = READ_STR(); |
| 58 | if (!strcmp(side, "T")) |
| 59 | part.mounting_side = BRDPartMountingSide::Top; |
| 60 | else if (!strcmp(side, "B")) |
| 61 | part.mounting_side = BRDPartMountingSide::Bottom; |
| 62 | else if (!strcmp(side, "O")) |
| 63 | part.mounting_side = BRDPartMountingSide::Both; |
| 64 | } else if (!strncmp(line, "PART_ORIGIN ", 12)) { |
| 65 | p += 12; |
| 66 | double origin_x = READ_DOUBLE(); |
| 67 | part.pos.x = trunc(origin_x); |
| 68 | double origin_y = READ_DOUBLE(); |
| 69 | part.pos.y = trunc(origin_y); |
| 70 | } else if (!strncmp(line, "PART_MOUNT ", 11)) { |
| 71 | p += 11; |
| 72 | char *mount = READ_STR(); |
| 73 | if (!strcmp(mount, "SMD")) |
| 74 | part.part_type = BRDPartType::SMD; |
| 75 | else |
| 76 | part.part_type = BRDPartType::ThroughHole; |
| 77 | } else if (!strncmp(line, "PART_OUTLINE_RELATIVE ", 22)) { |
nothing calls this directly
no test coverage detected