author | František Kučera <franta-hg@frantovo.cz> |
Wed, 23 Sep 2020 16:58:48 +0200 | |
branch | v_0 |
changeset 16 | 15ee963675af |
parent 15 | 157bb1d5e08a |
child 19 | 0d858e0eedf8 |
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 |
|
10
1ae185cac1f3
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
3
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 |
#include <cstdlib> |
|
1
5eb4d149c6e2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
#include <vector> |
0 | 19 |
#include <memory> |
20 |
#include <regex> |
|
21 |
#include <algorithm> |
|
22 |
#include <unistd.h> |
|
23 |
||
24 |
#include <relpipe/writer/RelationalWriter.h> |
|
25 |
#include <relpipe/writer/RelpipeWriterException.h> |
|
1
5eb4d149c6e2
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
26 |
#include <relpipe/writer/AttributeMetadata.h> |
0 | 27 |
#include <relpipe/writer/Factory.h> |
28 |
#include <relpipe/writer/TypeId.h> |
|
29 |
||
30 |
#include <relpipe/cli/CLI.h> |
|
31 |
||
14
012d491e219a
separate code into CSVCommand.h and CSVCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
32 |
#include "CSVCommand.h" |
16
15ee963675af
change CLI interface: options: --relation --attribute
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
33 |
#include "CLIParser.h" |
15ee963675af
change CLI interface: options: --relation --attribute
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
34 |
#include "Configuration.h" |
14
012d491e219a
separate code into CSVCommand.h and CSVCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
35 |
|
0 | 36 |
using namespace std; |
37 |
using namespace relpipe::cli; |
|
38 |
using namespace relpipe::writer; |
|
14
012d491e219a
separate code into CSVCommand.h and CSVCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
39 |
using namespace relpipe::in::csv; |
0 | 40 |
|
41 |
int main(int argc, char** argv) { |
|
42 |
setlocale(LC_ALL, ""); |
|
43 |
CLI::untieStdIO(); |
|
44 |
CLI cli(argc, argv); |
|
45 |
||
46 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
47 |
||
48 |
try { |
|
16
15ee963675af
change CLI interface: options: --relation --attribute
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
49 |
CLIParser cliParser; |
15ee963675af
change CLI interface: options: --relation --attribute
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
50 |
Configuration configuration = cliParser.parse(cli.arguments()); |
14
012d491e219a
separate code into CSVCommand.h and CSVCommand.h
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
51 |
CSVCommand command; |
15
157bb1d5e08a
work with writer instead of ostream
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
52 |
std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
16
15ee963675af
change CLI interface: options: --relation --attribute
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
53 |
command.process(cin, writer, configuration); |
0 | 54 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
55 |
} catch (RelpipeWriterException e) { |
|
56 |
fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str()); |
|
57 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
58 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
59 |
} |
|
60 |
||
61 |
return resultCode; |
|
62 |
} |