16 |
|
#include "lookup.h" |
17 |
|
#include "calcomp.h" |
18 |
|
|
19 |
+ |
#ifndef MAXMODLIST |
20 |
|
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
21 |
+ |
#endif |
22 |
|
|
23 |
|
int treebufsiz = BUFSIZ; /* current tree buffer size */ |
24 |
|
|
57 |
|
FILE *getofile(const char *ospec, const char *mname, int bn); |
58 |
|
int ofname(char *oname, const char *ospec, const char *mname, int bn); |
59 |
|
void printheader(FILE *fout, const char *info); |
60 |
+ |
void printresolu(FILE *fout); |
61 |
|
|
62 |
|
/* |
63 |
|
* The rcont structure is used to manage i/o with a particular |
113 |
|
const char *modname[MAXMODLIST]; /* ordered modifier name list */ |
114 |
|
int nmods = 0; /* number of modifiers */ |
115 |
|
|
116 |
+ |
#define queue_length() (lastray - lastdone) |
117 |
+ |
|
118 |
|
MODCONT *addmodifier(char *modn, char *outf, char *binv); |
119 |
|
void addmodfile(char *fname, char *outf, char *binv); |
120 |
|
|
131 |
|
void add_contrib(const char *modn); |
132 |
|
void done_contrib(void); |
133 |
|
|
134 |
+ |
/* return number of open rtrace processes */ |
135 |
+ |
static int |
136 |
+ |
nrtprocs(void) |
137 |
+ |
{ |
138 |
+ |
int nrtp = 0; |
139 |
+ |
struct rtproc *rtp; |
140 |
+ |
|
141 |
+ |
for (rtp = &rt0; rtp != NULL; rtp = rtp->next) |
142 |
+ |
nrtp += rtp->pd.running; |
143 |
+ |
return(nrtp); |
144 |
+ |
} |
145 |
+ |
|
146 |
|
/* set input/output format */ |
147 |
|
static void |
148 |
|
setformat(const char *fmt) |
188 |
|
char *binval = NULL; |
189 |
|
char fmt[8]; |
190 |
|
int i, j; |
191 |
+ |
/* need at least one argument */ |
192 |
+ |
if (argc < 2) { |
193 |
+ |
fprintf(stderr, |
194 |
+ |
"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", |
195 |
+ |
argv[0]); |
196 |
+ |
exit(1); |
197 |
+ |
} |
198 |
|
/* global program name */ |
199 |
|
gargv = argv; |
200 |
|
/* initialize calcomp routines */ |
218 |
|
recover++; |
219 |
|
continue; |
220 |
|
case 'n': /* number of processes */ |
221 |
< |
if (argv[i][2] || i >= argc-1) break; |
221 |
> |
if (argv[i][2] || i >= argc-2) break; |
222 |
|
nprocs = atoi(argv[++i]); |
223 |
|
if (nprocs <= 0) |
224 |
|
error(USER, "illegal number of processes"); |
243 |
|
case 'f': /* file or i/o format */ |
244 |
|
if (!argv[i][2]) { |
245 |
|
char *fpath; |
246 |
< |
if (i >= argc-1) break; |
246 |
> |
if (i >= argc-2) break; |
247 |
|
fpath = getpath(argv[++i], |
248 |
|
getrlibpath(), R_OK); |
249 |
|
if (fpath == NULL) { |
258 |
|
setformat(argv[i]+2); |
259 |
|
continue; |
260 |
|
case 'e': /* expression */ |
261 |
< |
if (argv[i][2] || i >= argc-1) break; |
261 |
> |
if (argv[i][2] || i >= argc-2) break; |
262 |
|
scompile(argv[++i], NULL, 0); |
263 |
|
continue; |
264 |
|
case 'o': /* output file spec. */ |
265 |
< |
if (argv[i][2] || i >= argc-1) break; |
265 |
> |
if (argv[i][2] || i >= argc-2) break; |
266 |
|
curout = argv[++i]; |
267 |
|
continue; |
268 |
|
case 'x': /* horiz. output resolution */ |
269 |
< |
if (argv[i][2] || i >= argc-1) break; |
269 |
> |
if (argv[i][2] || i >= argc-2) break; |
270 |
|
xres = atoi(argv[++i]); |
271 |
|
continue; |
272 |
|
case 'y': /* vert. output resolution */ |
273 |
< |
if (argv[i][2] || i >= argc-1) break; |
273 |
> |
if (argv[i][2] || i >= argc-2) break; |
274 |
|
yres = atoi(argv[++i]); |
275 |
|
continue; |
276 |
|
case 'b': /* bin expression */ |
277 |
< |
if (argv[i][2] || i >= argc-1) break; |
277 |
> |
if (argv[i][2] || i >= argc-2) break; |
278 |
|
binval = argv[++i]; |
279 |
|
continue; |
280 |
|
case 'm': /* modifier name */ |
281 |
< |
if (argv[i][2] || i >= argc-1) break; |
281 |
> |
if (argv[i][2] || i >= argc-2) break; |
282 |
|
rtargv[rtargc++] = "-ti"; |
283 |
|
rtargv[rtargc++] = argv[++i]; |
284 |
|
addmodifier(argv[i], curout, binval); |
285 |
|
continue; |
286 |
|
case 'M': /* modifier file */ |
287 |
< |
if (argv[i][2] || i >= argc-1) break; |
288 |
< |
addmodfile(argv[++i], curout, binval); |
287 |
> |
if (argv[i][2] || i >= argc-2) break; |
288 |
> |
rtargv[rtargc++] = "-tI"; |
289 |
> |
rtargv[rtargc++] = argv[++i]; |
290 |
> |
addmodfile(argv[i], curout, binval); |
291 |
|
continue; |
292 |
|
} |
293 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
337 |
|
error(USER, "missing octree argument"); |
338 |
|
rtargv[rtargc++] = octree = argv[i]; |
339 |
|
rtargv[rtargc] = NULL; |
340 |
< |
/* start rtrace & compute contributions */ |
340 |
> |
/* start rtrace */ |
341 |
|
init(nprocs); |
342 |
|
if (recover) /* perform recovery if requested */ |
343 |
|
recover_output(stdin); |
344 |
< |
trace_contribs(stdin); |
344 |
> |
trace_contribs(stdin); /* compute contributions */ |
345 |
|
quit(0); |
346 |
|
} |
347 |
|
|
348 |
+ |
#ifndef SIGALRM |
349 |
+ |
#define SIGALRM SIGTERM |
350 |
+ |
#endif |
351 |
|
/* kill persistent rtrace process */ |
352 |
|
static void |
353 |
|
killpersist(void) |
354 |
|
{ |
355 |
|
FILE *fp = fopen(persistfn, "r"); |
356 |
< |
int pid; |
356 |
> |
RT_PID pid; |
357 |
|
|
358 |
|
if (fp == NULL) |
359 |
|
return; |
493 |
|
{ |
494 |
|
char *mname[MAXMODLIST]; |
495 |
|
int i; |
496 |
< |
/* load the file & store strings */ |
497 |
< |
wordfile(mname, fname); |
496 |
> |
/* find the file & store strings */ |
497 |
> |
if (wordfile(mname, getpath(fname, getrlibpath(), R_OK)) < 0) { |
498 |
> |
sprintf(errmsg, "cannot find modifier file '%s'", fname); |
499 |
> |
error(SYSTEM, errmsg); |
500 |
> |
} |
501 |
|
for (i = 0; mname[i]; i++) /* add each one */ |
502 |
|
addmodifier(mname[i], outf, binv); |
503 |
|
} |
599 |
|
break; |
600 |
|
} |
601 |
|
fputc('\n', fout); |
602 |
+ |
} |
603 |
+ |
|
604 |
+ |
/* write resolution string to given output stream */ |
605 |
+ |
void |
606 |
+ |
printresolu(FILE *fout) |
607 |
+ |
{ |
608 |
|
if (xres > 0) { |
609 |
|
if (yres > 0) /* resolution string */ |
610 |
|
fprtresolu(xres, yres, fout); |
626 |
|
SET_FILE_BINARY(stdout); |
627 |
|
if (header) |
628 |
|
printheader(stdout, NULL); |
629 |
+ |
printresolu(stdout); |
630 |
|
} |
631 |
|
using_stdout = 1; |
632 |
|
return stdout; |
666 |
|
*cp = '\0'; |
667 |
|
printheader(fp, info); |
668 |
|
} |
669 |
+ |
printresolu(fp); |
670 |
|
/* play catch-up */ |
671 |
|
for (i = 0; i < lastdone; i++) { |
672 |
|
static const DCOLOR nocontrib = BLKCOLOR; |
741 |
|
bn = (int)(evalue(mp->binv) + .5); |
742 |
|
if (bn <= 0) |
743 |
|
bn = 0; |
744 |
< |
else if (bn > mp->nbins) { /* new bin */ |
744 |
> |
else if (bn >= mp->nbins) { /* new bin */ |
745 |
|
mp = (MODCONT *)realloc(mp, sizeof(MODCONT) + |
746 |
|
bn*sizeof(DCOLOR)); |
747 |
|
if (mp == NULL) |
940 |
|
if (rt->bsiz + BUFSIZ <= treebufsiz) |
941 |
|
rt->bsiz = treebufsiz; |
942 |
|
else |
943 |
< |
rt->bsiz = treebufsiz += BUFSIZ; |
943 |
> |
treebufsiz = rt->bsiz += BUFSIZ; |
944 |
|
rt->buf = (char *)realloc(rt->buf, rt->bsiz); |
945 |
|
} |
946 |
|
if (rt->buf == NULL) |
981 |
|
struct rtproc *rtp; |
982 |
|
/* loop over input */ |
983 |
|
while ((iblen = getinp(inpbuf, fin)) > 0) { |
984 |
< |
if (lastray+1 < lastray) { /* counter rollover? */ |
984 |
> |
if (lastray+1 < lastray || /* need reset? */ |
985 |
> |
queue_length() > 5*nrtprocs()) { |
986 |
|
while (wait_rproc() != NULL) |
987 |
|
process_queue(); |
988 |
|
lastdone = lastray = 0; |
1066 |
|
error(USER, "cannot recover from command"); |
1067 |
|
/* open output */ |
1068 |
|
fp = fopen(oname, "rb+"); |
1069 |
< |
if (fp == NULL) |
1070 |
< |
break; /* must be end of modifier */ |
1069 |
> |
if (fp == NULL) { |
1070 |
> |
if (j) |
1071 |
> |
break; /* assume end of modifier */ |
1072 |
> |
sprintf(errmsg, "missing recover file '%s'", |
1073 |
> |
oname); |
1074 |
> |
error(USER, errmsg); |
1075 |
> |
} |
1076 |
|
nvals = lseek(fileno(fp), 0, SEEK_END); |
1077 |
|
if (nvals <= 0) { |
1078 |
|
lastout = 0; /* empty output, quit here */ |
1127 |
|
error(WARNING, "no output files to recover"); |
1128 |
|
return; |
1129 |
|
} |
1130 |
+ |
if (raysleft && lastout >= raysleft) { |
1131 |
+ |
error(WARNING, "output appears to be complete"); |
1132 |
+ |
/* XXX should read & discard input? */ |
1133 |
+ |
quit(0); |
1134 |
+ |
} |
1135 |
|
/* seek on all files */ |
1136 |
|
nvals = lastout * outvsiz; |
1137 |
|
lu_doall(&ofiletab, myseeko, &nvals); |
1138 |
< |
/* discard input */ |
1138 |
> |
/* skip repeated input */ |
1139 |
|
for (nvals = 0; nvals < lastout; nvals++) |
1140 |
|
if (getinp(oname, fin) <= 0) |
1141 |
|
error(USER, "unexpected EOF on input"); |