diff options
author | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-06-28 23:15:16 -0400 |
---|---|---|
committer | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-06-28 23:15:16 -0400 |
commit | 950cfcd31e4f05d63b24fbce391a69a5f0b59dec (patch) | |
tree | a476d224dc103142beea43a92c181dc3b43fef9e | |
parent | 1037a469d313286b9f8683a0113f1d22d5d65fc3 (diff) |
Some OCDing over version.cpp, and make it so module.cpp doesn't need version.h (only main.cpp, modulemanager.cpp, and modules.cpp need version.h, to avoid rebuilding EVERYTHING every build)
-rw-r--r-- | include/version.cpp | 61 | ||||
-rw-r--r-- | src/module.cpp | 1 |
2 files changed, 28 insertions, 34 deletions
diff --git a/include/version.cpp b/include/version.cpp index 7b7d3314c..f3a2af5a7 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -17,68 +17,63 @@ int main(int argc, char *argv[]) { - using namespace std; - if (argc < 3) { - cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << endl; + std::cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << std::endl; return 1; } - fstream fd; + std::fstream fd; fd.clear(); - fd.open(argv[1], ios::in); + fd.open(argv[1], std::ios::in); if (!fd.is_open()) { - cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << endl; + std::cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << std::endl; return 1; } - string filebuf; - list<pair<string, string> > versions; + std::string filebuf; + std::list<std::pair<std::string, std::string> > versions; while (getline(fd, filebuf)) { - if (filebuf.find("VERSION_") == 0) + if (!filebuf.find("VERSION_")) { size_t eq = filebuf.find('='); - string type = filebuf.substr(8, 5); - string value = filebuf.substr(eq + 2, filebuf.length() - eq - 3); - versions.push_back(make_pair(type, value)); + std::string type = filebuf.substr(8, 5); + std::string value = filebuf.substr(eq + 2, filebuf.length() - eq - 3); + versions.push_back(std::make_pair(type, value)); } } fd.close(); fd.clear(); - fd.open(argv[2], ios::in); + fd.open(argv[2], std::ios::in); - string version_build = "#define VERSION_BUILD 1"; - string version_extra; - string build = "#define BUILD 1"; + std::string version_build = "#define VERSION_BUILD 1"; + std::string version_extra; + std::string build = "#define BUILD 1"; if (fd.is_open()) { while (getline(fd, filebuf)) { - if (filebuf.find("#define VERSION_BUILD") == 0) - { + if (!filebuf.find("#define VERSION_BUILD")) version_build = filebuf; - } - else if (filebuf.find("#define VERSION_EXTRA") == 0) + else if (!filebuf.find("#define VERSION_EXTRA")) { size_t q = filebuf.find('"'); version_extra = filebuf.substr(q + 1, filebuf.length() - q - 2); } - else if (filebuf.find("#define BUILD") == 0) + else if (!filebuf.find("#define BUILD")) { size_t tab = filebuf.find(' '); - int ibuild = atoi(filebuf.substr(tab + 1).c_str()); - ++ibuild; + int ibuild = atoi(filebuf.substr(tab + 1).c_str()) + 1; - stringstream ss; + std::stringstream ss; ss << "#define BUILD " << ibuild; build = ss.str(); } @@ -88,31 +83,31 @@ int main(int argc, char *argv[]) } fd.clear(); - fd.open(argv[2], ios::out); + fd.open(argv[2], std::ios::out); if (!fd.is_open()) { - cout << "Error: Unable to include/version.h for writing: " << argv[2]; + std::cout << "Error: Unable to include/version.h for writing: " << argv[2] << std::endl; return 1; } - fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << endl; + fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl; - for (list<pair<string, string> >::iterator it = versions.begin(), it_end = versions.end(); it != it_end; ++it) + for (std::list<std::pair<std::string, std::string> >::iterator it = versions.begin(), it_end = versions.end(); it != it_end; ++it) { if (it->first == "EXTRA") { if (!version_extra.empty()) - fd << "#define VERSION_EXTRA \"" << version_extra << "\"" << endl; + fd << "#define VERSION_EXTRA \"" << version_extra << "\"" << std::endl; else - fd << "#define VERSION_EXTRA \"" << it->second << "\"" << endl; + fd << "#define VERSION_EXTRA \"" << it->second << "\"" << std::endl; } else - fd << "#define VERSION_" << it->first << " " << it->second << endl; + fd << "#define VERSION_" << it->first << " " << it->second << std::endl; } - fd << version_build << endl; - fd << build << endl; + fd << version_build << std::endl; + fd << build << std::endl; fd.close(); diff --git a/src/module.cpp b/src/module.cpp index 7c83a7937..d2382eb02 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -8,7 +8,6 @@ #include "modules.h" #include "language.h" -#include "version.h" Module::Module(const std::string &mname, const std::string &creator) { |