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> |
21 |
|
|
22 |
|
char *progname; /* our program name */ |
23 |
|
char *hdkfile; /* holodeck file name */ |
24 |
< |
char froot[MAXPATH]; /* root file name */ |
24 |
> |
char froot[256]; /* root file name */ |
25 |
|
|
26 |
|
int nowarn = 0; /* turn warnings off? */ |
27 |
|
|
106 |
|
/* check settings */ |
107 |
|
checkvalues(); |
108 |
|
/* load RIF if any */ |
109 |
< |
if (vdef(RIF)) |
111 |
< |
getradfile(vval(RIF)); |
109 |
> |
getradfile(); |
110 |
|
/* set defaults */ |
111 |
|
setdefaults(&hdg); |
112 |
|
/* holodeck exists? */ |
120 |
|
/* check settings */ |
121 |
|
checkvalues(); |
122 |
|
/* load RIF if any */ |
123 |
< |
if (vdef(RIF)) |
126 |
< |
getradfile(vval(RIF)); |
123 |
> |
getradfile(); |
124 |
|
/* set defaults */ |
125 |
|
setdefaults(NULL); |
126 |
|
} |
278 |
|
return(0); |
279 |
|
/* display only? */ |
280 |
|
if (nprocs <= 0) |
281 |
< |
return(1); |
281 |
> |
return(outdev != NULL); |
282 |
|
/* check file size */ |
283 |
|
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
284 |
|
error(WARNING, "file limit exceeded"); |
285 |
< |
return(0); |
285 |
> |
done_rtrace(); |
286 |
> |
idle = 1; |
287 |
> |
return(1); /* comes back */ |
288 |
|
} |
289 |
|
/* check time */ |
290 |
|
if (endtime > 0 || reporttime > 0) |
291 |
|
t = time(NULL); |
292 |
|
if (endtime > 0 && t >= endtime) { |
293 |
|
error(WARNING, "time limit exceeded"); |
294 |
< |
return(0); |
294 |
> |
done_rtrace(); |
295 |
> |
idle = 1; |
296 |
> |
return(1); /* comes back */ |
297 |
|
} |
298 |
|
if (reporttime > 0 && t >= reporttime) |
299 |
|
report(t); |
302 |
|
p = freepacks; freepacks = p->next; p->next = NULL; |
303 |
|
if (!next_packet(p)) { |
304 |
|
p->next = freepacks; freepacks = p; |
305 |
+ |
idle = 1; |
306 |
|
break; |
307 |
|
} |
308 |
|
if (pl == NULL) pl = p; |
309 |
|
else plend->next = p; |
310 |
|
plend = p; |
311 |
|
} |
312 |
< |
idle = pl == NULL && freepacks != NULL; |
311 |
< |
/* are we out of stuff to do? */ |
312 |
< |
if (idle && outdev == NULL) |
313 |
< |
return(0); |
314 |
< |
/* else process packets */ |
312 |
> |
/* process packets */ |
313 |
|
done_packets(do_packets(pl)); |
314 |
|
return(1); /* and continue */ |
315 |
|
} |
318 |
|
report(t) /* report progress so far */ |
319 |
|
time_t t; |
320 |
|
{ |
321 |
< |
if (t == 0) |
321 |
> |
static time_t seconds2go = 1000000; |
322 |
> |
|
323 |
> |
if (t == 0L) |
324 |
|
t = time(NULL); |
325 |
< |
fprintf(stderr, "%s: %ld packets (%ld rays) done after %.2f hours\n", |
326 |
< |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
327 |
< |
fflush(stderr); |
328 |
< |
if (vdef(REPORT)) |
329 |
< |
reporttime = t + (time_t)(vflt(REPORT)*60.+.5); |
325 |
> |
sprintf(errmsg, "%ld packets (%ld rays) done after %.2f hours\n", |
326 |
> |
npacksdone, nraysdone, (t-starttime)/3600.); |
327 |
> |
eputs(errmsg); |
328 |
> |
if (seconds2go == 1000000) |
329 |
> |
seconds2go = vdef(REPORT) ? (long)(vflt(REPORT)*60. + .5) : 0L; |
330 |
> |
if (seconds2go) |
331 |
> |
reporttime = t + seconds2go; |
332 |
|
} |
333 |
|
|
334 |
|
|
510 |
|
} |
511 |
|
|
512 |
|
|
511 |
– |
checkrad() /* check to make sure octree is up to date */ |
512 |
– |
{ |
513 |
– |
char combuf[128]; |
514 |
– |
|
515 |
– |
if (!vdef(RIF)) |
516 |
– |
return; |
517 |
– |
sprintf(combuf, "rad -v 0 -s -w %s", vval(RIF)); |
518 |
– |
if (system(combuf)) |
519 |
– |
error(WARNING, "error running rad"); |
520 |
– |
} |
521 |
– |
|
522 |
– |
|
523 |
– |
getradfile(rfargs) /* run rad and get needed variables */ |
524 |
– |
char *rfargs; |
525 |
– |
{ |
526 |
– |
static short mvar[] = {OCTREE,-1}; |
527 |
– |
static char tf1[] = TEMPLATE; |
528 |
– |
char tf2[64]; |
529 |
– |
char combuf[256]; |
530 |
– |
char *pippt; |
531 |
– |
register int i; |
532 |
– |
register char *cp; |
533 |
– |
/* create rad command */ |
534 |
– |
mktemp(tf1); |
535 |
– |
sprintf(tf2, "%s.rif", tf1); |
536 |
– |
sprintf(combuf, |
537 |
– |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
538 |
– |
rfargs, tf1); |
539 |
– |
cp = combuf; |
540 |
– |
while (*cp){ |
541 |
– |
if (*cp == '|') pippt = cp; |
542 |
– |
cp++; |
543 |
– |
} /* match unset variables */ |
544 |
– |
for (i = 0; mvar[i] >= 0; i++) |
545 |
– |
if (!vdef(mvar[i])) { |
546 |
– |
*cp++ = '|'; |
547 |
– |
strcpy(cp, vnam(mvar[i])); |
548 |
– |
while (*cp) cp++; |
549 |
– |
pippt = NULL; |
550 |
– |
} |
551 |
– |
if (pippt != NULL) |
552 |
– |
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
553 |
– |
else |
554 |
– |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
555 |
– |
if (system(combuf)) { |
556 |
– |
unlink(tf2); /* clean up */ |
557 |
– |
unlink(tf1); |
558 |
– |
error(SYSTEM, "cannot execute rad command"); |
559 |
– |
} |
560 |
– |
if (pippt == NULL) { |
561 |
– |
loadvars(tf2); /* load variables */ |
562 |
– |
unlink(tf2); |
563 |
– |
} |
564 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
565 |
– |
unlink(tf1); /* clean up */ |
566 |
– |
} |
567 |
– |
|
568 |
– |
|
513 |
|
rootname(rn, fn) /* remove tail from end of fn */ |
514 |
|
register char *rn, *fn; |
515 |
|
{ |
516 |
|
char *tp, *dp; |
517 |
|
|
518 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
519 |
< |
if (ISDIRSEP(*rn)) |
519 |
> |
if (*rn == '/') |
520 |
|
dp = rn; |
521 |
|
else if (*rn == '.') |
522 |
|
tp = rn; |
566 |
|
int status = 0; |
567 |
|
|
568 |
|
if (hdlist[0] != NULL) { /* flush holodeck */ |
569 |
< |
if (nprocs > 0) { |
570 |
< |
done_packets(flush_queue()); |
627 |
< |
status = end_rtrace(); /* close rtrace */ |
628 |
< |
} |
569 |
> |
if (nprocs > 0) |
570 |
> |
status = done_rtrace(); |
571 |
|
hdflush(NULL); |
572 |
|
if (ncprocs > 0 && vdef(REPORT)) { |
573 |
|
long fsiz, fuse; |
632 |
– |
report(0); |
574 |
|
fsiz = hdfilen(hdlist[0]->fd); |
575 |
|
fuse = hdfiluse(hdlist[0]->fd, 1); |
576 |
|
fprintf(stderr, |