author | František Kučera <franta-hg@frantovo.cz> |
Sat, 04 Dec 2021 21:14:53 +0100 | |
branch | v_0 |
changeset 11 | 0d49d5041a84 |
parent 10 | 840db0029136 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2021 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, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
||
18 |
#include <cstdio> |
|
19 |
#include <cstdlib> |
|
20 |
#include <memory> |
|
21 |
||
22 |
#include <relpipe/cli/CLI.h> |
|
23 |
#include <relpipe/cli/RelpipeCLIException.h> |
|
24 |
||
25 |
#include <relpipe/reader/Factory.h> |
|
26 |
#include <relpipe/reader/RelationalReader.h> |
|
27 |
#include <relpipe/reader/RelpipeReaderException.h> |
|
28 |
||
29 |
#include <relpipe/writer/RelationalWriter.h> |
|
30 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
31 |
#include <relpipe/writer/Factory.h> |
|
32 |
#include <relpipe/writer/TypeId.h> |
|
33 |
||
34 |
#include "Configuration.h" |
|
35 |
#include "CLIParser.h" |
|
36 |
#include "InferTypesHandler.h" |
|
37 |
||
38 |
using namespace relpipe::cli; |
|
39 |
using namespace relpipe::tr::infertypes; |
|
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 |
CLIParser cliParser; |
|
50 |
Configuration configuration = cliParser.parse(cli.arguments()); |
|
51 |
||
52 |
std::shared_ptr<writer::RelationalWriter> writer(relpipe::writer::Factory::create(std::cout)); |
|
53 |
std::shared_ptr<RelationalReader> reader(relpipe::reader::Factory::create(std::cin)); |
|
54 |
InferTypesHandler handler(writer, configuration); |
|
55 |
reader->addHandler(&handler); |
|
56 |
reader->process(); |
|
57 |
||
58 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
|
59 |
||
60 |
} catch (RelpipeCLIException& e) { |
|
10
840db0029136
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
61 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
0 | 62 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
63 |
resultCode = e.getExitCode(); |
|
64 |
} catch (RelpipeReaderException& e) { |
|
10
840db0029136
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
0 | 66 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
67 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
68 |
} |
|
69 |
||
70 |
return resultCode; |
|
71 |
} |