14 |
|
|
15 |
|
#include <stdio.h> |
16 |
|
|
17 |
– |
#include <signal.h> |
18 |
– |
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
|
#include "driver.h" |
20 |
|
|
21 |
|
int (*wrnvec)(), (*errvec)(), (*cmdvec)(); /* error vectors, unused */ |
22 |
|
|
25 |
– |
long nrays = 0; /* fake it */ |
26 |
– |
|
23 |
|
struct driver *dev = NULL; /* output device */ |
24 |
|
|
25 |
|
FILE *devin, *devout; /* communications channels */ |
26 |
|
|
31 |
– |
int notified = 0; /* notified parent of input? */ |
32 |
– |
|
27 |
|
char *progname; /* driver name */ |
28 |
|
|
29 |
< |
int r_clear(), r_paintr(), r_getcur(), r_comout(), r_comin(), r_mycomin(); |
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 |
|
|
57 |
|
if ((dev = dinit(argv[0], argv[3])) == NULL) |
58 |
|
quit(1); |
59 |
|
putw(COM_RECVM, devout); /* verify initialization */ |
65 |
– |
putw(dev->xsiz, devout); |
66 |
– |
putw(dev->ysiz, devout); |
67 |
– |
fwrite(dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
60 |
|
fflush(devout); |
61 |
|
/* loop on requests */ |
62 |
|
while ((com = getc(devin)) != EOF) { |
94 |
|
COLOR col; |
95 |
|
int xmin, ymin, xmax, ymax; |
96 |
|
|
97 |
< |
nrays += 5; /* pretend */ |
106 |
< |
fread(col, sizeof(COLOR), 1, devin); |
97 |
> |
fread((char *)col, sizeof(COLOR), 1, devin); |
98 |
|
xmin = getw(devin); ymin = getw(devin); |
99 |
|
xmax = getw(devin); ymax = getw(devin); |
100 |
|
(*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 |
– |
} |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
+ |
r_flush() /* flush output */ |
105 |
+ |
{ |
106 |
+ |
if (dev->flush != NULL) |
107 |
+ |
(*dev->flush)(); |
108 |
+ |
putc(COM_FLUSH, devout); |
109 |
+ |
fwrite((char *)&dev->pixaspect, sizeof(dev->pixaspect), 1, devout); |
110 |
+ |
putw(dev->xsiz, devout); |
111 |
+ |
putw(dev->ysiz, devout); |
112 |
+ |
putw(dev->inpready, devout); |
113 |
+ |
fflush(devout); |
114 |
+ |
} |
115 |
+ |
|
116 |
+ |
|
117 |
|
r_getcur() /* get and return cursor position */ |
118 |
|
{ |
119 |
|
int c; |
144 |
|
|
145 |
|
r_comin() /* read string from command line */ |
146 |
|
{ |
147 |
< |
char buf[256]; |
147 |
> |
char buf[256], *prompt; |
148 |
> |
/* get prompt */ |
149 |
> |
if (getc(devin)) { |
150 |
> |
mygets(buf, devin); |
151 |
> |
prompt = buf; |
152 |
> |
} else |
153 |
> |
prompt = NULL; |
154 |
|
/* get string */ |
155 |
< |
(*dev->comin)(buf); |
155 |
> |
(*dev->comin)(buf, prompt); |
156 |
|
/* reply */ |
157 |
|
putc(COM_COMIN, devout); |
158 |
|
myputs(buf, devout); |
159 |
+ |
putw(dev->inpready, devout); |
160 |
|
fflush(devout); |
155 |
– |
/* reset notify */ |
156 |
– |
notified = 0; |
161 |
|
} |
162 |
|
|
163 |
|
|