Skip to content
Snippets Groups Projects
Select Git revision
  • main
1 result

README.md

Blame
  • macaon_decode.cpp 2.54 KiB
    #include <cstdio>
    #include <cstdlib>
    #include <boost/program_options.hpp>
    #include "BD.hpp"
    #include "Config.hpp"
    #include "TapeMachine.hpp"
    #include "Decoder.hpp"
    
    namespace po = boost::program_options;
    
    po::options_description getOptionsDescription()
    {
      po::options_description desc("Command-Line Arguments ");
    
      po::options_description req("Required");
      req.add_options()
        ("expName", po::value<std::string>()->required(),
          "Name of this experiment")
        ("tm", po::value<std::string>()->required(),
          "File describing the Tape Machine to use")
        ("bd", po::value<std::string>()->required(),
          "BD file that describes the multi-tapes buffer")
        ("mcd", po::value<std::string>()->required(),
          "MCD file that describes the input")
        ("input,I", po::value<std::string>()->required(),
          "Input file formated according to the mcd");
    
      po::options_description opt("Optional");
      opt.add_options()
        ("help,h", "Produce this help message")
        ("lang", po::value<std::string>()->default_value("fr"),
          "Language you are working with");
    
    
      desc.add(req).add(opt);
    
      return desc;
    }
    
    po::variables_map checkOptions(po::options_description & od, int argc, char ** argv)
    {
      po::variables_map vm;
    
      try {po::store(po::parse_command_line(argc, argv, od), vm);}
      catch(std::exception& e)
      {
        std::cerr << "Error: " << e.what() << "\n";
        od.print(std::cerr);
        exit(1);
      }
    
      if (vm.count("help"))
      {
        std::cout << od << "\n";
        exit(0);
      }
    
      try {po::notify(vm);}
      catch(std::exception& e)
      {
        std::cerr << "Error: " << e.what() << "\n";
        od.print(std::cerr);
        exit(1);
      }
    
      return vm;
    }
    
    int main(int argc, char * argv[])
    {
      auto od = getOptionsDescription();
    
      po::variables_map vm = checkOptions(od, argc, argv);
    
      std::string tmFilename = vm["tm"].as<std::string>();
      std::string bdFilename = vm["bd"].as<std::string>();
      std::string mcdFilename = vm["mcd"].as<std::string>();
      std::string inputFilename = vm["input"].as<std::string>();
      std::string lang = vm["lang"].as<std::string>();
      std::string expName = vm["expName"].as<std::string>();
    
      const char * MACAON_DIR = std::getenv("MACAON_DIR");
      std::string slash = "/";
      std::string expPath = MACAON_DIR + slash + lang + slash + "bin/" + expName + slash;
    
      tmFilename = expPath + tmFilename;
      bdFilename = expPath + bdFilename;
    
      TapeMachine tapeMachine(tmFilename, false, expPath);
    
      BD bd(bdFilename, mcdFilename);
      Config config(bd, expPath);
      config.readInput(inputFilename);
    
      Decoder decoder(tapeMachine, bd, config);
    
      decoder.decode();
    
      return 0;
    }