--- ray/src/rt/devcomm.c 1990/01/19 00:00:08 1.10 +++ ray/src/rt/devcomm.c 1992/03/19 09:34:02 2.2 @@ -12,34 +12,26 @@ static char SCCSid[] = "$SunId$ LBL"; #include "standard.h" -#include - #include "color.h" #include "driver.h" +#include "vfork.h" + #ifndef DEVPATH #define DEVPATH getenv("PATH") /* device search path */ #endif -#ifndef BSD -#define vfork fork +#ifndef DELAY +#define DELAY 20 /* seconds to wait for response */ #endif -#ifndef WFLUSH -#define WFLUSH 30 /* flush after this many rays */ -#endif +static int comm_close(), comm_clear(), comm_paintr(), comm_errout(), + comm_getcur(), comm_comout(), comm_comin(), comm_flush(); -extern char *getpath(), *getenv(); - -int onsigio(); - -int comm_close(), comm_clear(), comm_paintr(), comm_errout(), - comm_getcur(), comm_comout(), comm_comin(); - -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; @@ -55,7 +47,7 @@ char *dname, *id; int p1[2], p2[2]; char pin[16], pout[16]; /* find driver program */ - if ((devname = getpath(dname, DEVPATH, 1)) == NULL) { + if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) { stderr_v(dname); stderr_v(": not found\n"); return(NULL); @@ -80,18 +72,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 */ + getstate(); /* set error vectors */ cmdvec = comm_comout; if (wrnvec != NULL) @@ -111,7 +98,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 +121,26 @@ 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"); + getstate(); +} + + static int comm_getcur(xp, yp) /* get and return cursor position */ int *xp, *yp; @@ -174,21 +164,28 @@ char *str; { putc(COM_COMOUT, devout); myputs(str, devout); - fflush(devout); + if (str[strlen(str)-1] == '\n') + fflush(devout); } static -comm_comin(buf) /* read string from command line */ +comm_comin(buf, prompt) /* read string from command line */ char *buf; +char *prompt; { putc(COM_COMIN, devout); + if (prompt == NULL) + putc(0, devout); + else { + putc(1, devout); + myputs(prompt, devout); + } fflush(devout); if (getc(devin) != COM_COMIN) reply_error("comin"); mygets(buf, devin); - if (comm_driver.inpready > 0) - comm_driver.inpready--; + getstate(); } @@ -237,7 +234,11 @@ char *routine; static -onsigio() /* input ready */ +getstate() /* get driver state variables */ { - comm_driver.inpready++; + 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); }