19 #include <memory> |
19 #include <memory> |
20 #include <regex> |
20 #include <regex> |
21 #include <algorithm> |
21 #include <algorithm> |
22 #include <unistd.h> |
22 #include <unistd.h> |
23 |
23 |
24 #include <libxml++-2.6/libxml++/libxml++.h> |
|
25 |
|
26 #include <relpipe/writer/RelationalWriter.h> |
24 #include <relpipe/writer/RelationalWriter.h> |
27 #include <relpipe/writer/RelpipeWriterException.h> |
25 #include <relpipe/writer/RelpipeWriterException.h> |
28 #include <relpipe/writer/Factory.h> |
26 #include <relpipe/writer/Factory.h> |
29 #include <relpipe/writer/TypeId.h> |
27 #include <relpipe/writer/TypeId.h> |
30 |
28 |
31 #include <relpipe/cli/CLI.h> |
29 #include <relpipe/cli/CLI.h> |
32 |
30 |
33 #include "XMLTableCommand.h" |
31 #include "ODSCommand.h" |
34 #include "CLIParser.h" |
|
35 #include "Configuration.h" |
|
36 |
32 |
37 using namespace relpipe::cli; |
33 using namespace relpipe::cli; |
38 using namespace relpipe::writer; |
34 using namespace relpipe::writer; |
39 using namespace relpipe::in::xmltable; |
35 using namespace relpipe::in::ods; |
40 |
36 |
41 int main(int argc, char** argv) { |
37 int main(int argc, char** argv) { |
42 setlocale(LC_ALL, ""); |
38 setlocale(LC_ALL, ""); |
43 CLI::untieStdIO(); |
39 CLI::untieStdIO(); |
44 CLI cli(argc, argv); |
40 CLI cli(argc, argv); |
45 |
41 |
46 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
42 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
47 |
43 |
48 try { |
44 try { |
49 CLIParser cliParser; |
45 std::shared_ptr<RelationalWriter> writer(Factory::create(cout)); |
50 Configuration configuration = cliParser.parse(cli.arguments()); |
46 ODSCommand command(writer); |
51 XMLCommand command; |
47 command.process(cin); |
52 command.process(cin, cout, configuration); |
|
53 resultCode = CLI::EXIT_CODE_SUCCESS; |
48 resultCode = CLI::EXIT_CODE_SUCCESS; |
54 } catch (RelpipeWriterException& e) { |
49 } catch (RelpipeWriterException& e) { |
55 fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessage().c_str()); |
50 fwprintf(stderr, L"Caught Writer 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()); |
51 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
57 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
52 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
58 } catch (RelpipeCLIException& e) { |
|
59 fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
|
60 fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
61 resultCode = e.getExitCode(); |
|
62 } // TODO: catch xmlpp::exception |
53 } // TODO: catch xmlpp::exception |
63 |
54 |
64 return resultCode; |
55 return resultCode; |
65 } |
56 } |