| 9 |
|
|
| 10 |
|
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
#include "standard.h" |
| 12 |
> |
#include <sys/types.h> |
| 13 |
> |
#ifndef _WIN32 |
| 14 |
> |
#include <sys/wait.h> |
| 15 |
> |
#endif |
| 16 |
|
|
| 17 |
< |
#include "color.h" |
| 18 |
< |
|
| 17 |
> |
#include "paths.h" |
| 18 |
> |
#include "platform.h" |
| 19 |
> |
#include "standard.h" |
| 20 |
|
#include "driver.h" |
| 21 |
|
|
| 18 |
– |
#include "vfork.h" |
| 19 |
– |
|
| 22 |
|
#ifndef DEVPATH |
| 23 |
|
#define DEVPATH getenv("PATH") /* device search path */ |
| 24 |
|
#endif |
| 25 |
|
|
| 26 |
< |
static int comm_getcur(); |
| 27 |
< |
static void comm_close(), comm_clear(), comm_paintr(), |
| 26 |
< |
comm_comin(), comm_comout(), comm_flush(); |
| 26 |
> |
FILE *devin, *devout; |
| 27 |
> |
int devchild; |
| 28 |
|
|
| 29 |
+ |
static struct driver * final_connect(void); |
| 30 |
+ |
static void mygets(char *s, FILE *fp); |
| 31 |
+ |
static void myputs(char *s, FILE *fp); |
| 32 |
+ |
static void reply_error(char *routine); |
| 33 |
+ |
static void getstate(void); |
| 34 |
+ |
|
| 35 |
+ |
static dr_closef_t comm_close; |
| 36 |
+ |
static dr_clearf_t comm_clear; |
| 37 |
+ |
static dr_paintrf_t comm_paintr; |
| 38 |
+ |
static dr_getcurf_t comm_getcur; |
| 39 |
+ |
static dr_comoutf_t comm_comout; |
| 40 |
+ |
static dr_cominf_t comm_comin; |
| 41 |
+ |
static dr_flushf_t comm_flush; |
| 42 |
+ |
|
| 43 |
|
struct driver comm_driver = { |
| 44 |
|
comm_close, comm_clear, comm_paintr, comm_getcur, |
| 45 |
|
comm_comout, comm_comin, comm_flush |
| 46 |
|
}; |
| 47 |
|
|
| 33 |
– |
static void mygets(), myputs(), reply_error(), getstate(); |
| 48 |
|
|
| 35 |
– |
FILE *devin, *devout; |
| 36 |
– |
|
| 37 |
– |
int devchild; |
| 38 |
– |
|
| 39 |
– |
|
| 49 |
|
static struct driver * |
| 50 |
< |
final_connect() /* verify and initialize connection */ |
| 50 |
> |
final_connect(void) /* verify and initialize connection */ |
| 51 |
|
{ |
| 52 |
|
putw(COM_SENDM, devout); |
| 53 |
|
fflush(devout); |
| 57 |
|
getstate(); |
| 58 |
|
/* set error vectors */ |
| 59 |
|
erract[COMMAND].pf = comm_comout; |
| 60 |
+ |
/* doesn't work with raypcalls.c |
| 61 |
|
if (erract[WARNING].pf != NULL) |
| 62 |
|
erract[WARNING].pf = comm_comout; |
| 63 |
+ |
*/ |
| 64 |
|
return(&comm_driver); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
< |
struct driver * |
| 69 |
< |
slave_init(dname, id) /* run rview in slave mode */ |
| 70 |
< |
char *dname, *id; |
| 68 |
> |
extern struct driver * |
| 69 |
> |
slave_init( /* run rview in slave mode */ |
| 70 |
> |
char *dname, |
| 71 |
> |
char *id |
| 72 |
> |
) |
| 73 |
|
{ |
| 74 |
|
devchild = -1; /* we're the slave here */ |
| 75 |
|
devout = stdout; /* use standard input */ |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
| 81 |
< |
struct driver * |
| 82 |
< |
comm_init(dname, id) /* set up and execute driver */ |
| 83 |
< |
char *dname, *id; |
| 81 |
> |
extern struct driver * |
| 82 |
> |
comm_init( /* set up and execute driver */ |
| 83 |
> |
char *dname, |
| 84 |
> |
char *id |
| 85 |
> |
) |
| 86 |
|
{ |
| 87 |
|
char *dvcname; |
| 88 |
|
int p1[2], p2[2]; |
| 97 |
|
/* open communication pipes */ |
| 98 |
|
if (pipe(p1) == -1 || pipe(p2) == -1) |
| 99 |
|
goto syserr; |
| 100 |
< |
if ((devchild = vfork()) == 0) { /* fork driver process */ |
| 100 |
> |
if ((devchild = fork()) == 0) { /* fork driver process */ |
| 101 |
|
close(p1[1]); |
| 102 |
|
close(p2[0]); |
| 103 |
|
sprintf(pin, "%d", p1[0]); |
| 104 |
|
sprintf(pout, "%d", p2[1]); |
| 105 |
< |
execl(dvcname, dname, pin, pout, id, 0); |
| 105 |
> |
execl(dvcname, dname, pin, pout, id, NULL); |
| 106 |
|
perror(dvcname); |
| 107 |
|
_exit(127); |
| 108 |
|
} |
| 110 |
|
goto syserr; |
| 111 |
|
close(p1[0]); |
| 112 |
|
close(p2[1]); |
| 113 |
+ |
/* |
| 114 |
+ |
* Close write stream on exec to avoid multiprocessing deadlock. |
| 115 |
+ |
* No use in read stream without it, so set flag there as well. |
| 116 |
+ |
*/ |
| 117 |
+ |
fcntl(p1[1], F_SETFD, FD_CLOEXEC); |
| 118 |
+ |
fcntl(p2[0], F_SETFD, FD_CLOEXEC); |
| 119 |
|
if ((devout = fdopen(p1[1], "w")) == NULL) |
| 120 |
|
goto syserr; |
| 121 |
|
if ((devin = fdopen(p2[0], "r")) == NULL) |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
static void |
| 139 |
< |
comm_close() /* done with driver */ |
| 139 |
> |
comm_close(void) /* done with driver */ |
| 140 |
|
{ |
| 141 |
|
int pid; |
| 142 |
|
|
| 147 |
|
fclose(devin); |
| 148 |
|
if (devchild < 0) |
| 149 |
|
return; |
| 150 |
+ |
#ifndef _WIN32 |
| 151 |
|
while ((pid = wait(0)) != -1 && pid != devchild) |
| 152 |
|
; |
| 153 |
+ |
#endif |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
static void |
| 158 |
< |
comm_clear(xres, yres) /* clear screen */ |
| 159 |
< |
int xres, yres; |
| 158 |
> |
comm_clear( /* clear screen */ |
| 159 |
> |
int xres, |
| 160 |
> |
int yres |
| 161 |
> |
) |
| 162 |
|
{ |
| 163 |
|
putc(COM_CLEAR, devout); |
| 164 |
|
putw(xres, devout); |
| 168 |
|
|
| 169 |
|
|
| 170 |
|
static void |
| 171 |
< |
comm_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */ |
| 172 |
< |
COLOR col; |
| 173 |
< |
int xmin, ymin, xmax, ymax; |
| 171 |
> |
comm_paintr( /* paint a rectangle */ |
| 172 |
> |
COLOR col, |
| 173 |
> |
int xmin, |
| 174 |
> |
int ymin, |
| 175 |
> |
int xmax, |
| 176 |
> |
int ymax |
| 177 |
> |
) |
| 178 |
|
{ |
| 179 |
|
putc(COM_PAINTR, devout); |
| 180 |
|
fwrite((char *)col, sizeof(COLOR), 1, devout); |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
static void |
| 189 |
< |
comm_flush() /* flush output to driver */ |
| 189 |
> |
comm_flush(void) /* flush output to driver */ |
| 190 |
|
{ |
| 191 |
|
putc(COM_FLUSH, devout); |
| 192 |
|
fflush(devout); |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
static int |
| 200 |
< |
comm_getcur(xp, yp) /* get and return cursor position */ |
| 201 |
< |
int *xp, *yp; |
| 200 |
> |
comm_getcur( /* get and return cursor position */ |
| 201 |
> |
int *xp, |
| 202 |
> |
int *yp |
| 203 |
> |
) |
| 204 |
|
{ |
| 205 |
|
int c; |
| 206 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
static void |
| 219 |
< |
comm_comout(str) /* print string to command line */ |
| 220 |
< |
char *str; |
| 219 |
> |
comm_comout( /* print string to command line */ |
| 220 |
> |
char *str |
| 221 |
> |
) |
| 222 |
|
{ |
| 223 |
|
putc(COM_COMOUT, devout); |
| 224 |
|
myputs(str, devout); |
| 228 |
|
|
| 229 |
|
|
| 230 |
|
static void |
| 231 |
< |
comm_comin(buf, prompt) /* read string from command line */ |
| 232 |
< |
char *buf; |
| 233 |
< |
char *prompt; |
| 231 |
> |
comm_comin( /* read string from command line */ |
| 232 |
> |
char *buf, |
| 233 |
> |
char *prompt |
| 234 |
> |
) |
| 235 |
|
{ |
| 236 |
|
putc(COM_COMIN, devout); |
| 237 |
|
if (prompt == NULL) |
| 249 |
|
|
| 250 |
|
|
| 251 |
|
static void |
| 252 |
< |
mygets(s, fp) /* get string from file (with nul) */ |
| 253 |
< |
register char *s; |
| 254 |
< |
register FILE *fp; |
| 252 |
> |
mygets( /* get string from file (with nul) */ |
| 253 |
> |
register char *s, |
| 254 |
> |
register FILE *fp |
| 255 |
> |
) |
| 256 |
|
{ |
| 257 |
|
register int c; |
| 258 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
static void |
| 267 |
< |
myputs(s, fp) /* put string to file (with nul) */ |
| 268 |
< |
register char *s; |
| 269 |
< |
register FILE *fp; |
| 267 |
> |
myputs( /* put string to file (with nul) */ |
| 268 |
> |
register char *s, |
| 269 |
> |
register FILE *fp |
| 270 |
> |
) |
| 271 |
|
{ |
| 272 |
|
do |
| 273 |
|
putc(*s, fp); |
| 276 |
|
|
| 277 |
|
|
| 278 |
|
static void |
| 279 |
< |
reply_error(routine) /* what should we do here? */ |
| 280 |
< |
char *routine; |
| 279 |
> |
reply_error( /* what should we do here? */ |
| 280 |
> |
char *routine |
| 281 |
> |
) |
| 282 |
|
{ |
| 283 |
|
eputs(routine); |
| 284 |
|
eputs(": driver reply error\n"); |
| 287 |
|
|
| 288 |
|
|
| 289 |
|
static void |
| 290 |
< |
getstate() /* get driver state variables */ |
| 290 |
> |
getstate(void) /* get driver state variables */ |
| 291 |
|
{ |
| 292 |
|
fread((char *)&comm_driver.pixaspect, |
| 293 |
|
sizeof(comm_driver.pixaspect), 1, devin); |