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

drl2gp.c: detect and report errors when writing to standard output

This commit is contained in:
Werner Almesberger 2010-12-08 09:09:21 -03:00
parent a865854a19
commit b75611a750

View File

@ -22,6 +22,7 @@
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
@ -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;
}