| 5 |  | * Radiance holodeck generation controller | 
| 6 |  | */ | 
| 7 |  |  | 
| 8 | – | #include "rholo.h" | 
| 9 | – | #include "random.h" | 
| 8 |  | #include <signal.h> | 
| 9 |  | #include <sys/stat.h> | 
| 10 | + | #include <string.h> | 
| 11 |  |  | 
| 12 | + | #include "rholo.h" | 
| 13 | + | #include "platform.h" | 
| 14 | + | #include "random.h" | 
| 15 | + |  | 
| 16 |  | #ifndef FRAGWARN | 
| 17 |  | #define FRAGWARN        20              /* fragmentation for warning (%) */ | 
| 18 |  | #endif | 
| 48 |  | time_t  endtime;                /* time we should end by */ | 
| 49 |  | time_t  reporttime;             /* time for next report */ | 
| 50 |  |  | 
| 51 | < | long    maxdisk;                /* maximum file space (bytes) */ | 
| 51 | > | off_t   maxdisk;                /* maximum file space (bytes) */ | 
| 52 |  |  | 
| 53 |  | int     rtargc = 1;             /* rtrace command */ | 
| 54 |  | char    *rtargv[128] = {"rtrace", NULL}; | 
| 155 |  | } | 
| 156 |  |  | 
| 157 |  |  | 
| 158 | + | void | 
| 159 |  | onsig(signo)                            /* fatal signal */ | 
| 160 |  | int  signo; | 
| 161 |  | { | 
| 218 |  | init_global(); | 
| 219 |  | /* record disk space limit */ | 
| 220 |  | if (!vdef(DISKSPACE)) | 
| 221 | < | maxdisk = (1L<<(sizeof(long)*8-2)) - 1024; | 
| 221 | > | maxdisk = ((off_t)1<<(sizeof(off_t)*8-2)) - 1024; | 
| 222 |  | else | 
| 223 |  | maxdisk = 1024.*1024.*vflt(DISKSPACE); | 
| 224 |  | /* set up memory cache */ | 
| 279 |  | sigdie(SIGXFSZ, "File size exceeded"); | 
| 280 |  | #endif | 
| 281 |  | /* protect holodeck file */ | 
| 282 | < | orig_mode = resfmode(hdlist[0]->fd, ncprocs>0&force>=0 ? 0 : 0444); | 
| 282 | > | orig_mode = resfmode(hdlist[0]->fd, (ncprocs>0) & (force>=0) ? 0 : 0444); | 
| 283 |  | return; | 
| 284 |  | memerr: | 
| 285 |  | error(SYSTEM, "out of memory in initrholo"); | 
| 291 |  | static long     nextfragwarn = 100*(1L<<20); | 
| 292 |  | static int      idle = 0; | 
| 293 |  | PACKET  *pl = NULL, *plend; | 
| 294 | < | long    fsiz; | 
| 294 | > | off_t   fsiz; | 
| 295 |  | int     pksiz; | 
| 296 |  | register PACKET *p; | 
| 297 |  | time_t  t; | 
| 416 |  | HDGRID  *gp; | 
| 417 |  | { | 
| 418 |  | extern char     VersionID[]; | 
| 419 | < | int4    lastloc, nextloc; | 
| 419 | > | int32   lastloc, nextloc; | 
| 420 |  | int     n; | 
| 421 |  | int     fd; | 
| 422 |  | FILE    *fp; | 
| 434 |  | putw(HOLOMAGIC, fp);            /* put magic number */ | 
| 435 |  | fd = dup(fileno(fp)); | 
| 436 |  | fclose(fp);                     /* flush and close stdio stream */ | 
| 437 | < | lastloc = lseek(fd, (off_t)0L, 2); | 
| 437 | > | lastloc = lseek(fd, (off_t)0, SEEK_END); | 
| 438 |  | for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */ | 
| 439 |  | nextloc = 0L; | 
| 440 |  | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 442 |  | if (!n) | 
| 443 |  | break; | 
| 444 |  | nextloc = hdfilen(fd);          /* write section pointer */ | 
| 445 | < | if (lseek(fd, (off_t)lastloc, 0) < 0) | 
| 445 | > | if (lseek(fd, (off_t)lastloc, SEEK_SET) < 0) | 
| 446 |  | error(SYSTEM, | 
| 447 |  | "cannot seek on holodeck file in creatholo"); | 
| 448 |  | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 449 | < | lseek(fd, (off_t)(lastloc=nextloc), 0); | 
| 449 | > | lseek(fd, (off_t)(lastloc=nextloc), SEEK_SET); | 
| 450 |  | } | 
| 451 |  | } | 
| 452 |  |  | 
| 479 |  |  | 
| 480 |  | loadholo()                      /* start loading a holodeck from fname */ | 
| 481 |  | { | 
| 478 | – | extern long     ftell(); | 
| 482 |  | FILE    *fp; | 
| 483 |  | int     fd; | 
| 484 |  | int     n; | 
| 485 | < | int4    nextloc; | 
| 485 | > | int32   nextloc; | 
| 486 |  |  | 
| 487 | < | if (ncprocs > 0 & force >= 0) | 
| 487 | > | if ((ncprocs > 0) & (force >= 0)) | 
| 488 |  | fp = fopen(hdkfile, "r+"); | 
| 489 |  | else | 
| 490 |  | fp = NULL; | 
| 513 |  | fd = dup(fileno(fp)); | 
| 514 |  | fclose(fp);                             /* done with stdio */ | 
| 515 |  | for (n = 0; nextloc > 0L; n++) {        /* initialize each section */ | 
| 516 | < | lseek(fd, (off_t)nextloc, 0); | 
| 516 | > | lseek(fd, (off_t)nextloc, SEEK_SET); | 
| 517 |  | read(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 518 |  | hdinit(fd, NULL); | 
| 519 |  | } | 
| 534 |  | while (pl != NULL) { | 
| 535 |  | p = pl; pl = p->next; p->next = NULL; | 
| 536 |  | if (p->nr > 0) {                /* add to holodeck */ | 
| 537 | < | bcopy((void *)p->ra, | 
| 538 | < | (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr), | 
| 537 | > | memcpy( (void *)hdnewrays(hdlist[p->hd],p->bi,p->nr), | 
| 538 | > | (void *)p->ra, | 
| 539 |  | p->nr*sizeof(RAYVAL)); | 
| 540 |  | if (outdev != NULL)     /* display it */ | 
| 541 |  | disp_packet((PACKHEAD *)p); | 
| 563 |  | { | 
| 564 |  | char    *tp, *dp; | 
| 565 |  |  | 
| 566 | < | for (tp = NULL, dp = rn; *rn = *fn++; rn++) | 
| 566 | > | for (tp = NULL, dp = rn; (*rn = *fn++); rn++) { | 
| 567 |  | if (*rn == '/') | 
| 568 |  | dp = rn; | 
| 569 |  | else if (*rn == '.') | 
| 570 |  | tp = rn; | 
| 571 | + | } | 
| 572 |  | if (tp != NULL && tp > dp) | 
| 573 |  | *tp = '\0'; | 
| 574 |  | } | 
| 611 |  | if (hdlist[0] != NULL) {        /* close holodeck */ | 
| 612 |  | if (nprocs > 0) | 
| 613 |  | status = done_rtrace();         /* calls hdsync() */ | 
| 614 | < | if (ncprocs > 0 & force >= 0 && vdef(REPORT)) { | 
| 615 | < | long    fsiz, fuse; | 
| 614 | > | if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) { | 
| 615 | > | off_t   fsiz, fuse; | 
| 616 |  | fsiz = hdfilen(hdlist[0]->fd); | 
| 617 |  | fuse = hdfiluse(hdlist[0]->fd, 1); | 
| 618 |  | fprintf(stderr, |