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