#!/usr/bin/perl -w

my $infile = $ARGV[0];
my $line = "";
my $oldline = "";
my $pos = "";

die "Usage: ./eagle2cnc.pl infile.cnc > outfile.cnc\n" unless $infile;

open (A, $infile) || die "Cannot open $infile: $!";

# Start to output G-code.
$xmax = 0;
$ymax = 0;

while (<A>) {
	$line = $_;
	# $ok = 0;
	$line =~ s/(X..)/$1./;
	$line =~ s/(Y..)/ $1./;
	print "$line";		

#	$num = $line;
#	if ($num =~ s/X(\d*) Y.*/$1/) {
#		$num /= 100;
#		print "X$num";
#		if ($num>$xmax) {
#			$xmax=$num;
#			}
#	}
#	
#	$num = $line;
#	if ($num =~ s/X.*Y(\d*)/$1/) {
#		$num /= 100;
#		print " Y$num\n";
#		$ok = 1;
#		if ($num>$ymax) {
#			$ymax=$num;
#		}
#	}
#	if ($ok == 0) {
#		print "$line";
#		}
}

# print "(MAX X $xmax, Y $ymax)\n";
# End of G-code output
close A;
