src/relpipe-out-xml.cpp
branchv_0
changeset 1 82ba555a97d1
child 2 13a41e435ea0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/relpipe-out-xml.cpp	Sun Sep 16 14:39:10 2018 +0200
@@ -0,0 +1,38 @@
+#include <cstdlib>
+#include <memory>
+
+#include <relpipe/cli/CLI.h>
+#include <relpipe/cli/RelpipeCLIException.h>
+#include <relpipe/reader/Factory.h>
+#include <relpipe/reader/RelationalReader.h>
+#include <relpipe/reader/RelpipeReaderException.h>
+
+#include "XmlHandler.h"
+
+using namespace relpipe::cli;
+using namespace relpipe::reader;
+using namespace relpipe::out::tabular;
+
+int main(int argc, char** argv) {
+	CLI cli(argc, argv);
+
+	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
+
+	try {
+		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
+		XmlHandler handler(std::cout);
+		reader->addHandler(&handler);
+		reader->process();
+		resultCode = CLI::EXIT_CODE_SUCCESS;
+	} catch (RelpipeCLIException e) {
+		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
+		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
+		resultCode = e.getExitCode();
+	} catch (RelpipeReaderException e) {
+		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
+		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
+		resultCode = CLI::EXIT_CODE_DATA_ERROR;
+	}
+
+	return resultCode;
+}