39 |
|
|
40 |
|
struct driver comm_driver, comm_default = { |
41 |
|
comm_close, comm_clear, comm_paintr, comm_getcur, |
42 |
< |
comm_comout, comm_comin, |
43 |
< |
MAXRES, MAXRES, 0 |
42 |
> |
comm_comout, comm_comin |
43 |
|
}; |
44 |
|
|
45 |
|
FILE *devin, *devout; |
48 |
|
|
49 |
|
|
50 |
|
struct driver * |
51 |
< |
comm_init(argv) /* set up and execute driver */ |
52 |
< |
char *argv[]; |
51 |
> |
comm_init(dname, id) /* set up and execute driver */ |
52 |
> |
char *dname, *id; |
53 |
|
{ |
54 |
|
char *devname; |
55 |
|
int p1[2], p2[2]; |
56 |
< |
|
57 |
< |
if ((devname = getpath(argv[0], DEVPATH)) == NULL) { |
58 |
< |
stderr_v(argv[0]); |
56 |
> |
char pin[16], pout[16]; |
57 |
> |
/* find driver program */ |
58 |
> |
if ((devname = getpath(dname, DEVPATH, 1)) == NULL) { |
59 |
> |
stderr_v(dname); |
60 |
|
stderr_v(": not found\n"); |
61 |
|
return(NULL); |
62 |
|
} |
63 |
+ |
/* open communication pipes */ |
64 |
|
if (pipe(p1) == -1 || pipe(p2) == -1) |
65 |
|
goto syserr; |
66 |
< |
if ((devchild = vfork()) == 0) { |
66 |
> |
if ((devchild = vfork()) == 0) { /* fork driver process */ |
67 |
|
close(p1[1]); |
68 |
|
close(p2[0]); |
69 |
< |
if (p1[0] != 0) { |
70 |
< |
dup2(p1[0], 0); |
71 |
< |
close(p1[0]); |
72 |
< |
} |
72 |
< |
if (p2[1] != 1) { |
73 |
< |
dup2(p2[1], 1); |
74 |
< |
close(p2[1]); |
75 |
< |
} |
76 |
< |
execv(devname, argv); |
77 |
< |
stderr_v(devname); |
78 |
< |
stderr_v(": cannot execute\n"); |
69 |
> |
sprintf(pin, "%d", p1[0]); |
70 |
> |
sprintf(pout, "%d", p2[1]); |
71 |
> |
execl(devname, dname, pin, pout, id, 0); |
72 |
> |
perror(devname); |
73 |
|
_exit(127); |
74 |
|
} |
75 |
|
if (devchild == -1) |
81 |
|
if ((devin = fdopen(p2[0], "r")) == NULL) |
82 |
|
goto syserr; |
83 |
|
bcopy(&comm_default, &comm_driver, sizeof(comm_driver)); |
84 |
+ |
/* verify & get resolution */ |
85 |
+ |
putw(COM_SENDM, devout); |
86 |
+ |
fflush(devout); |
87 |
+ |
if (getw(devin) != COM_RECVM) |
88 |
+ |
return(NULL); |
89 |
+ |
comm_driver.xsiz = getw(devin); |
90 |
+ |
comm_driver.ysiz = getw(devin); |
91 |
+ |
fread(comm_driver.pixaspect, sizeof(comm_driver.pixaspect), 1, devin); |
92 |
+ |
/* input handling */ |
93 |
|
signal(SIGIO, onsigio); |
94 |
< |
cmdvec = comm_comout; /* set error vectors */ |
94 |
> |
/* set error vectors */ |
95 |
> |
cmdvec = comm_comout; |
96 |
|
if (wrnvec != NULL) |
97 |
|
wrnvec = comm_comout; |
98 |
|
return(&comm_driver); |
99 |
|
syserr: |
100 |
< |
perror(argv[0]); |
100 |
> |
perror(dname); |
101 |
|
return(NULL); |
102 |
|
} |
103 |
|
|
123 |
|
int xres, yres; |
124 |
|
{ |
125 |
|
putc(COM_CLEAR, devout); |
126 |
< |
fwrite(&xres, sizeof(xres), 1, devout); |
127 |
< |
fwrite(&yres, sizeof(yres), 1, devout); |
126 |
> |
putw(xres, devout); |
127 |
> |
putw(yres, devout); |
128 |
|
fflush(devout); |
129 |
|
} |
130 |
|
|
139 |
|
|
140 |
|
putc(COM_PAINTR, devout); |
141 |
|
fwrite(col, sizeof(COLOR), 1, devout); |
142 |
< |
fwrite(&xmin, sizeof(xmin), 1, devout); |
143 |
< |
fwrite(&ymin, sizeof(ymin), 1, devout); |
144 |
< |
fwrite(&xmax, sizeof(xmax), 1, devout); |
145 |
< |
fwrite(&ymax, sizeof(ymax), 1, devout); |
142 |
> |
putw(xmin, devout); |
143 |
> |
putw(ymin, devout); |
144 |
> |
putw(xmax, devout); |
145 |
> |
putw(ymax, devout); |
146 |
|
if (nrays - lastflush >= WFLUSH) { |
147 |
|
fflush(devout); |
148 |
|
lastflush = nrays; |
161 |
|
if (getc(devin) != COM_GETCUR) |
162 |
|
reply_error("getcur"); |
163 |
|
c = getc(devin); |
164 |
< |
fread(xp, sizeof(*xp), 1, devin); |
165 |
< |
fread(yp, sizeof(*yp), 1, devin); |
164 |
> |
*xp = getw(devin); |
165 |
> |
*yp = getw(devin); |
166 |
|
return(c); |
167 |
|
} |
168 |
|
|
186 |
|
if (getc(devin) != COM_COMIN) |
187 |
|
reply_error("comin"); |
188 |
|
mygets(buf, devin); |
189 |
< |
comm_driver.inpready = 0; |
189 |
> |
if (comm_driver.inpready > 0) |
190 |
> |
comm_driver.inpready--; |
191 |
|
} |
192 |
|
|
193 |
|
|