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