mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Hide expand() implementation into settings.cpp.
This commit is contained in:
parent
74afa9f502
commit
4a0ddb4beb
3 changed files with 25 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "dindexer-common/settings.hpp"
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <ciso646>
|
||||
#include <wordexp.h>
|
||||
|
||||
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<dinlib::SettingsDB>();
|
||||
|
@ -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
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
# include <mutex>
|
||||
# include <condition_variable>
|
||||
#endif
|
||||
#include <wordexp.h>
|
||||
#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
|
||||
|
|
Loading…
Reference in a new issue