Ported PlaceholderParser::apply_env_variables() to XS
This commit is contained in:
parent
724e668a94
commit
f361d8ad43
4 changed files with 22 additions and 17 deletions
|
@ -2,20 +2,6 @@ package Slic3r::GCode::PlaceholderParser;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
sub new {
|
|
||||||
# TODO: move this code to C++ constructor, remove this method
|
|
||||||
my ($class) = @_;
|
|
||||||
|
|
||||||
my $self = $class->_new;
|
|
||||||
$self->apply_env_variables;
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub apply_env_variables {
|
|
||||||
my ($self) = @_;
|
|
||||||
$self->_single_set($_, $ENV{$_}) for grep /^SLIC3R_/, keys %ENV;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub process {
|
sub process {
|
||||||
my ($self, $string, $extra) = @_;
|
my ($self, $string, $extra) = @_;
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <unistd.h> // provides **environ
|
||||||
|
|
||||||
|
extern char **environ;
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
PlaceholderParser::PlaceholderParser()
|
PlaceholderParser::PlaceholderParser()
|
||||||
{
|
{
|
||||||
this->_single["version"] = SLIC3R_VERSION;
|
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();
|
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
|
void
|
||||||
PlaceholderParser::set(const std::string &key, const std::string &value)
|
PlaceholderParser::set(const std::string &key, const std::string &value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,7 @@ class PlaceholderParser
|
||||||
PlaceholderParser();
|
PlaceholderParser();
|
||||||
void update_timestamp();
|
void update_timestamp();
|
||||||
void apply_config(DynamicPrintConfig &config);
|
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, const std::string &value);
|
||||||
void set(const std::string &key, int value);
|
void set(const std::string &key, int value);
|
||||||
void set(const std::string &key, const std::vector<std::string> &values);
|
void set(const std::string &key, const std::vector<std::string> &values);
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%name{Slic3r::GCode::PlaceholderParser} class PlaceholderParser {
|
%name{Slic3r::GCode::PlaceholderParser} class PlaceholderParser {
|
||||||
%name{_new} PlaceholderParser();
|
PlaceholderParser();
|
||||||
~PlaceholderParser();
|
~PlaceholderParser();
|
||||||
|
|
||||||
void update_timestamp();
|
void update_timestamp();
|
||||||
|
void apply_env_variables();
|
||||||
void apply_config(DynamicPrintConfig *config)
|
void apply_config(DynamicPrintConfig *config)
|
||||||
%code%{ THIS->apply_config(*config); %};
|
%code%{ THIS->apply_config(*config); %};
|
||||||
void set(std::string key, std::string value);
|
void set(std::string key, std::string value);
|
||||||
|
|
Loading…
Add table
Reference in a new issue