From 3983fe66e902ed8c33d8c8e87852de74442935a2 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Tue, 23 Sep 2014 19:23:11 +0200 Subject: [PATCH] Config: Print parsing errors instead of ignoring them --- src/config.cpp | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 5fb3c49..8abc66b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -121,6 +121,8 @@ static bool validUtf8(const char *string) typedef std::vector StringVec; namespace po = boost::program_options; +#define CONF_FILE "mkxp.conf" + Config::Config() : rgssVersion(0), debugMode(false), @@ -190,26 +192,36 @@ void Config::read(int argc, char *argv[]) po::variables_map vm; /* Parse command line options */ - po::parsed_options cmdPo = - po::command_line_parser(argc, argv).options(podesc) - .allow_unregistered() - .run(); + try + { + po::parsed_options cmdPo = + po::command_line_parser(argc, argv).options(podesc).run(); + po::store(cmdPo, vm); + } + catch (po::error &error) + { + Debug() << "Command line:" << error.what(); + } - GUARD_ALL( po::store(cmdPo, vm); ) - - /* Parse configuration file (mkxp.conf) */ + /* Parse configuration file */ std::ifstream confFile; - confFile.open("mkxp.conf"); + confFile.open(CONF_FILE); if (confFile) { - GUARD_ALL( po::store(po::parse_config_file(confFile, podesc, true), vm); ) + try + { + po::store(po::parse_config_file(confFile, podesc, true), vm); + po::notify(vm); + } + catch (po::error &error) + { + Debug() << CONF_FILE":" << error.what(); + } + + confFile.close(); } - confFile.close(); - - po::notify(vm); - #undef PO_DESC #define PO_DESC(key, type) GUARD_ALL( key = vm[#key].as< type >(); ) @@ -276,7 +288,7 @@ void Config::readGameINI() iniFile.open((iniPath).c_str()); po::variables_map vm; - GUARD_ALL( po::store(po::parse_config_file(iniFile, podesc, true), vm); ) + po::store(po::parse_config_file(iniFile, podesc, true), vm); po::notify(vm); iniFile.close();