29 "uresourcegenerator.exe [option] \"file1\" \"file2\" ... \n" 30 " Create a file named \"file\".h with string\n" 31 " variable named \"file\" which contains the data of the file.\n" 32 " Warning, it overwrites the target file\n" 34 " -n \"namespace\" namespace used\n" 35 " -p \"targetPath\" target path where the file is created\n" 36 " -v version of the UtiLite library\n");
40 int main(
int argc,
char * argv[])
46 else if(argc == 2 && strcmp(argv[1],
"-v") == 0)
48 printf(
"%s\n", UTILITE_VERSION);
56 for(k=1; k<(argc-1); ++k)
58 if(strcmp(argv[k],
"-n") == 0)
65 printf(
" Using namespace=%s\n", nspace.c_str());
68 else if(strcmp(argv[k],
"-p") == 0)
74 targetDir = argv[k+1];
75 printf(
" Using target directory=%s\n", targetDir.c_str());
86 std::string filePath = argv[k];
89 for(
unsigned int i=0; i<varName.size(); ++i)
91 if(!((varName[i] >=
'0' && varName[i] <=
'9') ||
92 (varName[i] >=
'A' && varName[i] <=
'Z') ||
93 (varName[i] >=
'a' && varName[i] <=
'z')))
98 std::string targetFileName = varName +
".h";
100 for(
unsigned int i=0; i<varName.size(); ++i)
102 if(varName[i] >=
'a' && varName[i] <=
'z')
108 std::fstream outFile;
110 outFile.open(((targetDir +
"/") + targetFileName).c_str(), std::fstream::out);
111 inFile.open(filePath.c_str(), std::fstream::in | std::fstream::binary);
113 printf(
"Input file \"%s\" size = %ld bytes\n", filePath.c_str(),
UFile::length(filePath));
114 if(outFile.is_open() && inFile.is_open())
116 outFile <<
"/*This is a generated file...*/\n\n";
117 outFile <<
"#ifndef " << varName <<
"_H\n";
118 outFile <<
"#define " << varName <<
"_H\n\n";
122 outFile <<
"namespace " << nspace.c_str() <<
"\n{\n\n";
125 outFile <<
"static const char * " << varName.c_str() <<
" = ";
133 std::string startLine =
"\n \"";
134 std::string endLine =
"\"";
135 std::vector<char> buffer(1024);
138 inFile.read(buffer.data(), 1024);
139 std::streamsize count = inFile.gcount();
142 outFile.write(startLine.c_str(), startLine.size());
144 std::string hex =
uBytes2Hex(buffer.data(), count);
145 outFile.write(hex.c_str(), hex.size());
147 outFile.write(endLine.c_str(), endLine.size());
152 std::string endOfVar =
";\n\n";
153 outFile.write(endOfVar.c_str(), endOfVar.size());
160 outFile <<
"#endif //" << varName <<
"_H\n\n";
166 printf(
"Output file \"%s\" size = %ld bytes\n", ((targetDir +
"/") + targetFileName).c_str(),
UFile::length(((targetDir +
"/") + targetFileName).c_str()));
std::string UTILITE_EXP uBytes2Hex(const char *bytes, unsigned int bytesLen)
int main(int argc, char *argv[])
static std::string currentDir(bool trailingSeparator=false)