Retro68/LaunchAPPL/LaunchAPPL.cc

117 lines
2.4 KiB
C++
Raw Normal View History

2017-10-01 00:42:02 +00:00
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
#include <vector>
#include <string>
#include "LaunchMethod.h"
#include "Launcher.h"
2017-10-01 21:36:50 +00:00
2017-10-03 09:57:56 +00:00
#ifdef __APPLE__
#include "Classic.h"
#include "Carbon.h"
#endif
#include "Executor.h"
#include "MiniVMac.h"
2017-10-01 21:36:50 +00:00
2017-10-01 00:42:02 +00:00
namespace po = boost::program_options;
namespace fs = boost::filesystem;
using std::string;
using std::vector;
static po::options_description desc;
po::variables_map options;
static void usage()
{
std::cerr << "Usage: " << "LaunchAPPL [options] appl-file\n";
std::cerr << desc << std::endl;
}
int main(int argc, char *argv[])
{
std::vector<LaunchMethod*> methods = {
2017-10-03 09:57:56 +00:00
#ifdef __APPLE__
new Classic(), new Carbon(),
#endif
new Executor(), new MiniVMac()
};
2017-10-01 00:42:02 +00:00
desc.add_options()
2017-10-01 21:36:50 +00:00
("help,h", "show this help message")
("emulator,e", po::value<std::string>(), "what emulator/environment to use")
;
for(LaunchMethod *lm : methods)
lm->GetOptions(desc);
2017-10-01 21:36:50 +00:00
desc.add_options()
2017-10-01 00:42:02 +00:00
("timeout,t", po::value<int>(),"abort after timeout")
2017-10-01 21:36:50 +00:00
("timeout-ok","timeout counts as success")
2017-10-01 00:42:02 +00:00
("logfile", po::value<std::string>(), "read log file")
;
po::options_description hidden, alldesc;
hidden.add_options()
("application,a", po::value<std::string>(), "application" )
;
alldesc.add(desc).add(hidden);
try
{
auto parsed = po::command_line_parser(argc, argv)
.options(alldesc)
.positional(po::positional_options_description().add("application", -1))
.style(po::command_line_style::default_style)
.run();
po::store(parsed, options);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
usage();
return 1;
}
po::notify(options);
if(options.count("help") || !options.count("application") || !options.count("emulator"))
2017-10-01 00:42:02 +00:00
{
usage();
return 0;
}
LaunchMethod *method = NULL;
for(LaunchMethod *lm : methods)
2017-10-01 00:42:02 +00:00
{
if(lm->GetName() == options["emulator"].as<string>())
2017-10-01 00:42:02 +00:00
{
method = lm;
break;
2017-10-01 00:42:02 +00:00
}
2017-10-01 21:36:50 +00:00
}
if(!method)
2017-10-01 21:36:50 +00:00
{
std::cerr << "ERROR: unknown emulator/environment.\n";
return 1;
}
2017-10-01 21:36:50 +00:00
if(!method->CheckOptions(options))
{
std::cerr << "Missing configuration.\n";
return 1;
}
2017-10-01 21:36:50 +00:00
std::unique_ptr<Launcher> launcher = method->MakeLauncher(options);
2017-10-01 21:36:50 +00:00
int timeout = options.count("timeout") ? options["timeout"].as<int>() : 0;
2017-10-01 21:36:50 +00:00
bool result = launcher->Go(timeout);
2017-10-01 21:36:50 +00:00
launcher->DumpOutput();
2017-10-01 21:36:50 +00:00
2017-10-01 00:42:02 +00:00
return result ? 0 : 1;
2017-10-01 00:42:02 +00:00
}