src/relpipe-in-asn1.cpp
branchv_0
changeset 0 28294b895e5e
child 2 7128fabeede0
equal deleted inserted replaced
-1:000000000000 0:28294b895e5e
       
     1 /**
       
     2  * Relational pipes
       
     3  * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
       
     4  *
       
     5  * This program is free software: you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation, version 3 of the License.
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    16  */
       
    17 #include <cstdlib>
       
    18 #include <vector>
       
    19 #include <memory>
       
    20 #include <regex>
       
    21 #include <algorithm>
       
    22 #include <unistd.h>
       
    23 
       
    24 #include <relpipe/writer/RelationalWriter.h>
       
    25 #include <relpipe/writer/RelpipeWriterException.h>
       
    26 #include <relpipe/writer/AttributeMetadata.h>
       
    27 #include <relpipe/writer/Factory.h>
       
    28 #include <relpipe/writer/TypeId.h>
       
    29 
       
    30 #include <relpipe/cli/CLI.h>
       
    31 
       
    32 #include "ASN1Command.h"
       
    33 #include "CLIParser.h"
       
    34 #include "Configuration.h"
       
    35 
       
    36 using namespace std;
       
    37 using namespace relpipe::cli;
       
    38 using namespace relpipe::writer;
       
    39 using namespace relpipe::in::asn1;
       
    40 
       
    41 int main(int argc, char** argv) {
       
    42 	setlocale(LC_ALL, "");
       
    43 	CLI::untieStdIO();
       
    44 	CLI cli(argc, argv);
       
    45 
       
    46 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
       
    47 
       
    48 	try {
       
    49 		CLIParser cliParser;
       
    50 		Configuration configuration = cliParser.parse(cli.arguments());
       
    51 		ASN1Command command;
       
    52 		std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout));
       
    53 		command.process(cin, writer, configuration);
       
    54 		resultCode = CLI::EXIT_CODE_SUCCESS;
       
    55 	} catch (RelpipeWriterException e) {
       
    56 		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
       
    57 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    58 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
       
    59 	}
       
    60 
       
    61 	return resultCode;
       
    62 }