7 |
|
|
8 |
|
#include "standard.h" |
9 |
|
#include <ctype.h> |
10 |
+ |
#include <signal.h> |
11 |
|
#include "platform.h" |
12 |
|
#include "rtprocess.h" |
13 |
|
#include "selcall.h" |
64 |
|
int bsiz; /* ray tree buffer length */ |
65 |
|
char *buf; /* ray tree buffer */ |
66 |
|
int nbr; /* number of bytes from rtrace */ |
67 |
< |
}; /* rtrace process */ |
67 |
> |
}; /* rtrace process buffer */ |
68 |
|
|
69 |
|
/* rtrace command and defaults */ |
70 |
< |
char *rtargv[256] = { "rtrace", "-dt", "0", "-dj", ".5", "-dr", "3", |
71 |
< |
"-ab", "1", "-ad", "128", }; |
70 |
> |
char *rtargv[256] = { "rtrace", "-dj", ".5", "-dr", "3", |
71 |
> |
"-ab", "1", "-ad", "128", "-lr", "-10", }; |
72 |
|
int rtargc = 11; |
73 |
|
/* overriding rtrace options */ |
74 |
< |
char *myrtopts[] = { "-o~~TmWdp", "-h-", |
75 |
< |
"-x", "1", "-y", "0", |
75 |
< |
"-as", "0", "-aa", "0", NULL }; |
74 |
> |
char *myrtopts[] = { "-o~~TmWdp", "-h-", "-x", "1", "-y", "0", |
75 |
> |
"-dt", "0", "-as", "0", "-aa", "0", NULL }; |
76 |
|
|
77 |
|
struct rtproc rt0; /* head of rtrace process list */ |
78 |
|
|
79 |
|
struct rtproc *rt_unproc = NULL; /* unprocessed ray trees */ |
80 |
|
|
81 |
|
char persistfn[] = "pfXXXXXX"; /* persist file name */ |
82 |
– |
char fmt[8]; /* rtrace i/o format */ |
82 |
|
|
83 |
|
int gargc; /* global argc */ |
84 |
|
char **gargv; /* global argv */ |
106 |
|
|
107 |
|
MODCONT *addmodifier(char *modn, char *outf, char *binv); |
108 |
|
|
110 |
– |
int done_rprocs(struct rtproc *rtp); |
109 |
|
void init(int np); |
110 |
< |
void tracecontribs(FILE *fp); |
110 |
> |
int done_rprocs(struct rtproc *rtp); |
111 |
> |
void trace_contribs(FILE *fp); |
112 |
|
struct rtproc *wait_rproc(void); |
113 |
|
struct rtproc *get_rproc(void); |
114 |
|
void queue_raytree(struct rtproc *rtp); |
123 |
|
setformat(const char *fmt) |
124 |
|
{ |
125 |
|
switch (fmt[0]) { |
127 |
– |
case 'a': |
126 |
|
case 'f': |
127 |
|
case 'd': |
128 |
+ |
SET_FILE_BINARY(stdin); |
129 |
+ |
/* fall through */ |
130 |
+ |
case 'a': |
131 |
|
inpfmt = fmt[0]; |
132 |
|
break; |
133 |
|
default: |
160 |
|
int nprocs = 1; |
161 |
|
char *curout = NULL; |
162 |
|
char *binval = NULL; |
163 |
+ |
char fmt[8]; |
164 |
|
int i, j; |
165 |
|
/* global program name */ |
166 |
|
gargv = argv; |
204 |
|
break; |
205 |
|
case 'f': /* file or i/o format */ |
206 |
|
if (!argv[i][2]) { |
207 |
+ |
char *fpath; |
208 |
|
if (i >= argc-1) break; |
209 |
< |
fcompile(argv[++i]); |
209 |
> |
fpath = getpath(argv[++i], |
210 |
> |
getrlibpath(), R_OK); |
211 |
> |
if (fpath == NULL) { |
212 |
> |
sprintf(errmsg, |
213 |
> |
"cannot find file '%s'", |
214 |
> |
argv[i]); |
215 |
> |
error(USER, errmsg); |
216 |
> |
} |
217 |
> |
fcompile(fpath); |
218 |
|
continue; |
219 |
|
} |
220 |
|
setformat(argv[i]+2); |
280 |
|
execv(rtpath, rtargv); |
281 |
|
perror(rtpath); /* execv() should not return */ |
282 |
|
exit(1); |
283 |
< |
} else if (nprocs > 1) { /* add persist file if parallel */ |
283 |
> |
} |
284 |
> |
if (nprocs > 1) { /* add persist file if parallel */ |
285 |
|
rtargv[rtargc++] = "-PP"; |
286 |
|
rtargv[rtargc++] = mktemp(persistfn); |
287 |
|
} |
295 |
|
rtargv[rtargc] = NULL; |
296 |
|
/* start rtrace & compute contributions */ |
297 |
|
init(nprocs); |
298 |
< |
tracecontribs(stdin); |
298 |
> |
trace_contribs(stdin); |
299 |
|
quit(0); |
300 |
|
} |
301 |
|
|
347 |
|
exit(status); /* flushes all output streams */ |
348 |
|
} |
349 |
|
|
350 |
< |
/* start rtrace and initialize buffers */ |
350 |
> |
/* start rtrace processes and initialize */ |
351 |
|
void |
352 |
|
init(int np) |
353 |
|
{ |
500 |
|
LUENT *lep; |
501 |
|
|
502 |
|
if (ospec == NULL) { /* use stdout? */ |
503 |
< |
if (!using_stdout && header) |
504 |
< |
printheader(stdout); |
503 |
> |
if (!using_stdout) { |
504 |
> |
if (outfmt != 'a') |
505 |
> |
SET_FILE_BINARY(stdout); |
506 |
> |
if (header) |
507 |
> |
printheader(stdout); |
508 |
> |
} |
509 |
|
using_stdout = 1; |
510 |
|
return stdout; |
511 |
|
} |
547 |
|
if (lep->key == NULL) /* new entry */ |
548 |
|
lep->key = strcpy((char *)malloc(strlen(ofname)+1), ofname); |
549 |
|
if (lep->data == NULL) { /* open output file */ |
550 |
< |
FILE *fp = fopen(ofname, "w"); |
550 |
> |
FILE *fp; |
551 |
|
int i; |
552 |
+ |
if (ofname[0] == '!') /* output to command */ |
553 |
+ |
fp = popen(ofname+1, "w"); |
554 |
+ |
else |
555 |
+ |
fp = fopen(ofname, "w"); |
556 |
|
if (fp == NULL) { |
557 |
|
sprintf(errmsg, "cannot open '%s' for writing", ofname); |
558 |
|
error(SYSTEM, errmsg); |
559 |
|
} |
560 |
+ |
if (outfmt != 'a') |
561 |
+ |
SET_FILE_BINARY(fp); |
562 |
|
if (header) |
563 |
|
printheader(fp); |
564 |
|
/* play catch-up */ |
864 |
|
|
865 |
|
/* trace ray contributions (main loop) */ |
866 |
|
void |
867 |
< |
tracecontribs(FILE *fin) |
867 |
> |
trace_contribs(FILE *fin) |
868 |
|
{ |
869 |
|
char inpbuf[128]; |
870 |
|
int iblen; |