9 |
|
*/ |
10 |
|
|
11 |
|
#include "rholo.h" |
12 |
< |
#include "paths.h" |
12 |
> |
#include "random.h" |
13 |
> |
#include <signal.h> |
14 |
|
#include <sys/types.h> |
15 |
+ |
#include <sys/stat.h> |
16 |
|
|
17 |
|
/* the following must be consistent with rholo.h */ |
18 |
|
int NVARS = NRHVARS; /* total number of variables */ |
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 |
|
|
26 |
– |
double expval = 1.; /* global exposure value */ |
27 |
– |
|
28 |
|
int ncprocs = 0; /* desired number of compute processes */ |
29 |
|
|
30 |
|
char *outdev = NULL; /* output device name */ |
31 |
|
|
32 |
+ |
int readinp = 0; /* read commands from stdin */ |
33 |
+ |
|
34 |
+ |
int force = 0; /* allow overwrite of holodeck */ |
35 |
+ |
|
36 |
|
time_t starttime; /* time we got started */ |
37 |
|
time_t endtime; /* time we should end by */ |
38 |
|
time_t reporttime; /* time for next report */ |
39 |
|
|
40 |
+ |
long maxdisk; /* maximum file space (bytes) */ |
41 |
+ |
|
42 |
|
int rtargc = 1; /* rtrace command */ |
43 |
|
char *rtargv[128] = {"rtrace", NULL}; |
44 |
|
|
45 |
+ |
int orig_mode = -1; /* original file mode (-1 if unchanged) */ |
46 |
+ |
|
47 |
|
long nraysdone = 0L; /* number of rays done */ |
48 |
|
long npacksdone = 0L; /* number of packets done */ |
49 |
|
|
50 |
|
PACKET *freepacks; /* available packets */ |
51 |
|
|
52 |
+ |
char *sigerr[NSIG]; /* signal error messages */ |
53 |
+ |
|
54 |
|
extern time_t time(); |
55 |
|
|
56 |
|
|
60 |
|
{ |
61 |
|
HDGRID hdg; |
62 |
|
int i; |
63 |
< |
int force = 0; |
64 |
< |
|
63 |
> |
/* mark start time */ |
64 |
> |
starttime = time(NULL); |
65 |
> |
initurand(16384); /* initialize urand */ |
66 |
|
progname = argv[0]; /* get arguments */ |
67 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
68 |
|
switch (argv[i][1]) { |
72 |
|
case 'f': /* force overwrite */ |
73 |
|
force++; |
74 |
|
break; |
75 |
+ |
case 'i': /* read input from stdin */ |
76 |
+ |
readinp++; |
77 |
+ |
break; |
78 |
|
case 'n': /* compute processes */ |
79 |
|
if (i >= argc-2) |
80 |
|
goto userr; |
106 |
|
/* check settings */ |
107 |
|
checkvalues(); |
108 |
|
/* load RIF if any */ |
109 |
< |
if (vdef(RIF)) |
96 |
< |
getradfile(vval(RIF)); |
109 |
> |
getradfile(); |
110 |
|
/* set defaults */ |
111 |
|
setdefaults(&hdg); |
112 |
|
/* holodeck exists? */ |
115 |
|
"holodeck file exists -- use -f to overwrite"); |
116 |
|
/* create holodeck */ |
117 |
|
creatholo(&hdg); |
118 |
< |
} else /* else load holodeck */ |
118 |
> |
} else { /* else load holodeck */ |
119 |
|
loadholo(); |
120 |
+ |
/* check settings */ |
121 |
+ |
checkvalues(); |
122 |
+ |
/* load RIF if any */ |
123 |
+ |
getradfile(); |
124 |
+ |
/* set defaults */ |
125 |
+ |
setdefaults(NULL); |
126 |
+ |
} |
127 |
|
/* initialize */ |
128 |
|
initrholo(); |
129 |
< |
/* run */ |
129 |
> |
/* main loop */ |
130 |
|
while (rholo()) |
131 |
|
; |
132 |
|
/* done */ |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
+ |
onsig(signo) /* fatal signal */ |
143 |
+ |
int signo; |
144 |
+ |
{ |
145 |
+ |
static int gotsig = 0; |
146 |
+ |
|
147 |
+ |
if (gotsig++) /* two signals and we're gone! */ |
148 |
+ |
_exit(signo); |
149 |
+ |
|
150 |
+ |
alarm(30); /* allow 30 seconds to clean up */ |
151 |
+ |
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
152 |
+ |
eputs("signal - "); |
153 |
+ |
eputs(sigerr[signo]); |
154 |
+ |
eputs("\n"); |
155 |
+ |
quit(3); |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
|
159 |
+ |
sigdie(signo, msg) /* set fatal signal */ |
160 |
+ |
int signo; |
161 |
+ |
char *msg; |
162 |
+ |
{ |
163 |
+ |
if (signal(signo, onsig) == SIG_IGN) |
164 |
+ |
signal(signo, SIG_IGN); |
165 |
+ |
sigerr[signo] = msg; |
166 |
+ |
} |
167 |
+ |
|
168 |
+ |
|
169 |
+ |
int |
170 |
+ |
resfmode(fd, mod) /* restrict open file access mode */ |
171 |
+ |
int fd, mod; |
172 |
+ |
{ |
173 |
+ |
struct stat stbuf; |
174 |
+ |
/* get original mode */ |
175 |
+ |
if (fstat(fd, &stbuf) < 0) |
176 |
+ |
error(SYSTEM, "cannot stat open holodeck file"); |
177 |
+ |
mod &= stbuf.st_mode; /* always more restrictive */ |
178 |
+ |
if (mod == stbuf.st_mode) |
179 |
+ |
return(-1); /* already set */ |
180 |
+ |
/* else change it */ |
181 |
+ |
if (fchmod(fd, mod) < 0) { |
182 |
+ |
error(WARNING, "cannot change holodeck file access mode"); |
183 |
+ |
return(-1); |
184 |
+ |
} |
185 |
+ |
return(stbuf.st_mode); /* return original mode */ |
186 |
+ |
} |
187 |
+ |
|
188 |
+ |
|
189 |
|
initrholo() /* get our holodeck running */ |
190 |
|
{ |
191 |
|
extern int global_packet(); |
192 |
|
register int i; |
193 |
< |
/* check output device */ |
194 |
< |
if (outdev != NULL) |
195 |
< |
open_display(outdev); |
193 |
> |
/* close holodeck on exec() */ |
194 |
> |
fcntl(hdlist[0]->fd, F_SETFD, FD_CLOEXEC); |
195 |
> |
|
196 |
> |
if (outdev != NULL) /* open output device */ |
197 |
> |
disp_open(outdev); |
198 |
|
else if (ncprocs > 0) /* else use global ray feed */ |
199 |
|
init_global(); |
200 |
< |
/* record the time */ |
201 |
< |
starttime = time(NULL); |
200 |
> |
/* record disk space limit */ |
201 |
> |
if (!vdef(DISKSPACE)) |
202 |
> |
maxdisk = 0; |
203 |
> |
else |
204 |
> |
maxdisk = 1024.*1024.*vflt(DISKSPACE); |
205 |
> |
/* record end time */ |
206 |
|
if (!vdef(TIME) || vflt(TIME) <= FTINY) |
207 |
|
endtime = 0; |
208 |
|
else |
209 |
< |
endtime = starttime + vflt(TIME)*3600.; |
209 |
> |
endtime = starttime + vflt(TIME)*3600. + .5; |
210 |
|
/* set up memory cache */ |
211 |
< |
hdcachesize = 1024.*1024.*vflt(CACHE); |
211 |
> |
if (outdev == NULL) |
212 |
> |
hdcachesize = 0; /* manual flushing */ |
213 |
> |
else if (vdef(CACHE)) |
214 |
> |
hdcachesize = 1024.*1024.*vflt(CACHE); |
215 |
|
/* open report file */ |
216 |
|
if (vdef(REPORT)) { |
217 |
|
register char *s = sskip2(vval(REPORT), 1); |
222 |
|
if (ncprocs > 0) { |
223 |
|
i = start_rtrace(); |
224 |
|
if (i < 1) |
225 |
< |
error(USER, "cannot start rtrace process"); |
225 |
> |
error(USER, "cannot start rtrace process(es)"); |
226 |
|
if (vdef(REPORT)) { /* make first report */ |
227 |
|
printargs(rtargc, rtargv, stderr); |
228 |
|
report(0); |
247 |
|
freepacks[i].next = &freepacks[i+1]; |
248 |
|
} |
249 |
|
} |
250 |
+ |
/* set up signal handling */ |
251 |
+ |
sigdie(SIGINT, "Interrupt"); |
252 |
+ |
sigdie(SIGHUP, "Hangup"); |
253 |
+ |
sigdie(SIGTERM, "Terminate"); |
254 |
+ |
sigdie(SIGPIPE, "Broken pipe"); |
255 |
+ |
sigdie(SIGALRM, "Alarm clock"); |
256 |
+ |
#ifdef SIGXCPU |
257 |
+ |
sigdie(SIGXCPU, "CPU limit exceeded"); |
258 |
+ |
sigdie(SIGXFSZ, "File size exceeded"); |
259 |
+ |
#endif |
260 |
+ |
/* protect holodeck file */ |
261 |
+ |
orig_mode = resfmode(hdlist[0]->fd, ncprocs>0 ? 0 : 0444); |
262 |
|
return; |
263 |
|
memerr: |
264 |
|
error(SYSTEM, "out of memory in initrholo"); |
272 |
|
register PACKET *p; |
273 |
|
time_t t; |
274 |
|
long l; |
275 |
< |
/* check display */ |
276 |
< |
if (outdev != NULL && !disp_check(idle)) |
277 |
< |
return(0); |
275 |
> |
|
276 |
> |
if (outdev != NULL) /* check display */ |
277 |
> |
if (!disp_check(idle)) |
278 |
> |
return(0); |
279 |
|
/* display only? */ |
280 |
< |
if (ncprocs <= 0) |
281 |
< |
return(1); |
280 |
> |
if (nprocs <= 0) |
281 |
> |
return(outdev != NULL); |
282 |
|
/* check file size */ |
283 |
< |
if (l = 1024.*1024.*vflt(DISKSPACE) > 0 && |
284 |
< |
hdfiluse(hdlist[0]->fd, 0) + hdmemuse(0) >= l) |
285 |
< |
return(0); |
283 |
> |
if (maxdisk > 0 && hdfilen(hdlist[0]->fd) >= maxdisk) { |
284 |
> |
error(WARNING, "file limit exceeded"); |
285 |
> |
done_rtrace(); |
286 |
> |
idle = 1; |
287 |
> |
return(1); /* comes back */ |
288 |
> |
} |
289 |
|
/* check time */ |
290 |
< |
if (endtime > 0 || vdef(REPORT)) |
290 |
> |
if (endtime > 0 || reporttime > 0) |
291 |
|
t = time(NULL); |
292 |
< |
if (endtime > 0 && t >= endtime) |
293 |
< |
return(0); |
294 |
< |
if (vdef(REPORT) && t >= reporttime) |
292 |
> |
if (endtime > 0 && t >= endtime) { |
293 |
> |
error(WARNING, "time limit exceeded"); |
294 |
> |
done_rtrace(); |
295 |
> |
idle = 1; |
296 |
> |
return(1); /* comes back */ |
297 |
> |
} |
298 |
> |
if (reporttime > 0 && t >= reporttime) |
299 |
|
report(t); |
300 |
|
/* get packets to process */ |
301 |
|
while (freepacks != NULL) { |
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; |
216 |
< |
/* are we out of stuff to do? */ |
217 |
< |
if (idle && outdev == NULL) |
218 |
< |
return(0); |
219 |
< |
/* else process packets */ |
312 |
> |
/* process packets */ |
313 |
|
done_packets(do_packets(pl)); |
314 |
|
return(1); /* and continue */ |
315 |
|
} |
316 |
|
|
317 |
|
|
225 |
– |
report(t) /* report progress so far */ |
226 |
– |
time_t t; |
227 |
– |
{ |
228 |
– |
if (t == 0) |
229 |
– |
t = time(NULL); |
230 |
– |
fprintf(stderr, "%s: %ld packets done (%ld rays) after %.2f hours\n", |
231 |
– |
progname, npacksdone, nraysdone, (t-starttime)/3600.); |
232 |
– |
} |
233 |
– |
|
234 |
– |
|
318 |
|
setdefaults(gp) /* set default values */ |
319 |
|
register HDGRID *gp; |
320 |
|
{ |
331 |
|
sprintf(errmsg, "ignoring all but first %s", vnam(SECTION)); |
332 |
|
error(WARNING, errmsg); |
333 |
|
} |
251 |
– |
if (sscanf(vval(SECTION), |
252 |
– |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", |
253 |
– |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
254 |
– |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
255 |
– |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
256 |
– |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2]) != 12) |
257 |
– |
badvalue(SECTION); |
258 |
– |
maxlen = 0.; |
259 |
– |
for (i = 0; i < 3; i++) |
260 |
– |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
261 |
– |
maxlen = len[i]; |
262 |
– |
if (!vdef(GRID)) { |
263 |
– |
sprintf(buf, "%.4f", maxlen/16.); |
264 |
– |
vval(GRID) = savqstr(buf); |
265 |
– |
vdef(GRID)++; |
266 |
– |
} |
267 |
– |
if ((d = vflt(GRID)) <= FTINY) |
268 |
– |
badvalue(GRID); |
269 |
– |
for (i = 0; i < 3; i++) |
270 |
– |
gp->grid[i] = len[i]/d + (1.-FTINY); |
271 |
– |
if (!vdef(EXPOSURE)) { |
272 |
– |
sprintf(errmsg, "%s must be defined", vnam(EXPOSURE)); |
273 |
– |
error(USER, errmsg); |
274 |
– |
} |
275 |
– |
expval = vval(EXPOSURE)[0] == '-' || vval(EXPOSURE)[0] == '+' ? |
276 |
– |
pow(2., vflt(EXPOSURE)) : vflt(EXPOSURE); |
334 |
|
if (!vdef(OCTREE)) { |
335 |
|
if ((vval(OCTREE) = bmalloc(strlen(froot)+5)) == NULL) |
336 |
|
error(SYSTEM, "out of memory"); |
337 |
|
sprintf(vval(OCTREE), "%s.oct", froot); |
338 |
|
vdef(OCTREE)++; |
339 |
|
} |
283 |
– |
if (!vdef(DISKSPACE)) { |
284 |
– |
sprintf(errmsg, |
285 |
– |
"no %s setting, assuming 100 Mbytes available", |
286 |
– |
vnam(DISKSPACE)); |
287 |
– |
error(WARNING, errmsg); |
288 |
– |
vval(DISKSPACE) = "100"; |
289 |
– |
vdef(DISKSPACE)++; |
290 |
– |
} |
291 |
– |
if (!vdef(CACHE)) { |
292 |
– |
sprintf(errmsg, |
293 |
– |
"no %s setting, assuming 10 Mbytes available", |
294 |
– |
vnam(CACHE)); |
295 |
– |
error(WARNING, errmsg); |
296 |
– |
vval(CACHE) = "10"; |
297 |
– |
vdef(CACHE)++; |
298 |
– |
} |
340 |
|
if (!vdef(OBSTRUCTIONS)) { |
341 |
|
vval(OBSTRUCTIONS) = "T"; |
342 |
|
vdef(OBSTRUCTIONS)++; |
343 |
|
} |
344 |
+ |
if (!vdef(VDIST)) { |
345 |
+ |
vval(VDIST) = "F"; |
346 |
+ |
vdef(VDIST)++; |
347 |
+ |
} |
348 |
|
if (!vdef(OCCUPANCY)) { |
349 |
|
vval(OCCUPANCY) = "U"; |
350 |
|
vdef(OCCUPANCY)++; |
352 |
|
/* append rendering options */ |
353 |
|
if (vdef(RENDER)) |
354 |
|
rtargc += wordstring(rtargv+rtargc, vval(RENDER)); |
355 |
+ |
|
356 |
+ |
if (gp == NULL) /* already initialized? */ |
357 |
+ |
return; |
358 |
+ |
/* set grid parameters */ |
359 |
+ |
gp->grid[0] = gp->grid[1] = gp->grid[2] = 0; |
360 |
+ |
if (sscanf(vval(SECTION), |
361 |
+ |
"%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %hd %hd %hd", |
362 |
+ |
&gp->orig[0], &gp->orig[1], &gp->orig[2], |
363 |
+ |
&gp->xv[0][0], &gp->xv[0][1], &gp->xv[0][2], |
364 |
+ |
&gp->xv[1][0], &gp->xv[1][1], &gp->xv[1][2], |
365 |
+ |
&gp->xv[2][0], &gp->xv[2][1], &gp->xv[2][2], |
366 |
+ |
&gp->grid[0], &gp->grid[1], &gp->grid[2]) < 12) |
367 |
+ |
badvalue(SECTION); |
368 |
+ |
maxlen = 0.; |
369 |
+ |
for (i = 0; i < 3; i++) |
370 |
+ |
if ((len[i] = VLEN(gp->xv[i])) > maxlen) |
371 |
+ |
maxlen = len[i]; |
372 |
+ |
if (!vdef(GRID)) { |
373 |
+ |
sprintf(buf, "%.4f", maxlen/8.); |
374 |
+ |
vval(GRID) = savqstr(buf); |
375 |
+ |
vdef(GRID)++; |
376 |
+ |
} |
377 |
+ |
if ((d = vflt(GRID)) <= FTINY) |
378 |
+ |
badvalue(GRID); |
379 |
+ |
for (i = 0; i < 3; i++) |
380 |
+ |
if (gp->grid[i] <= 0) |
381 |
+ |
gp->grid[i] = len[i]/d + (1.-FTINY); |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
|
creatholo(gp) /* create a holodeck output file */ |
386 |
|
HDGRID *gp; |
387 |
|
{ |
388 |
+ |
extern char VersionID[]; |
389 |
|
long endloc = 0; |
390 |
+ |
int fd; |
391 |
|
FILE *fp; |
392 |
|
/* open & truncate file */ |
393 |
|
if ((fp = fopen(hdkfile, "w+")) == NULL) { |
396 |
|
} |
397 |
|
/* write information header */ |
398 |
|
newheader("RADIANCE", fp); |
399 |
+ |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
400 |
|
printvars(fp); |
401 |
|
fputformat(HOLOFMT, fp); |
402 |
|
fputc('\n', fp); |
403 |
|
putw(HOLOMAGIC, fp); /* put magic number & terminus */ |
404 |
|
fwrite(&endloc, sizeof(long), 1, fp); |
405 |
< |
fflush(fp); /* flush buffer */ |
406 |
< |
initholo(fileno(fp), gp); /* allocate and initialize index */ |
407 |
< |
/* we're dropping fp here.... */ |
405 |
> |
fd = dup(fileno(fp)); |
406 |
> |
fclose(fp); /* flush and close stdio stream */ |
407 |
> |
hdinit(fd, gp); /* allocate and initialize index */ |
408 |
|
} |
409 |
|
|
410 |
|
|
415 |
|
register char *cp; |
416 |
|
char fmt[32]; |
417 |
|
|
418 |
< |
if (headidval(fmt, s)) { |
418 |
> |
if (formatval(fmt, s)) { |
419 |
|
if (strcmp(fmt, HOLOFMT)) { |
420 |
|
sprintf(errmsg, "%s file \"%s\" has %s%s", |
421 |
|
HOLOFMT, hdkfile, FMTSTR, fmt); |
434 |
|
|
435 |
|
loadholo() /* start loading a holodeck from fname */ |
436 |
|
{ |
437 |
+ |
extern long ftell(); |
438 |
|
FILE *fp; |
439 |
< |
long endloc; |
440 |
< |
/* open input file */ |
441 |
< |
if ((fp = fopen(hdkfile, "r+")) == NULL) { |
442 |
< |
sprintf(errmsg, "cannot open \"%s\" for appending", hdkfile); |
439 |
> |
int fd; |
440 |
> |
long fpos; |
441 |
> |
/* open holodeck file */ |
442 |
> |
if ((fp = fopen(hdkfile, ncprocs>0 ? "r+" : "r")) == NULL) { |
443 |
> |
sprintf(errmsg, "cannot open \"%s\" for %s", hdkfile, |
444 |
> |
ncprocs>0 ? "appending" : "reading"); |
445 |
|
error(SYSTEM, errmsg); |
446 |
|
} |
447 |
|
/* load variables from header */ |
452 |
|
hdkfile); |
453 |
|
error(USER, errmsg); |
454 |
|
} |
455 |
< |
fread(&endloc, sizeof(long), 1, fp); |
456 |
< |
if (endloc != 0) |
455 |
> |
fread(&fpos, sizeof(long), 1, fp); |
456 |
> |
if (fpos != 0) |
457 |
|
error(WARNING, "ignoring multiple sections in holodeck file"); |
458 |
< |
fseek(fp, 0L, 1); /* align system file pointer */ |
459 |
< |
initholo(fileno(fp), NULL); /* allocate and load index */ |
460 |
< |
/* we're dropping fp here.... */ |
458 |
> |
fpos = ftell(fp); /* get stdio position */ |
459 |
> |
fd = dup(fileno(fp)); |
460 |
> |
fclose(fp); /* done with stdio */ |
461 |
> |
lseek(fd, fpos, 0); /* align system file pointer */ |
462 |
> |
hdinit(fd, NULL); /* allocate and load index */ |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
done_packets(pl) /* handle finished packets */ |
467 |
|
PACKET *pl; |
468 |
|
{ |
469 |
+ |
static int n2flush = 0; |
470 |
|
register PACKET *p; |
471 |
|
|
472 |
|
while (pl != NULL) { |
476 |
|
(char *)hdnewrays(hdlist[p->hd],p->bi,p->nr), |
477 |
|
p->nr*sizeof(RAYVAL)); |
478 |
|
if (outdev != NULL) /* display it */ |
479 |
< |
disp_packet(p); |
479 |
> |
disp_packet((PACKHEAD *)p); |
480 |
> |
if (hdcachesize <= 0) /* manual flushing */ |
481 |
> |
n2flush += p->nr; |
482 |
> |
nraysdone += p->nr; |
483 |
> |
npacksdone++; |
484 |
|
} |
400 |
– |
nraysdone += p->nr; |
401 |
– |
npacksdone++; |
485 |
|
p->nr = 0; /* push onto free list */ |
486 |
|
p->next = freepacks; |
487 |
|
freepacks = p; |
488 |
|
} |
489 |
< |
} |
490 |
< |
|
491 |
< |
|
409 |
< |
getradfile(rfargs) /* run rad and get needed variables */ |
410 |
< |
char *rfargs; |
411 |
< |
{ |
412 |
< |
static short mvar[] = {VIEW,OCTREE,EXPOSURE,REPORT,-1}; |
413 |
< |
static char tf1[] = TEMPLATE; |
414 |
< |
char tf2[64]; |
415 |
< |
char combuf[256]; |
416 |
< |
register int i; |
417 |
< |
register char *cp; |
418 |
< |
/* create rad command */ |
419 |
< |
mktemp(tf1); |
420 |
< |
sprintf(tf2, "%s.rif", tf1); |
421 |
< |
sprintf(combuf, |
422 |
< |
"rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH", |
423 |
< |
rfargs, tf1); |
424 |
< |
cp = combuf; |
425 |
< |
while (*cp) cp++; /* match unset variables */ |
426 |
< |
for (i = 0; mvar[i] >= 0; i++) |
427 |
< |
if (!vdef(mvar[i])) { |
428 |
< |
*cp++ = '|'; |
429 |
< |
strcpy(cp, vnam(mvar[i])); |
430 |
< |
while (*cp) cp++; |
431 |
< |
} |
432 |
< |
sprintf(cp, ")[ \t]*=' > %s", tf2); |
433 |
< |
if (system(combuf)) { |
434 |
< |
error(SYSTEM, "cannot execute rad command"); |
435 |
< |
unlink(tf2); /* clean up */ |
436 |
< |
unlink(tf1); |
437 |
< |
quit(1); |
489 |
> |
if (n2flush > 512*RPACKSIZ*nprocs) { |
490 |
> |
hdflush(NULL); /* flush holodeck buffers */ |
491 |
> |
n2flush = 0; |
492 |
|
} |
439 |
– |
loadvars(tf2); /* load variables */ |
440 |
– |
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
441 |
– |
unlink(tf2); /* clean up */ |
442 |
– |
unlink(tf1); |
493 |
|
} |
494 |
|
|
495 |
|
|
499 |
|
char *tp, *dp; |
500 |
|
|
501 |
|
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
502 |
< |
if (ISDIRSEP(*rn)) |
502 |
> |
if (*rn == '/') |
503 |
|
dp = rn; |
504 |
|
else if (*rn == '.') |
505 |
|
tp = rn; |
549 |
|
int status = 0; |
550 |
|
|
551 |
|
if (hdlist[0] != NULL) { /* flush holodeck */ |
552 |
< |
if (ncprocs > 0) { |
553 |
< |
done_packets(flush_queue()); |
554 |
< |
status = end_rtrace(); /* close rtrace */ |
555 |
< |
hdflush(NULL); |
556 |
< |
if (vdef(REPORT)) { |
557 |
< |
long fsiz, fuse; |
558 |
< |
report(0); |
559 |
< |
fsiz = lseek(hdlist[0]->fd, 0L, 2); |
560 |
< |
fuse = hdfiluse(hdlist[0]->fd, 1); |
561 |
< |
fprintf(stderr, |
562 |
< |
"%s: %.1f Mbyte holodeck file, %.2f%% fragmentation\n", |
563 |
< |
hdkfile, fsiz/(1024.*1024.), |
514 |
< |
100.*(fsiz-fuse)/fsiz); |
515 |
< |
} |
516 |
< |
} else |
517 |
< |
hdflush(NULL); |
552 |
> |
if (nprocs > 0) |
553 |
> |
status = done_rtrace(); |
554 |
> |
hdflush(NULL); |
555 |
> |
if (ncprocs > 0 && vdef(REPORT)) { |
556 |
> |
long fsiz, fuse; |
557 |
> |
fsiz = hdfilen(hdlist[0]->fd); |
558 |
> |
fuse = hdfiluse(hdlist[0]->fd, 1); |
559 |
> |
fprintf(stderr, |
560 |
> |
"%s: %.1f Mbyte holodeck file, %.1f%% fragmentation\n", |
561 |
> |
hdkfile, fsiz/(1024.*1024.), |
562 |
> |
100.*(fsiz-fuse)/fsiz); |
563 |
> |
} |
564 |
|
} |
565 |
+ |
if (orig_mode >= 0) /* reset holodeck access mode */ |
566 |
+ |
fchmod(hdlist[0]->fd, orig_mode); |
567 |
+ |
if (outdev != NULL) /* close display */ |
568 |
+ |
disp_close(); |
569 |
|
exit(ec ? ec : status); /* exit */ |
570 |
|
} |