author | František Kučera <franta-hg@frantovo.cz> |
Tue, 30 Jul 2019 23:55:40 +0200 | |
branch | v_0 |
changeset 33 | 5288af2e4921 |
parent 28 | 4fdbe30d8c58 |
child 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 |
|
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> |
|
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
|
22 |
#include <functional> |
0 | 23 |
|
24 |
#include <relpipe/cli/CLI.h> |
|
25 |
#include <relpipe/cli/RelpipeCLIException.h> |
|
26 |
||
27 |
#include <relpipe/reader/Factory.h> |
|
28 |
#include <relpipe/reader/RelationalReader.h> |
|
29 |
#include <relpipe/reader/RelpipeReaderException.h> |
|
30 |
||
31 |
#include <relpipe/writer/RelationalWriter.h> |
|
32 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
33 |
#include <relpipe/writer/Factory.h> |
|
34 |
#include <relpipe/writer/TypeId.h> |
|
35 |
||
36 |
#include "AwkHandler.h" |
|
37 |
#include "CLIParser.h" |
|
38 |
#include "Configuration.h" |
|
39 |
||
40 |
using namespace relpipe::cli; |
|
41 |
using namespace relpipe::reader; |
|
42 |
using namespace relpipe::tr::awk; |
|
43 |
||
44 |
int main(int argc, char**argv) { |
|
45 |
setlocale(LC_ALL, ""); |
|
46 |
CLI::untieStdIO(); |
|
47 |
CLI cli(argc, argv); |
|
48 |
||
49 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
50 |
||
51 |
try { |
|
52 |
CLIParser cliParser; |
|
53 |
Configuration configuration = cliParser.parse(cli.arguments()); |
|
54 |
std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin)); |
|
55 |
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
|
56 |
AwkHandler handler(writer.get(), std::bind(fflush, stdout), configuration); // std::bind(fflush, XXX) writer::Factory::create(XXX) must be the same stream XXX |
0 | 57 |
reader->addHandler(&handler); |
58 |
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
|
59 |
|
0 | 60 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
61 |
||
62 |
} catch (RelpipeCLIException& e) { |
|
63 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); |
|
64 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
65 |
resultCode = e.getExitCode(); |
|
28
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
66 |
} catch (AwkException& e) { |
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
67 |
fwprintf(stderr, L"Caught AWK exception: %ls\n", e.getMessge().c_str()); |
4fdbe30d8c58
introduce AwkException
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
68 |
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
|
69 |
resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
0 | 70 |
} catch (RelpipeReaderException& e) { |
71 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str()); |
|
72 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
73 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
74 |
} |
|
75 |
||
76 |
return resultCode; |
|
77 |
} |