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