mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 03:13:39 +00:00
Ported PlaceholderParser::apply_env_variables() to XS
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ class PlaceholderParser
|
||||
PlaceholderParser();
|
||||
void update_timestamp();
|
||||
void apply_config(DynamicPrintConfig &config);
|
||||
void apply_env_variables();
|
||||
void set(const std::string &key, const std::string &value);
|
||||
void set(const std::string &key, int value);
|
||||
void set(const std::string &key, const std::vector<std::string> &values);
|
||||
|
||||
Reference in New Issue
Block a user