src/relpipe-in-recfile.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 27 Nov 2021 23:15:15 +0100
branchv_0
changeset 15 a55f4c95f756
parent 8 9c8c20c3bd64
permissions -rw-r--r--
exception: fix typo: getMessge() → getMessage()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
515a697cc9cd 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
515a697cc9cd 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
8
9c8c20c3bd64 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
515a697cc9cd 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,
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
515a697cc9cd 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
515a697cc9cd 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/>.
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <fstream>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <regex>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <algorithm>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <unistd.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/RelationalWriter.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/writer/RelpipeWriterException.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/writer/Factory.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/writer/TypeId.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/cli/CLI.h>
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include "RecfileCommand.h"
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
using namespace relpipe::cli;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
using namespace relpipe::writer;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
using namespace relpipe::in::recfile;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
int main(int argc, char** argv) {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	setlocale(LC_ALL, "");
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	CLI::untieStdIO();
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	CLI cli(argc, argv);
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	try {
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		RecfileCommand command;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		command.process(cin, cout);
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		resultCode = CLI::EXIT_CODE_SUCCESS;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	} catch (RelpipeWriterException& e) {
15
a55f4c95f756 exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    49
		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessage().c_str());
0
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	}
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	return resultCode;
515a697cc9cd project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
}