src/relpipe-out-tabular.cpp
branchv_0
changeset 11 663e3c9fe7ef
parent 10 6af5371af82d
child 24 992dde455b04
equal deleted inserted replaced
10:6af5371af82d 11:663e3c9fe7ef
       
     1 /**
       
     2  * Relational pipes
       
     3  * Copyright © 2018 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, either version 3 of the License, or
       
     8  * (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17  */
       
    18 #include <cstdlib>
       
    19 #include <memory>
       
    20 
       
    21 #include <relpipe/cli/CLI.h>
       
    22 #include <relpipe/cli/RelpipeCLIException.h>
       
    23 #include <relpipe/reader/Factory.h>
       
    24 #include <relpipe/reader/RelationalReader.h>
       
    25 #include <relpipe/reader/RelpipeReaderException.h>
       
    26 
       
    27 #include "TabularPrefetchingHandler.h"
       
    28 
       
    29 using namespace relpipe::cli;
       
    30 using namespace relpipe::reader;
       
    31 using namespace relpipe::out::tabular;
       
    32 
       
    33 int main(int argc, char** argv) {
       
    34 	setlocale(LC_ALL, "");
       
    35 	CLI::untieStdIO();
       
    36 	CLI cli(argc, argv);
       
    37 
       
    38 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
       
    39 
       
    40 	try {
       
    41 		// if (cli.arguments().size() > 0) {
       
    42 
       
    43 		// const wstring commandName = cli.arguments()[0];
       
    44 		// vector<wstring> arguments(cli.arguments().size() - 1);
       
    45 		// for (int i = 1; i < cli.arguments().size(); i++) {
       
    46 		//	arguments[i - 1] = cli.arguments()[i];
       
    47 		// }
       
    48 
       
    49 		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
       
    50 		TabularPrefetchingHandler handler(std::cout);
       
    51 		reader->addHandler(&handler);
       
    52 		reader->process();
       
    53 
       
    54 		resultCode = CLI::EXIT_CODE_SUCCESS;
       
    55 
       
    56 		// } else {
       
    57 		//	throw RelpipeCLIException(L"Missing command…", CLI::EXIT_CODE_BAD_SYNTAX);
       
    58 		// }
       
    59 	} catch (RelpipeCLIException e) {
       
    60 		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str());
       
    61 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    62 		resultCode = e.getExitCode();
       
    63 	} catch (RelpipeReaderException e) {
       
    64 		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str());
       
    65 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    66 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
       
    67 	}
       
    68 
       
    69 	return resultCode;
       
    70 }