author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Nov 2021 23:15:17 +0100 | |
branch | v_0 |
changeset 21 | 5ba5baf24257 |
parent 15 | 638f581903d0 |
child 25 | 58de33c1af03 |
permissions | -rw-r--r-- |
0 | 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 |
|
15
638f581903d0
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
4
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 |
||
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
#include <cstdlib> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
19 |
#include <memory> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
20 |
|
0 | 21 |
#include <relpipe/cli/CLI.h> |
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
#include <relpipe/cli/RelpipeCLIException.h> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
23 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
24 |
#include <relpipe/reader/Factory.h> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
#include <relpipe/reader/RelationalReader.h> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
#include <relpipe/reader/RelpipeReaderException.h> |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
27 |
|
4
12ffbdbb3574
NullByteHandler: produces \0-separated values
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
28 |
#include "NullByteHandler.h" |
0 | 29 |
|
30 |
using namespace relpipe::cli; |
|
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
31 |
using namespace relpipe::reader; |
4
12ffbdbb3574
NullByteHandler: produces \0-separated values
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
32 |
using namespace relpipe::out::nullbyte; |
0 | 33 |
|
34 |
int main(int argc, char**argv) { |
|
35 |
CLI cli(argc, argv); |
|
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
36 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
37 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
38 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
39 |
try { |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
40 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
4
12ffbdbb3574
NullByteHandler: produces \0-separated values
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
41 |
NullByteHandler handler(std::cout); |
12ffbdbb3574
NullByteHandler: produces \0-separated values
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
42 |
reader->addHandler(&handler); |
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
43 |
reader->process(); |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
44 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
45 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
46 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
} catch (RelpipeCLIException e) { |
21
5ba5baf24257
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
48 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
49 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
50 |
resultCode = e.getExitCode(); |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
} catch (RelpipeReaderException e) { |
21
5ba5baf24257
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
52 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
2
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
53 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
} |
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
|
eb2066405f79
reader without any output
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
57 |
return resultCode; |
0 | 58 |
} |