| 21 |
|
#define FRAGWARN 20 /* fragmentation for warning (%) */ |
| 22 |
|
#endif |
| 23 |
|
#ifndef MAXQTIME |
| 24 |
< |
#define MAXQTIME 5 /* target maximum seconds in queue */ |
| 24 |
> |
#define MAXQTIME 3 /* target maximum seconds in queue */ |
| 25 |
|
#endif |
| 26 |
|
/* manual cache flushing frequency */ |
| 27 |
|
#ifndef RTFLUSH |
| 55 |
|
off_t maxdisk; /* maximum file space (bytes) */ |
| 56 |
|
|
| 57 |
|
int rtargc = 1; /* rtrace command */ |
| 58 |
< |
char *rtargv[128] = {"rtrace", NULL}; |
| 58 |
> |
char *rtargv[MAXRTARGC] = {"rtrace", NULL}; |
| 59 |
|
|
| 60 |
|
int orig_mode = -1; /* original file mode (-1 if unchanged) */ |
| 61 |
|
|
| 90 |
|
{ |
| 91 |
|
int i; |
| 92 |
|
|
| 93 |
– |
initurand(16384); /* initialize urand */ |
| 93 |
|
progname = argv[0]; /* get arguments */ |
| 94 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
| 95 |
|
switch (argv[i][1]) { |
| 164 |
|
quit(0); |
| 165 |
|
userr: |
| 166 |
|
fprintf(stderr, |
| 167 |
< |
"Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
| 167 |
> |
"Usage: %s [-n nprocs][-o disp][-i][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", |
| 168 |
|
progname); |
| 169 |
|
quit(1); |
| 170 |
|
return 1; /* pro forma return */ |
| 184 |
|
hdsync(NULL, 0); /* don't leave w/o saying goodbye */ |
| 185 |
|
_exit(signo); |
| 186 |
|
} |
| 187 |
< |
alarm(300); /* allow 5 minutes to clean up */ |
| 187 |
> |
alarm(300); /* allow 10 minutes to clean up */ |
| 188 |
|
eputs("signal - "); |
| 189 |
|
eputs(sigerr[signo]); |
| 190 |
|
eputs("\n"); |
| 229 |
|
static void |
| 230 |
|
initrholo(void) /* get our holodeck running */ |
| 231 |
|
{ |
| 232 |
< |
extern int global_packet(); |
| 234 |
< |
register int i; |
| 232 |
> |
int i; |
| 233 |
|
/* close holodeck on exec() */ |
| 234 |
|
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
| 235 |
|
|
| 249 |
|
hdcachesize = 1024.*1024.*vflt(CACHE); |
| 250 |
|
/* open report file */ |
| 251 |
|
if (vdef(REPORT)) { |
| 252 |
< |
register char *s = sskip2(vval(REPORT), 1); |
| 252 |
> |
char *s = sskip2(vval(REPORT), 1); |
| 253 |
|
if (*s && freopen(s, "a", stderr) == NULL) |
| 254 |
|
quit(2); |
| 255 |
|
} |
| 318 |
|
static int |
| 319 |
|
rholo(void) /* holodeck main loop */ |
| 320 |
|
{ |
| 321 |
< |
static long nextfragwarn = 100*(1L<<20); |
| 321 |
> |
static off_t nextfragwarn = 100L<<20; |
| 322 |
|
static int idle = 0; |
| 323 |
|
PACKET *pl = NULL, *plend; |
| 324 |
|
off_t fsiz; |
| 325 |
|
int pksiz; |
| 326 |
< |
register PACKET *p; |
| 326 |
> |
PACKET *p; |
| 327 |
|
time_t t; |
| 328 |
|
/* check display */ |
| 329 |
|
if (nprocs <= 0) |
| 337 |
|
return(0); /* all done */ |
| 338 |
|
fsiz = hdfilen(hdlist[0]->fd); /* check file size */ |
| 339 |
|
if (maxdisk > 0 && fsiz >= maxdisk) { |
| 340 |
< |
error(WARNING, "file limit exceeded"); |
| 340 |
> |
error(USER, "file limit exceeded"); |
| 341 |
|
done_rtrace(); |
| 342 |
|
return(1); /* comes back */ |
| 343 |
|
} |
| 344 |
|
#if FRAGWARN |
| 345 |
< |
if (fsiz >= nextfragwarn && |
| 346 |
< |
(fsiz-hdfiluse(hdlist[0]->fd,0))/(fsiz/100) > FRAGWARN) { |
| 347 |
< |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
| 348 |
< |
100.*(fsiz-hdfiluse(hdlist[0]->fd,1))/fsiz); |
| 349 |
< |
error(WARNING, errmsg); |
| 350 |
< |
nextfragwarn = fsiz + (fsiz>>2); /* decent interval */ |
| 345 |
> |
if (fsiz >= nextfragwarn) { |
| 346 |
> |
double pctfrag = 100.*(fsiz-hdfiluse(hdlist[0]->fd))/fsiz; |
| 347 |
> |
if (pctfrag >= (double)FRAGWARN) { |
| 348 |
> |
sprintf(errmsg, "holodeck file fragmentation is %.0f%%", |
| 349 |
> |
pctfrag); |
| 350 |
> |
error(WARNING, errmsg); |
| 351 |
> |
nextfragwarn = fsiz + (fsiz>>2); |
| 352 |
> |
} else |
| 353 |
> |
nextfragwarn = fsiz + (10L<<20); |
| 354 |
|
} |
| 355 |
|
#endif |
| 356 |
|
t = time(NULL); /* check time */ |
| 357 |
|
if (endtime > 0 && t >= endtime) { |
| 358 |
< |
error(WARNING, "time limit exceeded"); |
| 358 |
> |
error(USER, "time limit exceeded"); |
| 359 |
|
done_rtrace(); |
| 360 |
|
return(1); /* comes back */ |
| 361 |
|
} |
| 390 |
|
|
| 391 |
|
static void |
| 392 |
|
setdefaults( /* set default values */ |
| 393 |
< |
register HDGRID *gp |
| 393 |
> |
HDGRID *gp |
| 394 |
|
) |
| 395 |
|
{ |
| 396 |
< |
extern char *atos(); |
| 396 |
< |
register int i; |
| 396 |
> |
int i; |
| 397 |
|
int n; |
| 398 |
|
double len[3], d; |
| 399 |
|
|
| 413 |
|
} |
| 414 |
|
/* append rendering options */ |
| 415 |
|
if (vdef(RENDER)) |
| 416 |
< |
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
| 416 |
> |
rtargc += wordstring(rtargv+rtargc, MAXRTARGC-rtargc, vval(RENDER)); |
| 417 |
|
|
| 418 |
|
if (gp == NULL) /* already initialized? */ |
| 419 |
|
return; |
| 451 |
|
) |
| 452 |
|
{ |
| 453 |
|
extern char VersionID[]; |
| 454 |
< |
int32 lastloc, nextloc; |
| 454 |
> |
off_t lastloc, nextloc; |
| 455 |
|
int n; |
| 456 |
|
int fd; |
| 457 |
|
FILE *fp; |
| 458 |
|
/* open & truncate file */ |
| 459 |
< |
if ((fp = fopen(hdkfile, "w+")) == NULL) { |
| 459 |
> |
if ((fp = fopen(hdkfile, "wb+")) == NULL) { |
| 460 |
|
sprintf(errmsg, "cannot open \"%s\" for writing", hdkfile); |
| 461 |
|
error(SYSTEM, errmsg); |
| 462 |
|
} |
| 464 |
|
newheader("RADIANCE", fp); |
| 465 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 466 |
|
printvars(fp); |
| 467 |
+ |
fputendian(fp); |
| 468 |
|
fputformat(HOLOFMT, fp); |
| 469 |
|
fputc('\n', fp); |
| 470 |
|
putw(HOLOMAGIC, fp); /* put magic number */ |
| 478 |
|
if (!n) |
| 479 |
|
break; |
| 480 |
|
nextloc = hdfilen(fd); /* write section pointer */ |
| 481 |
< |
if (lseek(fd, (off_t)lastloc, SEEK_SET) < 0) |
| 481 |
> |
if (lseek(fd, lastloc, SEEK_SET) < 0) |
| 482 |
|
error(SYSTEM, |
| 483 |
|
"cannot seek on holodeck file in creatholo"); |
| 484 |
|
write(fd, (char *)&nextloc, sizeof(nextloc)); |
| 485 |
< |
lseek(fd, (off_t)(lastloc=nextloc), SEEK_SET); |
| 485 |
> |
lseek(fd, (lastloc=nextloc), SEEK_SET); |
| 486 |
|
} |
| 487 |
|
} |
| 488 |
|
|
| 494 |
|
) |
| 495 |
|
{ |
| 496 |
|
extern char FMTSTR[]; |
| 497 |
< |
register char *cp; |
| 498 |
< |
char fmt[32]; |
| 497 |
> |
char *cp; |
| 498 |
> |
char fmt[MAXFMTLEN]; |
| 499 |
|
|
| 500 |
|
if (formatval(fmt, s)) { |
| 501 |
|
if (strcmp(fmt, HOLOFMT)) { |
| 521 |
|
FILE *fp; |
| 522 |
|
int fd; |
| 523 |
|
int n; |
| 524 |
< |
int32 nextloc; |
| 524 |
> |
off_t nextloc; |
| 525 |
|
|
| 526 |
|
if ((ncprocs > 0) & (force >= 0)) |
| 527 |
< |
fp = fopen(hdkfile, "r+"); |
| 527 |
> |
fp = fopen(hdkfile, "rb+"); |
| 528 |
|
else |
| 529 |
|
fp = NULL; |
| 530 |
|
if (fp == NULL) { |
| 531 |
< |
if ((fp = fopen(hdkfile, "r")) == NULL) { |
| 531 |
> |
if ((fp = fopen(hdkfile, "rb")) == NULL) { |
| 532 |
|
sprintf(errmsg, "cannot open \"%s\"", hdkfile); |
| 533 |
|
error(SYSTEM, errmsg); |
| 534 |
|
} |
| 535 |
|
if (ncprocs > 0) { |
| 536 |
< |
sprintf(errmsg, |
| 537 |
< |
"\"%s\" opened read-only; new rays will be discarded", |
| 538 |
< |
hdkfile); |
| 536 |
> |
sprintf(errmsg, "\"%s\" is read-only", hdkfile); |
| 537 |
> |
if (outdev == NULL) |
| 538 |
> |
error(USER, errmsg); |
| 539 |
> |
strcat(errmsg, "; new rays will be discarded"); |
| 540 |
|
error(WARNING, errmsg); |
| 541 |
|
force = -1; |
| 542 |
|
} |
| 553 |
|
fd = dup(fileno(fp)); |
| 554 |
|
fclose(fp); /* done with stdio */ |
| 555 |
|
for (n = 0; nextloc > 0L; n++) { /* initialize each section */ |
| 556 |
< |
lseek(fd, (off_t)nextloc, SEEK_SET); |
| 556 |
> |
lseek(fd, nextloc, SEEK_SET); |
| 557 |
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 558 |
|
hdinit(fd, NULL); |
| 559 |
|
} |
| 565 |
|
} |
| 566 |
|
|
| 567 |
|
|
| 568 |
< |
extern void |
| 568 |
> |
void |
| 569 |
|
done_packets( /* handle finished packets */ |
| 570 |
|
PACKET *pl |
| 571 |
|
) |
| 572 |
|
{ |
| 573 |
|
static int n2flush = 0; |
| 574 |
< |
register PACKET *p; |
| 574 |
> |
PACKET *p; |
| 575 |
|
|
| 576 |
|
while (pl != NULL) { |
| 577 |
|
p = pl; pl = p->next; p->next = NULL; |
| 602 |
|
|
| 603 |
|
static void |
| 604 |
|
rootname( /* remove tail from end of fn */ |
| 605 |
< |
register char *rn, |
| 606 |
< |
register char *fn |
| 605 |
> |
char *rn, |
| 606 |
> |
char *fn |
| 607 |
|
) |
| 608 |
|
{ |
| 609 |
|
char *tp, *dp; |
| 630 |
|
|
| 631 |
|
|
| 632 |
|
void |
| 633 |
< |
eputs(s) /* put error message to stderr */ |
| 632 |
< |
register char *s; |
| 633 |
> |
eputs(const char *s) /* put error message to stderr */ |
| 634 |
|
{ |
| 635 |
|
static int midline = 0; |
| 636 |
|
|
| 649 |
|
|
| 650 |
|
|
| 651 |
|
void |
| 652 |
< |
quit(ec) /* exit program gracefully */ |
| 652 |
< |
int ec; |
| 652 |
> |
quit(int ec) /* exit program gracefully */ |
| 653 |
|
{ |
| 654 |
|
int status = 0; |
| 655 |
|
|
| 659 |
|
if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) { |
| 660 |
|
off_t fsiz, fuse; |
| 661 |
|
fsiz = hdfilen(hdlist[0]->fd); |
| 662 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
| 662 |
> |
fuse = hdfiluse(hdlist[0]->fd); |
| 663 |
|
fprintf(stderr, |
| 664 |
|
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
| 665 |
|
hdkfile, fsiz/(1024.*1024.), |