chiark / gitweb /
quacks-ingredients: gcode manipulation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 20 Feb 2020 14:36:26 +0000 (14:36 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 20 Feb 2020 14:36:26 +0000 (14:36 +0000)
reformat nfc

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
quacks-ingredients-make-copy-gcodes

index df1c3e9c1e16a9f40cf73e4ed672020d79ffd481..742d9246d2114f5e397cc45008906adbae6413a9 100755 (executable)
@@ -41,19 +41,25 @@ done
 
 for l in 2 4 5; do
        gh
-       perl -i~ -0777 -pe '
-               s{
-                       ^G1 \ Z([0-9.]+) \s*\n
-               (       ^G0 \ F(\d+) \ X\S+ \ Y\S+ \s*\n
-                       (?: ; .* \s*\n )?
-                       ^G1 \ Z([0-9.]+) \s*\n  )
-               }{
-                       die unless $1 > $4;
-                       die unless $3 > 9000;
-                       "G0 F$3\n".
-                       "G1 Z".($4 + 0.5)."\n" .
-                       $2
-               }gmxe or die;
+       perl -i~ -0777 -ne '
+               @l = split m{^(?=;LAYER:\d+\n)}m, $_;
+               foreach my $i (0..$#l) {
+                       $l[$i] =~
+                               s{
+                                       ^G1 \ Z([0-9.]+) \s*\n
+                               (       ^G0 \ F(\d+) \ X\S+ \ Y\S+ \s*\n
+                                       (?: ; .* \s*\n )?
+                                       ^G1 \ Z([0-9.]+) \s*\n  )
+                               }{
+                                       die unless $1 > $4;
+                                       die unless $3 > 9000;
+                                       my $z = $i == $#l ? $1 : $4 + 0.5;
+                                       "G0 F$3\n".
+                                       "G1 Z$z\n" .
+                                       $2
+                               }gmxe or $l==0 or die $i;
+               }
+               print or die $! foreach @l;
        ' $g
 done