Debian Codegraph @

src/LibBGCode/binarize/meatpack.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/src/LibBGCode/binarize/meatpack.cpp`/include "meatpack.hpp"cxx . . $ `<file>/src/LibBGCode/binarize/meatpack.hpp`/
2
3 #include <unordered_map>
4 #include <algorithm>
5 #include <cassert>
6
7 namespace MeatPackcxx . . $ MeatPack/ {
8
9 static constexpr const uint8_tcxx . . $ uint8_t# Command_Nonecxx . . $ MeatPack/Command_None.{ 0 };
10 //#Command_TogglePacking = 253 -- Currently unused, byte 253 can be reused later.
11 static constexpr const uint8_tcxx . . $ uint8_t# Command_EnablePackingcxx . . $ MeatPack/Command_EnablePacking.{ 251 };
12 static constexpr const uint8_tcxx . . $ uint8_t# Command_DisablePackingcxx . . $ MeatPack/Command_DisablePacking.{ 250 };
13 static constexpr const uint8_tcxx . . $ uint8_t# Command_ResetAllcxx . . $ MeatPack/Command_ResetAll.{ 249 };
14 static constexpr const uint8_tcxx . . $ uint8_t# Command_QueryConfigcxx . . $ MeatPack/Command_QueryConfig.{ 248 };
15 static constexpr const uint8_tcxx . . $ uint8_t# Command_EnableNoSpacescxx . . $ MeatPack/Command_EnableNoSpaces.{ 247 };
16 static constexpr const uint8_tcxx . . $ uint8_t# Command_DisableNoSpacescxx . . $ MeatPack/Command_DisableNoSpaces.{ 246 };
17 static constexpr const uint8_tcxx . . $ uint8_t# Command_SignalBytecxx . . $ MeatPack/Command_SignalByte.{ 0xFF };
18
19 static constexpr const uint8_tcxx . . $ uint8_t# BothUnpackablecxx . . $ MeatPack/BothUnpackable.{ 0b11111111 };
20 static constexpr const char SpaceReplacedCharactercxx . . $ MeatPack/SpaceReplacedCharacter.{ 'E' };
21
22 static constexpr const unsigned char SecondNotPackedcxx . . $ MeatPack/SecondNotPacked.{ 0b11110000 };
23 static constexpr const unsigned char FirstNotPackedcxx . . $ MeatPack/FirstNotPacked.{ 0b00001111 };
24 static constexpr const unsigned char NextPackedFirstcxx . . $ MeatPack/NextPackedFirst.{ 0b00000001 };
25 static constexpr const unsigned char NextPackedSecondcxx . . $ MeatPack/NextPackedSecond.{ 0b00000010 };
26
27 static const stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<char, uint8_tcxx . . $ uint8_t#> ReverseLookupTblcxx . . $ MeatPack/ReverseLookupTbl. = {cxx . . $ std/unordered_map#unordered_map(715c419ed25a2697).
28 { '0', 0b00000000 },
29 { '1', 0b00000001 },
30 { '2', 0b00000010 },
31 { '3', 0b00000011 },
32 { '4', 0b00000100 },
33 { '5', 0b00000101 },
34 { '6', 0b00000110 },
35 { '7', 0b00000111 },
36 { '8', 0b00001000 },
37 { '9', 0b00001001 },
38 { '.', 0b00001010 },
39 { ' ', 0b00001011 },
40 { '\n', 0b00001100 },
41 { 'G', 0b00001101 },
42 { 'X', 0b00001110 },
43 { '\0', 0b00001111 } // never used, 0b1111 is used to indicate the next 8-bits is a full character
44 };
45
46 static stdcxx . . $ std/::string_viewcxx . . $ std/string_view# trimcxx . . $ MeatPack/trim(179724d1ca8872d5).(const stdcxx . . $ std/::string_viewcxx . . $ std/string_view#& str)
47 {
48 if (str.emptycxx . . $ std/basic_string_view#empty(3482b152b9333168).())
49 return stdcxx . . $ std/basic_string_view#basic_string_view(ced63f7c635d850d).::string_viewcxx . . $ std/string_view#();
50 size_t start = 0;
51 while (start < str.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).() - 1 && (str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).start] == ' ' || str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).start] == '\t')) { ++start; }
52 size_t end = str.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).() - 1;
53 while (end > 0 && (str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).end] == ' ' || str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).end] == '\t')) { --end; }
54 if ((start == end && (str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).end] == ' ' || str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).end] == '\t')) || (start > end))
55 return stdcxx . . $ std/basic_string_view#basic_string_view(ced63f7c635d850d).::string_viewcxx . . $ std/string_view#();
56 else
57 return stdcxx . . $ std/basic_string_view#basic_string_view(f8b699e64a75d442).::string_viewcxx . . $ std/string_view#(&str[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).start], end - start + 1);
58 }
59
60 static stdcxx . . $ std/::string_viewcxx . . $ std/string_view# ltrimcxx . . $ MeatPack/ltrim(179724d1ca8872d5).(const stdcxx . . $ std/::string_viewcxx . . $ std/string_view#& str)
61 {
62 const size_t start = str.find_first_not_ofcxx . . $ std/basic_string_view#find_first_not_of(36b1ea5aa9fdc150).(" \t");
63 return start == stdcxx . . $ std/::string_viewcxx . . $ std/string_view#::nposcxx . . $ std/basic_string_view#npos. ? stdcxx . . $ std/basic_string_view#basic_string_view(ced63f7c635d850d).::string_viewcxx . . $ std/string_view#() : str.substrcxx . . $ std/basic_string_view#substr(6f25e9449f081971).(start);
64 }
65
66 MPBinarizercxx . . $ MeatPack/MPBinarizer#::LookupTablescxx . . $ MeatPack/MPBinarizer#LookupTables# MPBinarizercxx . . $ MeatPack/MPBinarizer#::s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables. = { { 0 }, { 0 }, false, 0 };
67
68 MPBinarizercxx . . $ MeatPack/MPBinarizer#::MPBinarizercxx . . $ MeatPack/MPBinarizer#MPBinarizer(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# flags) : m_flagscxx . . $ MeatPack/MPBinarizer#m_flags.(flags) {}
69
70 void MPBinarizercxx . . $ MeatPack/MPBinarizer#::initializecxx . . $ MeatPack/MPBinarizer#initialize(d8e103f392b62d52).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#>& dst)
71 {
72 initialize_lookup_tablescxx . . $ MeatPack/MPBinarizer#initialize_lookup_tables(49f6e7a06ebc5aa8).();
73 append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(Command_EnablePackingcxx . . $ MeatPack/Command_EnablePacking., dst);
74 if ((m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. & Flag_OmitWhitespacescxx . . $ MeatPack/Flag_OmitWhitespaces.) != 0)
75 append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(Command_EnableNoSpacescxx . . $ MeatPack/Command_EnableNoSpaces., dst);
76 m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing. = true;
77 }
78
79 void MPBinarizercxx . . $ MeatPack/MPBinarizer#::finalizecxx . . $ MeatPack/MPBinarizer#finalize(d8e103f392b62d52).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#>& dst)
80 {
81 if ((m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. & Flag_RemoveCommentscxx . . $ MeatPack/Flag_RemoveComments.) != 0) {
82 assertcxx . . $ `<external>/4398592474888995393/assert.h:137:11`!(m_binarizing);
83 append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(Command_ResetAllcxx . . $ MeatPack/Command_ResetAll., dst);
84 m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing. = false;
85 }
86 }
87
88 void MPBinarizercxx . . $ MeatPack/MPBinarizer#::binarize_linecxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).(const stdcxx . . $ std/::stringcxx . . $ std/string#& line, stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#>& dst)
89 {
90 auto unified_method = [this](const stdcxx . . $ std/::stringcxx . . $ std/string#& line) {
91 const stdcxx . . $ std/::stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# g_idx = line.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('G');
92 if (g_idx != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) {
93 if (g_idx + 1 < line.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() && line[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).g_idx + 1] >= '0' && line[cxx . . $ std/__cxx11/basic_string#`operator[]`(dd01cf3f78ddc127).g_idx + 1] <= '9') {
94 if ((m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. & Flag_OmitWhitespacescxx . . $ MeatPack/Flag_OmitWhitespaces.) != 0) {
95 stdcxx . . $ std/::stringcxx . . $ std/string# result = linecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
96 stdcxx . . $ std/::replacecxx . . $ std/replace(816cee973d7ce286).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), 'e', 'E');
97 stdcxx . . $ std/::replacecxx . . $ std/replace(816cee973d7ce286).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), 'x', 'X');
98 stdcxx . . $ std/::replacecxx . . $ std/replace(816cee973d7ce286).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), 'g', 'G');
99 result.erasecxx . . $ std/__cxx11/basic_string#erase(f23000f056cf625a).(stdcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).::removecxx . . $ std/remove(a92da12e15934614).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), ' '), resultcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).());
100 if (result.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('*') != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) {
101 size_t checksum = 0;
102 result.erasecxx . . $ std/__cxx11/basic_string#erase(f23000f056cf625a).(stdcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).::removecxx . . $ std/remove(a92da12e15934614).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), '*'), resultcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).());
103 for (size_t i = 0; i < result.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(); ++i) {
104 checksum ^= static_cast<uint8_tcxx . . $ uint8_t#>(result[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i]);
105 }
106 result +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). "*" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(354ce04007c9ea85).(checksum);
107 }
108 result +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). '\n';
109 return resultcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).;
110 }
111 else {
112 stdcxx . . $ std/::stringcxx . . $ std/string# result = linecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
113 stdcxx . . $ std/::replacecxx . . $ std/replace(816cee973d7ce286).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), 'x', 'X');
114 stdcxx . . $ std/::replacecxx . . $ std/replace(816cee973d7ce286).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), 'g', 'G');
115 result.erasecxx . . $ std/__cxx11/basic_string#erase(f23000f056cf625a).(stdcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).::removecxx . . $ std/remove(a92da12e15934614).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), ' '), resultcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).());
116 if (result.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('*') != stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) {
117 size_t checksum = 0;
118 result.erasecxx . . $ std/__cxx11/basic_string#erase(f23000f056cf625a).(stdcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).::removecxx . . $ std/remove(a92da12e15934614).(result.begincxx . . $ std/__cxx11/basic_string#begin(417acd00ce8503f4).(), result.endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), '*'), resultcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).());
119 for (size_t i = 0; i < result.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).(); ++i) {
120 checksum ^= static_cast<uint8_tcxx . . $ uint8_t#>(result[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i]);
121 }
122 result +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). "*" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(354ce04007c9ea85).(checksum);
123 }
124 result +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). '\n';
125 return resultcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).;
126 }
127 }
128 }
129 return linecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).;
130 };
131 auto is_packable = [](char c) {
132 return (s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(c)] != 0);
133 };
134 auto pack_chars = [](char low, char high) {
135 return (((s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..valuecxx . . $ MeatPack/MPBinarizer#LookupTables#value.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(high)] & 0xF) << 4) |
136 (s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..valuecxx . . $ MeatPack/MPBinarizer#LookupTables#value.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(low)] & 0xF));
137 };
138
139 if (!line.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) {
140 const stdcxx . . $ std/::string_viewcxx . . $ std/string_view# trimmed_line = ltrimcxx . . $ MeatPack/ltrim(179724d1ca8872d5).(line);
141
142 if ((m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. & Flag_RemoveCommentscxx . . $ MeatPack/Flag_RemoveComments.) == 0) {
143 if (!trimmed_line.emptycxx . . $ std/basic_string_view#empty(3482b152b9333168).() && trimmed_line[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).0] == ';') {
144 if (m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing.) {
145 append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(Command_DisablePackingcxx . . $ MeatPack/Command_DisablePacking., dst);
146 m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing. = false;
147 }
148
149 dst.insertcxx . . $ std/vector#insert(134ef7853f0b3ebe).(dstcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/vector#end(55a6de06420d4903).(), line.begincxx . . $ std/__cxx11/basic_string#begin(a479f6ffbc603b2b).(), line.endcxx . . $ std/__cxx11/basic_string#end(a479f6ffbc603b2b).());
150 return;
151 }
152 }
153
154 if (trimmed_line.emptycxx . . $ std/basic_string_view#empty(3482b152b9333168).() ||
155 trimmed_line[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).0] == ';' ||
156 trimmed_line[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).0] == '\n' ||
157 trimmed_line[cxx . . $ std/basic_string_view#`operator[]`(c65000e556194d6f).0] == '\r' ||
158 line.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() < 2)
159 return;
160
161 stdcxx . . $ std/::stringcxx . . $ std/string# modifiedLine = stdcxx . . $ std/::stringcxx . . $ std/string#(trimcxx . . $ MeatPack/trim(179724d1ca8872d5).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view#(line.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0, line.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).(';')))));
162 if (modifiedLine.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).())
163 return;
164 modifiedLine =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). unified_method(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_0#`operator()`(ed3976f106e8bf8e).modifiedLine);
165 if (modifiedLine.backcxx . . $ std/__cxx11/basic_string#back(da5fe8e926c570ad).() != '\n')
166 modifiedLine.push_backcxx . . $ std/__cxx11/basic_string#push_back(9b289cee16747614).('\n');
167 const size_t line_len = modifiedLine.sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).();
168 stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> temp_buffercxx . . $ std/vector#vector(49f6e7a06ebc5aa8).;
169 temp_buffer.reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(line_len);
170
171 for (size_t line_idx = 0; line_idx < line_len; line_idx += 2) {
172 const bool skip_last = line_idx == (line_len - 1);
173 const char char_1 = modifiedLine[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).line_idx];
174 const char char_2 = (skip_last ? '\n' : modifiedLine[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).line_idx + 1]);
175 const bool c1_p = is_packable(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_1#`operator()`(aec1b1cad4a17585).char_1);
176 const bool c2_p = is_packable(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_1#`operator()`(aec1b1cad4a17585).char_2);
177
178 if (c1_p) {
179 if (c2_p)
180 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(pack_chars(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_2#`operator()`(6ce21b6b85a09be6).char_1, char_2)));
181 else {
182 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(pack_chars(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_2#`operator()`(6ce21b6b85a09be6).char_1, '\0')));
183 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(char_2));
184 }
185 }
186 else {
187 if (c2_p) {
188 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(pack_chars(cxx . . $ MeatPack/MPBinarizer#binarize_line(9db05115f854ad40).$anonymous_type_2#`operator()`(6ce21b6b85a09be6).'\0', char_2)));
189 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(char_1));
190 }
191 else {
192 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(BothUnpackablecxx . . $ MeatPack/BothUnpackable.));
193 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(char_1));
194 temp_buffer.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(static_cast<uint8_tcxx . . $ uint8_t#>(char_2));
195 }
196 }
197 }
198
199 if (!m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing. && !temp_buffer.emptycxx . . $ std/vector#empty(3482b152b9333168).()) {
200 append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(Command_EnablePackingcxx . . $ MeatPack/Command_EnablePacking., dst);
201 m_binarizingcxx . . $ MeatPack/MPBinarizer#m_binarizing. = true;
202 }
203
204 dst.insertcxx . . $ std/vector#insert(134ef7853f0b3ebe).(dstcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/vector#end(55a6de06420d4903).(), temp_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).(), temp_buffer.endcxx . . $ std/vector#end(55a6de06420d4903).());
205 }
206 }
207
208 void MPBinarizercxx . . $ MeatPack/MPBinarizer#::append_commandcxx . . $ MeatPack/MPBinarizer#append_command(985d2bc0ea417148).(unsigned char cmd, stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#>& dst) {
209 dst.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(Command_SignalBytecxx . . $ MeatPack/Command_SignalByte.);
210 dst.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(Command_SignalBytecxx . . $ MeatPack/Command_SignalByte.);
211 dst.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(cmd);
212 }
213
214 void MPBinarizercxx . . $ MeatPack/MPBinarizer#::initialize_lookup_tablescxx . . $ MeatPack/MPBinarizer#initialize_lookup_tables(49f6e7a06ebc5aa8).() {
215 if (s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..initializedcxx . . $ MeatPack/MPBinarizer#LookupTables#initialized. && m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. == s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..flagscxx . . $ MeatPack/MPBinarizer#LookupTables#flags.)
216 return;
217
218 for (const auto& [c, value] : ReverseLookupTblcxx . . $ MeatPack/ReverseLookupTbl.) {
219 const int index = static_cast<int>(c);
220 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).index] = 1;
221 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..valuecxx . . $ MeatPack/MPBinarizer#LookupTables#value.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).index] = value;
222 }
223
224 if ((m_flagscxx . . $ MeatPack/MPBinarizer#m_flags. & Flag_OmitWhitespacescxx . . $ MeatPack/Flag_OmitWhitespaces.) != 0) {
225 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..valuecxx . . $ MeatPack/MPBinarizer#LookupTables#value.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(SpaceReplacedCharactercxx . . $ MeatPack/SpaceReplacedCharacter.)] = ReverseLookupTblcxx . . $ MeatPack/ReverseLookupTbl..atcxx . . $ std/unordered_map#at(7589f80bac630479).(' ');
226 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(SpaceReplacedCharactercxx . . $ MeatPack/SpaceReplacedCharacter.)] = 1;
227 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(' ')] = 0;
228 }
229 else {
230 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(SpaceReplacedCharactercxx . . $ MeatPack/SpaceReplacedCharacter.)] = 0;
231 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..packablecxx . . $ MeatPack/MPBinarizer#LookupTables#packable.[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).static_cast<uint8_tcxx . . $ uint8_t#>(' ')] = 1;
232 }
233
234 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..initializedcxx . . $ MeatPack/MPBinarizer#LookupTables#initialized. = true;
235 s_lookup_tablescxx . . $ MeatPack/MPBinarizer#s_lookup_tables..flagscxx . . $ MeatPack/MPBinarizer#LookupTables#flags. = m_flagscxx . . $ MeatPack/MPBinarizer#m_flags.;
236 }
237
238 // See for reference: https://github.com/scottmudge/Prusa-Firmware-MeatPack/blob/MK3_sm_MeatPack/Firmware/meatpack.cpp
239 void unbinarizecxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#>& src, stdcxx . . $ std/::stringcxx . . $ std/string#& dst)
240 {
241 bool unbinarizing = false;
242 bool nospace_enabled = false;
243 bool cmd_active = false; // Is a command pending
244 uint8_tcxx . . $ uint8_t# char_buf = 0; // Buffers a character if dealing with out-of-sequence pairs
245 size_t cmd_count = 0; // Counts how many command bytes are received (need 2)
246 size_t full_char_queue = 0; // Counts how many full-width characters are to be received
247 stdcxx . . $ std/::arraycxx . . $ std/array#<uint8_tcxx . . $ uint8_t#, 2> char_out_buf; // Output buffer for caching up to 2 characters
248 size_t char_out_count = 0; // Stores number of characters to be read out
249
250 auto handle_command = [&](uint8_tcxx . . $ uint8_t# c) {
251 switch (c)
252 {
253 case Command_EnablePackingcxx . . $ MeatPack/Command_EnablePacking.: { unbinarizing = true; break; }
254 case Command_DisablePackingcxx . . $ MeatPack/Command_DisablePacking.: { unbinarizing = false; break; }
255 case Command_EnableNoSpacescxx . . $ MeatPack/Command_EnableNoSpaces.: { nospace_enabled = true; break; }
256 case Command_DisableNoSpacescxx . . $ MeatPack/Command_DisableNoSpaces.: { nospace_enabled = false; break; }
257 case Command_ResetAllcxx . . $ MeatPack/Command_ResetAll.: { unbinarizing = false; break; }
258 default:
259 case Command_QueryConfigcxx . . $ MeatPack/Command_QueryConfig.: { break; }
260 }
261 };
262
263 auto handle_output_char = [&](uint8_tcxx . . $ uint8_t# c) {
264 char_out_buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).char_out_count++] = c;
265 };
266
267 auto get_char = [&](uint8_tcxx . . $ uint8_t# c) {
268 switch (c)
269 {
270 case 0b0000: { return '0'; }
271 case 0b0001: { return '1'; }
272 case 0b0010: { return '2'; }
273 case 0b0011: { return '3'; }
274 case 0b0100: { return '4'; }
275 case 0b0101: { return '5'; }
276 case 0b0110: { return '6'; }
277 case 0b0111: { return '7'; }
278 case 0b1000: { return '8'; }
279 case 0b1001: { return '9'; }
280 case 0b1010: { return '.'; }
281 case 0b1011: { return nospace_enabled ? 'E' : ' '; }
282 case 0b1100: { return '\n'; }
283 case 0b1101: { return 'G'; }
284 case 0b1110: { return 'X'; }
285 }
286 return '\0';
287 };
288
289 auto unpack_chars = [&](uint8_tcxx . . $ uint8_t# pk, stdcxx . . $ std/::arraycxx . . $ std/array#<uint8_tcxx . . $ uint8_t#, 2>& chars_out) {
290 uint8_tcxx . . $ uint8_t# out = 0;
291
292 // If lower 4 bytes is 0b1111, the higher 4 are unused, and next char is full.
293 if ((pk & FirstNotPackedcxx . . $ MeatPack/FirstNotPacked.) == FirstNotPackedcxx . . $ MeatPack/FirstNotPacked.)
294 out |= NextPackedFirstcxx . . $ MeatPack/NextPackedFirst.;
295 else
296 chars_out[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).0] = get_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_3#`operator()`(3393123d56cc5373).pk & 0xF); // Assign lower char
297
298 // Check if upper 4 bytes is 0b1111... if so, we don't need the second char.
299 if ((pk & SecondNotPackedcxx . . $ MeatPack/SecondNotPacked.) == SecondNotPackedcxx . . $ MeatPack/SecondNotPacked.)
300 out |= NextPackedSecondcxx . . $ MeatPack/NextPackedSecond.;
301 else
302 chars_out[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).1] = get_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_3#`operator()`(3393123d56cc5373).(pk >> 4) & 0xF); // Assign upper char
303
304 return out;
305 };
306
307 auto handle_rx_char = [&](uint8_tcxx . . $ uint8_t# c) {
308 if (unbinarizing) {
309 if (full_char_queue > 0) {
310 handle_output_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_4#`operator()`(e12573c5bd0830df).c);
311 if (char_buf > 0) {
312 handle_output_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_4#`operator()`(e12573c5bd0830df).char_buf);
313 char_buf = 0;
314 }
315 --full_char_queue;
316 }
317 else {
318 stdcxx . . $ std/::arraycxx . . $ std/array#<uint8_tcxx . . $ uint8_t#, 2> buf = { 0, 0 };
319 const uint8_tcxx . . $ uint8_t# res = unpack_chars(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_5#`operator()`(a406b8c4bd83cd5).c, buf);
320
321 if ((res & NextPackedFirstcxx . . $ MeatPack/NextPackedFirst.) != 0) {
322 ++full_char_queue;
323 if ((res & NextPackedSecondcxx . . $ MeatPack/NextPackedSecond.) != 0)
324 ++full_char_queue;
325 else
326 char_buf = buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).1];
327 }
328 else {
329 handle_output_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_4#`operator()`(e12573c5bd0830df).buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).0]);
330 if (buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).0] != '\n') {
331 if ((res & NextPackedSecondcxx . . $ MeatPack/NextPackedSecond.) != 0)
332 ++full_char_queue;
333 else
334 handle_output_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_4#`operator()`(e12573c5bd0830df).buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).1]);
335 }
336 }
337 }
338 }
339 else // Packing not enabled, just copy character to output
340 handle_output_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_4#`operator()`(e12573c5bd0830df).c);
341 };
342
343 auto get_result_char = [&](stdcxx . . $ std/::arraycxx . . $ std/array#<char, 2>& chars_out) {
344 if (char_out_count > 0) {
345 const size_t res = char_out_count;
346 for (uint8_tcxx . . $ uint8_t# i = 0; i < char_out_count; ++i) {
347 chars_out[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i] = (char)char_out_buf[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i];
348 }
349 char_out_count = 0;
350 return res;
351 }
352 return (size_t)0;
353 };
354
355 stdcxx . . $ std/::vectorcxx . . $ std/vector#<uint8_tcxx . . $ uint8_t#> unbin_buffercxx . . $ std/vector#vector(229e4d6bd205de31).(2 * src.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), 0);
356 auto it_unbin_end = unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).();
357
358 bool add_space = false;
359
360 auto begin = src.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).();
361 auto end = src.endcxx . . $ std/vector#end(d1e1699016b9d7e6).();
362
363 auto it_bin = begin;
364 while (it_bin !=cxx . . $ __gnu_cxx/`operator!=`(3cd84a314b671a91). end) {
365 uint8_tcxx . . $ uint8_t# c_bin = *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).it_bin;
366 if (c_bin == Command_SignalBytecxx . . $ MeatPack/Command_SignalByte.) {
367 if (cmd_count > 0) {
368 cmd_active = true;
369 cmd_count = 0;
370 }
371 else
372 ++cmd_count;
373 }
374 else {
375 if (cmd_active) {
376 handle_command(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_6#`operator()`(e12573c5bd0830df).c_bin);
377 cmd_active = false;
378 }
379 else {
380 if (cmd_count > 0) {
381 handle_rx_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_7#`operator()`(e12573c5bd0830df).Command_SignalBytecxx . . $ MeatPack/Command_SignalByte.);
382 cmd_count = 0;
383 }
384
385 handle_rx_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_7#`operator()`(e12573c5bd0830df).c_bin);
386 }
387 }
388
389 auto is_gline_parameter = [](const char c) {
390 static const stdcxx . . $ std/::vectorcxx . . $ std/vector#<char> parameters = {cxx . . $ std/vector#vector(9619226211e5a241).
391 // G0, G1
392 'X', 'Y', 'Z', 'E', 'F',
393 // G2, G3
394 'I', 'J', 'R',
395 // G4
396 'S',
397 // G29
398 'G', 'P', 'W', 'H', 'C', 'A'
399 };
400 return stdcxx . . $ std/::findcxx . . $ std/find(a92da12e15934614).(parameters.begincxx . . $ std/vector#begin(d1e1699016b9d7e6).(), parameters.endcxx . . $ std/vector#end(d1e1699016b9d7e6).(), c) !=cxx . . $ __gnu_cxx/`operator!=`(3cd84a314b671a91). parameters.endcxx . . $ std/vector#end(d1e1699016b9d7e6).();
401 };
402
403 stdcxx . . $ std/::arraycxx . . $ std/array#<char, 2> c_unbin{ 0, 0 };
404 const size_t char_count = get_result_char(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_8#`operator()`(1c43bebe12785ede).c_unbin);
405 for (size_t i = 0; i < char_count; ++i) {
406 // GCodeReader::parse_line_internal() is unable to parse a G line where the data are not separated by spaces
407 // so we add them where needed
408 const size_t curr_unbin_buffer_length = stdcxx . . $ std/::distancecxx . . $ std/distance(4883b9d540cf40e9).(unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).(), it_unbin_end);
409 bool new_line = false;
410 if (c_unbin[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i] == 'G' && (curr_unbin_buffer_length == 0 || *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).stdcxx . . $ std/::prevcxx . . $ std/prev(31d62cd24490f169).(it_unbin_end, 1) == '\n')) {
411 add_space = true;
412 new_line = true;
413 }
414 else if (c_unbin[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i] == '\n')
415 add_space = false;
416
417 if (!new_line && add_space && (curr_unbin_buffer_length == 0 || *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).stdcxx . . $ std/::prevcxx . . $ std/prev(31d62cd24490f169).(it_unbin_end, 1) != ' ') &&
418 is_gline_parameter(cxx . . $ MeatPack/unbinarize(66c8f0577a1d24f9).$anonymous_type_9#`operator()`(aec1b1cad4a17585).c_unbin[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i])) {
419 *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).it_unbin_end = ' ';
420 ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).it_unbin_end;
421 if (it_unbin_end ==cxx . . $ __gnu_cxx/`operator==`(3cd84a314b671a91). unbin_buffer.endcxx . . $ std/vector#end(55a6de06420d4903).()) {
422 // the buffer is not big enough, resize it
423 unbin_buffer.resizecxx . . $ std/vector#resize(3804226c8c0acbc3).(2 * unbin_buffer.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), 0);
424 it_unbin_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(331dd0bfcd0ac606). unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ __gnu_cxx/__normal_iterator#operator+(192bf940fa7bb3b2). curr_unbin_buffer_length +cxx . . $ __gnu_cxx/__normal_iterator#operator+(192bf940fa7bb3b2). 1;
425 }
426 }
427
428 if (c_unbin[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i] != '\n' || stdcxx . . $ std/::distancecxx . . $ std/distance(4883b9d540cf40e9).(unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).(), it_unbin_end) == 0 || *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).stdcxx . . $ std/::prevcxx . . $ std/prev(31d62cd24490f169).(it_unbin_end, 1) != '\n') {
429 *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).it_unbin_end = c_unbin[cxx . . $ std/array#`operator[]`(b18cc97d22f46aed).i];
430 ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).it_unbin_end;
431 if (it_unbin_end ==cxx . . $ __gnu_cxx/`operator==`(3cd84a314b671a91). unbin_buffer.endcxx . . $ std/vector#end(55a6de06420d4903).()) {
432 // the buffer is not big enough, resize it
433 unbin_buffer.resizecxx . . $ std/vector#resize(3804226c8c0acbc3).(2 * unbin_buffer.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(), 0);
434 it_unbin_end =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(331dd0bfcd0ac606). unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ __gnu_cxx/__normal_iterator#operator+(192bf940fa7bb3b2). curr_unbin_buffer_length +cxx . . $ __gnu_cxx/__normal_iterator#operator+(192bf940fa7bb3b2). 1;
435 }
436 }
437 }
438
439 ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).it_bin;
440 }
441
442 dst.insertcxx . . $ std/__cxx11/basic_string#insert(3a043201c3912ce8).(dstcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(417acd00ce8503f4).(), unbin_buffer.begincxx . . $ std/vector#begin(55a6de06420d4903).(), it_unbin_end);
443 }
444
445 } // namespace MeatPack