src/relpipe-out-xml.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 16 Sep 2018 14:39:10 +0200
branchv_0
changeset 1 82ba555a97d1
child 2 13a41e435ea0
permissions -rw-r--r--
relpipe-out-xml skeleton

#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;
}