--- ray/src/rt/devcomm.c 1991/11/12 17:09:13 2.1 +++ ray/src/rt/devcomm.c 1997/11/11 19:55:03 2.5 @@ -16,19 +16,13 @@ static char SCCSid[] = "$SunId$ LBL"; #include "driver.h" +#include "vfork.h" + #ifndef DEVPATH #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 - -static int comm_close(), comm_clear(), comm_paintr(), comm_errout(), +static int comm_close(), comm_clear(), comm_paintr(), comm_getcur(), comm_comout(), comm_comin(), comm_flush(); struct driver comm_driver = { @@ -36,12 +30,42 @@ struct driver comm_driver = { comm_comout, comm_comin, comm_flush }; +static int mygets(), myputs(), reply_error(), getstate(); + FILE *devin, *devout; int devchild; +static struct driver * +final_connect() /* verify and initialize connection */ +{ + putw(COM_SENDM, devout); + fflush(devout); + if (getw(devin) != COM_RECVM) + return(NULL); + /* get driver parameters */ + getstate(); + /* set error vectors */ + erract[COMMAND].pf = comm_comout; + if (erract[WARNING].pf != NULL) + erract[WARNING].pf = comm_comout; + return(&comm_driver); +} + + struct driver * +slave_init(dname, id) /* run rview in slave mode */ +char *dname, *id; +{ + devchild = -1; /* we're the slave here */ + devout = stdout; /* use standard input */ + devin = stdin; /* and standard output */ + return(final_connect()); /* verify initialization */ +} + + +struct driver * comm_init(dname, id) /* set up and execute driver */ char *dname, *id; { @@ -50,8 +74,8 @@ char *dname, *id; char pin[16], pout[16]; /* find driver program */ if ((devname = getpath(dname, DEVPATH, X_OK)) == NULL) { - stderr_v(dname); - stderr_v(": not found\n"); + eputs(dname); + eputs(": not found\n"); return(NULL); } /* open communication pipes */ @@ -74,18 +98,7 @@ char *dname, *id; goto syserr; if ((devin = fdopen(p2[0], "r")) == NULL) goto syserr; - /* verify initialization */ - putw(COM_SENDM, devout); - fflush(devout); - if (getw(devin) != COM_RECVM) - return(NULL); - /* get driver parameters */ - getstate(); - /* set error vectors */ - cmdvec = comm_comout; - if (wrnvec != NULL) - wrnvec = comm_comout; - return(&comm_driver); + return(final_connect()); /* verify initialization */ syserr: perror(dname); return(NULL); @@ -97,11 +110,13 @@ comm_close() /* done with driver */ { int pid; - cmdvec = NULL; /* reset error vectors */ - if (wrnvec != NULL) - wrnvec = stderr_v; + erract[COMMAND].pf = NULL; /* reset error vectors */ + if (erract[WARNING].pf != NULL) + erract[WARNING].pf = wputs; fclose(devout); fclose(devin); + if (devchild < 0) + return; while ((pid = wait(0)) != -1 && pid != devchild) ; } @@ -192,15 +207,6 @@ char *prompt; static -comm_errout(str) /* display an error message */ -char *str; -{ - comm_comout(str); - stderr_v(str); /* send to standard error also */ -} - - -static mygets(s, fp) /* get string from file (with nul) */ register char *s; register FILE *fp; @@ -229,8 +235,8 @@ static reply_error(routine) /* what should we do here? */ char *routine; { - stderr_v(routine); - stderr_v(": driver reply error\n"); + eputs(routine); + eputs(": driver reply error\n"); quit(1); }