| 10 |  |  | 
| 11 |  | #include "rholo.h" | 
| 12 |  | #include "random.h" | 
| 13 | – | #include "paths.h" | 
| 13 |  | #include <signal.h> | 
| 14 |  | #include <sys/types.h> | 
| 15 |  | #include <sys/stat.h> | 
| 16 |  |  | 
| 17 | + | #ifndef MAXQTIME | 
| 18 | + | #define MAXQTIME        5               /* target maximum seconds in queue */ | 
| 19 | + | #endif | 
| 20 |  | /* the following must be consistent with rholo.h */ | 
| 21 |  | int     NVARS = NRHVARS;                /* total number of variables */ | 
| 22 |  |  | 
| 24 |  |  | 
| 25 |  | char    *progname;              /* our program name */ | 
| 26 |  | char    *hdkfile;               /* holodeck file name */ | 
| 27 | < | char    froot[MAXPATH];         /* root file name */ | 
| 27 | > | char    froot[256];             /* root file name */ | 
| 28 |  |  | 
| 29 |  | int     nowarn = 0;             /* turn warnings off? */ | 
| 30 |  |  | 
| 51 |  | long    npacksdone = 0L;        /* number of packets done */ | 
| 52 |  |  | 
| 53 |  | PACKET  *freepacks;             /* available packets */ | 
| 54 | + | int     avgqlen;                /* average queue length when full */ | 
| 55 |  |  | 
| 56 |  | char  *sigerr[NSIG];            /* signal error messages */ | 
| 57 |  |  | 
| 62 |  | int     argc; | 
| 63 |  | char    *argv[]; | 
| 64 |  | { | 
| 62 | – | HDGRID  hdg; | 
| 65 |  | int     i; | 
| 66 | < | /* mark start time */ | 
| 65 | < | starttime = time(NULL); | 
| 66 | > |  | 
| 67 |  | initurand(16384);                       /* initialize urand */ | 
| 68 |  | progname = argv[0];                     /* get arguments */ | 
| 69 |  | for (i = 1; i < argc && argv[i][0] == '-'; i++) | 
| 90 |  | default: | 
| 91 |  | goto userr; | 
| 92 |  | } | 
| 92 | – | /* do we have a job? */ | 
| 93 | – | if (outdev == NULL && ncprocs <= 0) | 
| 94 | – | goto userr; | 
| 93 |  | /* get root file name */ | 
| 94 | + | if (i >= argc) | 
| 95 | + | goto userr; | 
| 96 |  | rootname(froot, hdkfile=argv[i++]); | 
| 97 | < | /* load... */ | 
| 98 | < | if (i < argc) {                         /* variables */ | 
| 99 | < | loadvars(argv[i++]); | 
| 100 | < | /* cmdline settings */ | 
| 101 | < | for ( ; i < argc; i++) | 
| 102 | < | if (setvariable(argv[i], matchvar) < 0) { | 
| 103 | < | sprintf(errmsg, "unknown variable: %s", | 
| 104 | < | argv[i]); | 
| 105 | < | error(USER, errmsg); | 
| 106 | < | } | 
| 107 | < | /* check settings */ | 
| 108 | < | checkvalues(); | 
| 109 | < | /* load RIF if any */ | 
| 110 | < | if (vdef(RIF)) | 
| 111 | < | getradfile(vval(RIF)); | 
| 97 | > | /* load variables? */ | 
| 98 | > | if (i < argc) | 
| 99 | > | if (argv[i][0] != '-' && argv[i][0] != '+') | 
| 100 | > | loadvars(argv[i]);      /* load variables from file */ | 
| 101 | > |  | 
| 102 | > | if (i >= argc || argv[i][0] == '+') | 
| 103 | > | loadholo();                     /* load existing holodeck */ | 
| 104 | > |  | 
| 105 | > | while (++i < argc)                      /* get command line settings */ | 
| 106 | > | if (setvariable(argv[i], matchvar) < 0) { | 
| 107 | > | sprintf(errmsg, "unknown variable: %s", argv[i]); | 
| 108 | > | error(USER, errmsg); | 
| 109 | > | } | 
| 110 | > | /* check settings */ | 
| 111 | > | checkvalues(); | 
| 112 | > | /* load RIF if rtrace */ | 
| 113 | > | if (ncprocs) | 
| 114 | > | getradfile(); | 
| 115 | > |  | 
| 116 | > | if (hdlist[0] == NULL) {                /* create new holodeck */ | 
| 117 | > | HDGRID  hdg[HDMAX]; | 
| 118 |  | /* set defaults */ | 
| 119 | < | setdefaults(&hdg); | 
| 119 | > | setdefaults(hdg); | 
| 120 |  | /* holodeck exists? */ | 
| 121 |  | if (!force && access(hdkfile, R_OK|W_OK) == 0) | 
| 122 |  | error(USER, | 
| 123 |  | "holodeck file exists -- use -f to overwrite"); | 
| 124 |  | /* create holodeck */ | 
| 125 | < | creatholo(&hdg); | 
| 126 | < | } else {                                /* else load holodeck */ | 
| 121 | < | loadholo(); | 
| 122 | < | /* check settings */ | 
| 123 | < | checkvalues(); | 
| 124 | < | /* load RIF if any */ | 
| 125 | < | if (vdef(RIF)) | 
| 126 | < | getradfile(vval(RIF)); | 
| 127 | < | /* set defaults */ | 
| 125 | > | creatholo(hdg); | 
| 126 | > | } else                                  /* else just set defaults */ | 
| 127 |  | setdefaults(NULL); | 
| 129 | – | } | 
| 128 |  | /* initialize */ | 
| 129 |  | initrholo(); | 
| 130 |  | /* main loop */ | 
| 134 |  | quit(0); | 
| 135 |  | userr: | 
| 136 |  | fprintf(stderr, | 
| 137 | < | "Usage: %s {-n nprocs|-o disp} [-w][-f] output.hdk [control.hif [VAR=val ..]]\n", | 
| 137 | > | "Usage: %s [-n nprocs][-o disp][-w][-f] output.hdk [control.hif|+|- [VAR=val ..]]\n", | 
| 138 |  | progname); | 
| 139 |  | quit(1); | 
| 140 |  | } | 
| 148 |  | if (gotsig++)                   /* two signals and we're gone! */ | 
| 149 |  | _exit(signo); | 
| 150 |  |  | 
| 151 | < | alarm(30);                      /* allow 30 seconds to clean up */ | 
| 151 | > | alarm(60);                      /* allow 60 seconds to clean up */ | 
| 152 |  | signal(SIGALRM, SIG_DFL);       /* make certain we do die */ | 
| 153 |  | eputs("signal - "); | 
| 154 |  | eputs(sigerr[signo]); | 
| 203 |  | maxdisk = 0; | 
| 204 |  | else | 
| 205 |  | maxdisk = 1024.*1024.*vflt(DISKSPACE); | 
| 208 | – | /* record end time */ | 
| 209 | – | if (!vdef(TIME) || vflt(TIME) <= FTINY) | 
| 210 | – | endtime = 0; | 
| 211 | – | else | 
| 212 | – | endtime = starttime + vflt(TIME)*3600.; | 
| 206 |  | /* set up memory cache */ | 
| 207 |  | if (outdev == NULL) | 
| 208 |  | hdcachesize = 0;        /* manual flushing */ | 
| 214 |  | if (*s && freopen(s, "a", stderr) == NULL) | 
| 215 |  | quit(2); | 
| 216 |  | } | 
| 217 | + | /* mark the starting time */ | 
| 218 | + | starttime = time(NULL); | 
| 219 | + | /* compute end time */ | 
| 220 | + | if (!vdef(TIME) || vflt(TIME) <= FTINY) | 
| 221 | + | endtime = 0; | 
| 222 | + | else | 
| 223 | + | endtime = starttime + vflt(TIME)*3600. + .5; | 
| 224 |  | /* start rtrace */ | 
| 225 |  | if (ncprocs > 0) { | 
| 226 |  | i = start_rtrace(); | 
| 234 |  | freepacks = (PACKET *)bmalloc(i*sizeof(PACKET)); | 
| 235 |  | if (freepacks == NULL) | 
| 236 |  | goto memerr; | 
| 237 | + | if (!(avgqlen = i/nprocs))      /* record mean queue length */ | 
| 238 | + | avgqlen = 1; | 
| 239 |  | freepacks[--i].nr = 0; | 
| 240 |  | freepacks[i].next = NULL; | 
| 241 | < | if (!vbool(OBSTRUCTIONS)) { | 
| 241 | > | if (!vdef(OBSTRUCTIONS) || !vbool(OBSTRUCTIONS)) { | 
| 242 |  | freepacks[i].offset = (float *)bmalloc( | 
| 243 |  | RPACKSIZ*sizeof(float)*(i+1) ); | 
| 244 |  | if (freepacks[i].offset == NULL) | 
| 272 |  |  | 
| 273 |  | rholo()                         /* holodeck main loop */ | 
| 274 |  | { | 
| 275 | < | static int      idle = 1; | 
| 275 | > | static int      idle = 0; | 
| 276 |  | PACKET  *pl = NULL, *plend; | 
| 277 | + | int     pksiz; | 
| 278 |  | register PACKET *p; | 
| 279 |  | time_t  t; | 
| 280 | < | long    l; | 
| 278 | < |  | 
| 279 | < | if (outdev != NULL)             /* check display */ | 
| 280 | < | if (!disp_check(idle)) | 
| 281 | < | return(0); | 
| 282 | < | /* display only? */ | 
| 280 | > | /* check display */ | 
| 281 |  | if (nprocs <= 0) | 
| 282 | < | return(outdev != NULL); | 
| 282 | > | idle = 1; | 
| 283 | > | if (outdev != NULL) { | 
| 284 | > | if (!disp_check(idle)) | 
| 285 | > | return(0);      /* quit request */ | 
| 286 | > | if (nprocs <= 0) | 
| 287 | > | return(1); | 
| 288 | > | } else if (idle) | 
| 289 | > | return(0);              /* all done */ | 
| 290 |  | /* check file size */ | 
| 291 |  | if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { | 
| 292 |  | error(WARNING, "file limit exceeded"); | 
| 293 |  | done_rtrace(); | 
| 289 | – | idle = 1; | 
| 294 |  | return(1);      /* comes back */ | 
| 295 |  | } | 
| 296 | < | /* check time */ | 
| 293 | < | if (endtime > 0 || reporttime > 0) | 
| 294 | < | t = time(NULL); | 
| 296 | > | t = time(NULL);                 /* check time */ | 
| 297 |  | if (endtime > 0 && t >= endtime) { | 
| 298 |  | error(WARNING, "time limit exceeded"); | 
| 299 |  | done_rtrace(); | 
| 298 | – | idle = 1; | 
| 300 |  | return(1);      /* comes back */ | 
| 301 |  | } | 
| 302 |  | if (reporttime > 0 && t >= reporttime) | 
| 303 |  | report(t); | 
| 304 | < | /* get packets to process */ | 
| 304 | > | /* figure out good packet size */ | 
| 305 | > | #if MAXQTIME | 
| 306 | > | pksiz = nraysdone*MAXQTIME/(avgqlen*(t - starttime + 1L)); | 
| 307 | > | if (pksiz < 1) | 
| 308 | > | pksiz = 1; | 
| 309 | > | else if (pksiz > RPACKSIZ) | 
| 310 | > | #endif | 
| 311 | > | pksiz = RPACKSIZ; | 
| 312 | > | idle = 0;                       /* get packets to process */ | 
| 313 |  | while (freepacks != NULL) { | 
| 314 |  | p = freepacks; freepacks = p->next; p->next = NULL; | 
| 315 | < | if (!next_packet(p)) { | 
| 315 | > | if (!next_packet(p, pksiz)) { | 
| 316 |  | p->next = freepacks; freepacks = p; | 
| 317 |  | idle = 1; | 
| 318 |  | break; | 
| 327 |  | } | 
| 328 |  |  | 
| 329 |  |  | 
| 321 | – | report(t)                       /* report progress so far */ | 
| 322 | – | time_t  t; | 
| 323 | – | { | 
| 324 | – | static time_t   seconds2go = 1000000; | 
| 325 | – |  | 
| 326 | – | if (t == 0L) | 
| 327 | – | t = time(NULL); | 
| 328 | – | sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n", | 
| 329 | – | npacksdone, nraysdone, (t-starttime)/3600.); | 
| 330 | – | eputs(errmsg); | 
| 331 | – | if (seconds2go == 1000000) | 
| 332 | – | seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L; | 
| 333 | – | if (seconds2go) | 
| 334 | – | reporttime = t + seconds2go; | 
| 335 | – | } | 
| 336 | – |  | 
| 337 | – |  | 
| 330 |  | setdefaults(gp)                 /* set default values */ | 
| 331 |  | register HDGRID *gp; | 
| 332 |  | { | 
| 333 |  | extern char     *atos(); | 
| 334 |  | register int    i; | 
| 335 | + | int     n; | 
| 336 |  | double  len[3], maxlen, d; | 
| 337 |  | char    buf[64]; | 
| 338 |  |  | 
| 340 |  | sprintf(errmsg, "%s must be defined", vnam(SECTION)); | 
| 341 |  | error(USER, errmsg); | 
| 342 |  | } | 
| 350 | – | if (vdef(SECTION) > 1) { | 
| 351 | – | sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); | 
| 352 | – | error(WARNING, errmsg); | 
| 353 | – | } | 
| 343 |  | if (!vdef(OCTREE)) { | 
| 344 |  | if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) | 
| 345 |  | error(SYSTEM, "out of memory"); | 
| 346 |  | sprintf(vval(OCTREE), "%s.oct", froot); | 
| 347 |  | vdef(OCTREE)++; | 
| 348 |  | } | 
| 360 | – | if (!vdef(OBSTRUCTIONS)) { | 
| 361 | – | vval(OBSTRUCTIONS) = "T"; | 
| 362 | – | vdef(OBSTRUCTIONS)++; | 
| 363 | – | } | 
| 349 |  | if (!vdef(VDIST)) { | 
| 350 |  | vval(VDIST) = "F"; | 
| 351 |  | vdef(VDIST)++; | 
| 352 |  | } | 
| 368 | – | if (!vdef(OCCUPANCY)) { | 
| 369 | – | vval(OCCUPANCY) = "U"; | 
| 370 | – | vdef(OCCUPANCY)++; | 
| 371 | – | } | 
| 353 |  | /* append rendering options */ | 
| 354 |  | if (vdef(RENDER)) | 
| 355 |  | rtargc += wordstring(rtargv+rtargc, vval(RENDER)); | 
| 357 |  | if (gp == NULL)         /* already initialized? */ | 
| 358 |  | return; | 
| 359 |  | /* set grid parameters */ | 
| 360 | < | gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; | 
| 361 | < | if (sscanf(vval(SECTION), | 
| 360 | > | for (n = 0; n < vdef(SECTION); n++, gp++) { | 
| 361 | > | gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; | 
| 362 | > | if (sscanf(nvalue(SECTION, n), | 
| 363 |  | "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", | 
| 364 | < | &gp->orig[0], &gp->orig[1], &gp->orig[2], | 
| 365 | < | &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], | 
| 366 | < | &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], | 
| 367 | < | &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], | 
| 368 | < | &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) | 
| 369 | < | badvalue(SECTION); | 
| 370 | < | maxlen = 0.; | 
| 371 | < | for (i = 0; i < 3; i++) | 
| 372 | < | if ((len[i] = VLEN(gp->xv[i])) > maxlen) | 
| 373 | < | maxlen = len[i]; | 
| 374 | < | if (!vdef(GRID)) { | 
| 375 | < | sprintf(buf, "%.4f", maxlen/8.); | 
| 376 | < | vval(GRID) = savqstr(buf); | 
| 377 | < | vdef(GRID)++; | 
| 364 | > | &gp->orig[0], &gp->orig[1], &gp->orig[2], | 
| 365 | > | &gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], | 
| 366 | > | &gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], | 
| 367 | > | &gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], | 
| 368 | > | &gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) | 
| 369 | > | badvalue(SECTION); | 
| 370 | > | maxlen = 0.; | 
| 371 | > | for (i = 0; i < 3; i++) | 
| 372 | > | if ((len[i] = VLEN(gp->xv[i])) > maxlen) | 
| 373 | > | maxlen = len[i]; | 
| 374 | > | if (!vdef(GRID)) | 
| 375 | > | d = 0.125*maxlen; | 
| 376 | > | else if ((d = vflt(GRID)) <= FTINY) | 
| 377 | > | badvalue(GRID); | 
| 378 | > | for (i = 0; i < 3; i++) | 
| 379 | > | if (gp->grid[i] <= 0) | 
| 380 | > | gp->grid[i] = len[i]/d + (1.-FTINY); | 
| 381 |  | } | 
| 397 | – | if ((d = vflt(GRID)) <= FTINY) | 
| 398 | – | badvalue(GRID); | 
| 399 | – | for (i = 0; i < 3; i++) | 
| 400 | – | if (gp->grid[i] <= 0) | 
| 401 | – | gp->grid[i] = len[i]/d + (1.-FTINY); | 
| 382 |  | } | 
| 383 |  |  | 
| 384 |  |  | 
| 386 |  | HDGRID  *gp; | 
| 387 |  | { | 
| 388 |  | extern char     VersionID[]; | 
| 389 | < | long    endloc = 0; | 
| 389 | > | int4    lastloc, nextloc; | 
| 390 | > | int     n; | 
| 391 |  | int     fd; | 
| 392 |  | FILE    *fp; | 
| 393 |  | /* open & truncate file */ | 
| 401 |  | printvars(fp); | 
| 402 |  | fputformat(HOLOFMT, fp); | 
| 403 |  | fputc('\n', fp); | 
| 404 | < | putw(HOLOMAGIC, fp);            /* put magic number & terminus */ | 
| 424 | < | fwrite(&endloc, sizeof(long), 1, fp); | 
| 404 | > | putw(HOLOMAGIC, fp);            /* put magic number */ | 
| 405 |  | fd = dup(fileno(fp)); | 
| 406 |  | fclose(fp);                     /* flush and close stdio stream */ | 
| 407 | < | hdinit(fd, gp);                 /* allocate and initialize index */ | 
| 407 | > | lastloc = lseek(fd, 0L, 2); | 
| 408 | > | for (n = vdef(SECTION); n--; gp++) {    /* initialize each section */ | 
| 409 | > | nextloc = 0L; | 
| 410 | > | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 411 | > | hdinit(fd, gp);                 /* writes beam index */ | 
| 412 | > | if (!n) | 
| 413 | > | break; | 
| 414 | > | nextloc = hdfilen(fd);          /* write section pointer */ | 
| 415 | > | if (lseek(fd, (long)lastloc, 0) < 0) | 
| 416 | > | error(SYSTEM, | 
| 417 | > | "cannot seek on holodeck file in creatholo"); | 
| 418 | > | write(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 419 | > | lseek(fd, (long)(lastloc=nextloc), 0); | 
| 420 | > | } | 
| 421 |  | } | 
| 422 |  |  | 
| 423 |  |  | 
| 450 |  | extern long     ftell(); | 
| 451 |  | FILE    *fp; | 
| 452 |  | int     fd; | 
| 453 | < | long    fpos; | 
| 453 | > | int     n; | 
| 454 | > | int4    nextloc; | 
| 455 |  | /* open holodeck file */ | 
| 456 |  | if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { | 
| 457 |  | sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, | 
| 466 |  | hdkfile); | 
| 467 |  | error(USER, errmsg); | 
| 468 |  | } | 
| 469 | < | fread(&fpos, sizeof(long), 1, fp); | 
| 476 | < | if (fpos != 0) | 
| 477 | < | error(WARNING, "ignoring multiple sections in holodeck file"); | 
| 478 | < | fpos = ftell(fp);                       /* get stdio position */ | 
| 469 | > | nextloc = ftell(fp);                    /* get stdio position */ | 
| 470 |  | fd = dup(fileno(fp)); | 
| 471 |  | fclose(fp);                             /* done with stdio */ | 
| 472 | < | lseek(fd, fpos, 0);                     /* align system file pointer */ | 
| 473 | < | hdinit(fd, NULL);                       /* allocate and load index */ | 
| 472 | > | for (n = 0; nextloc > 0L; n++) {        /* initialize each section */ | 
| 473 | > | lseek(fd, (long)nextloc, 0); | 
| 474 | > | read(fd, (char *)&nextloc, sizeof(nextloc)); | 
| 475 | > | hdinit(fd, NULL); | 
| 476 | > | } | 
| 477 | > | if (n != vdef(SECTION)) { | 
| 478 | > | sprintf(errmsg, "number of sections does not match %s setting", | 
| 479 | > | vnam(SECTION)); | 
| 480 | > | error(WARNING, errmsg); | 
| 481 | > | } | 
| 482 |  | } | 
| 483 |  |  | 
| 484 |  |  | 
| 497 |  | if (outdev != NULL)     /* display it */ | 
| 498 |  | disp_packet((PACKHEAD *)p); | 
| 499 |  | if (hdcachesize <= 0)   /* manual flushing */ | 
| 500 | < | n2flush += p->nr; | 
| 500 | > | n2flush++; | 
| 501 |  | nraysdone += p->nr; | 
| 502 |  | npacksdone++; | 
| 503 | + | p->nr = 0; | 
| 504 |  | } | 
| 505 | < | p->nr = 0;                      /* push onto free list */ | 
| 506 | < | p->next = freepacks; | 
| 505 | > | p->next = freepacks;            /* push onto free list */ | 
| 506 |  | freepacks = p; | 
| 507 |  | } | 
| 508 | < | if (n2flush > 512*RPACKSIZ*nprocs) { | 
| 508 | > | if (n2flush > 300/MAXQTIME*avgqlen*nprocs) { | 
| 509 |  | hdflush(NULL);                  /* flush holodeck buffers */ | 
| 510 |  | n2flush = 0; | 
| 511 |  | } | 
| 512 |  | } | 
| 513 |  |  | 
| 514 |  |  | 
| 516 | – | int | 
| 517 | – | done_rtrace()                   /* clean up and close rtrace calculation */ | 
| 518 | – | { | 
| 519 | – | int     status; | 
| 520 | – | /* already closed? */ | 
| 521 | – | if (!nprocs) | 
| 522 | – | return; | 
| 523 | – | /* report activity */ | 
| 524 | – | wputs("closing rtrace process...\n"); | 
| 525 | – | /* flush beam queue */ | 
| 526 | – | done_packets(flush_queue()); | 
| 527 | – | /* close rtrace */ | 
| 528 | – | if ((status = end_rtrace())) | 
| 529 | – | error(WARNING, "bad exit status from rtrace"); | 
| 530 | – | if (vdef(REPORT))               /* report time */ | 
| 531 | – | report(0); | 
| 532 | – | return(status);                 /* return status */ | 
| 533 | – | } | 
| 534 | – |  | 
| 535 | – |  | 
| 536 | – | new_rtrace()                    /* restart rtrace calculation */ | 
| 537 | – | { | 
| 538 | – | char    combuf[128]; | 
| 539 | – |  | 
| 540 | – | if (nprocs > 0)                 /* already running? */ | 
| 541 | – | return; | 
| 542 | – | wputs("restarting rtrace process...\n"); | 
| 543 | – | if (vdef(RIF)) {                /* rerun rad to update octree */ | 
| 544 | – | sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); | 
| 545 | – | if (system(combuf)) | 
| 546 | – | error(WARNING, "error running rad"); | 
| 547 | – | } | 
| 548 | – | if (start_rtrace() < 1)         /* start rtrace */ | 
| 549 | – | error(WARNING, "cannot restart rtrace"); | 
| 550 | – | else if (vdef(REPORT)) | 
| 551 | – | report(0); | 
| 552 | – | } | 
| 553 | – |  | 
| 554 | – |  | 
| 555 | – | getradfile(rfargs)              /* run rad and get needed variables */ | 
| 556 | – | char    *rfargs; | 
| 557 | – | { | 
| 558 | – | static short    mvar[] = {OCTREE,-1}; | 
| 559 | – | static char     tf1[] = TEMPLATE; | 
| 560 | – | char    tf2[64]; | 
| 561 | – | char    combuf[256]; | 
| 562 | – | char    *pippt; | 
| 563 | – | register int    i; | 
| 564 | – | register char   *cp; | 
| 565 | – | /* create rad command */ | 
| 566 | – | mktemp(tf1); | 
| 567 | – | sprintf(tf2, "%s.rif", tf1); | 
| 568 | – | sprintf(combuf, | 
| 569 | – | "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", | 
| 570 | – | rfargs, tf1); | 
| 571 | – | cp = combuf; | 
| 572 | – | while (*cp){ | 
| 573 | – | if (*cp == '|') pippt = cp; | 
| 574 | – | cp++; | 
| 575 | – | }                               /* match unset variables */ | 
| 576 | – | for (i = 0; mvar[i] >= 0; i++) | 
| 577 | – | if (!vdef(mvar[i])) { | 
| 578 | – | *cp++ = '|'; | 
| 579 | – | strcpy(cp, vnam(mvar[i])); | 
| 580 | – | while (*cp) cp++; | 
| 581 | – | pippt = NULL; | 
| 582 | – | } | 
| 583 | – | if (pippt != NULL) | 
| 584 | – | strcpy(pippt, "> /dev/null");   /* nothing to match */ | 
| 585 | – | else | 
| 586 | – | sprintf(cp, ")[ \t]*=' > %s", tf2); | 
| 587 | – | if (system(combuf)) { | 
| 588 | – | unlink(tf2);                    /* clean up */ | 
| 589 | – | unlink(tf1); | 
| 590 | – | error(SYSTEM, "cannot execute rad command"); | 
| 591 | – | } | 
| 592 | – | if (pippt == NULL) { | 
| 593 | – | loadvars(tf2);                  /* load variables */ | 
| 594 | – | unlink(tf2); | 
| 595 | – | } | 
| 596 | – | rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ | 
| 597 | – | unlink(tf1);                    /* clean up */ | 
| 598 | – | } | 
| 599 | – |  | 
| 600 | – |  | 
| 515 |  | rootname(rn, fn)                /* remove tail from end of fn */ | 
| 516 |  | register char   *rn, *fn; | 
| 517 |  | { | 
| 518 |  | char    *tp, *dp; | 
| 519 |  |  | 
| 520 |  | for (tp = NULL, dp = rn; *rn = *fn++; rn++) | 
| 521 | < | if (ISDIRSEP(*rn)) | 
| 521 | > | if (*rn == '/') | 
| 522 |  | dp = rn; | 
| 523 |  | else if (*rn == '.') | 
| 524 |  | tp = rn; | 
| 567 |  | { | 
| 568 |  | int     status = 0; | 
| 569 |  |  | 
| 570 | < | if (hdlist[0] != NULL) {        /* flush holodeck */ | 
| 570 | > | if (hdlist[0] != NULL) {        /* close holodeck */ | 
| 571 |  | if (nprocs > 0) | 
| 572 | < | status = done_rtrace(); | 
| 659 | < | hdflush(NULL); | 
| 572 | > | status = done_rtrace();         /* calls hdsync() */ | 
| 573 |  | if (ncprocs > 0 && vdef(REPORT)) { | 
| 574 |  | long    fsiz, fuse; | 
| 575 |  | fsiz = hdfilen(hdlist[0]->fd); |