|
1 /** |
|
2 * Relational pipes |
|
3 * Copyright © 2018 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #include <cstdio> |
|
20 #include <cstdlib> |
|
21 #include <memory> |
|
22 |
|
23 #include <relpipe/cli/CLI.h> |
|
24 #include <relpipe/cli/RelpipeCLIException.h> |
|
25 |
|
26 #include <relpipe/reader/Factory.h> |
|
27 #include <relpipe/reader/RelationalReader.h> |
|
28 #include <relpipe/reader/RelpipeReaderException.h> |
|
29 |
|
30 #include <relpipe/writer/RelationalWriter.h> |
|
31 #include <relpipe/writer/RelpipeWriterException.h> |
|
32 #include <relpipe/writer/Factory.h> |
|
33 #include <relpipe/writer/TypeId.h> |
|
34 |
|
35 #include "CutHandler.h" |
|
36 |
|
37 using namespace relpipe::cli; |
|
38 using namespace relpipe::reader; |
|
39 using namespace relpipe::tr::grep; |
|
40 |
|
41 int main(int argc, char**argv) { |
|
42 setlocale(LC_ALL, ""); |
|
43 CLI::untieStdIO(); |
|
44 CLI cli(argc, argv); |
|
45 |
|
46 int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
47 |
|
48 try { |
|
49 std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
|
50 GrepHandler handler(std::cout, cli.arguments()); |
|
51 reader->addHandler(&handler); |
|
52 reader->process(); |
|
53 |
|
54 resultCode = CLI::EXIT_CODE_SUCCESS; |
|
55 |
|
56 } catch (RelpipeCLIException& e) { |
|
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()); |
|
59 resultCode = e.getExitCode(); |
|
60 } catch (RelpipeReaderException& e) { |
|
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()); |
|
63 resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
64 } |
|
65 |
|
66 return resultCode; |
|
67 } |