Commit 13779fec authored by Kučera Petr RNDr. Ph.D.'s avatar Kučera Petr RNDr. Ph.D.
Browse files

nnfsmooth options with PrgOptions

parent 5f3ebe2b
......@@ -7,7 +7,6 @@
*/
#include <csignal>
#include <cxxopts.hpp>
#include <iostream>
#include "dnnf.h"
......@@ -22,7 +21,6 @@ struct config_t
{
std::string input_file{};
std::string output_file{};
unsigned verbosity{3}; // 0 means no output
bool check_only{false};
};
......@@ -33,57 +31,25 @@ dump_config(const config_t &conf, unsigned level)
SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl;
SUBool::logs.TLog(level)
<< "\toutput_file: " << conf.output_file << std::endl;
SUBool::logs.TLog(level) << "\tverbosity: " << conf.verbosity << std::endl;
SUBool::logs.TLog(level)
<< "\tverbosity: " << SUBool::logs.mVerbLevel << std::endl;
SUBool::logs.TLog(level) << "\tcheck_only: " << conf.check_only << std::endl;
}
int
parse_arguments(int argc, char *argv[], config_t &conf)
std::optional<config_t>
parse_arguments(int argc, char *argv[])
{
try
{
cxxopts::Options options(SUBool::kPrgName, SUBool::kPrgDesc);
options.positional_help("[input [output]]");
options.add_options()("h,help", "Print help")(
"v,version", "Print version info")("b,verbosity",
"Verbosity level of the log which is written to standard output."
" 0 means no log is written, however messages of glucose can still "
"appear.",
cxxopts::value<unsigned>(conf.verbosity)
->default_value(SUBool::LogStream::kMaxLogLevels))("i,input",
"Input file with a DNNF in the format of c2d",
cxxopts::value<std::string>(conf.input_file))("o,output",
"Output file with the DNNF in the format of c2d",
cxxopts::value<std::string>(conf.output_file))("c,check-only",
"Only check if the given NNF is smooth.",
cxxopts::value<bool>(conf.check_only)->default_value("false"));
options.parse_positional({"input", "output", "positional"});
auto result = options.parse(argc, argv);
if (result.count("help"))
{
std::cout << options.help() << std::endl;
return 1;
}
if (result.count("version"))
{
SUBool::print_version(std::cout);
return 1;
}
if (result.count("positional"))
{
SUBool::logs.TLog(0) << "Multiple files passed as parameters, ";
SUBool::logs.TLog(0)
<< "only input and output are allowed" << std::endl;
SUBool::logs.TLog(0) << options.help() << std::endl;
return 1;
}
}
catch (const cxxopts::OptionException &e)
config_t conf;
SUBool::PrgOptions opts;
opts.InputOutput(&conf.input_file, &conf.output_file);
po::options_description desc("Configuration options");
desc.add_options()("check-only,k", po::bool_switch(&conf.check_only),
"Only check if the given NNF is smooth.");
if (!opts.Parse(argc, argv))
{
std::cerr << "Error parsing options: " << e.what() << std::endl;
return 1;
return {};
}
return 0;
return conf;
}
void
......@@ -96,19 +62,17 @@ term_func(int signal)
int
main(int argc, char *argv[])
{
config_t conf;
int r = parse_arguments(argc, argv, conf);
if (r != 0)
auto conf = parse_arguments(argc, argv);
if (!conf)
{
return r;
return 1;
}
SUBool::logs.mVerbLevel = conf.verbosity;
std::signal(SIGTERM, term_func);
std::signal(SIGQUIT, term_func);
std::signal(SIGINT, term_func);
dump_config(conf, 0);
auto nnf = SUBool::input_or_die<SUBool::Nnf>(conf.input_file, SUBool::logs);
if (conf.check_only)
dump_config(*conf, 3);
auto nnf = SUBool::input_or_die<SUBool::Nnf>(conf->input_file, SUBool::logs);
if (conf->check_only)
{
auto traits = SUBool::nnf_traits(nnf);
if (traits.smooth)
......@@ -123,7 +87,7 @@ main(int argc, char *argv[])
}
auto smooth_nnf = SUBool::nnf_smooth(std::move(nnf));
SUBool::logs.TLog(1) << "Finished" << std::endl;
SUBool::output(conf.output_file, smooth_nnf);
SUBool::output(conf->output_file, smooth_nnf);
SUBool::logs.TLog(1) << "Output written" << std::endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment