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