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