--- ray/src/rt/devmain.c 1989/10/25 15:37:42 1.1 +++ ray/src/rt/devmain.c 1990/03/22 20:58:09 1.12 @@ -14,8 +14,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include -#include - #include "color.h" #include "driver.h" @@ -26,15 +24,14 @@ 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(); +int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush(); int (*dev_func[NREQUESTS])() = { /* request handlers */ r_clear, r_paintr, - r_getcur, r_comout, r_comin + r_getcur, r_comout, + r_comin, r_flush }; @@ -57,13 +54,10 @@ char *argv[]; quit(1); } /* open device */ - if ((dev = dinit(argv[0], argv[3])) == NULL) { - stderr_v("initialization failure\n"); + if ((dev = dinit(argv[0], argv[3])) == NULL) quit(1); - } putw(COM_RECVM, devout); /* verify initialization */ - putw(dev->xsiz, devout); - putw(dev->ysiz, devout); + sendstate(); fflush(devout); /* loop on requests */ while ((com = getc(devin)) != EOF) { @@ -101,18 +95,23 @@ r_paintr() /* paint a rectangle */ COLOR col; int xmin, ymin, xmax, ymax; - fread(col, sizeof(COLOR), 1, devin); + fread((char *)col, sizeof(COLOR), 1, devin); xmin = getw(devin); ymin = getw(devin); xmax = getw(devin); ymax = getw(devin); (*dev->paintr)(col, xmin, ymin, xmax, ymax); - /* check for input */ - if (dev->inpready > notified) { - kill(getppid(), SIGIO); - notified = dev->inpready; - } } +r_flush() /* flush output */ +{ + if (dev->flush != NULL) + (*dev->flush)(); + putc(COM_FLUSH, devout); + sendstate(); + fflush(devout); +} + + r_getcur() /* get and return cursor position */ { int c; @@ -143,15 +142,20 @@ r_comout() /* print string to command line */ r_comin() /* read string from command line */ { - char buf[256]; + char buf[256], *prompt; + /* get prompt */ + if (getc(devin)) { + mygets(buf, devin); + prompt = buf; + } else + prompt = NULL; /* get string */ - (*dev->comin)(buf); + (*dev->comin)(buf, prompt); /* reply */ putc(COM_COMIN, devout); myputs(buf, devout); + sendstate(); fflush(devout); - /* reset notify */ - notified = 0; } @@ -178,25 +182,27 @@ register FILE *fp; } -repaint(xmin, ymin, xmax, ymax) /* repaint section of display */ -int xmin, ymin, xmax, ymax; -{ - stderr_v("repaint called!\n"); /* no can do! */ -} - - stderr_v(s) /* put string to stderr */ register char *s; { - static int inline = 0; + static int midline = 0; - if (!inline++) { + if (!midline++) { fputs(progname, stderr); fputs(": ", stderr); } fputs(s, stderr); if (*s && 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); }