7 |
|
* External symbols declared in driver.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
/* ==================================================================== |
11 |
< |
* The Radiance Software License, Version 1.0 |
12 |
< |
* |
13 |
< |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
< |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
< |
* |
16 |
< |
* Redistribution and use in source and binary forms, with or without |
17 |
< |
* modification, are permitted provided that the following conditions |
18 |
< |
* are met: |
19 |
< |
* |
20 |
< |
* 1. Redistributions of source code must retain the above copyright |
21 |
< |
* notice, this list of conditions and the following disclaimer. |
22 |
< |
* |
23 |
< |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
< |
* notice, this list of conditions and the following disclaimer in |
25 |
< |
* the documentation and/or other materials provided with the |
26 |
< |
* distribution. |
27 |
< |
* |
28 |
< |
* 3. The end-user documentation included with the redistribution, |
29 |
< |
* if any, must include the following acknowledgment: |
30 |
< |
* "This product includes Radiance software |
31 |
< |
* (http://radsite.lbl.gov/) |
32 |
< |
* developed by the Lawrence Berkeley National Laboratory |
33 |
< |
* (http://www.lbl.gov/)." |
34 |
< |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
< |
* if and wherever such third-party acknowledgments normally appear. |
36 |
< |
* |
37 |
< |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
< |
* and "The Regents of the University of California" must |
39 |
< |
* not be used to endorse or promote products derived from this |
40 |
< |
* software without prior written permission. For written |
41 |
< |
* permission, please contact [email protected]. |
42 |
< |
* |
43 |
< |
* 5. Products derived from this software may not be called "Radiance", |
44 |
< |
* nor may "Radiance" appear in their name, without prior written |
45 |
< |
* permission of Lawrence Berkeley National Laboratory. |
46 |
< |
* |
47 |
< |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
< |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
< |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
< |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
< |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
< |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
< |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
< |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
< |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
< |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
< |
* SUCH DAMAGE. |
59 |
< |
* ==================================================================== |
60 |
< |
* |
61 |
< |
* This software consists of voluntary contributions made by many |
62 |
< |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
< |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
< |
* <http://www.lbl.gov/>. |
65 |
< |
*/ |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "standard.h" |
12 |
> |
#include <sys/types.h> |
13 |
> |
#include <sys/wait.h> /* XXX platform specific */ |
14 |
|
|
15 |
< |
#include "color.h" |
16 |
< |
|
15 |
> |
#include "platform.h" |
16 |
> |
#include "standard.h" |
17 |
|
#include "driver.h" |
18 |
|
|
73 |
– |
#include "vfork.h" |
74 |
– |
|
19 |
|
#ifndef DEVPATH |
20 |
|
#define DEVPATH getenv("PATH") /* device search path */ |
21 |
|
#endif |
22 |
|
|
23 |
< |
static int comm_getcur(); |
24 |
< |
static void comm_close(), comm_clear(), comm_paintr(), |
81 |
< |
comm_comin(), comm_comout(), comm_flush(); |
23 |
> |
FILE *devin, *devout; |
24 |
> |
int devchild; |
25 |
|
|
26 |
+ |
static struct driver * final_connect(void); |
27 |
+ |
static void mygets(char *s, FILE *fp); |
28 |
+ |
static void myputs(char *s, FILE *fp); |
29 |
+ |
static void reply_error(char *routine); |
30 |
+ |
static void getstate(void); |
31 |
+ |
|
32 |
+ |
static dr_closef_t comm_close; |
33 |
+ |
static dr_clearf_t comm_clear; |
34 |
+ |
static dr_paintrf_t comm_paintr; |
35 |
+ |
static dr_getcurf_t comm_getcur; |
36 |
+ |
static dr_comoutf_t comm_comout; |
37 |
+ |
static dr_cominf_t comm_comin; |
38 |
+ |
static dr_flushf_t comm_flush; |
39 |
+ |
|
40 |
|
struct driver comm_driver = { |
41 |
|
comm_close, comm_clear, comm_paintr, comm_getcur, |
42 |
|
comm_comout, comm_comin, comm_flush |
43 |
|
}; |
44 |
|
|
88 |
– |
static void mygets(), myputs(), reply_error(), getstate(); |
45 |
|
|
90 |
– |
FILE *devin, *devout; |
91 |
– |
|
92 |
– |
int devchild; |
93 |
– |
|
94 |
– |
|
46 |
|
static struct driver * |
47 |
< |
final_connect() /* verify and initialize connection */ |
47 |
> |
final_connect(void) /* verify and initialize connection */ |
48 |
|
{ |
49 |
|
putw(COM_SENDM, devout); |
50 |
|
fflush(devout); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
< |
struct driver * |
64 |
< |
slave_init(dname, id) /* run rview in slave mode */ |
65 |
< |
char *dname, *id; |
63 |
> |
extern struct driver * |
64 |
> |
slave_init( /* run rview in slave mode */ |
65 |
> |
char *dname, |
66 |
> |
char *id |
67 |
> |
) |
68 |
|
{ |
69 |
|
devchild = -1; /* we're the slave here */ |
70 |
|
devout = stdout; /* use standard input */ |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
< |
struct driver * |
77 |
< |
comm_init(dname, id) /* set up and execute driver */ |
78 |
< |
char *dname, *id; |
76 |
> |
extern struct driver * |
77 |
> |
comm_init( /* set up and execute driver */ |
78 |
> |
char *dname, |
79 |
> |
char *id |
80 |
> |
) |
81 |
|
{ |
82 |
|
char *dvcname; |
83 |
|
int p1[2], p2[2]; |
88 |
|
eputs(": not found\n"); |
89 |
|
return(NULL); |
90 |
|
} |
91 |
+ |
#ifdef RHAS_FORK_EXEC |
92 |
|
/* open communication pipes */ |
93 |
|
if (pipe(p1) == -1 || pipe(p2) == -1) |
94 |
|
goto syserr; |
95 |
< |
if ((devchild = vfork()) == 0) { /* fork driver process */ |
95 |
> |
if ((devchild = fork()) == 0) { /* fork driver process */ |
96 |
|
close(p1[1]); |
97 |
|
close(p2[0]); |
98 |
|
sprintf(pin, "%d", p1[0]); |
99 |
|
sprintf(pout, "%d", p2[1]); |
100 |
< |
execl(dvcname, dname, pin, pout, id, 0); |
100 |
> |
execl(dvcname, dname, pin, pout, id, NULL); |
101 |
|
perror(dvcname); |
102 |
|
_exit(127); |
103 |
|
} |
105 |
|
goto syserr; |
106 |
|
close(p1[0]); |
107 |
|
close(p2[1]); |
108 |
+ |
/* |
109 |
+ |
* Close write stream on exec to avoid multiprocessing deadlock. |
110 |
+ |
* No use in read stream without it, so set flag there as well. |
111 |
+ |
*/ |
112 |
+ |
fcntl(p1[1], F_SETFD, FD_CLOEXEC); |
113 |
+ |
fcntl(p2[0], F_SETFD, FD_CLOEXEC); |
114 |
|
if ((devout = fdopen(p1[1], "w")) == NULL) |
115 |
|
goto syserr; |
116 |
|
if ((devin = fdopen(p2[0], "r")) == NULL) |
119 |
|
syserr: |
120 |
|
perror(dname); |
121 |
|
return(NULL); |
122 |
+ |
|
123 |
+ |
#else /* ! RHAS_FORK_EXEC */ |
124 |
+ |
|
125 |
+ |
eputs(dname); |
126 |
+ |
eputs(": no fork/exec\n"); |
127 |
+ |
return(NULL); |
128 |
+ |
|
129 |
+ |
#endif /* ! RHAS_FORK_EXEC */ |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
static void |
134 |
< |
comm_close() /* done with driver */ |
134 |
> |
comm_close(void) /* done with driver */ |
135 |
|
{ |
136 |
|
int pid; |
137 |
|
|
148 |
|
|
149 |
|
|
150 |
|
static void |
151 |
< |
comm_clear(xres, yres) /* clear screen */ |
152 |
< |
int xres, yres; |
151 |
> |
comm_clear( /* clear screen */ |
152 |
> |
int xres, |
153 |
> |
int yres |
154 |
> |
) |
155 |
|
{ |
156 |
|
putc(COM_CLEAR, devout); |
157 |
|
putw(xres, devout); |
161 |
|
|
162 |
|
|
163 |
|
static void |
164 |
< |
comm_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */ |
165 |
< |
COLOR col; |
166 |
< |
int xmin, ymin, xmax, ymax; |
164 |
> |
comm_paintr( /* paint a rectangle */ |
165 |
> |
COLOR col, |
166 |
> |
int xmin, |
167 |
> |
int ymin, |
168 |
> |
int xmax, |
169 |
> |
int ymax |
170 |
> |
) |
171 |
|
{ |
172 |
|
putc(COM_PAINTR, devout); |
173 |
|
fwrite((char *)col, sizeof(COLOR), 1, devout); |
179 |
|
|
180 |
|
|
181 |
|
static void |
182 |
< |
comm_flush() /* flush output to driver */ |
182 |
> |
comm_flush(void) /* flush output to driver */ |
183 |
|
{ |
184 |
|
putc(COM_FLUSH, devout); |
185 |
|
fflush(devout); |
190 |
|
|
191 |
|
|
192 |
|
static int |
193 |
< |
comm_getcur(xp, yp) /* get and return cursor position */ |
194 |
< |
int *xp, *yp; |
193 |
> |
comm_getcur( /* get and return cursor position */ |
194 |
> |
int *xp, |
195 |
> |
int *yp |
196 |
> |
) |
197 |
|
{ |
198 |
|
int c; |
199 |
|
|
209 |
|
|
210 |
|
|
211 |
|
static void |
212 |
< |
comm_comout(str) /* print string to command line */ |
213 |
< |
char *str; |
212 |
> |
comm_comout( /* print string to command line */ |
213 |
> |
char *str |
214 |
> |
) |
215 |
|
{ |
216 |
|
putc(COM_COMOUT, devout); |
217 |
|
myputs(str, devout); |
221 |
|
|
222 |
|
|
223 |
|
static void |
224 |
< |
comm_comin(buf, prompt) /* read string from command line */ |
225 |
< |
char *buf; |
226 |
< |
char *prompt; |
224 |
> |
comm_comin( /* read string from command line */ |
225 |
> |
char *buf, |
226 |
> |
char *prompt |
227 |
> |
) |
228 |
|
{ |
229 |
|
putc(COM_COMIN, devout); |
230 |
|
if (prompt == NULL) |
242 |
|
|
243 |
|
|
244 |
|
static void |
245 |
< |
mygets(s, fp) /* get string from file (with nul) */ |
246 |
< |
register char *s; |
247 |
< |
register FILE *fp; |
245 |
> |
mygets( /* get string from file (with nul) */ |
246 |
> |
register char *s, |
247 |
> |
register FILE *fp |
248 |
> |
) |
249 |
|
{ |
250 |
|
register int c; |
251 |
|
|
257 |
|
|
258 |
|
|
259 |
|
static void |
260 |
< |
myputs(s, fp) /* put string to file (with nul) */ |
261 |
< |
register char *s; |
262 |
< |
register FILE *fp; |
260 |
> |
myputs( /* put string to file (with nul) */ |
261 |
> |
register char *s, |
262 |
> |
register FILE *fp |
263 |
> |
) |
264 |
|
{ |
265 |
|
do |
266 |
|
putc(*s, fp); |
269 |
|
|
270 |
|
|
271 |
|
static void |
272 |
< |
reply_error(routine) /* what should we do here? */ |
273 |
< |
char *routine; |
272 |
> |
reply_error( /* what should we do here? */ |
273 |
> |
char *routine |
274 |
> |
) |
275 |
|
{ |
276 |
|
eputs(routine); |
277 |
|
eputs(": driver reply error\n"); |
280 |
|
|
281 |
|
|
282 |
|
static void |
283 |
< |
getstate() /* get driver state variables */ |
283 |
> |
getstate(void) /* get driver state variables */ |
284 |
|
{ |
285 |
|
fread((char *)&comm_driver.pixaspect, |
286 |
|
sizeof(comm_driver.pixaspect), 1, devin); |