MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / buildInclude

Function buildInclude

src/api_builder/build_include.cpp:26–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24static char hexdigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
25
26void buildInclude(const std::string& mode, const std::string& input, const std::string& output)
27{
28 std::ofstream outfile(output.c_str());
29
30 std::ifstream infile(input.c_str(), std::ios_base::binary);
31
32 char buff[2048];
33 std::streamsize total_bytes = 0;
34
35 outfile << "const unsigned char " << varSafeName(output) << "[] = {\n";
36
37 while (infile) {
38 infile.read(buff, sizeof(buff));
39 auto bytes_read = infile.gcount();
40 total_bytes += bytes_read;
41 for (int i = 0; i < bytes_read; ++i) {
42 if ((i % 16) == 0) {
43 outfile << "\t";
44 }
45 outfile << "0x" << hexdigit[(buff[i] >> 4) & 0xf] << hexdigit[buff[i] & 0xf] << ", ";
46 if ((i % 16) == 15) {
47 outfile << "\n";
48 }
49 }
50 }
51
52 outfile << "};\n";
53 outfile << "unsigned int " << varSafeName(output) << "_len = " << total_bytes << ";\n";
54}

Callers 1

mainFunction · 0.85

Calls 3

varSafeNameFunction · 0.85
c_strMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected