35 #if defined(__APPLE__) && defined(__DYNAMIC__)
36 #include <crt_externs.h>
37 #define environ (*_NSGetEnviron())
40 #include <boost/algorithm/string.hpp>
41 #include <boost/program_options.hpp>
42 #include <boost/program_options/environment_iterator.hpp>
48 using namespace boost;
49 using namespace boost::filesystem;
51 using namespace rsc::logging;
69 if (prefix ==
"/usr") {
72 return prefix /
"etc/";
81 char* rawHome = getenv(
"HOME");
83 throw runtime_error(
"Home directory not defined in HOME variable.");
85 string home = string(rawHome) + string(
"/");
87 char* rawHomeDrive = getenv(
"HOMEDRIVE");
89 throw runtime_error(
"HOMEDRIVE variable not set.");
91 char* rawHomePath = getenv(
"HOMEPATH");
93 throw runtime_error(
"HOMEPATH variable not set.");
95 string home = string(rawHomeDrive) + string(rawHomePath) + string(
"\\");
105 const bool& stripPrefix) {
106 if (starts_with(name, prefix)) {
108 string::const_iterator start = name.begin();
110 start = start + prefix.size();
112 transform(start, name.end(), back_inserter(result), &::tolower);
119 EnvironmentVariableSource::EnvironmentVariableSource(
const string& prefix,
120 const bool& stripPrefix) :
121 logger(
Logger::
getLogger(
"rsc.config.EnvironmentVariableSource")), prefix(
122 prefix), stripPrefix(stripPrefix) {
126 for (environment_iterator it = environment_iterator(environ); it
127 != environment_iterator(); ++it) {
128 string name =
transformName(it->first, this->prefix, this->stripPrefix);
134 split(key, name, is_any_of(
"_"));
135 string value = it->second;