#!/bin/sh
#
# Simple AWK script to convert EAGLE drill data files
# into metric macro input files for VariCAD.
# (c) Gerhard Reithofer, 2005-08-11
#
LANG=C # for correct decimal delimiters,
MIRROR=1 # usually we get the top view whereas
# drill data may com from bottom view
if [ $MIRROR = 1 ]
then SCALE_X=-0.00254
OFFSETX=100.474
else SCALE_X=0.00254
OFFSETX=-0.16
fi
SCALE_Y=0.00254
OFFSETY=-0.169
if [ -z "$1" ] ; then
echo "Usage: `basename $0` drd-file"
exit 1
fi
INP_FILE=$1
if [ ! -f "$INP_FILE" ] ; then
echo "drd-file '$INP_FILE' does not exist."
exit 2
fi
rm -f tool*.dat
awk -v scx=$SCALE_X -v scy=$SCALE_Y \
-v ofx=$OFFSETX -v ofy=$OFFSETY \
'BEGIN{
mode="";
glb_tool_cnt=0;
cur_tool_idx=0;
max_tool_idx=0;
}
function get_tindex(idx) {
for (i=1;i<=max_tool_idx;i++) {
if (glb_tool_num[i] == idx) break;
}
return i;
}
{
iso=toupper($1);
if (iso == "") next;
mode=substr(iso,1,1);
if (mode == "T") {
idx=substr(iso,2,2);
c_pos=index(iso,"C");
if (c_pos) {
siz=substr(iso,5);
cur_tool_idx=get_tindex(idx);
glb_tool_siz[cur_tool_idx]=siz;
glb_tool_num[cur_tool_idx]=idx;
} else {
cur_tool_idx=get_tindex(idx);
cur_tool_siz=glb_tool_siz[cur_tool_idx];
print "Tool change (" idx "): " cur_tool_idx "-" cur_tool_siz;
out_file = "tool-" cur_tool_siz ".dat";
system("rm " out_file " 2>/dev/null");
system("touch " out_file);
}
if (cur_tool_idx>max_tool_idx)
max_tool_idx=cur_tool_idx;
} else if (mode == "X") {
d_len = length(iso);
y_pos = index(iso,"Y");
x_len = y_pos-x_pos-2;
cur_x = substr(iso,2,x_len);
cur_y = substr(iso,y_pos+1);
# Exchgange X and Y values because the drill data
# was created in mirror mode
print scx*cur_x+ofx " " scy*cur_y+ofy >> out_file;
} else if (mode == "G") {
g_code = substr(iso,2);
} else if (mode == "M") {
m_code = substr(iso,2);
} else if (mode == "%") {
comment = substr(iso,2);
} else {
print "# Unexpected line: " iso;
}
}' $INP_FILE
gerhard.reithofer@tech-edv.co.at