diff --git a/game/main.cpp b/game/main.cpp index 4271ec3976..5d4eb9d031 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -4,71 +4,69 @@ #include #include -#include #include "engine.hpp" using namespace std; -void maintest (boost::filesystem::path dataDir, const std::string& cellName, - std::string master) +/// Parse command line options and openmw.cfg file (if one exists). Results are directly +/// written to \a engine. +/// \return Run OpenMW? + +bool parseOptions (int argc, char**argv, OMW::Engine& engine) { - assert (!dataDir.empty()); - - OMW::Engine engine; - - engine.setDataDir (dataDir); - - engine.setCell (cellName); - - engine.addMaster (master); - - engine.go(); -} - -int main(int argc, char**argv) -{ - try - { boost::program_options::options_description desc ( - "Syntax: openmw \nAllowed options"); + "Syntax: openmw \nAllowed options"); desc.add_options() - ("help", "print help message") - ("data", boost::program_options::value()->default_value ("data"), - "set data directory") - ("start", boost::program_options::value()->default_value ("Beshara"), - "set initial cell (only interior cells supported at the moment") - ("master", boost::program_options::value()->default_value ("Morrowind"), - "master file") - ; + ("help", "print help message") + ("data", boost::program_options::value()->default_value ("data"), + "set data directory") + ("start", boost::program_options::value()->default_value ("Beshara"), + "set initial cell (only interior cells supported at the moment") + ("master", boost::program_options::value()->default_value ("Morrowind"), + "master file") + ; boost::program_options::variables_map variables; std::ifstream configFile ("openmw.cfg"); boost::program_options::store ( - boost::program_options::parse_command_line (argc, argv, desc), variables); + boost::program_options::parse_command_line (argc, argv, desc), variables); boost::program_options::notify (variables); if (configFile.is_open()) - boost::program_options::store ( - boost::program_options::parse_config_file (configFile, desc), variables); + boost::program_options::store ( + boost::program_options::parse_config_file (configFile, desc), variables); if (variables.count ("help")) { - std::cout << desc << std::endl; + std::cout << desc << std::endl; + return false; } - else - { - maintest (variables["data"].as(), variables["start"].as(), - variables["master"].as()); - } - } - catch(exception &e) - { - cout << "\nERROR: " << e.what() << endl; - return 1; - } - return 0; + + engine.setDataDir (variables["data"].as()); + engine.setCell (variables["start"].as()); + engine.addMaster (variables["master"].as()); +} + +int main(int argc, char**argv) +{ + try + { + OMW::Engine engine; + + if (parseOptions (argc, argv, engine)) + { + engine.go(); + } + } + catch(exception &e) + { + cout << "\nERROR: " << e.what() << endl; + return 1; + } + + return 0; }