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 GrepHandler handler(std::cout); |
50 GrepHandler 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 |