From 61f5f4fbdf3f7b05715badad035f391718d282aa Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 24 Jul 2009 07:45:17 +0000 Subject: Fixed compiler issues... --- server/src/Makefile.am | 16 ++-- server/src/macrolist.cc | 14 ++-- server/src/macrolist.h | 4 +- server/src/macrotool.cc | 3 + server/src/macrotool_fieldnames.cc | 2 + server/src/macrotool_filehandler.cc | 2 + server/src/server.cc | 2 +- server/src/version.cc | 143 -------------------------------- server/src/version.h | 49 ----------- server/src/versionstr.cc | 157 ++++++++++++++++++++++++++++++++++++ server/src/versionstr.h | 60 ++++++++++++++ 11 files changed, 242 insertions(+), 210 deletions(-) delete mode 100644 server/src/version.cc delete mode 100644 server/src/version.h create mode 100644 server/src/versionstr.cc create mode 100644 server/src/versionstr.h diff --git a/server/src/Makefile.am b/server/src/Makefile.am index 99863f0..cdc4bfe 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -32,7 +32,7 @@ pracrod_SOURCES = \ transactionparser.cc \ tcpsocket.cc \ utf8.cc \ - version.cc \ + versionstr.cc \ widgetgenerator.cc \ xml_encode_decode.cc @@ -59,7 +59,7 @@ macrotool_SOURCES = \ pracrodaopgsql.cc \ saxparser.cc \ templateparser.cc \ - version.cc + versionstr.cc EXTRA_DIST = \ configuration.h \ @@ -93,12 +93,12 @@ EXTRA_DIST = \ transactionparser.h \ tcpsocket.h \ utf8.h \ - version.h \ + versionstr.h \ widgetgenerator.h \ xml_encode_decode.h TESTFILES = \ - test_version \ + test_versionstr \ test_macrolist \ test_queryhandlerpentominos \ test_queryhandlerpracro \ @@ -124,11 +124,11 @@ test: $(TESTFILES) test_clean: rm -f $(TESTFILES) -test_version: version.cc - @../../tools/test version.cc +test_versionstr: versionstr.cc + @../../tools/test versionstr.cc test_macrolist: macrolist.cc - @../../tools/test macrolist.cc version.cc macroheaderparser.cc $(PARSERBASICS) $(BASICS) + @../../tools/test macrolist.cc versionstr.cc macroheaderparser.cc $(PARSERBASICS) $(BASICS) test_queryhandlerpentominos: queryhandlerpentominos.cc @../../tools/test queryhandlerpentominos.cc tcpsocket.cc queryparser.cc $(PARSERBASICS) $(BASICS) @@ -149,7 +149,7 @@ test_macroparser: macroparser.cc @../../tools/test macroparser.cc $(PARSERBASICS) $(BASICS) test_server: server.cc - @../../tools/test server.cc templateparser.cc queryparser.cc queryhandlerpentominos.cc journal_commit.cc macrolist.cc queryhandlerpracro.cc macroheaderparser.cc version.cc resumeparser.cc luaquerymapper.cc tcpsocket.cc $(BASICS) transactionparser.cc widgetgenerator.cc database.cc pracrodao.cc pracrodaopgsql.cc luaresume.cc macroparser.cc xml_encode_decode.cc $(PARSERBASICS) $(LUA_LIBS) $(CONFIG_LIBS) $(PQXX_LIBS) $(PQXX_CXXFLAGS) + @../../tools/test server.cc templateparser.cc queryparser.cc queryhandlerpentominos.cc journal_commit.cc macrolist.cc queryhandlerpracro.cc macroheaderparser.cc versionstr.cc resumeparser.cc luaquerymapper.cc tcpsocket.cc $(BASICS) transactionparser.cc widgetgenerator.cc database.cc pracrodao.cc pracrodaopgsql.cc luaresume.cc macroparser.cc xml_encode_decode.cc $(PARSERBASICS) $(LUA_LIBS) $(CONFIG_LIBS) $(PQXX_LIBS) $(PQXX_CXXFLAGS) @sleep 1s; killall -9 test_server test_pracrodaopgsql: pracrodaopgsql.cc diff --git a/server/src/macrolist.cc b/server/src/macrolist.cc index 8207b06..1117ed9 100644 --- a/server/src/macrolist.cc +++ b/server/src/macrolist.cc @@ -65,7 +65,7 @@ MacroList::MacroList(std::string macropath) MacroHeaderParser parser(macropath + "/" + *i); parser.parse(); Macro *macro = parser.getMacro(); - (*this)[macro->attributes["name"]][Version(macro->attributes["version"])] = *i; + (*this)[macro->attributes["name"]][VersionStr(macro->attributes["version"])] = *i; i++; } } @@ -88,12 +88,12 @@ int main() { MacroList lst("/home"); - lst["macro1"][Version("1.0")] = "macro1-1.0.xml"; - lst["macro1"][Version("1.1")] = "macro1-1.1.xml"; - lst["macro1"][Version("1.1.1")] = "macro1-1.1.1.xml"; - lst["macro1"][Version("1.2")] = "macro1-1.2.xml"; - lst["macro2"][Version("1.0")] = "macro2.xml"; - lst["macro3"][Version("1.0")] = "macro3.xml"; + lst["macro1"][VersionStr("1.0")] = "macro1-1.0.xml"; + lst["macro1"][VersionStr("1.1")] = "macro1-1.1.xml"; + lst["macro1"][VersionStr("1.1.1")] = "macro1-1.1.1.xml"; + lst["macro1"][VersionStr("1.2")] = "macro1-1.2.xml"; + lst["macro2"][VersionStr("1.0")] = "macro2.xml"; + lst["macro3"][VersionStr("1.0")] = "macro3.xml"; MacroList::iterator i = lst.begin(); while(i != lst.end()) { diff --git a/server/src/macrolist.h b/server/src/macrolist.h index 278bc07..328e522 100644 --- a/server/src/macrolist.h +++ b/server/src/macrolist.h @@ -30,9 +30,9 @@ #include #include -#include "version.h" +#include "versionstr.h" -typedef std::map MacroListItem; +typedef std::map MacroListItem; class MacroList : public std::map { public: diff --git a/server/src/macrotool.cc b/server/src/macrotool.cc index 11c634e..bb8c8fc 100644 --- a/server/src/macrotool.cc +++ b/server/src/macrotool.cc @@ -28,6 +28,9 @@ // For ETC #include +#include +#include + // For getopt_long and friends #include diff --git a/server/src/macrotool_fieldnames.cc b/server/src/macrotool_fieldnames.cc index d7cc7f9..4c18de5 100644 --- a/server/src/macrotool_fieldnames.cc +++ b/server/src/macrotool_fieldnames.cc @@ -27,6 +27,8 @@ */ #include "macrotool_fieldnames.h" +#include + #include "macrotool_util.h" #include "macroparser.h" diff --git a/server/src/macrotool_filehandler.cc b/server/src/macrotool_filehandler.cc index 4caa889..6e3470a 100644 --- a/server/src/macrotool_filehandler.cc +++ b/server/src/macrotool_filehandler.cc @@ -30,6 +30,8 @@ #include #include +#include + #include "macroheaderparser.h" #include "macroparser.h" #include "template.h" diff --git a/server/src/server.cc b/server/src/server.cc index 6e480ed..884284a 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -55,7 +55,7 @@ #include "xml_encode_decode.h" #include "macrolist.h" -#include "version.h" +#include "versionstr.h" static std::string error_box(std::string message) { diff --git a/server/src/version.cc b/server/src/version.cc deleted file mode 100644 index e2c64ec..0000000 --- a/server/src/version.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * version.cc - * - * Wed Jul 22 11:41:32 CEST 2009 - * Copyright 2009 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of Pracro. - * - * Pracro is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Pracro is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Pracro; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "version.h" - -Version::Version(std::string v) -{ - memset(version, 0, sizeof(version)); - set(v); -} - -void Version::set(std::string v) -{ - std::string num; - size_t idx = 0; - for(size_t i = 0; i < v.length(); i++) { - if(v[i] == '.') { - if(idx > 2) printf("Too long\n"); - version[idx] = atoi(num.c_str()); - idx++; - num = ""; - } else if(v[i] >= '0' && v[i] <= '9') { - num.append(1, v[i]); - } else { - printf("Illigal character: [%c]\n", v[i]); - } - } - if(idx > 2) printf("Too long\n"); - version[idx] = atoi(num.c_str()); -} - -Version::operator std::string() const -{ - std::string v; - char *buf; - if(patch()) asprintf(&buf, "%d.%d.%d", major(), minor(), patch()); - else asprintf(&buf, "%d.%d", major(), minor()); - v = buf; - free(buf); - return v; -} - -void Version::operator=(std::string v) -{ - set(v); -} - -bool Version::operator<(const Version &other) const -{ - if(other.major() < major()) return true; - if(other.major() > major()) return false; - if(other.minor() < minor()) return true; - if(other.minor() > minor()) return false; - if(other.patch() < patch()) return true; - if(other.patch() > patch()) return false; - return false; -} - -size_t Version::major() const -{ - return version[0]; -} - -size_t Version::minor() const -{ - return version[1]; -} - -size_t Version::patch() const -{ - return version[2]; -} - -#ifdef TEST_VERSION - -#include - -int main() -{ - Version v1("1.2.3"); - printf("Version: %s\n", ((std::string)v1).c_str()); - if((std::string)v1 != "1.2.3") return 1; - - Version v2("1.2"); - printf("Version: %s\n", ((std::string)v2).c_str()); - if((std::string)v2 != "1.2") return 1; - - Version v3("1"); - printf("Version: %s\n", ((std::string)v3).c_str()); - if((std::string)v3 != "1.0") return 1; - - Version v4("1.2.3.4"); // too long - printf("Version: %s\n", ((std::string)v4).c_str()); - if((std::string)v4 != "1.2.3") return 1; - - Version v5("1.2.a"); // illigal character - printf("Version: %s\n", ((std::string)v5).c_str()); - if((std::string)v5 != "1.2") return 1; - - std::set versions; - versions.insert(Version("1.0")); - versions.insert(Version("1.0.0")); - versions.insert(Version("2.0")); - versions.insert(Version("1.1")); - versions.insert(Version("0.1")); - versions.insert(Version("1.0.1")); - versions.insert(Version("1.0.3")); - versions.insert(Version("1.0.2")); - - std::set::iterator i = versions.begin(); - while(i != versions.end()) { - printf("%s\n", ((std::string)*i).c_str()); - i++; - } - - return 0; -} - -#endif/*TEST_VERSION*/ diff --git a/server/src/version.h b/server/src/version.h deleted file mode 100644 index fa86deb..0000000 --- a/server/src/version.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * version.h - * - * Wed Jul 22 11:41:32 CEST 2009 - * Copyright 2009 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of Pracro. - * - * Pracro is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Pracro is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Pracro; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#ifndef __PRACRO_VERSION_H__ -#define __PRACRO_VERSION_H__ - -#include - -class Version { -public: - Version(std::string v); - operator std::string() const; - void operator=(std::string v); - bool operator<(const Version &other) const; - - size_t major() const; - size_t minor() const; - size_t patch() const; - -private: - void set(std::string v); - size_t version[3]; -}; - -#endif/*__PRACRO_VERSION_H__*/ diff --git a/server/src/versionstr.cc b/server/src/versionstr.cc new file mode 100644 index 0000000..0d334b3 --- /dev/null +++ b/server/src/versionstr.cc @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * versionstr.cc + * + * Wed Jul 22 11:41:32 CEST 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "versionstr.h" + +#include +#include + +// Workaround - major, minor and patch are defined as macros when using _GNU_SOURCES +#ifdef major +#undef major +#endif +#ifdef minor +#undef minor +#endif +#ifdef patch +#undef patch +#endif + +VersionStr::VersionStr(std::string v) +{ + memset(version, 0, sizeof(version)); + set(v); +} + +void VersionStr::set(std::string v) +{ + std::string num; + size_t idx = 0; + for(size_t i = 0; i < v.length(); i++) { + if(v[i] == '.') { + if(idx > 2) printf("Too long\n"); + version[idx] = atoi(num.c_str()); + idx++; + num = ""; + } else if(v[i] >= '0' && v[i] <= '9') { + num.append(1, v[i]); + } else { + printf("Illigal character: [%c]\n", v[i]); + } + } + if(idx > 2) printf("Too long\n"); + version[idx] = atoi(num.c_str()); +} + +VersionStr::operator std::string() const +{ + std::string v; + char *buf; + if(patch()) asprintf(&buf, "%d.%d.%d", major(), minor(), patch()); + else asprintf(&buf, "%d.%d", major(), minor()); + v = buf; + free(buf); + return v; +} + +void VersionStr::operator=(std::string v) +{ + set(v); +} + +bool VersionStr::operator<(const VersionStr &other) const +{ + if(other.major() < major()) return true; + if(other.major() > major()) return false; + if(other.minor() < minor()) return true; + if(other.minor() > minor()) return false; + if(other.patch() < patch()) return true; + if(other.patch() > patch()) return false; + return false; +} + +size_t VersionStr::major() const +{ + return version[0]; +} + +size_t VersionStr::minor() const +{ + return version[1]; +} + +size_t VersionStr::patch() const +{ + return version[2]; +} + +#ifdef TEST_VERSIONSTR + +#include + +int main() +{ + VersionStr v1("1.2.3"); + printf("VersionStr: %s\n", ((std::string)v1).c_str()); + if((std::string)v1 != "1.2.3") return 1; + + VersionStr v2("1.2"); + printf("VersionStr: %s\n", ((std::string)v2).c_str()); + if((std::string)v2 != "1.2") return 1; + + VersionStr v3("1"); + printf("VersionStr: %s\n", ((std::string)v3).c_str()); + if((std::string)v3 != "1.0") return 1; + + VersionStr v4("1.2.3.4"); // too long + printf("VersionStr: %s\n", ((std::string)v4).c_str()); + if((std::string)v4 != "1.2.3") return 1; + + VersionStr v5("1.2.a"); // illigal character + printf("VersionStr: %s\n", ((std::string)v5).c_str()); + if((std::string)v5 != "1.2") return 1; + + std::set versions; + versions.insert(VersionStr("1.0")); + versions.insert(VersionStr("1.0.0")); + versions.insert(VersionStr("2.0")); + versions.insert(VersionStr("1.1")); + versions.insert(VersionStr("0.1")); + versions.insert(VersionStr("1.0.1")); + versions.insert(VersionStr("1.0.3")); + versions.insert(VersionStr("1.0.2")); + + std::set::iterator i = versions.begin(); + while(i != versions.end()) { + printf("%s\n", ((std::string)*i).c_str()); + i++; + } + + return 0; +} + +#endif/*TEST_VERSIONSTR*/ diff --git a/server/src/versionstr.h b/server/src/versionstr.h new file mode 100644 index 0000000..a840bd2 --- /dev/null +++ b/server/src/versionstr.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * versionstr.h + * + * Wed Jul 22 11:41:32 CEST 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_VERSIONSTR_H__ +#define __PRACRO_VERSIONSTR_H__ + +#include + +// Workaround - major, minor and patch are defined as macros when using _GNU_SOURCES +#ifdef major +#undef major +#endif +#ifdef minor +#undef minor +#endif +#ifdef patch +#undef patch +#endif + +class VersionStr { +public: + VersionStr(std::string v); + operator std::string() const; + void operator=(std::string v); + bool operator<(const VersionStr &other) const; + + size_t major() const; + size_t minor() const; + size_t patch() const; + +private: + void set(std::string v); + size_t version[3]; +}; + +#endif/*__PRACRO_VERSIONSTR_H__*/ -- cgit v1.2.3