diff --git a/drl2gp/drl2gp.c b/drl2gp/drl2gp.c index 4f43fc3..bd03269 100644 --- a/drl2gp/drl2gp.c +++ b/drl2gp/drl2gp.c @@ -22,6 +22,7 @@ */ +#include #include #include #include @@ -47,6 +48,19 @@ static double depth, d0, d1; #define MIL2MM(mil) IN2MM((mil)/1000) +static void eprintf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + if (vprintf(fmt, ap) < 0) { + perror("stdout"); + exit(1); + } + va_end(ap); +} + + static void header(void) { enum { @@ -182,12 +196,12 @@ static void half_circle(double cx, double cy, double rx, double ry, double s) m[3] = m[0]; for (a = 0; a < M_PI; a += s) { - printf("%f %f %f\n", cx+x, cy+y, -depth); + eprintf("%f %f %f\n", cx+x, cy+y, -depth); tmp = x*m[0]+y*m[1]; y = x*m[2]+y*m[3]; x = tmp; } - printf("%f %f %f\n", cx-rx, cy-ry, -depth); + eprintf("%f %f %f\n", cx-rx, cy-ry, -depth); } @@ -208,7 +222,7 @@ static void slot(double xa, double ya, double xb, double yb, double d) half_circle(xa, ya, nx, ny, s); half_circle(xb, yb, -nx, -ny, s); - printf("%f %f %f\n\n", xa+nx, ya+ny, -depth); + eprintf("%f %f %f\n\n", xa+nx, ya+ny, -depth); } @@ -221,15 +235,15 @@ static void circle(double cx, double cy, double d) assert(mill); for (a = 0; a < 2*M_PI; a += s) - printf("%f %f %f\n", + eprintf("%f %f %f\n", cx+(cr-tr)*cos(a), cy+(cr-tr)*sin(a), -depth); - printf("%f %f %f\n\n", cx+(cr-tr), cy, -depth); + eprintf("%f %f %f\n\n", cx+(cr-tr), cy, -depth); } static void drill(double x, double y) { - printf("%f %f %f\n\n", x, y, -depth); + eprintf("%f %f %f\n\n", x, y, -depth); } @@ -443,5 +457,10 @@ int main(int argc, char **argv) header(); body(); + if (fflush(stdout) == EOF) { + perror("stdout"); + exit(1); + } + return 0; }