From f346adb6e199b818a31ecbb5a6e14c9bf15ce98f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 10 Jun 2010 10:31:50 +0200 Subject: [PATCH] implemented program argument handling via boost program options --- CMakeLists.txt | 2 +- game/main.cpp | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cbeb5433..de2061298 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ endif (WIN32) # Dependencies find_package(OGRE REQUIRED) -find_package(Boost REQUIRED COMPONENTS system filesystem) +find_package(Boost REQUIRED COMPONENTS system filesystem program_options) find_package(OIS REQUIRED) include_directories("." ${OGRE_INCLUDE_DIR} ${OIS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} diff --git a/game/main.cpp b/game/main.cpp index 556be85bc..164c258e0 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -1,5 +1,7 @@ #include +#include "boost/program_options.hpp" + #include "esm_store/cell_store.hpp" #include "bsa/bsa_archive.hpp" #include "ogre/renderer.hpp" @@ -65,9 +67,30 @@ void maintest() cout << "\nThat's all for now!\n"; } -int main(/*int argc, char**argv*/) +int main(int argc, char**argv) { - try { maintest(); } + try + { + boost::program_options::options_description desc ( + "Syntax: openmw \nAllowed options"); + + desc.add_options() + ("help", "print help message"); + + boost::program_options::variables_map variables; + boost::program_options::store ( + boost::program_options::parse_command_line (argc, argv, desc), variables); + boost::program_options::notify (variables); + + if (variables.count ("help")) + { + std::cout << desc << std::endl; + } + else + { + maintest(); + } + } catch(exception &e) { cout << "\nERROR: " << e.what() << endl;