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