src/relpipe-out-asn1.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 27 Nov 2021 23:15:16 +0100
branchv_0
changeset 13 e20fecb0bcf1
parent 7 c155b441306f
permissions -rw-r--r--
exception: fix typo: getMessge() → getMessage()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
f4f9cdf7ed59 project and code skeleton: text output
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
7
c155b441306f fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
0
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
#include <cstdlib>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <unistd.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/CLI.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/RelpipeCLIException.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
#include <relpipe/reader/Factory.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/reader/RelationalReader.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/RelpipeReaderException.h>
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#include "ASN1Handler.h"
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
using namespace relpipe::cli;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
using namespace relpipe::reader;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
using namespace relpipe::out::asn1;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
int main(int argc, char** argv) {
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	setlocale(LC_ALL, "");
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	CLI::untieStdIO();
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	CLI cli(argc, argv);
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	try {
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		ASN1Handler handler(std::cout);
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		reader->addHandler(&handler);
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		reader->process();
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		resultCode = CLI::EXIT_CODE_SUCCESS;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	} catch (RelpipeCLIException e) {
13
e20fecb0bcf1 exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    47
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
0
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		resultCode = e.getExitCode();
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	} catch (RelpipeReaderException e) {
13
e20fecb0bcf1 exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents: 7
diff changeset
    51
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str());
0
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	}
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	return resultCode;
f4f9cdf7ed59 project and code skeleton: text output
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
}