src/relpipe-tr-sed.cpp
branchv_0
changeset 7 92d85e02b276
parent 6 abf1d424f2a0
child 19 9bac174d11b6
equal deleted inserted replaced
6:abf1d424f2a0 7:92d85e02b276
    30 #include <relpipe/writer/RelationalWriter.h>
    30 #include <relpipe/writer/RelationalWriter.h>
    31 #include <relpipe/writer/RelpipeWriterException.h>
    31 #include <relpipe/writer/RelpipeWriterException.h>
    32 #include <relpipe/writer/Factory.h>
    32 #include <relpipe/writer/Factory.h>
    33 #include <relpipe/writer/TypeId.h>
    33 #include <relpipe/writer/TypeId.h>
    34 
    34 
    35 #include "PassthroughHandler.h"
    35 #include "SedHandler.h"
    36 
    36 
    37 using namespace relpipe::cli;
    37 using namespace relpipe::cli;
    38 using namespace relpipe::reader;
    38 using namespace relpipe::reader;
    39 using namespace relpipe::tr::validator;
    39 using namespace relpipe::tr::sed;
    40 
    40 
    41 int main(int argc, char**argv) {
    41 int main(int argc, char**argv) {
    42 	setlocale(LC_ALL, "");
    42 	setlocale(LC_ALL, "");
    43 	CLI::untieStdIO();
    43 	CLI::untieStdIO();
    44 	CLI cli(argc, argv);
    44 	CLI cli(argc, argv);
    45 	
    45 
    46 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
    46 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
    47 
    47 
    48 	try {
    48 	try {
    49 		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
    49 		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
    50 		PassthroughHandler handler(std::cout);
    50 		SedHandler handler(std::cout, cli.arguments());
    51 		reader->addHandler(&handler);
    51 		reader->addHandler(&handler);
    52 		reader->process();
    52 		reader->process();
    53 
    53 
    54 		resultCode = CLI::EXIT_CODE_SUCCESS;
    54 		resultCode = CLI::EXIT_CODE_SUCCESS;
    55 
    55 
    56 	} catch (RelpipeCLIException e) {
    56 	} catch (RelpipeCLIException& e) {
    57 		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
    57 		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
    58 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    58 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    59 		resultCode = e.getExitCode();
    59 		resultCode = e.getExitCode();
    60 	} catch (RelpipeReaderException e) {
    60 	} catch (RelpipeReaderException& e) {
    61 		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
    61 		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
    62 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    62 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
    63 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
    63 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
    64 	}
    64 	}
    65 
    65