author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Nov 2021 23:15:17 +0100 | |
branch | v_0 |
changeset 44 | cca41f80b89f |
parent 35 | eafffeea6a3e |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2019 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 |
|
35
eafffeea6a3e
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
28
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
0 | 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> |
|
13
b74001992ec3
implement --relation option (thus some relations might pass unmodified by AWK), support per-relation variables
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
21 |
#include <functional> |
0 | 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 "AwkHandler.h" |
|
36 |
#include "CLIParser.h" |
|
37 |
#include "Configuration.h" |
|
38 |
||
39 |
using namespace relpipe::cli; |
|
40 |
using namespace relpipe::reader; |
|
41 |
using namespace relpipe::tr::awk; |
|
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<reader::RelationalReader> reader(reader::Factory::create(std::cin)); |
|
54 |
std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout)); |
|
13
b74001992ec3
implement --relation option (thus some relations might pass unmodified by AWK), support per-relation variables
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
AwkHandler handler(writer.get(), std::bind(fflush, stdout), configuration); // std::bind(fflush, XXX) writer::Factory::create(XXX) must be the same stream XXX |
0 | 56 |
reader->addHandler(&handler); |
57 |
reader->process(); |
|
13
b74001992ec3
implement --relation option (thus some relations might pass unmodified by AWK), support per-relation variables
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
58 |
|
0 | 59 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
60 |
||
61 |
} catch (RelpipeCLIException& e) { |
|
44
cca41f80b89f
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
35
diff
changeset
|
62 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
0 | 63 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
64 |
resultCode = e.getExitCode(); |
|
28
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
65 |
} catch (AwkException& e) { |
44
cca41f80b89f
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
35
diff
changeset
|
66 |
fwprintf(stderr, L"Caught AWK exception: %ls\n", e.getMessage().c_str()); |
28
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
67 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
68 |
resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
0 | 69 |
} catch (RelpipeReaderException& e) { |
44
cca41f80b89f
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
35
diff
changeset
|
70 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
0 | 71 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
72 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
73 |
} |
|
74 |
||
75 |
return resultCode; |
|
76 |
} |