author | František Kučera <franta-hg@frantovo.cz> |
Fri, 18 Jan 2019 20:26:31 +0100 | |
branch | v_0 |
changeset 4 | 534535aa4de4 |
parent 2 | 75aeeb022302 |
child 10 | 4bcf3fb7cc48 |
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 |
|
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 <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 "CSVHandler.h" |
|
1
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
30 |
#include "RelpipeCSVWriterException.h" |
0 | 31 |
|
32 |
using namespace relpipe::cli; |
|
33 |
using namespace relpipe::reader; |
|
34 |
using namespace relpipe::out::csv; |
|
35 |
||
36 |
int main(int argc, char**argv) { |
|
37 |
CLI cli(argc, argv); |
|
2
75aeeb022302
untie STDIO → utilize buffering
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
38 |
CLI::untieStdIO(); |
0 | 39 |
|
40 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
41 |
||
42 |
try { |
|
43 |
std::shared_ptr<RelationalReader> reader(Factory::create(std::cin)); |
|
44 |
CSVHandler handler(std::cout); |
|
45 |
reader->addHandler(&handler); |
|
46 |
reader->process(); |
|
47 |
||
48 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
|
49 |
||
50 |
} catch (RelpipeCLIException e) { |
|
51 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); |
|
52 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
53 |
resultCode = e.getExitCode(); |
|
54 |
} catch (RelpipeReaderException e) { |
|
55 |
fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str()); |
|
56 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
57 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
|
1
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
58 |
} catch (RelpipeCSVWriterException e) { |
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
59 |
fwprintf(stderr, L"Error while generating CSV: %ls\n", e.getMessge().c_str()); |
82f86dc48339
first working version
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
60 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
0 | 61 |
} |
62 |
||
63 |
return resultCode; |
|
64 |
} |