From 4a0ddb4bebeb451297af0a0f0888869cf1d502bc Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 12 Dec 2015 20:02:42 +0000 Subject: [PATCH] Hide expand() implementation into settings.cpp. --- include/dindexer-common/settings.hpp | 2 +- src/common/settings.cpp | 25 +++++++++++++++++++++++-- src/scan/main.cpp | 15 +-------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/include/dindexer-common/settings.hpp b/include/dindexer-common/settings.hpp index b0d0461..9f0ed50 100644 --- a/include/dindexer-common/settings.hpp +++ b/include/dindexer-common/settings.hpp @@ -34,7 +34,7 @@ namespace dinlib { SettingsDB db; }; - bool load_settings ( const std::string& parPath, Settings& parOut ); + bool load_settings ( const std::string& parPath, Settings& parOut, bool parExpand=true ); } //namespace dinlib #endif diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 5e794ab..0328ee6 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -18,6 +18,7 @@ #include "dindexer-common/settings.hpp" #include #include +#include namespace YAML { template<> @@ -48,9 +49,15 @@ namespace YAML { } //namespace YAML namespace dinlib { - bool load_settings (const std::string& parPath, dinlib::Settings& parOut) { + namespace { + std::string expand ( const char* parString ); + } //unnamed namespace + + bool load_settings (const std::string& parPath, dinlib::Settings& parOut, bool parExpand) { + const std::string path = (parExpand ? expand(parPath.c_str()) : parPath); + try { - auto settings = YAML::LoadFile(parPath); + auto settings = YAML::LoadFile(path); if (settings["db_settings"]) { parOut.db = settings["db_settings"].as(); @@ -63,4 +70,18 @@ namespace dinlib { return false; } + + namespace { + std::string expand (const char* parString) { + wordexp_t p; + wordexp(parString, &p, 0); + char** w = p.we_wordv; + std::ostringstream oss; + for (std::size_t z = 0; z < p.we_wordc; ++z) { + oss << w[z]; + } + wordfree(&p); + return oss.str(); + } + } //unnamed namespace } //namespace dinlib diff --git a/src/scan/main.cpp b/src/scan/main.cpp index 66bd913..4dc3605 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -30,7 +30,6 @@ # include # include #endif -#include #include "dindexerConfig.h" #include "filesearcher.hpp" #include "indexer.hpp" @@ -39,7 +38,6 @@ namespace { void run_hash_calculation ( din::Indexer& parIndexer, bool parShowProgress ); - std::string expand ( const char* parString ); } //unnamed namespace int main (int parArgc, char* parArgv[]) { @@ -66,7 +64,7 @@ int main (int parArgc, char* parArgv[]) { dinlib::Settings settings; { - const bool loaded = dinlib::load_settings(expand(CONFIG_FILE_PATH), settings); + const bool loaded = dinlib::load_settings(CONFIG_FILE_PATH, settings); if (not loaded) { std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n"; return 1; @@ -175,15 +173,4 @@ namespace { #endif } - std::string expand (const char* parString) { - wordexp_t p; - wordexp(parString, &p, 0); - char** w = p.we_wordv; - std::ostringstream oss; - for (std::size_t z = 0; z < p.we_wordc; ++z) { - oss << w[z]; - } - wordfree(&p); - return oss.str(); - } } //unnamed namespace