This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/apps/plasp-app/main.cpp

103 lines
2.6 KiB
C++
Raw Normal View History

#include <algorithm>
2016-05-20 15:29:24 +02:00
#include <iostream>
#include <string>
2016-05-20 15:29:24 +02:00
#include <boost/program_options.hpp>
#include <plasp/pddl/Description.h>
2016-05-20 15:29:24 +02:00
#include <plasp/sas/Description.h>
#include <plasp/sas/TranslatorASP.h>
2016-05-20 15:29:24 +02:00
int main(int argc, char **argv)
{
namespace po = boost::program_options;
po::options_description description("Allowed options");
description.add_options()
2016-05-24 16:24:37 +02:00
("help,h", "Display this help message.")
("version,v", "Display version information.")
2016-06-07 15:54:01 +02:00
("input,i", po::value<std::vector<std::string>>(), "Specify the SAS input file.")
("format,f", po::value<std::string>()->default_value("SAS"), "Specify the file format (SAS or PDDL).");
2016-05-20 15:29:24 +02:00
po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1);
po::variables_map variablesMap;
2016-05-24 16:24:37 +02:00
const auto printHelp =
[&]()
{
std::cout << "Usage: plasp file [options]" << std::endl;
std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl;
std::cout << description;
};
try
{
po::store(po::command_line_parser(argc, argv)
.options(description)
.positional(positionalOptionsDescription)
.run(),
variablesMap);
po::notify(variablesMap);
}
catch (const po::error &e)
{
std::cerr << "Error: " << e.what() << std::endl << std::endl;
printHelp();
return EXIT_FAILURE;
}
2016-05-20 15:29:24 +02:00
if (variablesMap.count("help"))
{
2016-05-24 16:24:37 +02:00
printHelp();
return EXIT_SUCCESS;
}
if (variablesMap.count("version"))
{
std::cout << "plasp version 3.0.0" << std::endl;
2016-05-20 15:29:24 +02:00
return EXIT_SUCCESS;
}
try
{
auto format = variablesMap["format"].as<std::string>();
std::transform(format.begin(), format.end(), format.begin(), ::tolower);
2016-06-07 15:54:01 +02:00
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
if (format == "sas")
{
2016-06-07 15:54:01 +02:00
if (inputFiles.size() > 0)
{
std::cerr << "Error: Only one input file allowed for SAS translation" << std::endl;
printHelp();
return EXIT_FAILURE;
}
const auto sasDescription = variablesMap.count("input")
2016-06-07 15:54:01 +02:00
? plasp::sas::Description::fromFile(inputFiles.front())
: plasp::sas::Description::fromStream(std::cin);
const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription);
sasTranslator.translate(std::cout);
}
else if (format == "pddl")
{
const auto pddlDescription = variablesMap.count("input")
2016-06-07 15:54:01 +02:00
? plasp::pddl::Description::fromFiles(inputFiles)
: plasp::pddl::Description::fromStream(std::cin);
//std::cout << pddlDescription << std::endl;
}
}
catch (const std::exception &e)
{
2016-05-24 16:24:37 +02:00
std::cerr << "Error: " << e.what() << std::endl << std::endl;
printHelp();
return EXIT_FAILURE;
}
2016-05-20 15:29:24 +02:00
return EXIT_SUCCESS;
}