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

cnfdiff using PrgOptions

parent b51ffc69
......@@ -71,6 +71,10 @@ parse_arguments(int argc, char *argv[])
void
dump_config(const config_t &conf, unsigned level)
{
if (!SUBool::logs.CheckLevel(level))
{
return;
}
SUBool::logs.TLog(level) << "Configuration:" << std::endl;
SUBool::logs.TLog(level) << "\tinput_file: " << conf.input_file << std::endl;
SUBool::logs.TLog(level)
......@@ -154,7 +158,7 @@ main(int argc, char *argv[])
{
return 1;
}
dump_config(*conf, 1);
dump_config(*conf, 4);
SUBool::CNF cnf;
int ret = input(*conf, &cnf);
if (ret != 0)
......
......@@ -61,6 +61,10 @@ struct config_t
void
dump_config(const config_t &conf, unsigned level)
{
if (!SUBool::logs.CheckLevel(level))
{
return;
}
SUBool::logs.TLog(level) << "Configuration:" << std::endl;
SUBool::logs.TLog(level) << "\tfile_left: " << conf.file_left << std::endl;
SUBool::logs.TLog(level) << "\tfile_right: " << conf.file_right << std::endl;
......@@ -300,7 +304,7 @@ main(int argc, char *argv[])
{
return 1;
}
dump_config(*conf, 0);
dump_config(*conf, 4);
auto left_cnf =
SUBool::input_or_die<SUBool::CNF>(conf->file_left, SUBool::logs);
auto right_cnf =
......
......@@ -6,8 +6,6 @@
* Program for comparing two CNFs as sets of clauses (not as representations of
* functions).
*/
#include <cxxopts.hpp>
#include "normalform.h"
#include "prgutil.h"
......@@ -20,7 +18,6 @@ struct config_t
{
std::string file_left{};
std::string file_right{};
unsigned verbosity{3}; // 0 means no output
bool suppress_first{false};
bool suppress_second{false};
bool suppress_third{false};
......@@ -29,68 +26,39 @@ struct config_t
void
dump_config(const config_t &conf, unsigned level)
{
if (!SUBool::logs.CheckLevel(level))
{
return;
}
SUBool::logs.TLog(level) << "Configuration:" << std::endl;
SUBool::logs.DumpValue("\t", level, "file_left", conf.file_left);
SUBool::logs.DumpValue("\t", level, "file_right", conf.file_right);
SUBool::logs.DumpValue("\t", level, "verbosity", conf.verbosity);
SUBool::logs.DumpValue("\t", level, "verbosity", SUBool::logs.mVerbLevel);
SUBool::logs.DumpValue("\t", level, "suppress_first", conf.suppress_first);
SUBool::logs.DumpValue("\t", level, "suppress_second", conf.suppress_second);
SUBool::logs.DumpValue("\t", level, "suppress_third", conf.suppress_third);
}
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-left [input-right]]");
std::string check_kind;
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))("l,input-left",
"The left hand input file",
cxxopts::value<std::string>(conf.file_left))("r,input-right",
"The right hand input file",
cxxopts::value<std::string>(conf.file_right))("1",
"Suppress printing the clauses unique to the first CNF.",
cxxopts::value<bool>(conf.suppress_first)
->default_value("false"))("2",
"Suppress printing the clauses unique to the second CNF.",
cxxopts::value<bool>(conf.suppress_second)
->default_value("false"))("3",
"Suppress printing the clauses which are in both CNF formulas.",
cxxopts::value<bool>(conf.suppress_third)->default_value("false"));
options.parse_positional({"input-left", "input-right", "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 two input files 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.InputPair(
{&conf.file_left, "input-left"}, {&conf.file_right, "input-right"});
po::options_description desc("Configuration options");
desc.add_options()(",1", po::bool_switch(&conf.suppress_first),
"Suppress printing the clauses unique to the first CNF.")(",2",
po::bool_switch(&conf.suppress_second),
"Suppress printing the clauses unique to the second CNF.")(",3",
po::bool_switch(&conf.suppress_third),
"Suppress printing the clauses unique to the third CNF.");
opts.Add(desc);
if (!opts.Parse(argc, argv))
{
std::cerr << "Error parsing options: " << e.what() << std::endl;
return 1;
return {};
}
return 0;
return conf;
}
void
......@@ -151,13 +119,14 @@ compare(SUBool::CNF left, SUBool::CNF right, config_t &conf)
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;
}
compare(SUBool::input_or_die<SUBool::CNF>(conf.file_left, SUBool::logs),
SUBool::input_or_die<SUBool::CNF>(conf.file_right, SUBool::logs), conf);
dump_config(*conf, 4);
compare(SUBool::input_or_die<SUBool::CNF>(conf->file_left, SUBool::logs),
SUBool::input_or_die<SUBool::CNF>(conf->file_right, SUBool::logs),
*conf);
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