Add some comments.
Originally committed to SVN as r5177.
This commit is contained in:
parent
5d6730919d
commit
357adc07dc
1 changed files with 11 additions and 8 deletions
|
@ -24,6 +24,8 @@
|
|||
#include <string>
|
||||
|
||||
|
||||
/// Clean a filename for use as an identity.
|
||||
/// @param str[in] String containing filename.
|
||||
inline void clean(std::string &str) {
|
||||
// Remove path.
|
||||
std::string::size_type pos = str.rfind('/');
|
||||
|
@ -65,12 +67,9 @@ int main(int argc, const char *argv[]) {
|
|||
std::ofstream file_cpp(argv[2]);
|
||||
std::ofstream file_h(argv[3]);
|
||||
|
||||
|
||||
|
||||
// If the manifest has a path use that as the base for finding files.
|
||||
std::string manifest(argv[1]);
|
||||
std::string path_base;
|
||||
|
||||
std::string::size_type pos = manifest.rfind('/');
|
||||
if (pos != std::string::npos) {
|
||||
path_base = manifest.substr(0, pos+1);
|
||||
|
@ -79,28 +78,29 @@ int main(int argc, const char *argv[]) {
|
|||
|
||||
file_cpp << "#include \"libresrc.h\"" << std::endl;
|
||||
|
||||
|
||||
std::string file;
|
||||
std::string file; // File for array.
|
||||
while (file_manifest) {
|
||||
std::getline(file_manifest, file);
|
||||
if (file.empty()) continue;
|
||||
|
||||
std::ifstream ifp((path_base + file).c_str());
|
||||
std::istreambuf_iterator<char> ifp_i(ifp);
|
||||
std::istreambuf_iterator<char> eof;
|
||||
|
||||
|
||||
if (!ifp.is_open()) {
|
||||
std::cout << "Error opening file: " << file << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Identity used in C/Header files.
|
||||
std::string ident(file);
|
||||
clean(ident);
|
||||
|
||||
file_cpp << "const unsigned char " << ident << "[] = {";
|
||||
|
||||
/// Create byte-array.
|
||||
std::istreambuf_iterator<char> ifp_i(ifp);
|
||||
std::istreambuf_iterator<char> eof;
|
||||
int length = 0;
|
||||
|
||||
while (ifp_i != eof) {
|
||||
if (length > 0) file_cpp << ",";
|
||||
file_cpp << (int)*ifp_i;
|
||||
|
@ -109,7 +109,10 @@ int main(int argc, const char *argv[]) {
|
|||
length++;
|
||||
}
|
||||
|
||||
// Finish
|
||||
file_cpp << "};" << std::endl;
|
||||
|
||||
// Prototype.
|
||||
file_h << "extern const unsigned char " << ident << "[" << length << "];" << std::endl;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue