From 357adc07dc6ab5507438c3f28fc90c17872bf14e Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Tue, 11 Jan 2011 21:47:59 +0000 Subject: [PATCH] Add some comments. Originally committed to SVN as r5177. --- aegisub/tools/common-respack.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/aegisub/tools/common-respack.cpp b/aegisub/tools/common-respack.cpp index 916fe769c..e7e213919 100644 --- a/aegisub/tools/common-respack.cpp +++ b/aegisub/tools/common-respack.cpp @@ -24,6 +24,8 @@ #include +/// 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 ifp_i(ifp); - std::istreambuf_iterator 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 ifp_i(ifp); + std::istreambuf_iterator 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; }