--- ray/src/rt/devmain.c 1990/02/22 11:46:24 1.8 +++ ray/src/rt/devmain.c 1997/11/11 20:02:59 2.2 @@ -12,22 +12,16 @@ static char SCCSid[] = "$SunId$ LBL"; * 10/25/89 */ -#include +#include "standard.h" -#include - #include "color.h" #include "driver.h" -int (*wrnvec)(), (*errvec)(), (*cmdvec)(); /* error vectors, unused */ - struct driver *dev = NULL; /* output device */ FILE *devin, *devout; /* communications channels */ -int notified = 0; /* notified parent of input? */ - char *progname; /* driver name */ int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush(); @@ -48,27 +42,25 @@ char *argv[]; /* set up I/O */ progname = argv[0]; if (argc < 3) { - stderr_v("arg count\n"); + eputs("arg count\n"); quit(1); } devin = fdopen(atoi(argv[1]), "r"); devout = fdopen(atoi(argv[2]), "w"); if (devin == NULL || devout == NULL || getw(devin) != COM_SENDM) { - stderr_v("connection failure\n"); + eputs("connection failure\n"); quit(1); } /* open device */ if ((dev = dinit(argv[0], argv[3])) == NULL) quit(1); putw(COM_RECVM, devout); /* verify initialization */ - fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); - putw(dev->xsiz, devout); - putw(dev->ysiz, devout); + sendstate(); fflush(devout); /* loop on requests */ while ((com = getc(devin)) != EOF) { if (com >= NREQUESTS || dev_func[com] == NULL) { - stderr_v("invalid request\n"); + eputs("invalid request\n"); quit(1); } (*dev_func[com])(); /* process request */ @@ -105,11 +97,6 @@ r_paintr() /* paint a rectangle */ xmin = getw(devin); ymin = getw(devin); xmax = getw(devin); ymax = getw(devin); (*dev->paintr)(col, xmin, ymin, xmax, ymax); - /* check for input */ - if (!notified && dev->inpready > 0) { - notified = 1; - kill(getppid(), SIGIO); - } } @@ -117,6 +104,9 @@ r_flush() /* flush output */ { if (dev->flush != NULL) (*dev->flush)(); + putc(COM_FLUSH, devout); + sendstate(); + fflush(devout); } @@ -162,9 +152,8 @@ r_comin() /* read string from command line */ /* reply */ putc(COM_COMIN, devout); myputs(buf, devout); + sendstate(); fflush(devout); - /* reset notify */ - notified = 0; } @@ -191,18 +180,29 @@ register FILE *fp; } -stderr_v(s) /* put string to stderr */ +eputs(s) /* put string to stderr */ register char *s; { - static int inline = 0; + static int midline = 0; - if (!inline++) { + if (!*s) + return; + if (!midline++) { fputs(progname, stderr); fputs(": ", stderr); } fputs(s, stderr); - if (*s && s[strlen(s)-1] == '\n') { + if (s[strlen(s)-1] == '\n') { fflush(stderr); - inline = 0; + midline = 0; } +} + + +sendstate() /* send driver state variables */ +{ + fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); + putw(dev->xsiz, devout); + putw(dev->ysiz, devout); + putw(dev->inpready, devout); }