<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl -w

use strict;

my $state = "top";

sub dim($) {
    my $x = shift;
    if ($x =~ m/^([-.0-9]+)mm$/) {
	return $1;
    }
    if ($x =~ m/^([-.0-9]+)(mil)?$/) {
	return $1 * 0.0254;
    }
    # error
    return 0;
}

my %drill = ();
sub add_hole($$$) {
    my $x = shift;
    my $y = shift;
    my $d = shift;
    if (!defined($drill{$d})) {
	$drill{$d} = [];
    }

    push @{$drill{$d}}, [ 132 - $x, 82 - $y ];
}
#132.00x82.00

my $EX = 0;
my $EY = 0;
while (&lt;&gt;) {
    chomp;
    tr/ \t\r\n/ /s;
    s/^ //;
    s/ $//;

    if ($state eq "top") {
	if (m/^Via ?\[ ?(.*) ?\]/) {
	    my ($X, $Y, $Thickness, $Clearance, $Mask, $Drill, $Name, $SFlags) = split(/ /, $1);
	    my $x = dim($X);
	    my $y = dim($Y);
	    my $d = dim($Drill);
	    add_hole($x, $y, $d);
	    next;
	}

	if (m/^Element ?\[ ?(.*) ?\] ?$/) {
	    my ($SFlags, $Desc, $Name, $Value, $MX, $MY, $TX, $TY, $TDir, $TScale, $TSFlags) = split(/ /, $1);
	    $EX = dim($MX);
	    $EY = dim($MY);
	    #print " $Name\n";
	    $state = "element";
	    next;
	}

	#print $_, "\n";
	next;
    }

    if ($state eq "element") {
	if (m/^\($/) {
	    $state = "element(";
	    next;
	}

	next;
    }

    if ($state eq "element(") {
	if (m/^\)$/) {
	    $state = "top";
	    $EX = 0;
	    $EY = 0;
	    next;
	}

	if (m/^Pin ?\[ ?(.*) ?\]$/) {
	    my ($rX, $rY, $Thickness, $Clearance, $Mask, $Drill, $Name, $Number, $SFlags) = split(/ /, $1);
	    my $x = dim($rX);
	    my $y = dim($rY);
	    my $d = dim($Drill);
	    add_hole($EX + $x, $EY + $y, $d);
	}
    }

    next;
}


for my $d (sort { $a &lt;=&gt; $b } keys %drill) {
    my @list = sort { $$a[0] &lt;=&gt; $$b[0] || $$a[1] &lt;=&gt; $$b[1] } @{$drill{$d}};

    for my $r (@list) {
	printf("%5.2f: %7.3f %7.3f\n", $d, $$r[0], $$r[1]);
    }
}
</pre></body></html>