Add some comments.

Originally committed to SVN as r5177.
This commit is contained in:
Amar Takhar 2011-01-11 21:47:59 +00:00
parent 5d6730919d
commit 357adc07dc

View file

@ -24,6 +24,8 @@
#include <string> #include <string>
/// Clean a filename for use as an identity.
/// @param str[in] String containing filename.
inline void clean(std::string &str) { inline void clean(std::string &str) {
// Remove path. // Remove path.
std::string::size_type pos = str.rfind('/'); 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_cpp(argv[2]);
std::ofstream file_h(argv[3]); std::ofstream file_h(argv[3]);
// If the manifest has a path use that as the base for finding files. // If the manifest has a path use that as the base for finding files.
std::string manifest(argv[1]); std::string manifest(argv[1]);
std::string path_base; std::string path_base;
std::string::size_type pos = manifest.rfind('/'); std::string::size_type pos = manifest.rfind('/');
if (pos != std::string::npos) { if (pos != std::string::npos) {
path_base = manifest.substr(0, pos+1); 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; file_cpp << "#include \"libresrc.h\"" << std::endl;
std::string file; // File for array.
std::string file;
while (file_manifest) { while (file_manifest) {
std::getline(file_manifest, file); std::getline(file_manifest, file);
if (file.empty()) continue; if (file.empty()) continue;
std::ifstream ifp((path_base + file).c_str()); std::ifstream ifp((path_base + file).c_str());
std::istreambuf_iterator<char> ifp_i(ifp);
std::istreambuf_iterator<char> eof;
if (!ifp.is_open()) { if (!ifp.is_open()) {
std::cout << "Error opening file: " << file << std::endl; std::cout << "Error opening file: " << file << std::endl;
return 1; return 1;
} }
// Identity used in C/Header files.
std::string ident(file); std::string ident(file);
clean(ident); clean(ident);
file_cpp << "const unsigned char " << 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; int length = 0;
while (ifp_i != eof) { while (ifp_i != eof) {
if (length > 0) file_cpp << ","; if (length > 0) file_cpp << ",";
file_cpp << (int)*ifp_i; file_cpp << (int)*ifp_i;
@ -109,7 +109,10 @@ int main(int argc, const char *argv[]) {
length++; length++;
} }
// Finish
file_cpp << "};" << std::endl; file_cpp << "};" << std::endl;
// Prototype.
file_h << "extern const unsigned char " << ident << "[" << length << "];" << std::endl; file_h << "extern const unsigned char " << ident << "[" << length << "];" << std::endl;
} }