--- ray/src/rt/devcomm.c 1990/01/30 11:37:36 1.11 +++ ray/src/rt/devcomm.c 1990/03/06 17:44:37 1.15 @@ -12,8 +12,6 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" -#include - #include "color.h" #include "driver.h" @@ -22,24 +20,24 @@ static char SCCSid[] = "$SunId$ LBL"; #define DEVPATH getenv("PATH") /* device search path */ #endif +#ifndef DELAY +#define DELAY 20 /* seconds to wait for response */ +#endif + #ifndef BSD #define vfork fork #endif -#ifndef WFLUSH -#define WFLUSH 30 /* flush after this many rays */ -#endif - extern char *getpath(), *getenv(); int onsigio(); int comm_close(), comm_clear(), comm_paintr(), comm_errout(), - comm_getcur(), comm_comout(), comm_comin(); + comm_getcur(), comm_comout(), comm_comin(), comm_flush(); -struct driver comm_driver, comm_default = { +struct driver comm_driver = { comm_close, comm_clear, comm_paintr, comm_getcur, - comm_comout, comm_comin + comm_comout, comm_comin, comm_flush }; FILE *devin, *devout; @@ -80,18 +78,13 @@ char *dname, *id; goto syserr; if ((devin = fdopen(p2[0], "r")) == NULL) goto syserr; - copystruct(&comm_driver, &comm_default); - /* verify & get resolution */ + /* verify initialization */ putw(COM_SENDM, devout); fflush(devout); if (getw(devin) != COM_RECVM) return(NULL); - fread((char *)&comm_driver.pixaspect, - sizeof(comm_driver.pixaspect), 1, devin); - comm_driver.xsiz = getw(devin); - comm_driver.ysiz = getw(devin); - /* input handling */ - signal(SIGIO, onsigio); + /* get driver parameters */ + comm_flush(); /* set error vectors */ cmdvec = comm_comout; if (wrnvec != NULL) @@ -111,7 +104,6 @@ comm_close() /* done with driver */ cmdvec = NULL; /* reset error vectors */ if (wrnvec != NULL) wrnvec = stderr_v; - signal(SIGIO, SIG_DFL); fclose(devout); fclose(devin); while ((pid = wait(0)) != -1 && pid != devchild) @@ -135,22 +127,30 @@ comm_paintr(col, xmin, ymin, xmax, ymax) /* paint a re COLOR col; int xmin, ymin, xmax, ymax; { - extern long nrays; /* number of rays traced */ - static long lastflush = 0; /* ray count at last flush */ - putc(COM_PAINTR, devout); fwrite((char *)col, sizeof(COLOR), 1, devout); putw(xmin, devout); putw(ymin, devout); putw(xmax, devout); putw(ymax, devout); - if (nrays - lastflush >= WFLUSH) { - fflush(devout); - lastflush = nrays; - } } +static +comm_flush() /* flush output to driver */ +{ + putc(COM_FLUSH, devout); + fflush(devout); + if (getc(devin) != COM_FLUSH) + reply_error("flush"); + fread((char *)&comm_driver.pixaspect, + sizeof(comm_driver.pixaspect), 1, devin); + comm_driver.xsiz = getw(devin); + comm_driver.ysiz = getw(devin); + comm_driver.inpready = getw(devin); +} + + static int comm_getcur(xp, yp) /* get and return cursor position */ int *xp, *yp; @@ -174,7 +174,6 @@ char *str; { putc(COM_COMOUT, devout); myputs(str, devout); - fflush(devout); } @@ -194,8 +193,7 @@ char *prompt; if (getc(devin) != COM_COMIN) reply_error("comin"); mygets(buf, devin); - if (comm_driver.inpready > 0) - comm_driver.inpready--; + comm_driver.inpready = getw(devin); } @@ -240,11 +238,4 @@ char *routine; stderr_v(routine); stderr_v(": driver reply error\n"); quit(1); -} - - -static -onsigio() /* input ready */ -{ - comm_driver.inpready++; }