Add calls to search::search() to main().
All that's missing now is the actual search functionality. 😊
This commit is contained in:
parent
3222019c69
commit
44ffeb07ec
60
src/main.cpp
60
src/main.cpp
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "options.hpp"
|
||||
#include "zip.hpp"
|
||||
#include "search.hpp"
|
||||
|
||||
#include <boost/locale/generator.hpp>
|
||||
#include <boost/locale/message.hpp>
|
||||
|
@ -23,6 +23,7 @@
|
|||
#include <boost/program_options/variables_map.hpp>
|
||||
|
||||
#include <clocale>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
@ -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<std::string>))
|
||||
{
|
||||
for (const auto &str : opt.second.as<std::vector<std::string>>())
|
||||
{
|
||||
cout << opt.first << ": " << str << '\n';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto second{opt.second.as<std::string>()};
|
||||
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<std::vector<std::string>>())
|
||||
{
|
||||
for (const auto ®ex :
|
||||
vm["regexp"].as<std::vector<std::string>>())
|
||||
{
|
||||
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<std::uint64_t>();
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user