src/relpipe-in-filesystem.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 19:50:23 +0200
branchv_0
changeset 24 4353cd19a6b5
parent 10 3e1608320b6c
child 52 fea625f0a096
permissions -rw-r--r--
fix license version: GNU GPLv3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
4
d44ed75822e7 modular design
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     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
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <fstream>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <regex>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <algorithm>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <unistd.h>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/RelationalWriter.h>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/writer/RelpipeWriterException.h>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/writer/Factory.h>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/writer/TypeId.h>
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/cli/CLI.h>
10
3e1608320b6c parse CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    30
#include <relpipe/cli/RelpipeCLIException.h>
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include "FilesystemCommand.h"
4
d44ed75822e7 modular design
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    33
#include "CLIParser.h"
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
using namespace relpipe::cli;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
using namespace relpipe::writer;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
using namespace relpipe::in::filesystem;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
int main(int argc, char** argv) {
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	setlocale(LC_ALL, "");
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	CLI::untieStdIO();
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	CLI cli(argc, argv);
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	try {
4
d44ed75822e7 modular design
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    47
		CLIParser cliParser;
d44ed75822e7 modular design
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    48
		Configuration configuration = cliParser.parse(cli.arguments());
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		FilesystemCommand command;
4
d44ed75822e7 modular design
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    50
		command.process(cin, cout, configuration);
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		resultCode = CLI::EXIT_CODE_SUCCESS;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	} catch (RelpipeWriterException e) {
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
10
3e1608320b6c parse CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    56
	} catch (RelpipeCLIException e) {
3e1608320b6c parse CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    57
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
3e1608320b6c parse CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    58
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
3e1608320b6c parse CLI arguments
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    59
		resultCode = e.getExitCode();
0
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	}
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	return resultCode;
467d09b62a12 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
}