CMakeLists.txt utils/CMakeLists.txt utils/kolabformatchecker.cpp
Christian Mollekopf
mollekopf at kolabsys.com
Thu Oct 11 12:42:48 CEST 2012
CMakeLists.txt | 5 ++
utils/CMakeLists.txt | 5 ++
utils/kolabformatchecker.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+)
New commits:
commit bf38efb1ab1efffd30afe39b0807ed77f9bbe279
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Thu Oct 11 12:40:29 2012 +0200
Added format checker to validate xml files.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8ff9af1..1d32e5f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,7 @@ endif()
cmake_minimum_required(VERSION 2.6)
option( BUILD_TESTS "Build the tests" TRUE )
+option( BUILD_UTILS "Build optional utils" FALSE )
option( DIST_ONLY "Build dist targets only (does not require a compiler)" FALSE )
option( PYTHON_BINDINGS "Build bindings for python" FALSE )
option( PHP_BINDINGS "Build bindings for php" FALSE )
@@ -179,6 +180,10 @@ include_directories(
add_subdirectory(src)
+if (BUILD_UTILS)
+ add_subdirectory(utils)
+endif()
+
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
new file mode 100644
index 0000000..762cf86
--- /dev/null
+++ b/utils/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+find_package(Boost REQUIRED COMPONENTS program_options)
+
+add_executable(kolabformatchecker kolabformatchecker.cpp)
+target_link_libraries(kolabformatchecker kolabxml ${Boost_LIBRARIES})
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
new file mode 100644
index 0000000..fc7df21
--- /dev/null
+++ b/utils/kolabformatchecker.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2011 Christian Mollekopf <mollekopf at kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <boost/program_options.hpp>
+#include <iostream>
+#include <string>
+#include <vector>
+#include "src/kolabformat.h"
+
+namespace po = boost::program_options;
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+ // Declare the supported options.
+ po::options_description desc("Allowed options");
+ desc.add_options()
+ ("help", "produce help message")
+ ("contact", "parse contact")
+ ("distlist", "parse distlist")
+ ("event", "parse event")
+ ("todo", "parse todo")
+ ("journal", "parse journal")
+ ("freebusy", "parse freebusy")
+ ("note", "parse note")
+ ("configuration", "parse configuration")
+ ("input-file", po::value<std::vector<std::string> >(), "input files of given type")
+ ;
+
+ po::positional_options_description p;
+ p.add("input-file", -1);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).
+ options(desc).positional(p).run(), vm);
+ po::notify(vm);
+
+ if (vm.count("help")) {
+ cout << desc << "\n";
+ return 1;
+ }
+
+ vector<string> inputFiles;
+ if (vm.count("input-file")) {
+ inputFiles = vm["input-file"].as< vector<string> >();
+ } else {
+ cout << "Specify input-file";
+ return -1;
+ }
+
+ for(vector<string>::const_iterator it = inputFiles.begin();
+ it != inputFiles.end(); it++){
+
+ if (vm.count("contact")) {
+ Kolab::readContact(*it, true);
+ } else if (vm.count("distlist")) {
+ Kolab::readDistlist(*it, true);
+ } else if (vm.count("event")) {
+ Kolab::readEvent(*it, true);
+ } else if (vm.count("todo")) {
+ Kolab::readTodo(*it, true);
+ } else if (vm.count("journal")) {
+ Kolab::readJournal(*it, true);
+ } else if (vm.count("freebusy")) {
+ Kolab::readFreebusy(*it, true);
+ } else if (vm.count("note")) {
+ Kolab::readNote(*it, true);
+ } else if (vm.count("configuration")) {
+ Kolab::readConfiguration(*it, true);
+ } else {
+ cout << "Specify type";
+ return -1;
+ }
+ if (Kolab::error()) {
+ cout << "Error: " << Kolab::errorMessage() << endl;
+ return -1;
+ } else {
+ cout << "Parsed message without error." << endl;
+ }
+ }
+ return 0;
+}
\ No newline at end of file
More information about the commits
mailing list