mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-18 06:55:53 +08:00
Makes post process scripts able to pass args along with filename (#4363)
Any whitespace is the boundrary between the args/filename. Whitespace can be escaped by putting a exxclamation point in front of it. And exclamation points can be escaped by putting an exclamation point in front of the exclamation point to be escaped. I thought about adding another box for arguments, but I think that would make it more confusing to use. The only worry I have with this method is peoples existing scripts with whitespace in the name.
This commit is contained in:
parent
7b8369d00e
commit
331764431e
@ -71,6 +71,34 @@ sub process {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub escaped_split {
|
||||||
|
my ($line) = @_;
|
||||||
|
|
||||||
|
# Free up three characters for temporary replacement
|
||||||
|
$line =~ s/%/%%/g;
|
||||||
|
$line =~ s/#/##/g;
|
||||||
|
$line =~ s/\?/\?\?/g;
|
||||||
|
|
||||||
|
# replace escaped !'s
|
||||||
|
$line =~ s/\!\!/%#\?/g;
|
||||||
|
|
||||||
|
# split on non-escaped whitespace
|
||||||
|
my @split = split /(?<=[^\!])\s+/, $line, -1;
|
||||||
|
|
||||||
|
for my $part (@split) {
|
||||||
|
# replace escaped whitespace with the whitespace
|
||||||
|
$part =~ s/\!(\s+)/$1/g;
|
||||||
|
|
||||||
|
# resub temp symbols
|
||||||
|
$part =~ s/%#\?/\!/g;
|
||||||
|
$part =~ s/%%/%/g;
|
||||||
|
$part =~ s/##/#/g;
|
||||||
|
$part =~ s/\?\?/\?/g;
|
||||||
|
}
|
||||||
|
|
||||||
|
return @split;
|
||||||
|
}
|
||||||
|
|
||||||
sub export_gcode {
|
sub export_gcode {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my %params = @_;
|
my %params = @_;
|
||||||
@ -121,11 +149,14 @@ sub export_gcode {
|
|||||||
$self->config->setenv;
|
$self->config->setenv;
|
||||||
for my $script (@{$self->config->post_process}) {
|
for my $script (@{$self->config->post_process}) {
|
||||||
Slic3r::debugf " '%s' '%s'\n", $script, $output_file;
|
Slic3r::debugf " '%s' '%s'\n", $script, $output_file;
|
||||||
|
my @parsed_script = escaped_split $script;
|
||||||
|
my $executable = shift @parsed_script ;
|
||||||
|
push @parsed_script, $output_file;
|
||||||
# -x doesn't return true on Windows except for .exe files
|
# -x doesn't return true on Windows except for .exe files
|
||||||
if (($^O eq 'MSWin32') ? !(-e $script) : !(-x $script)) {
|
if (($^O eq 'MSWin32') ? !(-e $executable) : !(-x $executable)) {
|
||||||
die "The configured post-processing script is not executable: check permissions. ($script)\n";
|
die "The configured post-processing script is not executable: check permissions or escape whitespace/exclamation points. ($executable) \n";
|
||||||
}
|
}
|
||||||
system($script, $output_file);
|
system($executable, @parsed_script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user