MCPcopy Create free account
hub / github.com/OpenBoardView/OpenBoardView / BVRFile

Method BVRFile

src/openboardview/FileFormats/BVRFile.cpp:24–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24BVRFile::BVRFile(std::vector<char> &buf) {
25 auto buffer_size = buf.size();
26
27 char *saved_locale;
28 char ppn[100] = {0}; // previous part name
29 saved_locale = setlocale(LC_NUMERIC, "C"); // Use '.' as delimiter for strtod
30
31 ENSURE_OR_FAIL(buffer_size > 4, error_msg, return);
32 size_t file_buf_size = 3 * (1 + buffer_size);
33 file_buf = (char *)calloc(1, file_buf_size);
34 ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return);
35
36 std::copy(buf.begin(), buf.end(), file_buf);
37 file_buf[buffer_size] = 0;
38 // This is for fixing degenerate utf8
39 char *arena = &file_buf[buffer_size + 1];
40 char *arena_end = file_buf + file_buf_size - 1;
41 *arena_end = 0;
42
43 int current_block = 0;
44
45 std::vector<char *> lines;
46 stringfile(file_buf, lines);
47
48 std::vector<char *>::iterator line_it = lines.begin();
49 while (line_it < lines.end()) {
50 char *line = *line_it;
51 ++line_it;
52
53 while (isspace((uint8_t)*line)) line++;
54 if (!line[0]) continue;
55
56 if (!strcmp(line, "<<Layout>>")) {
57 // fprintf(stderr,"HIT LAYOUT\n");
58 current_block = 1;
59 line_it += 1; // Skip 1 unused lines before 1st layout
60 continue;
61 }
62 if (!strcmp(line, "<<Pin>>")) {
63 current_block = 2;
64 // fprintf(stderr,"HIT PIN, block = %d\n", current_block);
65 line_it += 1; // Skip 1 unused lines before 1st pin
66 continue;
67 }
68 if (!strcmp(line, "<<Nail>>")) {
69 // fprintf(stderr,"HIT NAIL\n");
70 current_block = 3;
71 line_it += 1; // Skip 1 unused lines before 1st nail
72 continue;
73 }
74
75 char *p = line;
76 char *s;
77
78 switch (current_block) {
79 case 1: { // Format
80 BRDPoint point;
81 double x = READ_DOUBLE();

Callers

nothing calls this directly

Calls 2

stringfileFunction · 0.85
nextfieldFunction · 0.85

Tested by

no test coverage detected