--- ray/src/rt/devcomm.c 1989/11/01 17:33:03 1.7 +++ ray/src/rt/devcomm.c 1990/10/18 13:33:09 1.19 @@ -10,10 +10,8 @@ static char SCCSid[] = "$SunId$ LBL"; * 10/5/88 */ -#include +#include "standard.h" -#include - #include "color.h" #include "driver.h" @@ -22,25 +20,20 @@ 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 +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, - MAXRES, MAXRES, 0 + comm_comout, comm_comin, comm_flush }; FILE *devin, *devout; @@ -56,7 +49,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); @@ -81,16 +74,13 @@ char *dname, *id; goto syserr; if ((devin = fdopen(p2[0], "r")) == NULL) goto syserr; - bcopy(&comm_default, &comm_driver, sizeof(comm_driver)); - /* verify & get resolution */ + /* verify initialization */ putw(COM_SENDM, devout); fflush(devout); if (getw(devin) != COM_RECVM) return(NULL); - 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) @@ -110,7 +100,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) @@ -123,8 +112,8 @@ comm_clear(xres, yres) /* clear screen */ int xres, yres; { putc(COM_CLEAR, devout); - fwrite(&xres, sizeof(xres), 1, devout); - fwrite(&yres, sizeof(yres), 1, devout); + putw(xres, devout); + putw(yres, devout); fflush(devout); } @@ -134,22 +123,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(col, sizeof(COLOR), 1, devout); - fwrite(&xmin, sizeof(xmin), 1, devout); - fwrite(&ymin, sizeof(ymin), 1, devout); - fwrite(&xmax, sizeof(xmax), 1, devout); - fwrite(&ymax, sizeof(ymax), 1, devout); - if (nrays - lastflush >= WFLUSH) { - fflush(devout); - lastflush = nrays; - } + fwrite((char *)col, sizeof(COLOR), 1, devout); + putw(xmin, devout); + putw(ymin, devout); + putw(xmax, devout); + putw(ymax, devout); } +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; @@ -161,8 +154,8 @@ int *xp, *yp; if (getc(devin) != COM_GETCUR) reply_error("getcur"); c = getc(devin); - fread(xp, sizeof(*xp), 1, devin); - fread(yp, sizeof(*yp), 1, devin); + *xp = getw(devin); + *yp = getw(devin); return(c); } @@ -173,21 +166,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(); } @@ -236,7 +236,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); }