src/relpipe-tr-scheme.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 27 Nov 2021 23:15:18 +0100
branchv_0
changeset 37 673fe926619a
parent 33 e87c231afb77
permissions -rw-r--r--
exception: fix typo: getMessge() → getMessage()
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
26
421608ecc12a fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
f36bf14d45cb 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,
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
f36bf14d45cb 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
f36bf14d45cb 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/>.
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
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
#include <cstdio>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <cstdlib>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
#include <memory>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/CLI.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/cli/RelpipeCLIException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/Factory.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/reader/RelationalReader.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/reader/RelpipeReaderException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include <relpipe/writer/RelationalWriter.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include <relpipe/writer/RelpipeWriterException.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include <relpipe/writer/Factory.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include <relpipe/writer/TypeId.h>
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
33
e87c231afb77 relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    34
#include "SchemeHandler.h"
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    35
#include "CLIParser.h"
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
using namespace relpipe::cli;
33
e87c231afb77 relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    38
using namespace relpipe::tr::scheme;
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
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
    40
static void relpipeMain(void *closure, int argc, char **argv) {
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	setlocale(LC_ALL, "");
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	CLI::untieStdIO();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	CLI cli(argc, argv);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	try {
6
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    48
		CLIParser cliParser;
4062b8436838 CLI parser: first version (only single relation is supported)
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    49
		Configuration configuration = cliParser.parse(cli.arguments());
7
61fc569b77e6 RelationalWriter dependency injection
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    50
		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
    51
		std::shared_ptr<writer::RelationalWriter> writer(writer::Factory::create(std::cout));
33
e87c231afb77 relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    52
		SchemeHandler handler(writer.get(), configuration);
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		reader->addHandler(&handler);
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		reader->process();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		resultCode = CLI::EXIT_CODE_SUCCESS;
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	} catch (RelpipeCLIException& e) {
37
673fe926619a exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    59
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
0
f36bf14d45cb project skeleton
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());
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		resultCode = e.getExitCode();
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	} catch (RelpipeReaderException& e) {
37
673fe926619a exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    63
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str());
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		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
    65
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
33
e87c231afb77 relpipe-tr-guile → relpipe-tr-scheme
František Kučera <franta-hg@frantovo.cz>
parents: 26
diff changeset
    66
	} catch (SchemeException& e) {
37
673fe926619a exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    67
		fwprintf(stderr, L"Caught Scheme exception: %ls\n", e.getMessage().c_str());
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
    68
		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
    69
		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	}
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
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
    72
	exit(resultCode);
0
f36bf14d45cb project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
}
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
    74
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
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
    76
	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
    77
	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
    78
}