35 |
36 |
36 using namespace relpipe::cli; |
37 using namespace relpipe::cli; |
37 using namespace relpipe::writer; |
38 using namespace relpipe::writer; |
38 using namespace relpipe::in::posixmq; |
39 using namespace relpipe::in::posixmq; |
39 |
40 |
|
41 static std::shared_ptr<PosixMQCommand> command = nullptr; |
|
42 |
|
43 void finish(int sig) { |
|
44 if (command) command->finish(sig); |
|
45 } |
|
46 |
40 int main(int argc, char** argv) { |
47 int main(int argc, char** argv) { |
41 setlocale(LC_ALL, ""); |
48 setlocale(LC_ALL, ""); |
42 CLI::untieStdIO(); |
49 CLI::untieStdIO(); |
43 CLI cli(argc, argv); |
50 CLI cli(argc, argv); |
44 |
51 |
45 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
52 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
46 |
53 |
47 try { |
54 try { |
|
55 signal(SIGHUP, finish); |
|
56 signal(SIGINT, finish); |
48 CLIParser cliParser; |
57 CLIParser cliParser; |
49 Configuration configuration = cliParser.parse(cli.arguments()); |
58 Configuration configuration = cliParser.parse(cli.arguments()); |
50 PosixMQCommand command; |
59 command.reset(new PosixMQCommand()); |
51 std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
60 std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
52 command.process(writer, configuration); |
61 writer->setBufferingMode(BufferingMode::ENVIRONMENT, BufferingMode::RECORD); |
|
62 command->process(writer, configuration); |
53 resultCode = CLI::EXIT_CODE_SUCCESS; |
63 resultCode = CLI::EXIT_CODE_SUCCESS; |
54 } catch (RelpipeCLIException e) { |
64 } catch (RelpipeCLIException e) { |
55 fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
65 fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
56 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
66 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
57 resultCode = e.getExitCode(); |
67 resultCode = e.getExitCode(); |