author | František Kučera <franta-hg@frantovo.cz> |
Wed, 29 Jan 2020 12:40:43 +0100 | |
branch | v_0 |
changeset 71 | f8fe085c1c9f |
parent 57 | c40a241d6e0c |
child 93 | 979848ccdc9c |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
4 | 3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
0 | 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 |
|
24
4353cd19a6b5
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
10
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> |
|
18 |
#include <fstream> |
|
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> |
|
26 |
#include <relpipe/writer/Factory.h> |
|
27 |
#include <relpipe/writer/TypeId.h> |
|
28 |
||
29 |
#include <relpipe/cli/CLI.h> |
|
10 | 30 |
#include <relpipe/cli/RelpipeCLIException.h> |
0 | 31 |
|
53
170a993745be
parallel processing: rename FilesystemCommand to PlainFilesystemCommand
František Kučera <franta-hg@frantovo.cz>
parents:
52
diff
changeset
|
32 |
#include "PlainFilesystemCommand.h" |
52
fea625f0a096
parallel processing: prepare infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
33 |
#include "ParallelFilesystemCommand.h" |
4 | 34 |
#include "CLIParser.h" |
0 | 35 |
|
36 |
using namespace relpipe::cli; |
|
37 |
using namespace relpipe::writer; |
|
38 |
using namespace relpipe::in::filesystem; |
|
39 |
||
40 |
int main(int argc, char** argv) { |
|
41 |
setlocale(LC_ALL, ""); |
|
42 |
CLI::untieStdIO(); |
|
43 |
CLI cli(argc, argv); |
|
44 |
||
45 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
|
46 |
||
47 |
try { |
|
4 | 48 |
CLIParser cliParser; |
49 |
Configuration configuration = cliParser.parse(cli.arguments()); |
|
54
ef726975c34b
parallel processing: rename FilesystemCommandBase to FilesystemCommand
František Kučera <franta-hg@frantovo.cz>
parents:
53
diff
changeset
|
50 |
std::unique_ptr<FilesystemCommand> command; |
53
170a993745be
parallel processing: rename FilesystemCommand to PlainFilesystemCommand
František Kučera <franta-hg@frantovo.cz>
parents:
52
diff
changeset
|
51 |
if (configuration.parallelism == 1) command = std::make_unique<PlainFilesystemCommand>(); |
52
fea625f0a096
parallel processing: prepare infrastructure
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
52 |
else command = std::make_unique<ParallelFilesystemCommand>(); |
57
c40a241d6e0c
parallel processing: use directly file descriptors (FD) instead of STDIO streams
František Kučera <franta-hg@frantovo.cz>
parents:
54
diff
changeset
|
53 |
command->process(STDIN_FILENO, STDOUT_FILENO, 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; |
|
10 | 59 |
} catch (RelpipeCLIException e) { |
60 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); |
|
61 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
|
62 |
resultCode = e.getExitCode(); |
|
0 | 63 |
} |
64 |
||
65 |
return resultCode; |
|
66 |
} |