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

Method BRDFile

src/openboardview/FileFormats/BRDFile.cpp:26–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26BRDFile::BRDFile(std::vector<char> &buf) {
27 auto buffer_size = buf.size();
28 ENSURE_OR_FAIL(buffer_size > 4, error_msg, return);
29 size_t file_buf_size = 3 * (1 + buffer_size);
30 file_buf = (char *)calloc(1, file_buf_size);
31 ENSURE_OR_FAIL(file_buf != nullptr, error_msg, return);
32
33 std::copy(buf.begin(), buf.end(), file_buf);
34 file_buf[buffer_size] = 0;
35 // This is for fixing degenerate utf8
36 char *arena = &file_buf[buffer_size + 1];
37 char *arena_end = file_buf + file_buf_size - 1;
38 *arena_end = 0;
39
40 // decode the file if it appears to be encoded:
41 static const uint8_t encoded_header[] = {0x23, 0xe2, 0x63, 0x28};
42 if (!memcmp(file_buf, encoded_header, 4)) {
43 for (size_t i = 0; i < buffer_size; i++) {
44 char x = file_buf[i];
45 if (!(x == '\r' || x == '\n' || !x)) {
46 int c = x;
47 x = ~(((c >> 6) & 3) | (c << 2));
48 }
49 file_buf[i] = x;
50 }
51 }
52
53 int current_block = 0;
54 std::vector<char*> lines;
55 stringfile(file_buf, lines);
56
57 for (char *line : lines) {
58 while (isspace((uint8_t)*line)) line++;
59 if (!line[0]) continue;
60 if (!strcmp(line, "str_length:")) {
61 current_block = 1;
62 continue;
63 }
64 if (!strcmp(line, "var_data:")) {
65 current_block = 2;
66 continue;
67 }
68 if (!strcmp(line, "Format:") || !strcmp(line, "format:")) {
69 current_block = 3;
70 continue;
71 }
72 if (!strcmp(line, "Parts:") || !strcmp(line, "Pins1:")) {
73 current_block = 4;
74 continue;
75 }
76 if (!strcmp(line, "Pins:") || !strcmp(line, "Pins2:")) {
77 current_block = 5;
78 continue;
79 }
80 if (!strcmp(line, "Nails:")) {
81 current_block = 6;
82 continue;
83 }

Callers

nothing calls this directly

Calls 1

stringfileFunction · 0.85

Tested by

no test coverage detected