src/relpipe-out-jack.cpp
author František Kučera <franta-hg@frantovo.cz>
Tue, 29 Sep 2020 20:10:29 +0200
branchv_0
changeset 0 3bc3b33ccb02
child 3 baa8055c5b10
permissions -rw-r--r--
project skeleton
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
3bc3b33ccb02 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
3bc3b33ccb02 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
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
3bc3b33ccb02 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,
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
3bc3b33ccb02 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
3bc3b33ccb02 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/>.
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <cstdlib>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/CLI.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/RelpipeCLIException.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/common/type/typedefs.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/Factory.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/reader/RelationalReader.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/reader/RelpipeReaderException.h>
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include "Configuration.h"
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include "CLIParser.h"
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
#include "JackHandler.h"
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
#include "JackException.h"
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
using namespace relpipe::cli;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
using namespace relpipe::reader;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
using namespace relpipe::out::jack;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
int main(int argc, char**argv) {
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	CLI cli(argc, argv);
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	CLI::untieStdIO();
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	try {
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		CLIParser cliParser;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		Configuration configuration = cliParser.parse(cli.arguments());
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		JackHandler handler(configuration);
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		reader->addHandler(&handler);
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		reader->process();
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		resultCode = CLI::EXIT_CODE_SUCCESS;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	} catch (RelpipeCLIException e) {
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
3bc3b33ccb02 project skeleton
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());
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		resultCode = e.getExitCode();
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	} catch (RelpipeReaderException e) {
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
3bc3b33ccb02 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());
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	} catch (JackException e) {
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
		fwprintf(stderr, L"Error while generating Jack: %ls\n", e.getMessge().c_str());
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	}
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	return resultCode;
3bc3b33ccb02 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
}