| 1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Holodeck display process. |
| 6 |
|
*/ |
| 15 |
|
#define VIEWHISTLEN 4 /* number of remembered views */ |
| 16 |
|
#endif |
| 17 |
|
|
| 18 |
+ |
#ifndef FSIZDEF |
| 19 |
+ |
#define FSIZDEF 0.125 /* default focus frame size */ |
| 20 |
+ |
#endif |
| 21 |
+ |
|
| 22 |
+ |
#if defined(freebsd) |
| 23 |
+ |
#define fbufcnt(f) ((f)->_r) |
| 24 |
+ |
#elif defined(__GNUC__) |
| 25 |
+ |
#define fbufcnt(f) ((f)->_IO_read_end - (f)->_IO_read_ptr) |
| 26 |
+ |
#else |
| 27 |
+ |
#define fbufcnt(f) ((f)->_cnt) |
| 28 |
+ |
#endif |
| 29 |
+ |
|
| 30 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
| 31 |
|
|
| 32 |
+ |
char *hdgfn[HDMAX]; /* holodeck section geometry list */ |
| 33 |
+ |
char *hdpfn[HDMAX]; /* section portal list */ |
| 34 |
+ |
|
| 35 |
|
char cmdlist[DC_NCMDS][8] = DC_INIT; |
| 36 |
|
|
| 37 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
| 38 |
|
|
| 39 |
+ |
int do_outside = 0; /* render from outside sections */ |
| 40 |
+ |
|
| 41 |
+ |
double eyesepdist = 1; /* eye separation distance */ |
| 42 |
+ |
|
| 43 |
|
char *progname; /* global argv[0] */ |
| 44 |
|
|
| 45 |
|
FILE *sstdin, *sstdout; /* server's standard input and output */ |
| 46 |
|
|
| 47 |
+ |
#ifdef DEBUG |
| 48 |
+ |
extern time_t time(); |
| 49 |
+ |
static time_t tmodesw; |
| 50 |
+ |
static time_t timm, tadd; |
| 51 |
+ |
static long nimmrays, naddrays; |
| 52 |
+ |
#endif |
| 53 |
+ |
|
| 54 |
|
#define RDY_SRV 01 |
| 55 |
|
#define RDY_DEV 02 |
| 56 |
|
#define RDY_SIN 04 |
| 60 |
|
int argc; |
| 61 |
|
char *argv[]; |
| 62 |
|
{ |
| 40 |
– |
extern int eputs(); |
| 63 |
|
int rdy, inp, res = 0, pause = 0; |
| 64 |
|
|
| 65 |
|
progname = argv[0]; |
| 75 |
|
sstdin = fdopen(inp, "r"); |
| 76 |
|
/* set command error vector */ |
| 77 |
|
erract[COMMAND].pf = eputs; |
| 78 |
+ |
#ifdef DEBUG |
| 79 |
+ |
tmodesw = time(NULL); |
| 80 |
+ |
#endif |
| 81 |
|
/* enter main loop */ |
| 82 |
|
do { |
| 83 |
|
rdy = disp_wait(); |
| 84 |
+ |
if (rdy & RDY_SRV) { /* process server result */ |
| 85 |
+ |
res = serv_result(); |
| 86 |
+ |
if (pause && res != DS_SHUTDOWN) { |
| 87 |
+ |
serv_request(DR_ATTEN, 0, NULL); |
| 88 |
+ |
while ((res = serv_result()) != DS_ACKNOW && |
| 89 |
+ |
res != DS_SHUTDOWN) |
| 90 |
+ |
; |
| 91 |
+ |
} |
| 92 |
+ |
} |
| 93 |
|
if (rdy & RDY_DEV) { /* user input from driver */ |
| 94 |
|
inp = dev_input(); |
| 95 |
|
if (inp & DFL(DC_SETVIEW)) |
| 96 |
|
new_view(&odev.v); |
| 97 |
< |
if (inp & DFL(DC_GETVIEW)) |
| 64 |
< |
printview(); |
| 65 |
< |
if (inp & DFL(DC_LASTVIEW)) |
| 97 |
> |
else if (inp & DFL(DC_LASTVIEW)) |
| 98 |
|
new_view(NULL); |
| 67 |
– |
if (inp & DFL(DC_RESUME)) { |
| 68 |
– |
serv_request(DR_NOOP, 0, NULL); |
| 69 |
– |
pause = 0; |
| 70 |
– |
} |
| 71 |
– |
if (inp & DFL(DC_PAUSE)) |
| 72 |
– |
pause = 1; |
| 99 |
|
if (inp & DFL(DC_REDRAW)) |
| 100 |
< |
imm_mode = beam_sync() > 0; |
| 100 |
> |
imm_mode = beam_sync(1) > 0; |
| 101 |
> |
if (inp & DFL(DC_GETVIEW)) |
| 102 |
> |
printview(); |
| 103 |
> |
if (inp & DFL(DC_FOCUS)) |
| 104 |
> |
set_focus(odev_args); |
| 105 |
|
if (inp & DFL(DC_KILL)) { |
| 106 |
|
serv_request(DR_KILL, 0, NULL); |
| 107 |
|
pause = 0; |
| 112 |
|
serv_request(DR_RESTART, 0, NULL); |
| 113 |
|
pause = 0; |
| 114 |
|
} |
| 115 |
+ |
if (inp & DFL(DC_RESUME)) { |
| 116 |
+ |
serv_request(DR_NOOP, 0, NULL); |
| 117 |
+ |
pause = 0; |
| 118 |
+ |
} |
| 119 |
+ |
if (inp & DFL(DC_PAUSE)) |
| 120 |
+ |
pause = 1; |
| 121 |
|
if (inp & DFL(DC_QUIT)) |
| 122 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
| 123 |
|
} |
| 124 |
< |
if (rdy & RDY_SIN) /* user input from sstdin */ |
| 124 |
> |
if (rdy & RDY_SIN && !imm_mode) /* user input from sstdin */ |
| 125 |
|
switch (usr_input()) { |
| 126 |
|
case DC_PAUSE: |
| 127 |
|
pause = 1; |
| 134 |
|
pause = 0; |
| 135 |
|
break; |
| 136 |
|
} |
| 101 |
– |
if (rdy & RDY_SRV) { /* process server result */ |
| 102 |
– |
res = serv_result(); |
| 103 |
– |
if (pause && res != DS_SHUTDOWN) { |
| 104 |
– |
serv_request(DR_ATTEN, 0, NULL); |
| 105 |
– |
while ((res = serv_result()) != DS_ACKNOW && |
| 106 |
– |
res != DS_SHUTDOWN) |
| 107 |
– |
; |
| 108 |
– |
} |
| 109 |
– |
} |
| 137 |
|
} while (res != DS_SHUTDOWN); |
| 138 |
+ |
#ifdef DEBUG |
| 139 |
+ |
if (timm && nimmrays) |
| 140 |
+ |
fprintf(stderr, |
| 141 |
+ |
"%s: %.1f rays recalled/second (%ld rays total)\n", |
| 142 |
+ |
progname, (double)nimmrays/timm, nimmrays); |
| 143 |
+ |
if (tadd && naddrays) |
| 144 |
+ |
fprintf(stderr, |
| 145 |
+ |
"%s: %.1f rays calculated/second (%ld rays total)\n", |
| 146 |
+ |
progname, (double)naddrays/tadd, naddrays); |
| 147 |
+ |
#endif |
| 148 |
|
/* all done */ |
| 149 |
|
quit(0); |
| 150 |
|
} |
| 158 |
|
int n; |
| 159 |
|
register int i; |
| 160 |
|
/* see if we can avoid select call */ |
| 161 |
< |
if (imm_mode || stdin->_cnt > 0) |
| 162 |
< |
return(RDY_SRV); |
| 163 |
< |
if (sstdin != NULL && sstdin->_cnt > 0) |
| 164 |
< |
return(RDY_SIN); |
| 165 |
< |
if (dev_flush()) |
| 161 |
> |
if (hdlist[0] == NULL) |
| 162 |
> |
return(RDY_SRV); /* initialize first */ |
| 163 |
> |
flgs = 0; /* flag what's ready already */ |
| 164 |
> |
if (imm_mode || fbufcnt(stdin) > 0) |
| 165 |
> |
flgs |= RDY_SRV; |
| 166 |
> |
if (sstdin != NULL && fbufcnt(sstdin) > 0) |
| 167 |
> |
flgs |= RDY_SIN; |
| 168 |
> |
if (odev.inpready) |
| 169 |
> |
flgs |= RDY_DEV; |
| 170 |
> |
if (flgs) /* got something? */ |
| 171 |
> |
return(flgs); |
| 172 |
> |
if (dev_flush()) /* else flush output & check keyboard+mouse */ |
| 173 |
|
return(RDY_DEV); |
| 174 |
< |
/* make the call */ |
| 174 |
> |
/* if nothing, we need to call select */ |
| 175 |
|
FD_ZERO(&readset); FD_ZERO(&errset); |
| 176 |
|
FD_SET(0, &readset); |
| 177 |
|
FD_SET(0, &errset); |
| 180 |
|
n = odev.ifd+1; |
| 181 |
|
if (sstdin != NULL) { |
| 182 |
|
FD_SET(fileno(sstdin), &readset); |
| 183 |
+ |
FD_SET(fileno(sstdin), &errset); |
| 184 |
|
if (fileno(sstdin) >= n) |
| 185 |
|
n = fileno(sstdin) + 1; |
| 186 |
|
} |
| 190 |
|
return(0); |
| 191 |
|
error(SYSTEM, "select call failure in disp_wait"); |
| 192 |
|
} |
| 148 |
– |
flgs = 0; /* flag what's ready */ |
| 193 |
|
if (FD_ISSET(0, &readset) || FD_ISSET(0, &errset)) |
| 194 |
|
flgs |= RDY_SRV; |
| 195 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
| 196 |
|
flgs |= RDY_DEV; |
| 197 |
< |
if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) |
| 197 |
> |
if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) || |
| 198 |
> |
FD_ISSET(fileno(sstdin), &errset))) |
| 199 |
|
flgs |= RDY_SIN; |
| 200 |
|
return(flgs); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
< |
add_holo(hdg) /* register a new holodeck section */ |
| 204 |
> |
add_holo(hdg, gfn, pfn) /* register a new holodeck section */ |
| 205 |
|
HDGRID *hdg; |
| 206 |
+ |
char *gfn, *pfn; |
| 207 |
|
{ |
| 208 |
|
VIEW nv; |
| 209 |
+ |
double d; |
| 210 |
|
register int hd; |
| 211 |
|
|
| 212 |
|
for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++) |
| 218 |
|
error(SYSTEM, "out of memory in add_holo"); |
| 219 |
|
bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); |
| 220 |
|
hdcompgrid(hdlist[hd]); |
| 221 |
+ |
hdgfn[hd] = savestr(gfn); |
| 222 |
+ |
hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; |
| 223 |
|
if (hd) |
| 224 |
|
return; |
| 225 |
|
/* set initial viewpoint */ |
| 229 |
|
VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); |
| 230 |
|
fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]); |
| 231 |
|
VCOPY(nv.vup, hdlist[0]->xv[2]); |
| 232 |
+ |
if (do_outside) { |
| 233 |
+ |
normalize(nv.vdir); |
| 234 |
+ |
d = VLEN(hdlist[0]->xv[1]); |
| 235 |
+ |
d += VLEN(hdlist[0]->xv[2]); |
| 236 |
+ |
VSUM(nv.vp, nv.vp, nv.vdir, -d); |
| 237 |
+ |
} |
| 238 |
|
new_view(&nv); |
| 239 |
|
} |
| 240 |
|
|
| 255 |
|
for (i = p->nr; i--; ) { |
| 256 |
|
hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r); |
| 257 |
|
d = hddepth(hdlist[p->hd], packra(p)[i].d); |
| 258 |
< |
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
| 259 |
< |
dev_value(packra(p)[i].v, wp, rd); |
| 258 |
> |
if (d < .99*FHUGE) { |
| 259 |
> |
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
| 260 |
> |
dev_value(packra(p)[i].v, rd, wp); |
| 261 |
> |
} else |
| 262 |
> |
dev_value(packra(p)[i].v, rd, NULL); |
| 263 |
|
} |
| 264 |
+ |
#ifdef DEBUG |
| 265 |
+ |
if (imm_mode) nimmrays += p->nr; |
| 266 |
+ |
else naddrays += p->nr; |
| 267 |
+ |
#endif |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 273 |
|
{ |
| 274 |
|
static VIEW viewhist[VIEWHISTLEN]; |
| 275 |
|
static unsigned nhist; |
| 276 |
+ |
VIEW *dv; |
| 277 |
+ |
int i, res[2]; |
| 278 |
+ |
int2 *slist; |
| 279 |
|
char *err; |
| 280 |
|
/* restore previous view? */ |
| 281 |
|
if (v == NULL) { |
| 291 |
|
error(COMMAND, err); |
| 292 |
|
return; |
| 293 |
|
} |
| 294 |
+ |
if (!dev_view(v)) /* notify display driver */ |
| 295 |
+ |
goto again; |
| 296 |
|
if (v->type == VT_PAR) { |
| 297 |
|
error(COMMAND, "cannot handle parallel views"); |
| 298 |
|
return; |
| 299 |
|
} |
| 300 |
< |
if (!dev_view(v)) /* update display driver */ |
| 301 |
< |
goto again; |
| 302 |
< |
dev_flush(); /* update screen */ |
| 303 |
< |
if (!beam_view(v)) /* update beam list */ |
| 304 |
< |
goto again; |
| 300 |
> |
beam_init(odev.firstuse); /* compute new beam set */ |
| 301 |
> |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) { |
| 302 |
> |
if ((slist = beam_view(dv, res[0], res[1])) == NULL) { |
| 303 |
> |
if (!nhist) { |
| 304 |
> |
error(COMMAND, "invalid starting view"); |
| 305 |
> |
return; |
| 306 |
> |
} |
| 307 |
> |
copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); |
| 308 |
> |
goto again; /* poss. overloading dev_section()? */ |
| 309 |
> |
} |
| 310 |
> |
DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); |
| 311 |
> |
for ( ; *slist >= 0; slist++) |
| 312 |
> |
dev_section(hdgfn[*slist], hdpfn[*slist]); |
| 313 |
> |
} |
| 314 |
> |
dev_section(NULL,NULL); /* end section list */ |
| 315 |
> |
dev_flush(); /* update display */ |
| 316 |
> |
/* update server */ |
| 317 |
> |
imm_mode = beam_sync(odev.firstuse) > 0; |
| 318 |
|
/* record new view */ |
| 319 |
|
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
| 320 |
|
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
| 323 |
|
} |
| 324 |
|
|
| 325 |
|
|
| 326 |
+ |
set_focus(args) /* set focus frame */ |
| 327 |
+ |
char *args; |
| 328 |
+ |
{ |
| 329 |
+ |
double hcent, vcent, hsiz, vsiz; |
| 330 |
+ |
VIEW *dv, vwfocus; |
| 331 |
+ |
int i, res[2]; |
| 332 |
+ |
|
| 333 |
+ |
i = sscanf(args, "%lf %lf %lf %lf", &hcent, &vcent, &hsiz, &vsiz); |
| 334 |
+ |
if (i < 2 || hcent < 0 || hcent > 1 || vcent < 0 || vcent > 1) { |
| 335 |
+ |
beam_init(0); /* restore view */ |
| 336 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
| 337 |
+ |
beam_view(dv, res[0], res[1]); |
| 338 |
+ |
beam_sync(0); /* update server */ |
| 339 |
+ |
return; |
| 340 |
+ |
} |
| 341 |
+ |
if (i < 4 || hsiz <= hcent || hsiz > 1 || vsiz <= vcent || vsiz > 1) |
| 342 |
+ |
hsiz = vsiz = FSIZDEF; /* gave center only */ |
| 343 |
+ |
else { |
| 344 |
+ |
hsiz -= hcent; hcent += 0.5*hsiz; /* gave min and max */ |
| 345 |
+ |
vsiz -= vcent; vcent += 0.5*vsiz; |
| 346 |
+ |
} |
| 347 |
+ |
beam_init(0); /* add basic views */ |
| 348 |
+ |
for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) |
| 349 |
+ |
beam_view(dv, res[0]>>4, res[1]>>4); |
| 350 |
+ |
copystruct(&vwfocus, &odev.v); /* add focus view */ |
| 351 |
+ |
switch (odev.v.type) { |
| 352 |
+ |
case VT_PER: |
| 353 |
+ |
vwfocus.horiz = 2.*180./PI*atan( |
| 354 |
+ |
hsiz * tan(PI/180./2.*odev.v.horiz) ); |
| 355 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
| 356 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
| 357 |
+ |
break; |
| 358 |
+ |
case VT_PAR: |
| 359 |
+ |
case VT_ANG: |
| 360 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
| 361 |
+ |
vwfocus.vert = vsiz * odev.v.vert; |
| 362 |
+ |
break; |
| 363 |
+ |
case VT_HEM: |
| 364 |
+ |
vwfocus.horiz = 2.*180./PI*asin( |
| 365 |
+ |
hsiz * sin(PI/180./2.*odev.v.horiz) ); |
| 366 |
+ |
vwfocus.vert = 2.*180./PI*asin( |
| 367 |
+ |
vsiz * sin(PI/180./2.*odev.v.vert) ); |
| 368 |
+ |
break; |
| 369 |
+ |
case VT_CYL: |
| 370 |
+ |
vwfocus.horiz = hsiz * odev.v.horiz; |
| 371 |
+ |
vwfocus.vert = 2.*180./PI*atan( |
| 372 |
+ |
vsiz * tan(PI/180./2.*odev.v.vert) ); |
| 373 |
+ |
break; |
| 374 |
+ |
default: |
| 375 |
+ |
error(INTERNAL, "bad view type in set_focus"); |
| 376 |
+ |
} |
| 377 |
+ |
vwfocus.hoff = (odev.v.hoff + hcent - 0.5)/hsiz; |
| 378 |
+ |
vwfocus.voff = (odev.v.voff + vcent - 0.5)/vsiz; |
| 379 |
+ |
setview(&vwfocus); |
| 380 |
+ |
beam_view(&vwfocus, (int)(3*odev.hres*hsiz)+100, |
| 381 |
+ |
(int)(3*odev.vres*vsiz)+100); |
| 382 |
+ |
beam_sync(0); /* update server */ |
| 383 |
+ |
} |
| 384 |
+ |
|
| 385 |
+ |
|
| 386 |
|
int |
| 387 |
|
usr_input() /* get user input and process it */ |
| 388 |
|
{ |
| 389 |
|
VIEW vparams; |
| 390 |
< |
char cmd[128]; |
| 390 |
> |
char cmd[256]; |
| 391 |
|
register char *args; |
| 392 |
|
register int i; |
| 393 |
|
|
| 394 |
< |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) |
| 395 |
< |
return(DC_QUIT); |
| 394 |
> |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) { |
| 395 |
> |
fclose(sstdin); |
| 396 |
> |
sstdin = NULL; |
| 397 |
> |
return(-1); |
| 398 |
> |
} |
| 399 |
> |
if (*cmd == '\n') |
| 400 |
> |
return(DC_RESUME); |
| 401 |
|
for (args = cmd; *args && !isspace(*args); args++) |
| 402 |
|
; |
| 403 |
|
while (isspace(*args)) |
| 404 |
|
*args++ = '\0'; |
| 260 |
– |
if (!*cmd) |
| 261 |
– |
return(DC_RESUME); |
| 405 |
|
if (*args && args[i=strlen(args)-1] == '\n') |
| 406 |
|
args[i] = '\0'; |
| 407 |
|
for (i = 0; i < DC_NCMDS; i++) |
| 408 |
|
if (!strcmp(cmd, cmdlist[i])) |
| 409 |
|
break; |
| 410 |
|
if (i >= DC_NCMDS) { |
| 411 |
< |
sprintf(errmsg, "unknown command: %s", cmd); |
| 269 |
< |
error(COMMAND, errmsg); |
| 411 |
> |
dev_auxcom(cmd, args); |
| 412 |
|
return(-1); |
| 413 |
|
} |
| 414 |
|
switch (i) { |
| 425 |
|
case DC_LASTVIEW: /* restore previous view */ |
| 426 |
|
new_view(NULL); |
| 427 |
|
break; |
| 428 |
+ |
case DC_FOCUS: /* set focus frame */ |
| 429 |
+ |
set_focus(args); |
| 430 |
+ |
break; |
| 431 |
|
case DC_PAUSE: /* pause the current calculation */ |
| 432 |
|
case DC_RESUME: /* resume the calculation */ |
| 433 |
|
/* handled in main() */ |
| 434 |
|
break; |
| 435 |
|
case DC_REDRAW: /* redraw from server */ |
| 436 |
< |
imm_mode = beam_sync() > 0; |
| 436 |
> |
imm_mode = beam_sync(1) > 0; |
| 437 |
> |
dev_clear(); |
| 438 |
|
break; |
| 439 |
|
case DC_KILL: /* kill rtrace process(es) */ |
| 440 |
|
serv_request(DR_KILL, 0, NULL); |
| 479 |
|
if (buf == NULL) |
| 480 |
|
buf = (char *)malloc(bufsiz=msg.nbytes); |
| 481 |
|
else |
| 482 |
< |
buf = (char *)realloc(buf, bufsiz=msg.nbytes); |
| 482 |
> |
buf = (char *)realloc((void *)buf, |
| 483 |
> |
bufsiz=msg.nbytes); |
| 484 |
|
if (buf == NULL) |
| 485 |
|
error(SYSTEM, "out of memory in serv_result"); |
| 486 |
|
} |
| 495 |
|
disp_bundle((PACKHEAD *)buf); |
| 496 |
|
break; |
| 497 |
|
case DS_ADDHOLO: |
| 498 |
< |
if (msg.nbytes != sizeof(HDGRID)) |
| 498 |
> |
if (msg.nbytes < sizeof(HDGRID)+2) |
| 499 |
|
error(INTERNAL, "bad holodeck record from server"); |
| 500 |
< |
add_holo((HDGRID *)buf); |
| 500 |
> |
add_holo((HDGRID *)buf, buf+sizeof(HDGRID), |
| 501 |
> |
buf+sizeof(HDGRID)+strlen(buf+sizeof(HDGRID))+1); |
| 502 |
|
break; |
| 503 |
+ |
case DS_OUTSECT: |
| 504 |
+ |
do_outside = 1; |
| 505 |
+ |
goto noargs; |
| 506 |
+ |
case DS_EYESEP: |
| 507 |
+ |
if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY) |
| 508 |
+ |
error(INTERNAL, "bad eye separation from server"); |
| 509 |
+ |
break; |
| 510 |
|
case DS_STARTIMM: |
| 511 |
|
case DS_ENDIMM: |
| 512 |
< |
imm_mode = msg.type==DS_STARTIMM; |
| 513 |
< |
/* fall through */ |
| 512 |
> |
if (!(imm_mode = msg.type==DS_STARTIMM)) |
| 513 |
> |
dev_flush(); |
| 514 |
> |
#ifdef DEBUG |
| 515 |
> |
{ |
| 516 |
> |
time_t tnow = time(NULL); |
| 517 |
> |
if (msg.type==DS_STARTIMM) tadd += tnow - tmodesw; |
| 518 |
> |
else timm += tnow - tmodesw; |
| 519 |
> |
tmodesw = tnow; |
| 520 |
> |
} |
| 521 |
> |
#endif |
| 522 |
> |
goto noargs; |
| 523 |
|
case DS_ACKNOW: |
| 524 |
|
case DS_SHUTDOWN: |
| 525 |
< |
if (msg.nbytes) { |
| 362 |
< |
sprintf(errmsg, |
| 363 |
< |
"unexpected body with server message %d", |
| 364 |
< |
msg.type); |
| 365 |
< |
error(INTERNAL, errmsg); |
| 366 |
< |
} |
| 367 |
< |
break; |
| 525 |
> |
goto noargs; |
| 526 |
|
default: |
| 527 |
|
error(INTERNAL, "unrecognized result from server process"); |
| 528 |
|
} |
| 529 |
|
return(msg.type); /* return message type */ |
| 530 |
+ |
noargs: |
| 531 |
+ |
if (msg.nbytes) { |
| 532 |
+ |
sprintf(errmsg, "unexpected body with server message %d", |
| 533 |
+ |
msg.type); |
| 534 |
+ |
error(INTERNAL, errmsg); |
| 535 |
+ |
} |
| 536 |
+ |
return(msg.type); |
| 537 |
|
readerr: |
| 538 |
|
if (feof(stdin)) |
| 539 |
|
error(SYSTEM, "server process died"); |
| 547 |
|
{ |
| 548 |
|
MSGHEAD msg; |
| 549 |
|
int m; |
| 550 |
+ |
/* consistency checks */ |
| 551 |
+ |
DCHECK(nbytes < 0 || nbytes > 0 & p == NULL, |
| 552 |
+ |
CONSISTENCY, "bad buffer handed to serv_request"); |
| 553 |
|
/* get server's attention for big request */ |
| 554 |
|
if (nbytes >= BIGREQSIZ-sizeof(MSGHEAD)) { |
| 555 |
|
serv_request(DR_ATTEN, 0, NULL); |
| 567 |
|
} |
| 568 |
|
|
| 569 |
|
|
| 570 |
+ |
void |
| 571 |
|
eputs(s) /* put error message to stderr */ |
| 572 |
|
register char *s; |
| 573 |
|
{ |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
|
| 590 |
+ |
void |
| 591 |
|
quit(code) /* clean up and exit */ |
| 592 |
|
int code; |
| 593 |
|
{ |
| 594 |
+ |
if (code) |
| 595 |
+ |
exit(code); |
| 596 |
|
if (odev.v.type) |
| 597 |
|
dev_close(); |
| 598 |
< |
exit(code); |
| 598 |
> |
exit(0); |
| 599 |
|
} |