src/relpipe-in-xml.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 22 Oct 2019 19:53:12 +0200
branchv_0
changeset 15 177321664baf
parent 8 14e14a5db027
child 21 657a4ee574a7
permissions -rw-r--r--
fix license version: GNU GPLv3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
8
14e14a5db027 lossless bidirectional XML conversion of relational data
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
751260846c40 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
751260846c40 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
15
177321664baf fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
751260846c40 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,
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
751260846c40 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
751260846c40 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/>.
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <fstream>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <regex>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <algorithm>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <unistd.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/RelationalWriter.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/writer/RelpipeWriterException.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/writer/Factory.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/writer/TypeId.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/cli/CLI.h>
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include "XMLCommand.h"
6
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    32
#include "XercesStringConvertor.h"
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
using namespace relpipe::cli;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
using namespace relpipe::writer;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
using namespace relpipe::in::xml;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
int main(int argc, char** argv) {
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	setlocale(LC_ALL, "");
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	CLI::untieStdIO();
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	CLI cli(argc, argv);
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	try {
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		XMLCommand command;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		command.process(cin, cout);
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		resultCode = CLI::EXIT_CODE_SUCCESS;
2
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
	} catch (RelpipeWriterException& e) {
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
2
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    53
	} catch (const xercesc::XMLException& e) {
6
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    54
		XercesStringConvertor xConvertor;
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    55
		fwprintf(stderr, L"Caught xercesc::XMLException: %ls\n", xConvertor.toString(e.getMessage()).c_str());
2
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    56
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
3ab78bf63467 read XML from istream using Xerces (just parse/validate, no processing yet)
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    57
		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
4
1363ec0879ca report SAX events in a single relation
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    58
	} catch (const xercesc::SAXParseException& e) {
6
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    59
		XercesStringConvertor xConvertor;
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    60
		fwprintf(stderr, L"Caught xercesc::SAXParseException: %ls\n", xConvertor.toString(e.getMessage()).c_str());
be83e0f457a8 move string conversion method to a separate class + report SAX exception details if any
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    61
		fwprintf(stderr, L"\tat line: %d, column: %d\n", e.getLineNumber(), e.getColumnNumber());
4
1363ec0879ca report SAX events in a single relation
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    62
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
1363ec0879ca report SAX events in a single relation
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    63
		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
0
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	}
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	return resultCode;
751260846c40 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
}