From 65e6f1bfb5f2e513607f58e9b7653c3bd45b0dfc Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 18 Aug 2018 12:59:42 +0300 Subject: [PATCH] Now it read stdin if no file specifed. Also fixed segfault on invalid file. --- main/odcread.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/main/odcread.cc b/main/odcread.cc index 9a7f95a..e6e1748 100644 --- a/main/odcread.cc +++ b/main/odcread.cc @@ -147,18 +147,20 @@ namespace odc { } int main(int argc, char *argv[]) { - if (argc < 2) { - return 1; - } - // Set the locale according to the terminal's environment setlocale(LC_ALL, ""); - std::ifstream in(argv[1], std::ios::in | std::ios::binary); odc::Store* s; try { - s = odc::importDocument(in); + if (argc < 2) { + s = odc::importDocument(std::cin); + } else if (argc = 2) { + std::ifstream in(argv[1], std::ios::in | std::ios::binary); + s = odc::importDocument(in); + } else { + return 1; + } } catch (int trap) { std::cerr << "Exception in parsing file: BlackBox trap no. " << trap << std::endl; return 2; @@ -169,6 +171,10 @@ int main(int argc, char *argv[]) { // std::cout << s->toPlainText() << std::endl; // std::cout << std::endl << std::endl; + if (s == nullptr) { + return 1; + } + try { odc::MyVisitor visitor; s->accept(visitor); -- 2.29.2