src/relpipe-in-barcode.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 27 Nov 2021 23:15:14 +0100
branchv_0
changeset 6 70e7288481fd
parent 5 8f434dc38444
permissions -rw-r--r--
exception: fix typo: getMessge() → getMessage()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
0a0cb749c10f projekt 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
0a0cb749c10f projekt 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
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
0a0cb749c10f projekt 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,
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
0a0cb749c10f projekt 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
0a0cb749c10f projekt 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/>.
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <memory>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <functional>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/writer/RelationalWriter.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/writer/RelpipeWriterException.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/writer/Factory.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/writer/TypeId.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/cli/CLI.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include <relpipe/cli/RelpipeCLIException.h>
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include "CLIParser.h"
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include "Configuration.h"
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
5
8f434dc38444 rename: qr → barcode
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    32
#include "BarcodeCommand.h"
0
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
using namespace relpipe::cli;
5
8f434dc38444 rename: qr → barcode
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    35
using namespace relpipe::in::barcode;
0
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
using namespace relpipe::writer;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
int main(int argc, char** argv) {
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	setlocale(LC_ALL, "");
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	CLI::untieStdIO();
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	CLI cli(argc, argv);
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	try {
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		CLIParser cliParser;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		Configuration configuration = cliParser.parse(cli.arguments());
5
8f434dc38444 rename: qr → barcode
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    48
		BarcodeCommand command;
0
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		command.process(configuration, writer, std::bind(fflush, stdout)); // std::bind(fflush, XXX) Factory::create(XXX) must be the same stream XXX
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		resultCode = CLI::EXIT_CODE_SUCCESS;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	} catch (RelpipeWriterException& e) {
6
70e7288481fd exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    53
		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessage().c_str());
0
0a0cb749c10f projekt 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());
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	} catch (RelpipeCLIException& e) {
6
70e7288481fd exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    57
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
0
0a0cb749c10f projekt 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());
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		resultCode = e.getExitCode();
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	}
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	return resultCode;
0a0cb749c10f projekt skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
}