src/relpipe-tr-guile.cpp
author František Kučera <franta-hg@frantovo.cz>
Sun, 26 May 2019 19:46:47 +0200
branchv_0
changeset 23 6ee7a9e311e9
parent 20 dccbfd273a5a
child 26 421608ecc12a
permissions -rw-r--r--
add option: --debug-variable-mapping + different variables for attributes with ambiguous names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
f36bf14d45cb 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
f36bf14d45cb 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
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, either version 3 of the License, or
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 * (at your option) any later version.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 *
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 * GNU General Public License for more details.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 *
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
 */
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <cstdio>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <cstdlib>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <memory>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/cli/CLI.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/cli/RelpipeCLIException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/reader/Factory.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/reader/RelationalReader.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include <relpipe/reader/RelpipeReaderException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include <relpipe/writer/RelationalWriter.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include <relpipe/writer/RelpipeWriterException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include <relpipe/writer/Factory.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
#include <relpipe/writer/TypeId.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
#include "GuileHandler.h"
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    36
#include "CLIParser.h"
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
using namespace relpipe::cli;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
using namespace relpipe::tr::guile;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
1
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    41
static void relpipeMain(void *closure, int argc, char **argv) {
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	setlocale(LC_ALL, "");
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	CLI::untieStdIO();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	CLI cli(argc, argv);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	try {
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    49
		CLIParser cliParser;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    50
		Configuration configuration = cliParser.parse(cli.arguments());
7
61fc569b77e6 RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    51
		std::shared_ptr<reader::RelationalReader> reader(reader::Factory::create(std::cin));
61fc569b77e6 RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    52
		std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
20
dccbfd273a5a remove unused argument
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    53
		GuileHandler handler(writer.get(), configuration);
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		reader->addHandler(&handler);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		reader->process();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		resultCode = CLI::EXIT_CODE_SUCCESS;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	} catch (RelpipeCLIException& e) {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		resultCode = e.getExitCode();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	} catch (RelpipeReaderException& e) {
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
23
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    67
	} catch (GuileException& e) {
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    68
		fwprintf(stderr, L"Caught Guile exception: %ls\n", e.getMessge().c_str());
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    69
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
6ee7a9e311e9 add option: --debug-variable-mapping + different variables for attributes with ambiguous names
František Kučera <franta-hg@frantovo.cz>
parents: 20
diff changeset
    70
		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
1
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    73
	exit(resultCode);
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
}
1
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    75
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    76
int main(int argc, char**argv) {
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    77
	scm_boot_guile(argc, argv, relpipeMain, nullptr);
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    78
	return 222; // never reached – see exit(resultCode) above
1
9179406ab3b3 link to the Guile library and add some Guile demo code – evaluate code from CLI argument
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    79
}