author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Nov 2021 23:15:18 +0100 | |
branch | v_0 |
changeset 37 | 673fe926619a |
parent 33 | e87c231afb77 |
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 |
|
26
421608ecc12a
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
23
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> |
|
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 |
||
33
e87c231afb77
relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
34 |
#include "SchemeHandler.h" |
6
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
35 |
#include "CLIParser.h" |
0 | 36 |
|
37 |
using namespace relpipe::cli; |
|
33
e87c231afb77
relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
38 |
using namespace relpipe::tr::scheme; |
0 | 39 |
|
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
40 |
static void relpipeMain(void *closure, int argc, char **argv) { |
0 | 41 |
setlocale(LC_ALL, ""); |
42 |
CLI::untieStdIO(); |
|
43 |
CLI cli(argc, argv); |
|
44 |
||
45 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
46 |
||
47 |
try { |
|
6
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
48 |
CLIParser cliParser; |
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
49 |
Configuration configuration = cliParser.parse(cli.arguments()); |
7
61fc569b77e6
RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
50 |
std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin)); |
61fc569b77e6
RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
51 |
std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout)); |
33
e87c231afb77
relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
52 |
SchemeHandler handler(writer.get(), configuration); |
0 | 53 |
reader->addHandler(&handler); |
54 |
reader->process(); |
|
55 |
||
56 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
|
57 |
||
58 |
} catch (RelpipeCLIException& e) { |
|
37
673fe926619a
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
59 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
0 | 60 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
61 |
resultCode = e.getExitCode(); |
|
62 |
} catch (RelpipeReaderException& e) { |
|
37
673fe926619a
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
63 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str()); |
0 | 64 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
65 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
33
e87c231afb77
relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
66 |
} catch (SchemeException& e) { |
37
673fe926619a
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
33
diff
changeset
|
67 |
fwprintf(stderr, L"Caught Scheme exception: %ls\n", e.getMessage().c_str()); |
23
6ee7a9e311e9
add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
68 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
6ee7a9e311e9
add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
69 |
resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
0 | 70 |
} |
71 |
||
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
72 |
exit(resultCode); |
0 | 73 |
} |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
|
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
75 |
int main(int argc, char**argv) { |
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
76 |
scm_boot_guile(argc, argv, relpipeMain, nullptr); |
6
4062b8436838
CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
77 |
return 222; // never reached – see exit(resultCode) above |
1
9179406ab3b3
link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
78 |
} |