src/relpipe-out-xml.cpp
branchv_0
changeset 1 82ba555a97d1
child 2 13a41e435ea0
equal deleted inserted replaced
0:c043377a757f 1:82ba555a97d1
       
     1 #include <cstdlib>
       
     2 #include <memory>
       
     3 
       
     4 #include <relpipe/cli/CLI.h>
       
     5 #include <relpipe/cli/RelpipeCLIException.h>
       
     6 #include <relpipe/reader/Factory.h>
       
     7 #include <relpipe/reader/RelationalReader.h>
       
     8 #include <relpipe/reader/RelpipeReaderException.h>
       
     9 
       
    10 #include "XmlHandler.h"
       
    11 
       
    12 using namespace relpipe::cli;
       
    13 using namespace relpipe::reader;
       
    14 using namespace relpipe::out::tabular;
       
    15 
       
    16 int main(int argc, char** argv) {
       
    17 	CLI cli(argc, argv);
       
    18 
       
    19 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
       
    20 
       
    21 	try {
       
    22 		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
       
    23 		XmlHandler handler(std::cout);
       
    24 		reader->addHandler(&handler);
       
    25 		reader->process();
       
    26 		resultCode = CLI::EXIT_CODE_SUCCESS;
       
    27 	} catch (RelpipeCLIException e) {
       
    28 		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
       
    29 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    30 		resultCode = e.getExitCode();
       
    31 	} catch (RelpipeReaderException e) {
       
    32 		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
       
    33 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    34 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
       
    35 	}
       
    36 
       
    37 	return resultCode;
       
    38 }