12 |
|
* 10/25/89 |
13 |
|
*/ |
14 |
|
|
15 |
< |
#include <stdio.h> |
15 |
> |
#include "standard.h" |
16 |
|
|
17 |
– |
#include <signal.h> |
18 |
– |
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
|
#include "driver.h" |
20 |
|
|
23 |
– |
int (*wrnvec)(), (*errvec)(), (*cmdvec)(); /* error vectors, unused */ |
24 |
– |
|
25 |
– |
long nrays = 0; /* fake it */ |
26 |
– |
|
21 |
|
struct driver *dev = NULL; /* output device */ |
22 |
|
|
23 |
|
FILE *devin, *devout; /* communications channels */ |
24 |
|
|
31 |
– |
int notified = 0; /* notified parent of input? */ |
32 |
– |
|
25 |
|
char *progname; /* driver name */ |
26 |
|
|
27 |
< |
int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(); |
27 |
> |
int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush(); |
28 |
|
|
29 |
|
int (*dev_func[NREQUESTS])() = { /* request handlers */ |
30 |
|
r_clear, r_paintr, |
31 |
< |
r_getcur, r_comout, r_comin |
31 |
> |
r_getcur, r_comout, |
32 |
> |
r_comin, r_flush |
33 |
|
}; |
34 |
|
|
35 |
|
|
42 |
|
/* set up I/O */ |
43 |
|
progname = argv[0]; |
44 |
|
if (argc < 3) { |
45 |
< |
stderr_v("arg count\n"); |
45 |
> |
eputs("arg count\n"); |
46 |
|
quit(1); |
47 |
|
} |
48 |
|
devin = fdopen(atoi(argv[1]), "r"); |
49 |
|
devout = fdopen(atoi(argv[2]), "w"); |
50 |
|
if (devin == NULL || devout == NULL || getw(devin) != COM_SENDM) { |
51 |
< |
stderr_v("connection failure\n"); |
51 |
> |
eputs("connection failure\n"); |
52 |
|
quit(1); |
53 |
|
} |
54 |
|
/* open device */ |
55 |
|
if ((dev = dinit(argv[0], argv[3])) == NULL) |
56 |
|
quit(1); |
57 |
|
putw(COM_RECVM, devout); /* verify initialization */ |
58 |
< |
fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
66 |
< |
putw(dev->xsiz, devout); |
67 |
< |
putw(dev->ysiz, devout); |
58 |
> |
sendstate(); |
59 |
|
fflush(devout); |
60 |
|
/* loop on requests */ |
61 |
|
while ((com = getc(devin)) != EOF) { |
62 |
|
if (com >= NREQUESTS || dev_func[com] == NULL) { |
63 |
< |
stderr_v("invalid request\n"); |
63 |
> |
eputs("invalid request\n"); |
64 |
|
quit(1); |
65 |
|
} |
66 |
|
(*dev_func[com])(); /* process request */ |
93 |
|
COLOR col; |
94 |
|
int xmin, ymin, xmax, ymax; |
95 |
|
|
105 |
– |
nrays += 5; /* pretend */ |
96 |
|
fread((char *)col, sizeof(COLOR), 1, devin); |
97 |
|
xmin = getw(devin); ymin = getw(devin); |
98 |
|
xmax = getw(devin); ymax = getw(devin); |
99 |
|
(*dev->paintr)(col, xmin, ymin, xmax, ymax); |
110 |
– |
/* check for input */ |
111 |
– |
if (!notified && dev->inpready > 0) { |
112 |
– |
notified = 1; |
113 |
– |
kill(getppid(), SIGIO); |
114 |
– |
} |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
+ |
r_flush() /* flush output */ |
104 |
+ |
{ |
105 |
+ |
if (dev->flush != NULL) |
106 |
+ |
(*dev->flush)(); |
107 |
+ |
putc(COM_FLUSH, devout); |
108 |
+ |
sendstate(); |
109 |
+ |
fflush(devout); |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
|
113 |
|
r_getcur() /* get and return cursor position */ |
114 |
|
{ |
115 |
|
int c; |
152 |
|
/* reply */ |
153 |
|
putc(COM_COMIN, devout); |
154 |
|
myputs(buf, devout); |
155 |
+ |
sendstate(); |
156 |
|
fflush(devout); |
161 |
– |
/* reset notify */ |
162 |
– |
notified = 0; |
157 |
|
} |
158 |
|
|
159 |
|
|
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
< |
stderr_v(s) /* put string to stderr */ |
183 |
> |
eputs(s) /* put string to stderr */ |
184 |
|
register char *s; |
185 |
|
{ |
186 |
< |
static int inline = 0; |
186 |
> |
static int midline = 0; |
187 |
|
|
188 |
< |
if (!inline++) { |
188 |
> |
if (!*s) |
189 |
> |
return; |
190 |
> |
if (!midline++) { |
191 |
|
fputs(progname, stderr); |
192 |
|
fputs(": ", stderr); |
193 |
|
} |
194 |
|
fputs(s, stderr); |
195 |
< |
if (*s && s[strlen(s)-1] == '\n') { |
195 |
> |
if (s[strlen(s)-1] == '\n') { |
196 |
|
fflush(stderr); |
197 |
< |
inline = 0; |
197 |
> |
midline = 0; |
198 |
|
} |
199 |
+ |
} |
200 |
+ |
|
201 |
+ |
|
202 |
+ |
sendstate() /* send driver state variables */ |
203 |
+ |
{ |
204 |
+ |
fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
205 |
+ |
putw(dev->xsiz, devout); |
206 |
+ |
putw(dev->ysiz, devout); |
207 |
+ |
putw(dev->inpready, devout); |
208 |
|
} |