2021-05-20 04:30:31 +02:00
|
|
|
/* This file is part of epubgrep.
|
|
|
|
* Copyright © 2021 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "options.hpp"
|
2021-05-21 01:56:37 +02:00
|
|
|
#include "zip.hpp"
|
2021-05-20 04:30:31 +02:00
|
|
|
|
2021-05-20 07:07:47 +02:00
|
|
|
#include <boost/locale/generator.hpp>
|
2021-05-21 01:48:55 +02:00
|
|
|
#include <boost/locale/message.hpp>
|
2021-05-20 09:05:52 +02:00
|
|
|
#include <boost/program_options/errors.hpp>
|
|
|
|
#include <boost/program_options/variables_map.hpp>
|
2021-05-20 07:07:47 +02:00
|
|
|
|
2021-05-23 06:32:56 +02:00
|
|
|
#include <clocale>
|
2021-05-20 04:30:31 +02:00
|
|
|
#include <cstdlib>
|
2021-05-20 09:05:52 +02:00
|
|
|
#include <exception>
|
2021-05-20 04:30:31 +02:00
|
|
|
#include <iostream>
|
2021-05-20 07:07:47 +02:00
|
|
|
#include <locale>
|
2021-05-20 11:25:56 +02:00
|
|
|
#include <string>
|
2021-05-23 16:52:32 +02:00
|
|
|
#include <typeinfo>
|
2021-05-20 11:25:56 +02:00
|
|
|
#include <vector>
|
2021-05-20 04:30:31 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2021-05-20 09:05:52 +02:00
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
2021-05-21 01:48:55 +02:00
|
|
|
using boost::locale::translate;
|
2021-05-20 09:05:52 +02:00
|
|
|
using std::cerr;
|
2021-05-20 04:30:31 +02:00
|
|
|
using std::cout;
|
|
|
|
|
2021-05-23 06:32:56 +02:00
|
|
|
// locale_generator("").name.c_str() returns "*" instead of "". That's why
|
|
|
|
// the global C locale isn't changed. So we have to set it additionally.
|
|
|
|
std::setlocale(LC_ALL, "");
|
2021-05-20 07:07:47 +02:00
|
|
|
boost::locale::generator locale_generator;
|
|
|
|
locale_generator.add_messages_path("translations");
|
|
|
|
locale_generator.add_messages_path("/usr/share/locale");
|
|
|
|
locale_generator.add_messages_domain("epubgrep");
|
|
|
|
std::locale::global(locale_generator(""));
|
|
|
|
cout.imbue(std::locale());
|
2021-05-21 04:10:11 +02:00
|
|
|
cerr.imbue(std::locale());
|
2021-05-20 07:07:47 +02:00
|
|
|
|
2021-05-20 09:05:52 +02:00
|
|
|
po::variables_map vm;
|
|
|
|
try
|
|
|
|
{
|
2021-05-21 01:50:13 +02:00
|
|
|
vm = epubgrep::options::parse_options(argc, argv);
|
2021-05-20 09:05:52 +02:00
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{ // Exceptions we can't recover from or ones we don't know.
|
2021-05-23 08:55:15 +02:00
|
|
|
cerr << '\n' << translate("ERROR: ") << e.what() << '\n';
|
2021-05-21 01:48:55 +02:00
|
|
|
cerr << translate("Error while parsing options.") << '\n';
|
2021-05-20 09:05:52 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2021-05-20 04:30:31 +02:00
|
|
|
|
|
|
|
if (vm.count("help") + vm.count("version") > 0)
|
|
|
|
{
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-23 16:52:32 +02:00
|
|
|
// Print all options.
|
|
|
|
for (const auto &opt : vm)
|
2021-05-23 16:23:07 +02:00
|
|
|
{
|
2021-05-23 16:52:32 +02:00
|
|
|
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
|
2021-05-23 16:23:07 +02:00
|
|
|
{
|
2021-05-23 16:52:32 +02:00
|
|
|
auto second{opt.second.as<std::string>()};
|
|
|
|
if (second.empty())
|
|
|
|
{
|
|
|
|
cout << opt.first << ": true\n";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << opt.first << ": " << second << '\n';
|
|
|
|
}
|
2021-05-23 16:23:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 05:46:12 +02:00
|
|
|
if (vm.count("input-file") == 0)
|
2021-05-20 11:25:56 +02:00
|
|
|
{
|
2021-05-24 05:46:12 +02:00
|
|
|
// TODO: Read data from stdin.
|
2021-05-20 11:25:56 +02:00
|
|
|
}
|
2021-05-20 04:30:31 +02:00
|
|
|
}
|