From 44ffeb07ec307488290148b7439afb5bce122c51 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 24 May 2021 08:15:04 +0200 Subject: [PATCH] Add calls to search::search() to main(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All that's missing now is the actual search functionality. 😊 --- src/main.cpp | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 95adec0..7586d34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ */ #include "options.hpp" -#include "zip.hpp" +#include "search.hpp" #include #include @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -34,6 +35,7 @@ int main(int argc, char *argv[]) { namespace po = boost::program_options; + using namespace epubgrep; using boost::locale::translate; using std::cerr; @@ -53,7 +55,7 @@ int main(int argc, char *argv[]) po::variables_map vm; try { - vm = epubgrep::options::parse_options(argc, argv); + vm = options::parse_options(argc, argv); } catch (std::exception &e) { // Exceptions we can't recover from or ones we don't know. @@ -67,32 +69,38 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } - // Print all options. - for (const auto &opt : vm) - { - if (opt.second.value().type() == typeid(std::vector)) - { - for (const auto &str : opt.second.as>()) - { - cout << opt.first << ": " << str << '\n'; - } - } - else - { - auto second{opt.second.as()}; - if (second.empty()) - { - cout << opt.first << ": true\n"; - } - else - { - cout << opt.first << ": " << second << '\n'; - } - } - } - if (vm.count("input-file") == 0) { + cout << "NO INPUT FILE\n"; // TODO: Read data from stdin. } + else + { + for (const auto &filepath : + vm["input-file"].as>()) + { + for (const auto ®ex : + vm["regexp"].as>()) + { + search::options opts; + // TODO: regex type. + if (vm.count("ignore-case") > 0) + { + opts.ignore_case = true; + } + if (vm.count("raw") > 0) + { + opts.nostrip = true; + } + opts.context = vm["context"].as(); + + for (const auto &match : search::search(filepath, regex, opts)) + { + cout << match.filepath << ", " << match.headline << ", " + << match.page << ": " << match.context.first + << match.text << match.context.second << '\n'; + } + } + } + } }