diff options
author | Adam <Adam@Anope.org> | 2010-06-25 20:00:21 -0400 |
---|---|---|
committer | Adam <Adam@Anope.org> | 2010-06-25 20:00:21 -0400 |
commit | 03fbc7d281f5039a97c851970dea3cd8cfaefd64 (patch) | |
tree | c527046a41b97751b1a52ba7046e36337f0d0373 /include/version.cpp | |
parent | cbcead4e89b3dc0dfb236fff9cb3e62b1b0707c0 (diff) |
Changed the versioning system to use git
Diffstat (limited to 'include/version.cpp')
-rw-r--r-- | include/version.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/include/version.cpp b/include/version.cpp new file mode 100644 index 000000000..5b642c70b --- /dev/null +++ b/include/version.cpp @@ -0,0 +1,116 @@ +/* Build bumper + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for furhter details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +#include <iostream> +#include <fstream> +#include <sstream> +#include <list> + +int main(int argc, char *argv[]) +{ + using namespace std; + + if (argc < 3) + { + cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << endl; + return 1; + } + + fstream fd; + + fd.open(argv[1], ios::in); + if (!fd.is_open()) + { + cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << endl; + return 1; + } + + string filebuf; + list<pair<string, string> > versions; + while (getline(fd, filebuf)) + { + if (filebuf.find("VERSION_") == 0) + { + 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)); + } + } + + fd.close(); + + fd.open(argv[2], ios::in); + + string version_build = "#define VERSION_BUILD 1"; + string version_extra; + string build = "#define BUILD 1"; + if (fd.is_open()) + { + while (getline(fd, filebuf)) + { + if (filebuf.find("#define VERSION_BUILD") == 0) + { + version_build = filebuf; + } + else if (filebuf.find("#define VERSION_EXTRA") == 0) + { + size_t q = filebuf.find('"'); + + version_extra = filebuf.substr(q + 1, filebuf.length() - q - 2); + } + else if (filebuf.find("#define BUILD") == 0) + { + size_t tab = filebuf.find(' '); + + int ibuild = atoi(filebuf.substr(tab + 1).c_str()); + ++ibuild; + + stringstream ss; + ss << "#define BUILD " << ibuild; + build = ss.str(); + } + } + + fd.close(); + } + + fd.open(argv[2], ios::out); + + if (!fd.is_open()) + { + cout << "Error: Unable to include/version.h for writing: " << argv[2]; + return 1; + } + + fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << endl; + + for (list<pair<string, 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; + else + fd << "#define VERSION_EXTRA \"" << it->second << "\"" << endl; + } + else + fd << "#define VERSION_" << it->first << " " << it->second << endl; + } + + fd << version_build << endl; + fd << build << endl; + + fd.close(); + + return 0; +} |