Ported PlaceholderParser::apply_env_variables() to XS

This commit is contained in:
Alessandro Ranellucci 2015-07-01 17:56:38 +02:00
parent 724e668a94
commit f361d8ad43
4 changed files with 22 additions and 17 deletions

View file

@ -2,14 +2,16 @@
#include <ctime>
#include <iomanip>
#include <sstream>
#include <unistd.h> // provides **environ
extern char **environ;
namespace Slic3r {
PlaceholderParser::PlaceholderParser()
{
this->_single["version"] = SLIC3R_VERSION;
// TODO: port these methods to C++, then call them here
// this->apply_env_variables();
this->apply_env_variables();
this->update_timestamp();
}
@ -76,6 +78,21 @@ void PlaceholderParser::apply_config(DynamicPrintConfig &config)
}
}
void
PlaceholderParser::apply_env_variables()
{
for (char** env = environ; *env; env++) {
if (strncmp(*env, "SLIC3R_", 7) == 0) {
std::stringstream ss(*env);
std::string key, value;
std::getline(ss, key, '=');
ss >> value;
this->set(key, value);
}
}
}
void
PlaceholderParser::set(const std::string &key, const std::string &value)
{