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" |
20 |
|
#define DEVPATH getenv("PATH") /* device search path */ |
21 |
|
#endif |
22 |
|
|
23 |
+ |
#ifndef DELAY |
24 |
+ |
#define DELAY 20 /* seconds to wait for response */ |
25 |
+ |
#endif |
26 |
+ |
|
27 |
|
#ifndef BSD |
28 |
|
#define vfork fork |
29 |
|
#endif |
30 |
|
|
29 |
– |
#ifndef WFLUSH |
30 |
– |
#define WFLUSH 30 /* flush after this many rays */ |
31 |
– |
#endif |
32 |
– |
|
31 |
|
extern char *getpath(), *getenv(); |
32 |
|
|
33 |
|
int onsigio(); |
34 |
|
|
35 |
|
int comm_close(), comm_clear(), comm_paintr(), comm_errout(), |
36 |
< |
comm_getcur(), comm_comout(), comm_comin(); |
36 |
> |
comm_getcur(), comm_comout(), comm_comin(), comm_flush(); |
37 |
|
|
38 |
< |
struct driver comm_driver, comm_default = { |
38 |
> |
struct driver comm_driver = { |
39 |
|
comm_close, comm_clear, comm_paintr, comm_getcur, |
40 |
< |
comm_comout, comm_comin |
40 |
> |
comm_comout, comm_comin, comm_flush |
41 |
|
}; |
42 |
|
|
43 |
|
FILE *devin, *devout; |
78 |
|
goto syserr; |
79 |
|
if ((devin = fdopen(p2[0], "r")) == NULL) |
80 |
|
goto syserr; |
81 |
< |
bcopy(&comm_default, &comm_driver, sizeof(comm_driver)); |
84 |
< |
/* verify & get resolution */ |
81 |
> |
/* verify initialization */ |
82 |
|
putw(COM_SENDM, devout); |
83 |
|
fflush(devout); |
84 |
|
if (getw(devin) != COM_RECVM) |
85 |
|
return(NULL); |
86 |
< |
comm_driver.xsiz = getw(devin); |
87 |
< |
comm_driver.ysiz = getw(devin); |
91 |
< |
fread(comm_driver.pixaspect, sizeof(comm_driver.pixaspect), 1, devin); |
92 |
< |
/* input handling */ |
93 |
< |
signal(SIGIO, onsigio); |
86 |
> |
/* get driver parameters */ |
87 |
> |
comm_flush(); |
88 |
|
/* set error vectors */ |
89 |
|
cmdvec = comm_comout; |
90 |
|
if (wrnvec != NULL) |
104 |
|
cmdvec = NULL; /* reset error vectors */ |
105 |
|
if (wrnvec != NULL) |
106 |
|
wrnvec = stderr_v; |
113 |
– |
signal(SIGIO, SIG_DFL); |
107 |
|
fclose(devout); |
108 |
|
fclose(devin); |
109 |
|
while ((pid = wait(0)) != -1 && pid != devchild) |
127 |
|
COLOR col; |
128 |
|
int xmin, ymin, xmax, ymax; |
129 |
|
{ |
137 |
– |
extern long nrays; /* number of rays traced */ |
138 |
– |
static long lastflush = 0; /* ray count at last flush */ |
139 |
– |
|
130 |
|
putc(COM_PAINTR, devout); |
131 |
< |
fwrite(col, sizeof(COLOR), 1, devout); |
131 |
> |
fwrite((char *)col, sizeof(COLOR), 1, devout); |
132 |
|
putw(xmin, devout); |
133 |
|
putw(ymin, devout); |
134 |
|
putw(xmax, devout); |
135 |
|
putw(ymax, devout); |
146 |
– |
if (nrays - lastflush >= WFLUSH) { |
147 |
– |
fflush(devout); |
148 |
– |
lastflush = nrays; |
149 |
– |
} |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
+ |
static |
140 |
+ |
comm_flush() /* flush output to driver */ |
141 |
+ |
{ |
142 |
+ |
putc(COM_FLUSH, devout); |
143 |
+ |
fflush(devout); |
144 |
+ |
if (getc(devin) != COM_FLUSH) |
145 |
+ |
reply_error("flush"); |
146 |
+ |
fread((char *)&comm_driver.pixaspect, |
147 |
+ |
sizeof(comm_driver.pixaspect), 1, devin); |
148 |
+ |
comm_driver.xsiz = getw(devin); |
149 |
+ |
comm_driver.ysiz = getw(devin); |
150 |
+ |
comm_driver.inpready = getw(devin); |
151 |
+ |
} |
152 |
+ |
|
153 |
+ |
|
154 |
|
static int |
155 |
|
comm_getcur(xp, yp) /* get and return cursor position */ |
156 |
|
int *xp, *yp; |
174 |
|
{ |
175 |
|
putc(COM_COMOUT, devout); |
176 |
|
myputs(str, devout); |
176 |
– |
fflush(devout); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
static |
181 |
< |
comm_comin(buf) /* read string from command line */ |
181 |
> |
comm_comin(buf, prompt) /* read string from command line */ |
182 |
|
char *buf; |
183 |
+ |
char *prompt; |
184 |
|
{ |
185 |
|
putc(COM_COMIN, devout); |
186 |
+ |
if (prompt == NULL) |
187 |
+ |
putc(0, devout); |
188 |
+ |
else { |
189 |
+ |
putc(1, devout); |
190 |
+ |
myputs(prompt, devout); |
191 |
+ |
} |
192 |
|
fflush(devout); |
193 |
|
if (getc(devin) != COM_COMIN) |
194 |
|
reply_error("comin"); |
195 |
|
mygets(buf, devin); |
196 |
< |
if (comm_driver.inpready > 0) |
190 |
< |
comm_driver.inpready--; |
196 |
> |
comm_driver.inpready = getw(devin); |
197 |
|
} |
198 |
|
|
199 |
|
|
238 |
|
stderr_v(routine); |
239 |
|
stderr_v(": driver reply error\n"); |
240 |
|
quit(1); |
235 |
– |
} |
236 |
– |
|
237 |
– |
|
238 |
– |
static |
239 |
– |
onsigio() /* input ready */ |
240 |
– |
{ |
241 |
– |
comm_driver.inpready++; |
241 |
|
} |