2019-02-26 12:19:49 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <ios>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char const *argv[])
|
|
|
|
{
|
2019-08-19 08:35:18 +00:00
|
|
|
if (argc != 4) {
|
|
|
|
std::cerr << "Usage: " << argv[0] << " <file> <symbol name> <output file>" << std::endl;
|
2019-02-26 12:19:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-08-19 08:35:18 +00:00
|
|
|
const char* filename_in = argv[1];
|
2019-02-26 12:19:49 +00:00
|
|
|
const char* symbol = argv[2];
|
2019-08-19 08:35:18 +00:00
|
|
|
const char* filename_out = argv[3];
|
2019-02-26 12:19:49 +00:00
|
|
|
|
|
|
|
size_t size = 0;
|
2019-08-19 08:35:18 +00:00
|
|
|
std::fstream file(filename_in, std::ios::in | std::ios::binary);
|
2019-02-26 12:19:49 +00:00
|
|
|
if (!file.good()) {
|
2019-08-19 08:35:18 +00:00
|
|
|
std::cerr << "Cannot read file: " << filename_in << std::endl;
|
2019-02-26 12:19:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:12:32 +00:00
|
|
|
std::fstream output(filename_out, std::ios::out | std::ios::trunc);
|
2019-08-19 08:35:18 +00:00
|
|
|
if (!output.good()) {
|
|
|
|
std::cerr << "Cannot open output file: " << filename_out << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
output << "/* WARN: This file is auto-generated from `" << filename_in << "` */" << std::endl;
|
|
|
|
output << "const unsigned char " << symbol << "[] = {";
|
2019-02-26 12:19:49 +00:00
|
|
|
|
|
|
|
char c;
|
2019-08-19 08:35:18 +00:00
|
|
|
output << std::hex;
|
|
|
|
output.fill('0');
|
2019-02-26 12:19:49 +00:00
|
|
|
for (file.get(c); !file.eof(); size++, file.get(c)) {
|
2019-08-19 08:35:18 +00:00
|
|
|
if (size % 12 == 0) { output << "\n "; }
|
|
|
|
output << "0x" << std::setw(2) << (unsigned)c << ", ";
|
2019-02-26 12:19:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 08:35:18 +00:00
|
|
|
output << "\n 0, 0\n};\n";
|
2019-02-26 12:19:49 +00:00
|
|
|
|
2019-08-19 08:35:18 +00:00
|
|
|
output << std::dec;
|
|
|
|
output << "const size_t " << symbol << "_size = " << size << ";" << std::endl;
|
|
|
|
output << "const size_t " << symbol << "_size_yy = " << size + 2 << ";" << std::endl;
|
2019-02-26 12:19:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|