From d7998ef14401391c2e41beec9ad5cb423eeb4539 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 27 Jan 2015 20:17:50 +0100 Subject: [PATCH] configuration: initialize undefined variables after all files were parsed --- src/settings.cpp | 2 +- src/utility/option_parser.cpp | 7 ++++++- src/utility/option_parser.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 3bc903ed..d0791289 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -678,7 +678,7 @@ bool Configuration::read(const std::vector &config_paths) std::clog << "Reading configuration from " << config_path << "...\n"; return p.run(f); } - ); + ) && p.initialize_undefined(); } /* vim: set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab : */ diff --git a/src/utility/option_parser.cpp b/src/utility/option_parser.cpp index 21f4cbd6..a88637b9 100644 --- a/src/utility/option_parser.cpp +++ b/src/utility/option_parser.cpp @@ -66,6 +66,11 @@ bool option_parser::run(std::istream &is) } } } + return true; +} + +bool option_parser::initialize_undefined() +{ for (auto &p : m_parsers) { if (!p.second.defined()) @@ -73,7 +78,7 @@ bool option_parser::run(std::istream &is) try { p.second.run_default(); } catch (std::exception &e) { - std::cerr << "Error while finalizing option \"" << p.first << "\": " << e.what() << "\n"; + std::cerr << "Error while initializing option \"" << p.first << "\": " << e.what() << "\n"; return false; } } diff --git a/src/utility/option_parser.h b/src/utility/option_parser.h index 23065a75..ba11ffc1 100644 --- a/src/utility/option_parser.h +++ b/src/utility/option_parser.h @@ -140,6 +140,7 @@ struct option_parser } bool run(std::istream &is); + bool initialize_undefined(); private: std::unordered_map m_parsers;