Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
conf-generate.cpp File Reference
#include <iostream>
#include <fstream>
#include <ios>
#include <iomanip>
+ Include dependency graph for conf-generate.cpp:

Go to the source code of this file.

Functions

int main (int argc, char const *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char const argv[] 
)
8{
9 if (argc != 4) {
10 std::cerr << "Usage: " << argv[0] << " <file> <symbol name> <output file>" << std::endl;
11 return -1;
12 }
13
14 const char* filename_in = argv[1];
15 const char* symbol = argv[2];
16 const char* filename_out = argv[3];
17
18 size_t size = 0;
19 std::fstream file(filename_in, std::ios::in | std::ios::binary);
20 if (!file.good()) {
21 std::cerr << "Cannot read file: " << filename_in << std::endl;
22 }
23
24 std::fstream output(filename_out, std::ios::out | std::ios::trunc);
25 if (!output.good()) {
26 std::cerr << "Cannot open output file: " << filename_out << std::endl;
27 }
28
29 output << "/* WARN: This file is auto-generated from `" << filename_in << "` */" << std::endl;
30 output << "const unsigned char " << symbol << "[] = {";
31
32 char c;
33 output << std::hex;
34 output.fill('0');
35 for (file.get(c); !file.eof(); size++, file.get(c)) {
36 if (size % 12 == 0) { output << "\n "; }
37 output << "0x" << std::setw(2) << (unsigned)c << ", ";
38 }
39
40 output << "\n 0, 0\n};\n";
41
42 output << std::dec;
43 output << "const size_t " << symbol << "_size = " << size << ";" << std::endl;
44 output << "const size_t " << symbol << "_size_yy = " << size + 2 << ";" << std::endl;
45
46 return 0;
47}
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183