mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-08-07 13:29:49 +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;
|
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
|
} //namespace dinlib
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "dindexer-common/settings.hpp"
|
#include "dindexer-common/settings.hpp"
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
#include <wordexp.h>
|
||||||
|
|
||||||
namespace YAML {
|
namespace YAML {
|
||||||
template<>
|
template<>
|
||||||
|
@ -48,9 +49,15 @@ namespace YAML {
|
||||||
} //namespace YAML
|
} //namespace YAML
|
||||||
|
|
||||||
namespace dinlib {
|
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 {
|
try {
|
||||||
auto settings = YAML::LoadFile(parPath);
|
auto settings = YAML::LoadFile(path);
|
||||||
|
|
||||||
if (settings["db_settings"]) {
|
if (settings["db_settings"]) {
|
||||||
parOut.db = settings["db_settings"].as<dinlib::SettingsDB>();
|
parOut.db = settings["db_settings"].as<dinlib::SettingsDB>();
|
||||||
|
@ -63,4 +70,18 @@ namespace dinlib {
|
||||||
|
|
||||||
return false;
|
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
|
} //namespace dinlib
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
# include <mutex>
|
# include <mutex>
|
||||||
# include <condition_variable>
|
# include <condition_variable>
|
||||||
#endif
|
#endif
|
||||||
#include <wordexp.h>
|
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include "filesearcher.hpp"
|
#include "filesearcher.hpp"
|
||||||
#include "indexer.hpp"
|
#include "indexer.hpp"
|
||||||
|
@ -39,7 +38,6 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void run_hash_calculation ( din::Indexer& parIndexer, bool parShowProgress );
|
void run_hash_calculation ( din::Indexer& parIndexer, bool parShowProgress );
|
||||||
std::string expand ( const char* parString );
|
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
int main (int parArgc, char* parArgv[]) {
|
int main (int parArgc, char* parArgv[]) {
|
||||||
|
@ -66,7 +64,7 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
|
|
||||||
dinlib::Settings settings;
|
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) {
|
if (not loaded) {
|
||||||
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
|
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -175,15 +173,4 @@ namespace {
|
||||||
#endif
|
#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
|
} //unnamed namespace
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue