| 10 |
|
* 10/5/88 |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
< |
#include <stdio.h> |
| 13 |
> |
#include "standard.h" |
| 14 |
|
|
| 15 |
– |
#include <signal.h> |
| 16 |
– |
|
| 15 |
|
#include "color.h" |
| 16 |
|
|
| 17 |
|
#include "driver.h" |
| 24 |
|
#define vfork fork |
| 25 |
|
#endif |
| 26 |
|
|
| 29 |
– |
#ifndef WFLUSH |
| 30 |
– |
#define WFLUSH 30 /* flush after this many rays */ |
| 31 |
– |
#endif |
| 32 |
– |
|
| 27 |
|
extern char *getpath(), *getenv(); |
| 28 |
|
|
| 29 |
|
int onsigio(); |
| 30 |
|
|
| 31 |
|
int comm_close(), comm_clear(), comm_paintr(), comm_errout(), |
| 32 |
< |
comm_getcur(), comm_comout(), comm_comin(); |
| 32 |
> |
comm_getcur(), comm_comout(), comm_comin(), comm_flush(); |
| 33 |
|
|
| 34 |
< |
struct driver comm_driver, comm_default = { |
| 34 |
> |
struct driver comm_driver = { |
| 35 |
|
comm_close, comm_clear, comm_paintr, comm_getcur, |
| 36 |
< |
comm_comout, comm_comin, |
| 43 |
< |
MAXRES, MAXRES, 0 |
| 36 |
> |
comm_comout, comm_comin, comm_flush |
| 37 |
|
}; |
| 38 |
|
|
| 39 |
|
FILE *devin, *devout; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
struct driver * |
| 45 |
< |
comm_init(argv) /* set up and execute driver */ |
| 46 |
< |
char *argv[]; |
| 45 |
> |
comm_init(dname, id) /* set up and execute driver */ |
| 46 |
> |
char *dname, *id; |
| 47 |
|
{ |
| 48 |
|
char *devname; |
| 49 |
|
int p1[2], p2[2]; |
| 50 |
< |
|
| 51 |
< |
if ((devname = getpath(argv[0], DEVPATH)) == NULL) { |
| 52 |
< |
stderr_v(argv[0]); |
| 50 |
> |
char pin[16], pout[16]; |
| 51 |
> |
/* find driver program */ |
| 52 |
> |
if ((devname = getpath(dname, DEVPATH, 1)) == NULL) { |
| 53 |
> |
stderr_v(dname); |
| 54 |
|
stderr_v(": not found\n"); |
| 55 |
|
return(NULL); |
| 56 |
|
} |
| 57 |
+ |
/* open communication pipes */ |
| 58 |
|
if (pipe(p1) == -1 || pipe(p2) == -1) |
| 59 |
|
goto syserr; |
| 60 |
< |
if ((devchild = vfork()) == 0) { |
| 60 |
> |
if ((devchild = vfork()) == 0) { /* fork driver process */ |
| 61 |
|
close(p1[1]); |
| 62 |
|
close(p2[0]); |
| 63 |
< |
if (p1[0] != 0) { |
| 64 |
< |
dup2(p1[0], 0); |
| 65 |
< |
close(p1[0]); |
| 66 |
< |
} |
| 72 |
< |
if (p2[1] != 1) { |
| 73 |
< |
dup2(p2[1], 1); |
| 74 |
< |
close(p2[1]); |
| 75 |
< |
} |
| 76 |
< |
execv(devname, argv); |
| 77 |
< |
stderr_v(devname); |
| 78 |
< |
stderr_v(": cannot execute\n"); |
| 63 |
> |
sprintf(pin, "%d", p1[0]); |
| 64 |
> |
sprintf(pout, "%d", p2[1]); |
| 65 |
> |
execl(devname, dname, pin, pout, id, 0); |
| 66 |
> |
perror(devname); |
| 67 |
|
_exit(127); |
| 68 |
|
} |
| 69 |
|
if (devchild == -1) |
| 74 |
|
goto syserr; |
| 75 |
|
if ((devin = fdopen(p2[0], "r")) == NULL) |
| 76 |
|
goto syserr; |
| 77 |
< |
bcopy(&comm_default, &comm_driver, sizeof(comm_driver)); |
| 78 |
< |
signal(SIGIO, onsigio); |
| 79 |
< |
cmdvec = comm_comout; /* set error vectors */ |
| 77 |
> |
/* verify & get resolution */ |
| 78 |
> |
putw(COM_SENDM, devout); |
| 79 |
> |
fflush(devout); |
| 80 |
> |
if (getw(devin) != COM_RECVM) |
| 81 |
> |
return(NULL); |
| 82 |
> |
fread((char *)&comm_driver.pixaspect, |
| 83 |
> |
sizeof(comm_driver.pixaspect), 1, devin); |
| 84 |
> |
comm_driver.xsiz = getw(devin); |
| 85 |
> |
comm_driver.ysiz = getw(devin); |
| 86 |
> |
/* set error vectors */ |
| 87 |
> |
cmdvec = comm_comout; |
| 88 |
|
if (wrnvec != NULL) |
| 89 |
|
wrnvec = comm_comout; |
| 90 |
|
return(&comm_driver); |
| 91 |
|
syserr: |
| 92 |
< |
perror(argv[0]); |
| 92 |
> |
perror(dname); |
| 93 |
|
return(NULL); |
| 94 |
|
} |
| 95 |
|
|
| 102 |
|
cmdvec = NULL; /* reset error vectors */ |
| 103 |
|
if (wrnvec != NULL) |
| 104 |
|
wrnvec = stderr_v; |
| 109 |
– |
signal(SIGIO, SIG_DFL); |
| 105 |
|
fclose(devout); |
| 106 |
|
fclose(devin); |
| 107 |
|
while ((pid = wait(0)) != -1 && pid != devchild) |
| 114 |
|
int xres, yres; |
| 115 |
|
{ |
| 116 |
|
putc(COM_CLEAR, devout); |
| 117 |
< |
fwrite(&xres, sizeof(xres), 1, devout); |
| 118 |
< |
fwrite(&yres, sizeof(yres), 1, devout); |
| 117 |
> |
putw(xres, devout); |
| 118 |
> |
putw(yres, devout); |
| 119 |
|
fflush(devout); |
| 120 |
|
} |
| 121 |
|
|
| 125 |
|
COLOR col; |
| 126 |
|
int xmin, ymin, xmax, ymax; |
| 127 |
|
{ |
| 133 |
– |
extern long nrays; /* number of rays traced */ |
| 134 |
– |
static long lastflush = 0; /* ray count at last flush */ |
| 135 |
– |
|
| 128 |
|
putc(COM_PAINTR, devout); |
| 129 |
< |
fwrite(col, sizeof(COLOR), 1, devout); |
| 130 |
< |
fwrite(&xmin, sizeof(xmin), 1, devout); |
| 131 |
< |
fwrite(&ymin, sizeof(ymin), 1, devout); |
| 132 |
< |
fwrite(&xmax, sizeof(xmax), 1, devout); |
| 133 |
< |
fwrite(&ymax, sizeof(ymax), 1, devout); |
| 142 |
< |
if (nrays - lastflush >= WFLUSH) { |
| 143 |
< |
fflush(devout); |
| 144 |
< |
lastflush = nrays; |
| 145 |
< |
} |
| 129 |
> |
fwrite((char *)col, sizeof(COLOR), 1, devout); |
| 130 |
> |
putw(xmin, devout); |
| 131 |
> |
putw(ymin, devout); |
| 132 |
> |
putw(xmax, devout); |
| 133 |
> |
putw(ymax, devout); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
+ |
static |
| 138 |
+ |
comm_flush() /* flush output to driver */ |
| 139 |
+ |
{ |
| 140 |
+ |
putc(COM_FLUSH, devout); |
| 141 |
+ |
fflush(devout); |
| 142 |
+ |
if (getc(devin) != COM_FLUSH) |
| 143 |
+ |
reply_error("flush"); |
| 144 |
+ |
comm_driver.inpready = getw(devin); |
| 145 |
+ |
} |
| 146 |
+ |
|
| 147 |
+ |
|
| 148 |
|
static int |
| 149 |
|
comm_getcur(xp, yp) /* get and return cursor position */ |
| 150 |
|
int *xp, *yp; |
| 156 |
|
if (getc(devin) != COM_GETCUR) |
| 157 |
|
reply_error("getcur"); |
| 158 |
|
c = getc(devin); |
| 159 |
< |
fread(xp, sizeof(*xp), 1, devin); |
| 160 |
< |
fread(yp, sizeof(*yp), 1, devin); |
| 159 |
> |
*xp = getw(devin); |
| 160 |
> |
*yp = getw(devin); |
| 161 |
|
return(c); |
| 162 |
|
} |
| 163 |
|
|
| 168 |
|
{ |
| 169 |
|
putc(COM_COMOUT, devout); |
| 170 |
|
myputs(str, devout); |
| 172 |
– |
fflush(devout); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
static |
| 175 |
< |
comm_comin(buf) /* read string from command line */ |
| 175 |
> |
comm_comin(buf, prompt) /* read string from command line */ |
| 176 |
|
char *buf; |
| 177 |
+ |
char *prompt; |
| 178 |
|
{ |
| 179 |
|
putc(COM_COMIN, devout); |
| 180 |
+ |
if (prompt == NULL) |
| 181 |
+ |
putc(0, devout); |
| 182 |
+ |
else { |
| 183 |
+ |
putc(1, devout); |
| 184 |
+ |
myputs(prompt, devout); |
| 185 |
+ |
} |
| 186 |
|
fflush(devout); |
| 187 |
|
if (getc(devin) != COM_COMIN) |
| 188 |
|
reply_error("comin"); |
| 189 |
|
mygets(buf, devin); |
| 190 |
< |
comm_driver.inpready = 0; |
| 190 |
> |
comm_driver.inpready = getw(devin); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
|
| 232 |
|
stderr_v(routine); |
| 233 |
|
stderr_v(": driver reply error\n"); |
| 234 |
|
quit(1); |
| 230 |
– |
} |
| 231 |
– |
|
| 232 |
– |
|
| 233 |
– |
static |
| 234 |
– |
onsigio() /* input ready */ |
| 235 |
– |
{ |
| 236 |
– |
comm_driver.inpready++; |
| 235 |
|
} |