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