| 5 |  | * Radiance holodeck generation controller | 
| 6 |  | */ | 
| 7 |  |  | 
| 8 | + | #include <stdio.h> | 
| 9 | + | #include <time.h> | 
| 10 |  | #include <signal.h> | 
| 11 |  | #include <sys/stat.h> | 
| 12 |  | #include <string.h> | 
| 13 |  |  | 
| 14 | + | #include "platform.h" | 
| 15 | + | #include "rterror.h" | 
| 16 | + | #include "resolu.h" | 
| 17 |  | #include "rholo.h" | 
| 18 |  | #include "random.h" | 
| 19 |  |  | 
| 69 |  |  | 
| 70 |  | extern int      nowarn;         /* turn warnings off? */ | 
| 71 |  |  | 
| 72 | < | extern time_t   time(); | 
| 72 | > | static void onsig(int  signo); | 
| 73 | > | static void sigdie(int  signo, char  *msg); | 
| 74 | > | static int resfmode(int fd, int mod); | 
| 75 | > | static void initrholo(void); | 
| 76 | > | static int rholo(void); | 
| 77 | > | static void setdefaults(HDGRID  *gp); | 
| 78 | > | static void creatholo(HDGRID    *gp); | 
| 79 | > | static int headline(char        *s); | 
| 80 | > | static void loadholo(void); | 
| 81 | > | static void rootname(char       *rn, char       *fn); | 
| 82 | > | static void badvalue(int        vc); | 
| 83 |  |  | 
| 84 |  |  | 
| 85 | < | main(argc, argv) | 
| 86 | < | int     argc; | 
| 87 | < | char    *argv[]; | 
| 85 | > | int | 
| 86 | > | main( | 
| 87 | > | int     argc, | 
| 88 | > | char    *argv[] | 
| 89 | > | ) | 
| 90 |  | { | 
| 91 |  | int     i; | 
| 92 |  |  | 
| 168 |  | "Usage: %s [-n nprocs][-o disp][-w][-r|-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", | 
| 169 |  | progname); | 
| 170 |  | quit(1); | 
| 171 | + | return 1; /* pro forma return */ | 
| 172 |  | } | 
| 173 |  |  | 
| 174 |  |  | 
| 175 | < | void | 
| 176 | < | onsig(signo)                            /* fatal signal */ | 
| 177 | < | int  signo; | 
| 175 | > | static void | 
| 176 | > | onsig(                          /* fatal signal */ | 
| 177 | > | int  signo | 
| 178 | > | ) | 
| 179 |  | { | 
| 180 |  | static int  gotsig = 0; | 
| 181 |  |  | 
| 193 |  | } | 
| 194 |  |  | 
| 195 |  |  | 
| 196 | < | sigdie(signo, msg)                      /* set fatal signal */ | 
| 197 | < | int  signo; | 
| 198 | < | char  *msg; | 
| 196 | > | static void | 
| 197 | > | sigdie(                 /* set fatal signal */ | 
| 198 | > | int  signo, | 
| 199 | > | char  *msg | 
| 200 | > | ) | 
| 201 |  | { | 
| 202 |  | if (signal(signo, onsig) == SIG_IGN) | 
| 203 |  | signal(signo, SIG_IGN); | 
| 205 |  | } | 
| 206 |  |  | 
| 207 |  |  | 
| 208 | < | int | 
| 209 | < | resfmode(fd, mod)               /* restrict open file access mode */ | 
| 210 | < | int     fd, mod; | 
| 208 | > | static int | 
| 209 | > | resfmode(               /* restrict open file access mode */ | 
| 210 | > | int     fd, | 
| 211 | > | int     mod | 
| 212 | > | ) | 
| 213 |  | { | 
| 214 |  | struct stat     stbuf; | 
| 215 |  | /* get original mode */ | 
| 227 |  | } | 
| 228 |  |  | 
| 229 |  |  | 
| 230 | < | initrholo()                     /* get our holodeck running */ | 
| 230 | > | static void | 
| 231 | > | initrholo(void)                 /* get our holodeck running */ | 
| 232 |  | { | 
| 233 |  | extern int      global_packet(); | 
| 234 |  | register int    i; | 
| 293 |  | } | 
| 294 |  | /* set up signal handling */ | 
| 295 |  | sigdie(SIGINT, "Interrupt"); | 
| 272 | – | sigdie(SIGHUP, "Hangup"); | 
| 296 |  | sigdie(SIGTERM, "Terminate"); | 
| 297 | + | #ifdef SIGHUP | 
| 298 | + | sigdie(SIGHUP, "Hangup"); | 
| 299 | + | #endif | 
| 300 | + | #ifdef SIGPIPE | 
| 301 |  | sigdie(SIGPIPE, "Broken pipe"); | 
| 302 | + | #endif | 
| 303 | + | #ifdef SIGALRM | 
| 304 |  | sigdie(SIGALRM, "Alarm clock"); | 
| 305 | + | #endif | 
| 306 |  | #ifdef  SIGXCPU | 
| 307 |  | sigdie(SIGXCPU, "CPU limit exceeded"); | 
| 308 | + | #endif | 
| 309 | + | #ifdef  SIGXFSZ | 
| 310 |  | sigdie(SIGXFSZ, "File size exceeded"); | 
| 311 |  | #endif | 
| 312 |  | /* protect holodeck file */ | 
| 313 | < | orig_mode = resfmode(hdlist[0]->fd, ncprocs>0&force>=0 ? 0 : 0444); | 
| 313 | > | orig_mode = resfmode(hdlist[0]->fd, (ncprocs>0) & (force>=0) ? 0 : 0444); | 
| 314 |  | return; | 
| 315 |  | memerr: | 
| 316 |  | error(SYSTEM, "out of memory in initrholo"); | 
| 317 |  | } | 
| 318 |  |  | 
| 319 |  |  | 
| 320 | < | rholo()                         /* holodeck main loop */ | 
| 320 | > | static int | 
| 321 | > | rholo(void)                             /* holodeck main loop */ | 
| 322 |  | { | 
| 323 |  | static long     nextfragwarn = 100*(1L<<20); | 
| 324 |  | static int      idle = 0; | 
| 387 |  | } | 
| 388 |  |  | 
| 389 |  |  | 
| 390 | < | setdefaults(gp)                 /* set default values */ | 
| 391 | < | register HDGRID *gp; | 
| 390 | > | static void | 
| 391 | > | setdefaults(                    /* set default values */ | 
| 392 | > | register HDGRID *gp | 
| 393 | > | ) | 
| 394 |  | { | 
| 395 |  | extern char     *atos(); | 
| 396 |  | register int    i; | 
| 397 |  | int     n; | 
| 398 |  | double  len[3], d; | 
| 364 | – | char    buf[64]; | 
| 399 |  |  | 
| 400 |  | if (!vdef(SECTION)) { | 
| 401 |  | sprintf(errmsg, "%s must be defined", vnam(SECTION)); | 
| 445 |  | } | 
| 446 |  |  | 
| 447 |  |  | 
| 448 | < | creatholo(gp)                   /* create a holodeck output file */ | 
| 449 | < | HDGRID  *gp; | 
| 448 | > | static void | 
| 449 | > | creatholo(                      /* create a holodeck output file */ | 
| 450 | > | HDGRID  *gp | 
| 451 | > | ) | 
| 452 |  | { | 
| 453 |  | extern char     VersionID[]; | 
| 454 |  | int32   lastloc, nextloc; | 
| 469 |  | putw(HOLOMAGIC, fp);            /* put magic number */ | 
| 470 |  | fd = dup(fileno(fp)); | 
| 471 |  | fclose(fp);                     /* flush and close stdio stream */ | 
| 472 | < | lastloc = lseek(fd, (off_t)0, 2); | 
| 472 | > | lastloc = lseek(fd, (off_t)0, SEEK_END); | 
| 473 |  | for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */ | 
| 474 |  | nextloc = 0L; | 
| 475 |  | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 477 |  | if (!n) | 
| 478 |  | break; | 
| 479 |  | nextloc = hdfilen(fd);          /* write section pointer */ | 
| 480 | < | if (lseek(fd, (off_t)lastloc, 0) < 0) | 
| 480 | > | if (lseek(fd, (off_t)lastloc, SEEK_SET) < 0) | 
| 481 |  | error(SYSTEM, | 
| 482 |  | "cannot seek on holodeck file in creatholo"); | 
| 483 |  | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 484 | < | lseek(fd, (off_t)(lastloc=nextloc), 0); | 
| 484 | > | lseek(fd, (off_t)(lastloc=nextloc), SEEK_SET); | 
| 485 |  | } | 
| 486 |  | } | 
| 487 |  |  | 
| 488 |  |  | 
| 489 | < | int | 
| 490 | < | headline(s)                     /* process information header line */ | 
| 491 | < | char    *s; | 
| 489 | > | static int | 
| 490 | > | headline(                       /* process information header line */ | 
| 491 | > | char    *s | 
| 492 | > | ) | 
| 493 |  | { | 
| 494 |  | extern char     FMTSTR[]; | 
| 495 |  | register char   *cp; | 
| 513 |  | } | 
| 514 |  |  | 
| 515 |  |  | 
| 516 | < | loadholo()                      /* start loading a holodeck from fname */ | 
| 516 | > | static void | 
| 517 | > | loadholo(void)                  /* start loading a holodeck from fname */ | 
| 518 |  | { | 
| 519 |  | FILE    *fp; | 
| 520 |  | int     fd; | 
| 521 |  | int     n; | 
| 522 |  | int32   nextloc; | 
| 523 |  |  | 
| 524 | < | if (ncprocs > 0 & force >= 0) | 
| 524 | > | if ((ncprocs > 0) & (force >= 0)) | 
| 525 |  | fp = fopen(hdkfile, "r+"); | 
| 526 |  | else | 
| 527 |  | fp = NULL; | 
| 550 |  | fd = dup(fileno(fp)); | 
| 551 |  | fclose(fp);                             /* done with stdio */ | 
| 552 |  | for (n = 0; nextloc > 0L; n++) {        /* initialize each section */ | 
| 553 | < | lseek(fd, (off_t)nextloc, 0); | 
| 553 | > | lseek(fd, (off_t)nextloc, SEEK_SET); | 
| 554 |  | read(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 555 |  | hdinit(fd, NULL); | 
| 556 |  | } | 
| 562 |  | } | 
| 563 |  |  | 
| 564 |  |  | 
| 565 | < | done_packets(pl)                /* handle finished packets */ | 
| 566 | < | PACKET  *pl; | 
| 565 | > | extern void | 
| 566 | > | done_packets(           /* handle finished packets */ | 
| 567 | > | PACKET  *pl | 
| 568 | > | ) | 
| 569 |  | { | 
| 570 |  | static int      n2flush = 0; | 
| 571 |  | register PACKET *p; | 
| 597 |  | } | 
| 598 |  |  | 
| 599 |  |  | 
| 600 | < | rootname(rn, fn)                /* remove tail from end of fn */ | 
| 601 | < | register char   *rn, *fn; | 
| 600 | > | static void | 
| 601 | > | rootname(               /* remove tail from end of fn */ | 
| 602 | > | register char   *rn, | 
| 603 | > | register char   *fn | 
| 604 | > | ) | 
| 605 |  | { | 
| 606 |  | char    *tp, *dp; | 
| 607 |  |  | 
| 608 | < | for (tp = NULL, dp = rn; *rn = *fn++; rn++) | 
| 608 | > | for (tp = NULL, dp = rn; (*rn = *fn++); rn++) { | 
| 609 |  | if (*rn == '/') | 
| 610 |  | dp = rn; | 
| 611 |  | else if (*rn == '.') | 
| 612 |  | tp = rn; | 
| 613 | + | } | 
| 614 |  | if (tp != NULL && tp > dp) | 
| 615 |  | *tp = '\0'; | 
| 616 |  | } | 
| 617 |  |  | 
| 618 |  |  | 
| 619 | < | badvalue(vc)                    /* report bad variable value and exit */ | 
| 620 | < | int     vc; | 
| 619 | > | static void | 
| 620 | > | badvalue(                       /* report bad variable value and exit */ | 
| 621 | > | int     vc | 
| 622 | > | ) | 
| 623 |  | { | 
| 624 |  | sprintf(errmsg, "bad value for variable '%s'", vnam(vc)); | 
| 625 |  | error(USER, errmsg); | 
| 655 |  | if (hdlist[0] != NULL) {        /* close holodeck */ | 
| 656 |  | if (nprocs > 0) | 
| 657 |  | status = done_rtrace();         /* calls hdsync() */ | 
| 658 | < | if (ncprocs > 0 & force >= 0 && vdef(REPORT)) { | 
| 658 | > | if ((ncprocs > 0) & (force >= 0) && vdef(REPORT)) { | 
| 659 |  | off_t   fsiz, fuse; | 
| 660 |  | fsiz = hdfilen(hdlist[0]->fd); | 
| 661 |  | fuse = hdfiluse(hdlist[0]->fd, 1); |