src/relpipe-in-xmltable.cpp
author František Kučera <franta-hg@frantovo.cz>
Fri, 20 Nov 2020 10:03:07 +0100
branchv_0
changeset 22 53f1f3a5649a
parent 4 a0689654b3c2
child 45 0142a748169d
permissions -rw-r--r--
XML name escaping: in namespace aware mode: escape also the colon
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
4
a0689654b3c2 fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * 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
    15
 * 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
    16
 */
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <fstream>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <regex>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <algorithm>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <unistd.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <libxml++-2.6/libxml++/libxml++.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/writer/RelationalWriter.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/writer/RelpipeWriterException.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <relpipe/writer/Factory.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/writer/TypeId.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include <relpipe/cli/CLI.h>
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
#include "XMLTableCommand.h"
1
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    34
#include "CLIParser.h"
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    35
#include "Configuration.h"
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
using namespace relpipe::cli;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
using namespace relpipe::writer;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
using namespace relpipe::in::xmltable;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
int main(int argc, char** argv) {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	setlocale(LC_ALL, "");
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	CLI::untieStdIO();
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	CLI cli(argc, argv);
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	try {
1
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
		CLIParser cliParser;
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    50
		Configuration configuration = cliParser.parse(cli.arguments());
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		XMLCommand command;
2
0d3eb5129582 convert arbitrary XML to one or more relations
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    52
		command.process(cin, cout, configuration);
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		resultCode = CLI::EXIT_CODE_SUCCESS;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	} catch (RelpipeWriterException& e) {
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		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
    56
		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
    57
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
1
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    58
	} catch (RelpipeCLIException& e) {
7d6ac51c0d48 configuration and CLI parser
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    59
		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
    60
		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
    61
		resultCode = e.getExitCode();
0
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	} // TODO: catch xmlpp::exception
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	return resultCode;
a37196931f63 project skeleton, libxml2
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
}