src/relpipe-in-csv.cpp
branchv_0
changeset 0 eca0b23802e8
child 1 5eb4d149c6e2
equal deleted inserted replaced
-1:000000000000 0:eca0b23802e8
       
     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 <fstream>
       
    20 #include <memory>
       
    21 #include <regex>
       
    22 #include <algorithm>
       
    23 #include <unistd.h>
       
    24 
       
    25 #include <relpipe/writer/RelationalWriter.h>
       
    26 #include <relpipe/writer/RelpipeWriterException.h>
       
    27 #include <relpipe/writer/Factory.h>
       
    28 #include <relpipe/writer/TypeId.h>
       
    29 
       
    30 #include <relpipe/cli/CLI.h>
       
    31 
       
    32 using namespace std;
       
    33 using namespace relpipe::cli;
       
    34 using namespace relpipe::writer;
       
    35 
       
    36 /**
       
    37  * see https://hg.frantovo.cz/sql-api/file/tip/prototyp/prototyp.sql#l49
       
    38  */
       
    39 void processDataStream(ostream &output, istream* input) {
       
    40 
       
    41 	for (char ch; input->get(ch);) {
       
    42 		output << "ch: " << ch << endl;
       
    43 	}
       
    44 }
       
    45 
       
    46 int main(int argc, char** argv) {
       
    47 	setlocale(LC_ALL, "");
       
    48 	CLI::untieStdIO();
       
    49 	CLI cli(argc, argv);
       
    50 
       
    51 	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
       
    52 
       
    53 	try {
       
    54 		processDataStream(cout, &cin);
       
    55 		resultCode = CLI::EXIT_CODE_SUCCESS;
       
    56 	} catch (RelpipeWriterException e) {
       
    57 		fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessge().c_str());
       
    58 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
       
    59 		resultCode = CLI::EXIT_CODE_DATA_ERROR;
       
    60 	}
       
    61 
       
    62 	return resultCode;
       
    63 }