1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 08:39:33 +02:00

drl2gp.c: added parsing of INCH/METRIC in header

This commit is contained in:
Werner Almesberger 2010-12-08 06:12:16 -03:00
parent 32f36ccbc4
commit a865854a19

View File

@ -47,21 +47,21 @@ static double depth, d0, d1;
#define MIL2MM(mil) IN2MM((mil)/1000) #define MIL2MM(mil) IN2MM((mil)/1000)
/*
* @@@ should at least detect INCH/METRIC
*/
static void header(void) static void header(void)
{ {
enum { enum {
ts_nl, /* at beginning of line */ ts_nl, /* at beginning of line */
ts_t, /* seen a ^T */ ts_t, /* seen a ^T */
ts_metric, /* parsing METRIC,... */
ts_inch, /* parsing INCH,... */
ts_tc, /* seen ^T\d+C */ ts_tc, /* seen ^T\d+C */
ts_skip, /* skip to next \n */ ts_skip, /* skip to next \n */
} state = ts_nl; } state = ts_nl;
int c, tool; int c, tool;
double f = 1; double f = 1;
double tmp; double tmp;
const char *next = NULL;
int metric = 1;
while ((c = getchar()) != EOF) { while ((c = getchar()) != EOF) {
if (out) { if (out) {
@ -77,6 +77,14 @@ static void header(void)
state = ts_t; state = ts_t;
tool = 0; tool = 0;
break; break;
case 'I':
state = ts_inch;
next = "NCH";
break;
case 'M':
state = ts_metric;
next = "ETRIC";
break;
case '%': case '%':
return; return;
case '\n': case '\n':
@ -87,6 +95,24 @@ static void header(void)
break; break;
} }
break; break;
case ts_inch:
if (c == ',')
metric = 0;
else {
if (c == *next++)
break;
}
state = ts_skip;
break;
case ts_metric:
if (c == ',')
metric = 1;
else {
if (c == *next++)
break;
}
state = ts_skip;
break;
case ts_t: case ts_t:
if (isdigit(c)) if (isdigit(c))
tool = tool*10+c-'0'; tool = tool*10+c-'0';
@ -108,6 +134,7 @@ static void header(void)
case ts_tc: case ts_tc:
if (isdigit(c)) { if (isdigit(c)) {
tmp = c-'0'; tmp = c-'0';
if (!metric)
tmp = IN2MM(tmp); tmp = IN2MM(tmp);
if (f == 1) if (f == 1)
tool_d[tool] = tool_d[tool] =
@ -260,12 +287,10 @@ static void do_cmd(char cmd, double v, int nl)
exit(1); exit(1);
} }
d = tool_d[n]; d = tool_d[n];
fprintf(stderr, "T%d -> %f\n", n, d);
if (mill) if (mill)
active = d >= d0; active = d >= d0;
else else
active = d >= d0 && d <= d1; active = d >= d0 && d <= d1;
fprintf(stderr, "%g %g %g -> %d\n", d, d0, d1, active);
break; break;
case 'X': case 'X':
x = metric ? v : IN2MM(v); x = metric ? v : IN2MM(v);