0
|
1 |
/**
|
|
2 |
* Relational pipes
|
|
3 |
* Copyright © 2022 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 <unistd.h>
|
|
33 |
|
|
34 |
#include "SerializeHandler.h"
|
|
35 |
#include "CLIParser.h"
|
|
36 |
#include "Configuration.h"
|
|
37 |
|
|
38 |
using namespace relpipe::cli;
|
|
39 |
using namespace relpipe::reader;
|
|
40 |
using namespace relpipe::writer;
|
|
41 |
using namespace relpipe::tr::serialize;
|
|
42 |
|
|
43 |
int main(int argc, char**argv) {
|
|
44 |
setlocale(LC_ALL, "");
|
|
45 |
CLI::untieStdIO();
|
|
46 |
CLI cli(argc, argv);
|
|
47 |
|
|
48 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
|
|
49 |
|
|
50 |
try {
|
|
51 |
CLIParser cliParser;
|
|
52 |
Configuration configuration = cliParser.parse(cli.arguments());
|
|
53 |
std::shared_ptr<RelationalWriter> writer(relpipe::writer::Factory::create(std::cout));
|
|
54 |
std::shared_ptr<RelationalReader> reader(relpipe::reader::Factory::create(std::cin));
|
|
55 |
SerializeHandler handler(writer, configuration);
|
|
56 |
reader->addHandler(&handler);
|
|
57 |
reader->process();
|
|
58 |
resultCode = CLI::EXIT_CODE_SUCCESS;
|
|
59 |
} catch (RelpipeCLIException& e) {
|
|
60 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
|
|
61 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
|
|
62 |
resultCode = e.getExitCode();
|
|
63 |
} catch (RelpipeReaderException& e) {
|
|
64 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str());
|
|
65 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
|
|
66 |
resultCode = CLI::EXIT_CODE_DATA_ERROR;
|
|
67 |
}
|
|
68 |
|
|
69 |
return resultCode;
|
|
70 |
}
|