14 |
|
|
15 |
|
#include <stdio.h> |
16 |
|
|
17 |
– |
#include <signal.h> |
18 |
– |
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
|
#include "driver.h" |
24 |
|
|
25 |
|
FILE *devin, *devout; /* communications channels */ |
26 |
|
|
29 |
– |
int notified = 0; /* notified parent of input? */ |
30 |
– |
|
27 |
|
char *progname; /* driver name */ |
28 |
|
|
29 |
|
int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush(); |
57 |
|
if ((dev = dinit(argv[0], argv[3])) == NULL) |
58 |
|
quit(1); |
59 |
|
putw(COM_RECVM, devout); /* verify initialization */ |
60 |
< |
fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
65 |
< |
putw(dev->xsiz, devout); |
66 |
< |
putw(dev->ysiz, devout); |
60 |
> |
sendstate(); |
61 |
|
fflush(devout); |
62 |
|
/* loop on requests */ |
63 |
|
while ((com = getc(devin)) != EOF) { |
99 |
|
xmin = getw(devin); ymin = getw(devin); |
100 |
|
xmax = getw(devin); ymax = getw(devin); |
101 |
|
(*dev->paintr)(col, xmin, ymin, xmax, ymax); |
108 |
– |
/* check for input */ |
109 |
– |
if (!notified && dev->inpready > 0) { |
110 |
– |
notified = 1; |
111 |
– |
kill(getppid(), SIGIO); |
112 |
– |
} |
102 |
|
} |
103 |
|
|
104 |
|
|
106 |
|
{ |
107 |
|
if (dev->flush != NULL) |
108 |
|
(*dev->flush)(); |
109 |
+ |
putc(COM_FLUSH, devout); |
110 |
+ |
sendstate(); |
111 |
+ |
fflush(devout); |
112 |
|
} |
113 |
|
|
114 |
|
|
154 |
|
/* reply */ |
155 |
|
putc(COM_COMIN, devout); |
156 |
|
myputs(buf, devout); |
157 |
+ |
sendstate(); |
158 |
|
fflush(devout); |
166 |
– |
/* reset notify */ |
167 |
– |
notified = 0; |
159 |
|
} |
160 |
|
|
161 |
|
|
185 |
|
stderr_v(s) /* put string to stderr */ |
186 |
|
register char *s; |
187 |
|
{ |
188 |
< |
static int inline = 0; |
188 |
> |
static int midline = 0; |
189 |
|
|
190 |
< |
if (!inline++) { |
190 |
> |
if (!*s) |
191 |
> |
return; |
192 |
> |
if (!midline++) { |
193 |
|
fputs(progname, stderr); |
194 |
|
fputs(": ", stderr); |
195 |
|
} |
196 |
|
fputs(s, stderr); |
197 |
< |
if (*s && s[strlen(s)-1] == '\n') { |
197 |
> |
if (s[strlen(s)-1] == '\n') { |
198 |
|
fflush(stderr); |
199 |
< |
inline = 0; |
199 |
> |
midline = 0; |
200 |
|
} |
201 |
+ |
} |
202 |
+ |
|
203 |
+ |
|
204 |
+ |
sendstate() /* send driver state variables */ |
205 |
+ |
{ |
206 |
+ |
fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
207 |
+ |
putw(dev->xsiz, devout); |
208 |
+ |
putw(dev->ysiz, devout); |
209 |
+ |
putw(dev->inpready, devout); |
210 |
|
} |