-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathembedresource.cpp
More file actions
51 lines (41 loc) · 1.24 KB
/
embedresource.cpp
File metadata and controls
51 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
int main(int argc, char** argv)
{
if (argc < 3) {
std::cerr << "USAGE: " << argv[0] << " {sym} {rsrc}" << std::endl << std::endl
<< " Creates {sym}.c from the contents of {rsrc}" << std::endl;
return EXIT_FAILURE;
}
std::string sym(argv[2]);
std::replace(sym.begin(), sym.end(), '.', '_');
std::replace(sym.begin(), sym.end(), '-', '_');
std::replace(sym.begin(), sym.end(), '/', '_');
std::replace(sym.begin(), sym.end(), '\\', '_');
std::ifstream ifs;
ifs.open(argv[2]);
std::ofstream ofs;
ofs.open(argv[1]);
ofs << "#include <stdlib.h>" << std::endl;
ofs << "const char _resource_" << sym << "[] = {" << std::endl;
size_t lineCount = 0;
while (true)
{
char c;
ifs.get(c);
if (ifs.eof())
break;
ofs << "0x" << std::hex << (c & 0xff) << ", ";
if (++lineCount == 10) {
ofs << std::endl;
lineCount = 0;
}
}
ofs << "};" << std::endl;
ofs << "const size_t _resource_" << sym << "_len = sizeof(_resource_" << sym << ");";
ofs.close();
ifs.close();
return EXIT_SUCCESS;
}