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(); |
29 |
> |
int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_flush(); |
30 |
|
|
31 |
|
int (*dev_func[NREQUESTS])() = { /* request handlers */ |
32 |
|
r_clear, r_paintr, |
33 |
< |
r_getcur, r_comout, r_comin |
33 |
> |
r_getcur, r_comout, |
34 |
> |
r_comin, r_flush |
35 |
|
}; |
36 |
|
|
37 |
|
|
54 |
|
quit(1); |
55 |
|
} |
56 |
|
/* open device */ |
57 |
< |
if ((dev = dinit(argv[0], argv[3])) == NULL) { |
61 |
< |
stderr_v("initialization failure\n"); |
57 |
> |
if ((dev = dinit(argv[0], argv[3])) == NULL) |
58 |
|
quit(1); |
63 |
– |
} |
59 |
|
putw(COM_RECVM, devout); /* verify initialization */ |
60 |
< |
putw(dev->xsiz, devout); |
66 |
< |
putw(dev->ysiz, devout); |
60 |
> |
sendstate(); |
61 |
|
fflush(devout); |
62 |
|
/* loop on requests */ |
63 |
|
while ((com = getc(devin)) != EOF) { |
95 |
|
COLOR col; |
96 |
|
int xmin, ymin, xmax, ymax; |
97 |
|
|
98 |
< |
fread(col, sizeof(COLOR), 1, devin); |
98 |
> |
fread((char *)col, sizeof(COLOR), 1, devin); |
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 (dev->inpready > notified) { |
110 |
– |
kill(getppid(), SIGIO); |
111 |
– |
notified = dev->inpready; |
112 |
– |
} |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
+ |
r_flush() /* flush output */ |
106 |
+ |
{ |
107 |
+ |
if (dev->flush != NULL) |
108 |
+ |
(*dev->flush)(); |
109 |
+ |
putc(COM_FLUSH, devout); |
110 |
+ |
sendstate(); |
111 |
+ |
fflush(devout); |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
|
115 |
|
r_getcur() /* get and return cursor position */ |
116 |
|
{ |
117 |
|
int c; |
142 |
|
|
143 |
|
r_comin() /* read string from command line */ |
144 |
|
{ |
145 |
< |
char buf[256]; |
145 |
> |
char buf[256], *prompt; |
146 |
> |
/* get prompt */ |
147 |
> |
if (getc(devin)) { |
148 |
> |
mygets(buf, devin); |
149 |
> |
prompt = buf; |
150 |
> |
} else |
151 |
> |
prompt = NULL; |
152 |
|
/* get string */ |
153 |
< |
(*dev->comin)(buf); |
153 |
> |
(*dev->comin)(buf, prompt); |
154 |
|
/* reply */ |
155 |
|
putc(COM_COMIN, devout); |
156 |
|
myputs(buf, devout); |
157 |
+ |
sendstate(); |
158 |
|
fflush(devout); |
153 |
– |
/* reset notify */ |
154 |
– |
notified = 0; |
159 |
|
} |
160 |
|
|
161 |
|
|
182 |
|
} |
183 |
|
|
184 |
|
|
181 |
– |
repaint(xmin, ymin, xmax, ymax) /* repaint section of display */ |
182 |
– |
int xmin, ymin, xmax, ymax; |
183 |
– |
{ |
184 |
– |
stderr_v("repaint called!\n"); /* no can do! */ |
185 |
– |
} |
186 |
– |
|
187 |
– |
|
185 |
|
stderr_v(s) /* put string to stderr */ |
186 |
|
register char *s; |
187 |
|
{ |
196 |
|
fflush(stderr); |
197 |
|
inline = 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 |
|
} |