| 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 |
|
|
| 42 |
– |
char mybuf[512] = ""; |
| 37 |
|
|
| 44 |
– |
char *mybufp(); |
| 45 |
– |
|
| 46 |
– |
|
| 38 |
|
main(argc, argv) /* set up communications and main loop */ |
| 39 |
|
int argc; |
| 40 |
|
char *argv[]; |
| 57 |
|
if ((dev = dinit(argv[0], argv[3])) == NULL) |
| 58 |
|
quit(1); |
| 59 |
|
putw(COM_RECVM, devout); /* verify initialization */ |
| 60 |
< |
putw(dev->xsiz, devout); |
| 70 |
< |
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 |
< |
nrays += 5; /* pretend */ |
| 109 |
< |
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); |
| 113 |
– |
/* check for input */ |
| 114 |
– |
if (!notified && dev->inpready > 0) { |
| 115 |
– |
notified = 1; |
| 116 |
– |
kill(getppid(), SIGIO); |
| 117 |
– |
} |
| 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); |
| 158 |
– |
/* reset notify */ |
| 159 |
– |
notified = 0; |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
|
| 186 |
– |
r_mycomin() /* get command from my buffer */ |
| 187 |
– |
{ |
| 188 |
– |
register char *cp; |
| 189 |
– |
/* get next command */ |
| 190 |
– |
for (cp = mybuf; *cp != '\n'; cp++) |
| 191 |
– |
; |
| 192 |
– |
*cp++ = '\0'; |
| 193 |
– |
(*dev->comout)(mybuf); /* echo my command */ |
| 194 |
– |
/* send it as reply */ |
| 195 |
– |
putc(COM_COMIN, devout); |
| 196 |
– |
myputs(mybuf, devout); |
| 197 |
– |
fflush(devout); |
| 198 |
– |
/* get next command */ |
| 199 |
– |
(*dev->comout)("\n"); |
| 200 |
– |
strcpy(mybuf, cp); |
| 201 |
– |
if (mybuf[0]) |
| 202 |
– |
kill(getppid(), SIGIO); /* signal more */ |
| 203 |
– |
else |
| 204 |
– |
dev_func[COM_COMIN] = r_comin; /* else reset */ |
| 205 |
– |
} |
| 206 |
– |
|
| 207 |
– |
|
| 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 (!midline++) { |
| 191 |
|
fputs(progname, stderr); |
| 192 |
|
fputs(": ", stderr); |
| 193 |
|
} |
| 194 |
|
fputs(s, stderr); |
| 195 |
|
if (*s && s[strlen(s)-1] == '\n') { |
| 196 |
|
fflush(stderr); |
| 197 |
< |
inline = 0; |
| 197 |
> |
midline = 0; |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
|
| 202 |
< |
char * |
| 226 |
< |
mybufp() /* return buffer for my command */ |
| 202 |
> |
sendstate() /* send driver state variables */ |
| 203 |
|
{ |
| 204 |
< |
if (dev_func[COM_COMIN] != r_mycomin) { |
| 205 |
< |
dev_func[COM_COMIN] = r_mycomin; |
| 206 |
< |
kill(getppid(), SIGIO); |
| 207 |
< |
} |
| 232 |
< |
return(mybuf+strlen(mybuf)); |
| 233 |
< |
} |
| 234 |
< |
|
| 235 |
< |
|
| 236 |
< |
repaint(xmin, ymin, xmax, ymax) /* repaint section of display */ |
| 237 |
< |
int xmin, ymin, xmax, ymax; |
| 238 |
< |
{ |
| 239 |
< |
sprintf(mybufp(), "repaint %d %d %d %d\n", |
| 240 |
< |
xmin, ymin, xmax, ymax); |
| 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 |
|
} |