1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Executive program for oconv, rpict and pfilt |
6 |
|
*/ |
7 |
|
|
8 |
|
#include "standard.h" |
9 |
< |
#include "paths.h" |
9 |
> |
|
10 |
|
#include <ctype.h> |
11 |
< |
#include <sys/types.h> |
11 |
> |
#include <time.h> |
12 |
> |
#include <signal.h> |
13 |
|
|
14 |
+ |
#include "platform.h" |
15 |
+ |
#include "rtprocess.h" |
16 |
+ |
#include "view.h" |
17 |
+ |
#include "paths.h" |
18 |
+ |
#include "vars.h" |
19 |
|
|
20 |
< |
typedef struct { |
21 |
< |
char *name; /* variable name */ |
22 |
< |
short nick; /* # characters required for nickname */ |
23 |
< |
short nass; /* # assignments made */ |
24 |
< |
char *value; /* assigned value(s) */ |
25 |
< |
int (*fixval)(); /* assignment checking function */ |
26 |
< |
} VARIABLE; |
20 |
> |
#if defined(_WIN32) || defined(_WIN64) |
21 |
> |
#define DELCMD "del" |
22 |
> |
#define RENAMECMD "rename" |
23 |
> |
#else |
24 |
> |
#define DELCMD "rm -f" |
25 |
> |
#define RENAMECMD "mv" |
26 |
> |
#include <sys/types.h> |
27 |
> |
#include <sys/wait.h> |
28 |
> |
#include <signal.h> |
29 |
> |
#endif |
30 |
|
|
31 |
< |
int onevalue(), catvalues(), boolvalue(), |
32 |
< |
qualvalue(), fltvalue(), intvalue(); |
33 |
< |
|
34 |
< |
/* variables */ |
35 |
< |
#define OBJECT 0 /* object files */ |
36 |
< |
#define SCENE 1 /* scene files */ |
37 |
< |
#define MATERIAL 2 /* material files */ |
38 |
< |
#define ILLUM 3 /* mkillum input files */ |
39 |
< |
#define MKILLUM 4 /* mkillum options */ |
40 |
< |
#define RENDER 5 /* rendering options */ |
41 |
< |
#define OCONV 6 /* oconv options */ |
42 |
< |
#define PFILT 7 /* pfilt options */ |
37 |
< |
#define VIEW 8 /* view(s) for picture(s) */ |
38 |
< |
#define ZONE 9 /* simulation zone */ |
39 |
< |
#define QUALITY 10 /* desired rendering quality */ |
31 |
> |
/* variables (alphabetical by name) */ |
32 |
> |
#define AMBFILE 0 /* ambient file name */ |
33 |
> |
#define DETAIL 1 /* level of scene detail */ |
34 |
> |
#define EXPOSURE 2 /* picture exposure setting */ |
35 |
> |
#define EYESEP 3 /* interocular distance */ |
36 |
> |
#define ILLUM 4 /* mkillum input files */ |
37 |
> |
#define INDIRECT 5 /* indirection in lighting */ |
38 |
> |
#define MATERIAL 6 /* material files */ |
39 |
> |
#define MKILLUM 7 /* mkillum options */ |
40 |
> |
#define MKPMAP 8 /* mkpmap options */ |
41 |
> |
#define OBJECT 9 /* object files */ |
42 |
> |
#define OCONV 10 /* oconv options */ |
43 |
|
#define OCTREE 11 /* octree file name */ |
44 |
< |
#define PICTURE 12 /* picture file root name */ |
45 |
< |
#define AMBFILE 13 /* ambient file name */ |
46 |
< |
#define OPTFILE 14 /* rendering options file */ |
47 |
< |
#define EXPOSURE 15 /* picture exposure setting */ |
48 |
< |
#define RESOLUTION 16 /* maximum picture resolution */ |
49 |
< |
#define UP 17 /* view up (X, Y or Z) */ |
50 |
< |
#define INDIRECT 18 /* indirection in lighting */ |
51 |
< |
#define DETAIL 19 /* level of scene detail */ |
52 |
< |
#define PENUMBRAS 20 /* shadow penumbras are desired */ |
53 |
< |
#define VARIABILITY 21 /* level of light variability */ |
54 |
< |
#define REPORT 22 /* report frequency and errfile */ |
55 |
< |
#define RAWFILE 23 /* raw picture file root name */ |
56 |
< |
#define ZFILE 24 /* distance file root name */ |
44 |
> |
#define OPTFILE 12 /* rendering options file */ |
45 |
> |
#define PCMAP 13 /* caustic photon map */ |
46 |
> |
#define PENUMBRAS 14 /* shadow penumbras are desired */ |
47 |
> |
#define PFILT 15 /* pfilt options */ |
48 |
> |
#define PGMAP 16 /* global photon map */ |
49 |
> |
#define PICTURE 17 /* picture file root name */ |
50 |
> |
#define QUALITY 18 /* desired rendering quality */ |
51 |
> |
#define RAWFILE 19 /* raw picture file root name */ |
52 |
> |
#define RENDER 20 /* rendering options */ |
53 |
> |
#define REPORT 21 /* report frequency and errfile */ |
54 |
> |
#define RESOLUTION 22 /* maximum picture resolution */ |
55 |
> |
#define RPICT 23 /* rpict parameters */ |
56 |
> |
#define RVU 24 /* rvu parameters */ |
57 |
> |
#define SCENE 25 /* scene files */ |
58 |
> |
#define UP 26 /* view up (X, Y or Z) */ |
59 |
> |
#define VARIABILITY 27 /* level of light variability */ |
60 |
> |
#define VIEWS 28 /* view(s) for picture(s) */ |
61 |
> |
#define ZFILE 29 /* distance file root name */ |
62 |
> |
#define ZONE 30 /* simulation zone */ |
63 |
|
/* total number of variables */ |
64 |
< |
#define NVARS 25 |
64 |
> |
int NVARS = 31; |
65 |
|
|
66 |
< |
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
67 |
< |
{"objects", 3, 0, NULL, catvalues}, |
68 |
< |
{"scene", 3, 0, NULL, catvalues}, |
69 |
< |
{"materials", 3, 0, NULL, catvalues}, |
66 |
> |
VARIABLE vv[] = { /* variable-value pairs */ |
67 |
> |
{"AMBFILE", 3, 0, NULL, onevalue}, |
68 |
> |
{"DETAIL", 3, 0, NULL, qualvalue}, |
69 |
> |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
70 |
> |
{"EYESEP", 3, 0, NULL, fltvalue}, |
71 |
|
{"illum", 3, 0, NULL, catvalues}, |
72 |
+ |
{"INDIRECT", 3, 0, NULL, intvalue}, |
73 |
+ |
{"materials", 3, 0, NULL, catvalues}, |
74 |
|
{"mkillum", 3, 0, NULL, catvalues}, |
75 |
< |
{"render", 3, 0, NULL, catvalues}, |
75 |
> |
{"mkpmap", 3, 0, NULL, catvalues}, |
76 |
> |
{"objects", 3, 0, NULL, catvalues}, |
77 |
|
{"oconv", 3, 0, NULL, catvalues}, |
65 |
– |
{"pfilt", 2, 0, NULL, catvalues}, |
66 |
– |
{"view", 2, 0, NULL, NULL}, |
67 |
– |
{"ZONE", 2, 0, NULL, onevalue}, |
68 |
– |
{"QUALITY", 3, 0, NULL, qualvalue}, |
78 |
|
{"OCTREE", 3, 0, NULL, onevalue}, |
70 |
– |
{"PICTURE", 3, 0, NULL, onevalue}, |
71 |
– |
{"AMBFILE", 3, 0, NULL, onevalue}, |
79 |
|
{"OPTFILE", 3, 0, NULL, onevalue}, |
80 |
< |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
80 |
> |
{"PCMAP", 2, 0, NULL, onevalue}, |
81 |
> |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
82 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
83 |
> |
{"PGMAP", 2, 0, NULL, onevalue}, |
84 |
> |
{"PICTURE", 3, 0, NULL, onevalue}, |
85 |
> |
{"QUALITY", 3, 0, NULL, qualvalue}, |
86 |
> |
{"RAWFILE", 3, 0, NULL, onevalue}, |
87 |
> |
{"render", 3, 0, NULL, catvalues}, |
88 |
> |
{"REPORT", 3, 0, NULL, onevalue}, |
89 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
90 |
+ |
{"rpict", 3, 0, NULL, catvalues}, |
91 |
+ |
{"rvu", 3, 0, NULL, catvalues}, |
92 |
+ |
{"scene", 3, 0, NULL, catvalues}, |
93 |
|
{"UP", 2, 0, NULL, onevalue}, |
76 |
– |
{"INDIRECT", 3, 0, NULL, intvalue}, |
77 |
– |
{"DETAIL", 3, 0, NULL, qualvalue}, |
78 |
– |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
94 |
|
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
95 |
< |
{"REPORT", 3, 0, NULL, onevalue}, |
81 |
< |
{"RAWFILE", 3, 0, NULL, onevalue}, |
95 |
> |
{"view", 2, 0, NULL, NULL}, |
96 |
|
{"ZFILE", 2, 0, NULL, onevalue}, |
97 |
+ |
{"ZONE", 2, 0, NULL, onevalue}, |
98 |
|
}; |
99 |
|
|
85 |
– |
VARIABLE *matchvar(); |
86 |
– |
char *nvalue(); |
87 |
– |
|
88 |
– |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
89 |
– |
|
90 |
– |
#define vnam(vc) (vv[vc].name) |
91 |
– |
#define vdef(vc) (vv[vc].nass) |
92 |
– |
#define vval(vc) (vv[vc].value) |
93 |
– |
#define vint(vc) atoi(vval(vc)) |
94 |
– |
#define vlet(vc) UPPER(vval(vc)[0]) |
95 |
– |
#define vscale vlet |
96 |
– |
#define vbool(vc) (vlet(vc)=='T') |
97 |
– |
|
98 |
– |
#define HIGH 'H' |
99 |
– |
#define MEDIUM 'M' |
100 |
– |
#define LOW 'L' |
101 |
– |
|
100 |
|
/* overture calculation file */ |
101 |
< |
#ifdef NIX |
102 |
< |
char overfile[] = "overture.unf"; |
101 |
> |
#ifdef NULL_DEVICE |
102 |
> |
char overfile[] = NULL_DEVICE; |
103 |
|
#else |
104 |
< |
char overfile[] = "/dev/null"; |
104 |
> |
char overfile[] = "overture.unf"; |
105 |
|
#endif |
106 |
|
|
109 |
– |
extern time_t fdate(), time(); |
107 |
|
|
108 |
|
time_t scenedate; /* date of latest scene or object file */ |
109 |
|
time_t octreedate; /* date of octree */ |
115 |
|
char *oct1name; /* name of post-mkillum octree */ |
116 |
|
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
117 |
|
|
118 |
+ |
char *pgmapname; /* name of global photon map */ |
119 |
+ |
time_t pgmapdate; /* date of global photon map (>= oct1date) */ |
120 |
+ |
char *pcmapname; /* name of caustic photon map */ |
121 |
+ |
time_t pcmapdate; /* date of caustic photon map (>= oct1date) */ |
122 |
+ |
|
123 |
|
int nowarn = 0; /* no warnings */ |
124 |
|
int explicate = 0; /* explicate variables */ |
125 |
|
int silent = 0; /* do work silently */ |
126 |
|
int touchonly = 0; /* touch files only */ |
127 |
< |
int noaction = 0; /* don't do anything */ |
127 |
> |
int nprocs = 1; /* maximum executing processes */ |
128 |
|
int sayview = 0; /* print view out */ |
129 |
< |
char *rvdevice = NULL; /* rview output device */ |
129 |
> |
char *rvdevice = NULL; /* rvu output device */ |
130 |
|
char *viewselect = NULL; /* specific view only */ |
131 |
|
|
132 |
+ |
#define DEF_RPICT_PATH "rpict" /* default rpict path */ |
133 |
+ |
|
134 |
+ |
/* command paths */ |
135 |
+ |
char c_oconv[256] = "oconv"; |
136 |
+ |
char c_mkillum[256] = "mkillum"; |
137 |
+ |
char c_mkpmap[256] = "mkpmap"; |
138 |
+ |
char c_rvu[256] = "rvu"; |
139 |
+ |
char c_rpict[256] = DEF_RPICT_PATH; |
140 |
+ |
char c_rpiece[] = "rpiece"; |
141 |
+ |
char c_pfilt[256] = "pfilt"; |
142 |
+ |
|
143 |
|
int overture = 0; /* overture calculation needed */ |
144 |
|
|
145 |
+ |
int children_running = 0; /* set negative in children */ |
146 |
+ |
|
147 |
|
char *progname; /* global argv[0] */ |
148 |
|
char *rifname; /* global rad input file name */ |
149 |
|
|
150 |
< |
char radname[MAXPATH]; /* root Radiance file name */ |
150 |
> |
char radname[PATH_MAX]; /* root Radiance file name */ |
151 |
|
|
152 |
+ |
#define inchild() (children_running < 0) |
153 |
|
|
154 |
< |
main(argc, argv) |
155 |
< |
int argc; |
156 |
< |
char *argv[]; |
154 |
> |
static void rootname(char *rn, char *fn); |
155 |
> |
static time_t checklast(char *fnames); |
156 |
> |
static char * newfname(char *orig, int pred); |
157 |
> |
static void checkfiles(void); |
158 |
> |
static void getoctcube(double org[3], double *sizp); |
159 |
> |
static void setdefaults(void); |
160 |
> |
static void oconv(void); |
161 |
> |
static void mkpmap(void); |
162 |
> |
static char * addarg(char *op, char *arg); |
163 |
> |
static void oconvopts(char *oo); |
164 |
> |
static void mkillumopts(char *mo); |
165 |
> |
static void mkpmapopts(char *mo); |
166 |
> |
static void checkambfile(void); |
167 |
> |
static double ambval(void); |
168 |
> |
static void renderopts(char *op, char *po); |
169 |
> |
static void lowqopts(char *op, char *po); |
170 |
> |
static void medqopts(char *op, char *po); |
171 |
> |
static void hiqopts(char *op, char *po); |
172 |
> |
static void xferopts(char *ro); |
173 |
> |
static void pfiltopts(char *po); |
174 |
> |
static int matchword(char *s1, char *s2); |
175 |
> |
static char * specview(char *vs); |
176 |
> |
static char * getview(int n, char *vn); |
177 |
> |
static int myprintview(char *vopts, FILE *fp); |
178 |
> |
static void rvu(char *opts, char *po); |
179 |
> |
static void rpict(char *opts, char *po); |
180 |
> |
static int touch(char *fn); |
181 |
> |
static int runcom(char *cs); |
182 |
> |
static int rmfile(char *fn); |
183 |
> |
static int mvfile(char *fold, char *fnew); |
184 |
> |
static int next_process(int reserve); |
185 |
> |
static void wait_process(int all); |
186 |
> |
static void finish_process(void); |
187 |
> |
static void badvalue(int vc); |
188 |
> |
static void syserr(char *s); |
189 |
> |
|
190 |
> |
|
191 |
> |
int |
192 |
> |
main( |
193 |
> |
int argc, |
194 |
> |
char *argv[] |
195 |
> |
) |
196 |
|
{ |
197 |
|
char ropts[512]; |
198 |
|
char popts[64]; |
206 |
|
silent++; |
207 |
|
break; |
208 |
|
case 'n': |
209 |
< |
noaction++; |
209 |
> |
nprocs = 0; |
210 |
|
break; |
211 |
+ |
case 'N': |
212 |
+ |
nprocs = atoi(argv[++i]); |
213 |
+ |
if (nprocs < 0) |
214 |
+ |
nprocs = 0; |
215 |
+ |
break; |
216 |
|
case 't': |
217 |
|
touchonly++; |
218 |
|
break; |
240 |
|
/* assign Radiance root file name */ |
241 |
|
rootname(radname, rifname); |
242 |
|
/* load variable values */ |
243 |
< |
load(rifname); |
243 |
> |
loadvars(rifname); |
244 |
|
/* get any additional assignments */ |
245 |
|
for (i++; i < argc; i++) |
246 |
< |
setvariable(argv[i]); |
246 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
247 |
> |
fprintf(stderr, "%s: unknown variable: %s\n", |
248 |
> |
progname, argv[i]); |
249 |
> |
quit(1); |
250 |
> |
} |
251 |
|
/* check assignments */ |
252 |
|
checkvalues(); |
253 |
|
/* check files and dates */ |
256 |
|
setdefaults(); |
257 |
|
/* print all values if requested */ |
258 |
|
if (explicate) |
259 |
< |
printvals(); |
259 |
> |
printvars(stdout); |
260 |
|
/* build octree (and run mkillum) */ |
261 |
|
oconv(); |
262 |
+ |
/* run mkpmap if indicated */ |
263 |
+ |
mkpmap(); |
264 |
|
/* check date on ambient file */ |
265 |
|
checkambfile(); |
266 |
|
/* run simulation */ |
267 |
|
renderopts(ropts, popts); |
268 |
|
xferopts(ropts); |
269 |
|
if (rvdevice != NULL) |
270 |
< |
rview(ropts, popts); |
270 |
> |
rvu(ropts, popts); |
271 |
|
else |
272 |
|
rpict(ropts, popts); |
273 |
< |
exit(0); |
273 |
> |
quit(0); |
274 |
|
userr: |
275 |
|
fprintf(stderr, |
276 |
< |
"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
276 |
> |
"Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
277 |
|
progname); |
278 |
< |
exit(1); |
278 |
> |
quit(1); |
279 |
> |
return 1; /* pro forma return */ |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
rootname(rn, fn) /* remove tail from end of fn */ |
284 |
< |
register char *rn, *fn; |
283 |
> |
static void |
284 |
> |
rootname( /* remove tail from end of fn */ |
285 |
> |
char *rn, |
286 |
> |
char *fn |
287 |
> |
) |
288 |
|
{ |
289 |
|
char *tp, *dp; |
290 |
|
|
291 |
< |
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
291 |
> |
for (tp = NULL, dp = rn; (*rn = *fn++); rn++) |
292 |
|
if (ISDIRSEP(*rn)) |
293 |
|
dp = rn; |
294 |
|
else if (*rn == '.') |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
< |
#define NOCHAR 127 /* constant for character to delete */ |
302 |
< |
|
303 |
< |
|
304 |
< |
load(rfname) /* load Radiance simulation file */ |
235 |
< |
char *rfname; |
301 |
> |
static time_t |
302 |
> |
checklast( /* check files and find most recent */ |
303 |
> |
char *fnames |
304 |
> |
) |
305 |
|
{ |
306 |
< |
FILE *fp; |
238 |
< |
char buf[512]; |
239 |
< |
register char *cp; |
240 |
< |
|
241 |
< |
if (rfname == NULL) |
242 |
< |
fp = stdin; |
243 |
< |
else if ((fp = fopen(rfname, "r")) == NULL) |
244 |
< |
syserr(rfname); |
245 |
< |
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
246 |
< |
for (cp = buf; *cp; cp++) { |
247 |
< |
switch (*cp) { |
248 |
< |
case '\\': |
249 |
< |
*cp++ = NOCHAR; |
250 |
< |
continue; |
251 |
< |
case '#': |
252 |
< |
*cp = '\0'; |
253 |
< |
break; |
254 |
< |
default: |
255 |
< |
continue; |
256 |
< |
} |
257 |
< |
break; |
258 |
< |
} |
259 |
< |
setvariable(buf); |
260 |
< |
} |
261 |
< |
fclose(fp); |
262 |
< |
} |
263 |
< |
|
264 |
< |
|
265 |
< |
setvariable(ass) /* assign variable according to string */ |
266 |
< |
register char *ass; |
267 |
< |
{ |
268 |
< |
char varname[32]; |
269 |
< |
int n; |
270 |
< |
register char *cp; |
271 |
< |
register VARIABLE *vp; |
272 |
< |
register int i; |
273 |
< |
|
274 |
< |
while (isspace(*ass)) /* skip leading space */ |
275 |
< |
ass++; |
276 |
< |
cp = varname; /* extract name */ |
277 |
< |
while (cp < varname+sizeof(varname)-1 |
278 |
< |
&& *ass && !isspace(*ass) && *ass != '=') |
279 |
< |
*cp++ = *ass++; |
280 |
< |
*cp = '\0'; |
281 |
< |
if (!varname[0]) |
282 |
< |
return; /* no variable name! */ |
283 |
< |
/* trim value */ |
284 |
< |
while (isspace(*ass) || *ass == '=') |
285 |
< |
ass++; |
286 |
< |
for (n = strlen(ass); n > 0; n--) |
287 |
< |
if (!isspace(ass[n-1])) |
288 |
< |
break; |
289 |
< |
if (!n && !nowarn) { |
290 |
< |
fprintf(stderr, "%s: warning - missing value for variable '%s'\n", |
291 |
< |
progname, varname); |
292 |
< |
return; |
293 |
< |
} |
294 |
< |
/* match variable from list */ |
295 |
< |
vp = matchvar(varname); |
296 |
< |
if (vp == NULL) { |
297 |
< |
fprintf(stderr, "%s: unknown variable '%s'\n", |
298 |
< |
progname, varname); |
299 |
< |
exit(1); |
300 |
< |
} |
301 |
< |
/* assign new value */ |
302 |
< |
if (i = vp->nass) { |
303 |
< |
cp = vp->value; |
304 |
< |
while (i--) |
305 |
< |
while (*cp++) |
306 |
< |
; |
307 |
< |
i = cp - vp->value; |
308 |
< |
vp->value = realloc(vp->value, i+n+1); |
309 |
< |
} else |
310 |
< |
vp->value = malloc(n+1); |
311 |
< |
if (vp->value == NULL) |
312 |
< |
syserr(progname); |
313 |
< |
cp = vp->value+i; /* copy value, squeezing spaces */ |
314 |
< |
*cp = *ass; |
315 |
< |
for (i = 1; i <= n; i++) { |
316 |
< |
if (ass[i] == NOCHAR) |
317 |
< |
continue; |
318 |
< |
if (isspace(*cp)) |
319 |
< |
while (isspace(ass[i])) |
320 |
< |
i++; |
321 |
< |
*++cp = ass[i]; |
322 |
< |
} |
323 |
< |
if (isspace(*cp)) /* remove trailing space */ |
324 |
< |
*cp = '\0'; |
325 |
< |
vp->nass++; |
326 |
< |
} |
327 |
< |
|
328 |
< |
|
329 |
< |
VARIABLE * |
330 |
< |
matchvar(nam) /* match a variable by its name */ |
331 |
< |
char *nam; |
332 |
< |
{ |
333 |
< |
int n = strlen(nam); |
334 |
< |
register int i; |
335 |
< |
|
336 |
< |
for (i = 0; i < NVARS; i++) |
337 |
< |
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
338 |
< |
return(vv+i); |
339 |
< |
return(NULL); |
340 |
< |
} |
341 |
< |
|
342 |
< |
|
343 |
< |
char * |
344 |
< |
nvalue(vp, n) /* return nth variable value */ |
345 |
< |
VARIABLE *vp; |
346 |
< |
register int n; |
347 |
< |
{ |
348 |
< |
register char *cp; |
349 |
< |
|
350 |
< |
if (vp == NULL | n < 0 | n >= vp->nass) |
351 |
< |
return(NULL); |
352 |
< |
cp = vp->value; |
353 |
< |
while (n--) |
354 |
< |
while (*cp++) |
355 |
< |
; |
356 |
< |
return(cp); |
357 |
< |
} |
358 |
< |
|
359 |
< |
|
360 |
< |
checkvalues() /* check assignments */ |
361 |
< |
{ |
362 |
< |
register int i; |
363 |
< |
|
364 |
< |
for (i = 0; i < NVARS; i++) |
365 |
< |
if (vv[i].fixval != NULL) |
366 |
< |
(*vv[i].fixval)(vv+i); |
367 |
< |
} |
368 |
< |
|
369 |
< |
|
370 |
< |
onevalue(vp) /* only one assignment for this variable */ |
371 |
< |
register VARIABLE *vp; |
372 |
< |
{ |
373 |
< |
if (vp->nass < 2) |
374 |
< |
return; |
375 |
< |
if (!nowarn) |
376 |
< |
fprintf(stderr, |
377 |
< |
"%s: warning - multiple assignment of variable '%s'\n", |
378 |
< |
progname, vp->name); |
379 |
< |
do |
380 |
< |
vp->value += strlen(vp->value)+1; |
381 |
< |
while (--vp->nass > 1); |
382 |
< |
} |
383 |
< |
|
384 |
< |
|
385 |
< |
catvalues(vp) /* concatenate variable values */ |
386 |
< |
register VARIABLE *vp; |
387 |
< |
{ |
388 |
< |
register char *cp; |
389 |
< |
|
390 |
< |
if (vp->nass < 2) |
391 |
< |
return; |
392 |
< |
for (cp = vp->value; vp->nass > 1; vp->nass--) { |
393 |
< |
while (*cp) |
394 |
< |
cp++; |
395 |
< |
*cp++ = ' '; |
396 |
< |
} |
397 |
< |
} |
398 |
< |
|
399 |
< |
|
400 |
< |
int |
401 |
< |
badmatch(tv, cv) /* case insensitive truncated comparison */ |
402 |
< |
register char *tv, *cv; |
403 |
< |
{ |
404 |
< |
if (!*tv) return(1); /* null string cannot match */ |
405 |
< |
do |
406 |
< |
if (UPPER(*tv) != *cv++) |
407 |
< |
return(1); |
408 |
< |
while (*++tv); |
409 |
< |
return(0); /* OK */ |
410 |
< |
} |
411 |
< |
|
412 |
< |
|
413 |
< |
boolvalue(vp) /* check boolean for legal values */ |
414 |
< |
register VARIABLE *vp; |
415 |
< |
{ |
416 |
< |
if (!vp->nass) return; |
417 |
< |
onevalue(vp); |
418 |
< |
switch (UPPER(vp->value[0])) { |
419 |
< |
case 'T': |
420 |
< |
if (badmatch(vp->value, "TRUE")) break; |
421 |
< |
return; |
422 |
< |
case 'F': |
423 |
< |
if (badmatch(vp->value, "FALSE")) break; |
424 |
< |
return; |
425 |
< |
} |
426 |
< |
fprintf(stderr, "%s: illegal value for boolean variable '%s'\n", |
427 |
< |
progname, vp->name); |
428 |
< |
exit(1); |
429 |
< |
} |
430 |
< |
|
431 |
< |
|
432 |
< |
qualvalue(vp) /* check qualitative var. for legal values */ |
433 |
< |
register VARIABLE *vp; |
434 |
< |
{ |
435 |
< |
if (!vp->nass) return; |
436 |
< |
onevalue(vp); |
437 |
< |
switch (UPPER(vp->value[0])) { |
438 |
< |
case 'L': |
439 |
< |
if (badmatch(vp->value, "LOW")) break; |
440 |
< |
return; |
441 |
< |
case 'M': |
442 |
< |
if (badmatch(vp->value, "MEDIUM")) break; |
443 |
< |
return; |
444 |
< |
case 'H': |
445 |
< |
if (badmatch(vp->value, "HIGH")) break; |
446 |
< |
return; |
447 |
< |
} |
448 |
< |
fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n", |
449 |
< |
progname, vp->name); |
450 |
< |
exit(1); |
451 |
< |
} |
452 |
< |
|
453 |
< |
|
454 |
< |
intvalue(vp) /* check integer variable for legal values */ |
455 |
< |
register VARIABLE *vp; |
456 |
< |
{ |
457 |
< |
if (!vp->nass) return; |
458 |
< |
onevalue(vp); |
459 |
< |
if (isint(vp->value)) return; |
460 |
< |
fprintf(stderr, "%s: illegal value for integer variable '%s'\n", |
461 |
< |
progname, vp->name); |
462 |
< |
exit(1); |
463 |
< |
} |
464 |
< |
|
465 |
< |
|
466 |
< |
fltvalue(vp) /* check float variable for legal values */ |
467 |
< |
register VARIABLE *vp; |
468 |
< |
{ |
469 |
< |
if (!vp->nass) return; |
470 |
< |
onevalue(vp); |
471 |
< |
if (isflt(vp->value)) return; |
472 |
< |
fprintf(stderr, "%s: illegal value for real variable '%s'\n", |
473 |
< |
progname, vp->name); |
474 |
< |
exit(1); |
475 |
< |
} |
476 |
< |
|
477 |
< |
|
478 |
< |
time_t |
479 |
< |
checklast(fnames) /* check files and find most recent */ |
480 |
< |
register char *fnames; |
481 |
< |
{ |
482 |
< |
char thisfile[MAXPATH]; |
306 |
> |
char thisfile[PATH_MAX]; |
307 |
|
time_t thisdate, lastdate = 0; |
484 |
– |
register char *cp; |
308 |
|
|
309 |
|
if (fnames == NULL) |
310 |
|
return(0); |
311 |
< |
while (*fnames) { |
312 |
< |
while (isspace(*fnames)) fnames++; |
313 |
< |
cp = thisfile; |
314 |
< |
while (*fnames && !isspace(*fnames)) |
315 |
< |
*cp++ = *fnames++; |
316 |
< |
*cp = '\0'; |
311 |
> |
while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { |
312 |
> |
if (thisfile[0] == '!' || |
313 |
> |
(thisfile[0] == '\\' && thisfile[1] == '!')) { |
314 |
> |
if (!lastdate) |
315 |
> |
lastdate = 1; |
316 |
> |
continue; |
317 |
> |
} |
318 |
|
if (!(thisdate = fdate(thisfile))) |
319 |
|
syserr(thisfile); |
320 |
|
if (thisdate > lastdate) |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
< |
char * |
328 |
< |
newfname(orig, pred) /* create modified file name */ |
329 |
< |
char *orig; |
330 |
< |
int pred; |
327 |
> |
static char * |
328 |
> |
newfname( /* create modified file name */ |
329 |
> |
char *orig, |
330 |
> |
int pred |
331 |
> |
) |
332 |
|
{ |
333 |
< |
extern char *rindex(); |
334 |
< |
register char *cp; |
510 |
< |
register int n; |
333 |
> |
char *cp; |
334 |
> |
int n; |
335 |
|
int suffix; |
336 |
|
|
337 |
|
n = 0; cp = orig; suffix = -1; /* suffix position, length */ |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
< |
checkfiles() /* check for existence and modified times */ |
353 |
> |
static void |
354 |
> |
checkfiles(void) /* check for existence and modified times */ |
355 |
|
{ |
356 |
+ |
char fntemp[256]; |
357 |
|
time_t objdate; |
358 |
|
|
359 |
|
if (!vdef(OCTREE)) { |
361 |
|
syserr(progname); |
362 |
|
sprintf(vval(OCTREE), "%s.oct", radname); |
363 |
|
vdef(OCTREE)++; |
364 |
+ |
} else if (vval(OCTREE)[0] == '!') { |
365 |
+ |
fprintf(stderr, "%s: illegal '%s' specification\n", |
366 |
+ |
progname, vnam(OCTREE)); |
367 |
+ |
quit(1); |
368 |
|
} |
369 |
|
octreedate = fdate(vval(OCTREE)); |
370 |
|
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
381 |
|
if (!octreedate & !scenedate & !illumdate) { |
382 |
|
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
383 |
|
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
384 |
< |
exit(1); |
384 |
> |
quit(1); |
385 |
|
} |
386 |
+ |
if (vdef(PGMAP)) { |
387 |
+ |
if (!*sskip2(vval(PGMAP),1)) { |
388 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
389 |
+ |
progname, vnam(PGMAP)); |
390 |
+ |
quit(1); |
391 |
+ |
} |
392 |
+ |
atos(fntemp, sizeof(fntemp), vval(PGMAP)); |
393 |
+ |
pgmapname = savqstr(fntemp); |
394 |
+ |
pgmapdate = fdate(pgmapname); |
395 |
+ |
} |
396 |
+ |
if (vdef(PCMAP)) { |
397 |
+ |
if (!*sskip2(vval(PCMAP),1)) { |
398 |
+ |
fprintf(stderr, "%s: '%s' missing # photons argument\n", |
399 |
+ |
progname, vnam(PCMAP)); |
400 |
+ |
quit(1); |
401 |
+ |
} |
402 |
+ |
atos(fntemp, sizeof(fntemp), vval(PCMAP)); |
403 |
+ |
pcmapname = savqstr(fntemp); |
404 |
+ |
pcmapdate = fdate(pcmapname); |
405 |
+ |
} |
406 |
|
matdate = checklast(vval(MATERIAL)); |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
< |
getoctcube(org, sizp) /* get octree bounding cube */ |
411 |
< |
double org[3], *sizp; |
410 |
> |
static void |
411 |
> |
getoctcube( /* get octree bounding cube */ |
412 |
> |
double org[3], |
413 |
> |
double *sizp |
414 |
> |
) |
415 |
|
{ |
563 |
– |
extern FILE *popen(); |
416 |
|
static double oorg[3], osiz = 0.; |
417 |
|
double min[3], max[3]; |
418 |
|
char buf[1024]; |
419 |
|
FILE *fp; |
420 |
< |
register int i; |
420 |
> |
int i; |
421 |
|
|
422 |
< |
if (osiz <= FTINY) |
423 |
< |
if (noaction && fdate(oct1name) < |
422 |
> |
if (osiz <= FTINY) { |
423 |
> |
if (!nprocs && fdate(oct1name) < |
424 |
|
(scenedate>illumdate?scenedate:illumdate)) { |
425 |
|
/* run getbbox */ |
426 |
|
sprintf(buf, "getbbox -w -h %s", |
433 |
|
fprintf(stderr, |
434 |
|
"%s: error reading bounding box from getbbox\n", |
435 |
|
progname); |
436 |
< |
exit(1); |
436 |
> |
quit(1); |
437 |
|
} |
438 |
|
for (i = 0; i < 3; i++) |
439 |
|
if (max[i] - min[i] > osiz) |
451 |
|
fprintf(stderr, |
452 |
|
"%s: error reading bounding cube from getinfo\n", |
453 |
|
progname); |
454 |
< |
exit(1); |
454 |
> |
quit(1); |
455 |
|
} |
456 |
|
pclose(fp); |
457 |
|
} |
458 |
+ |
} |
459 |
|
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
460 |
|
} |
461 |
|
|
462 |
|
|
463 |
< |
setdefaults() /* set default values for unassigned var's */ |
463 |
> |
static void |
464 |
> |
setdefaults(void) /* set default values for unassigned var's */ |
465 |
|
{ |
466 |
< |
double org[3], size; |
466 |
> |
double org[3], lim[3], size; |
467 |
|
char buf[128]; |
468 |
|
|
469 |
|
if (!vdef(ZONE)) { |
473 |
|
vval(ZONE) = savqstr(buf); |
474 |
|
vdef(ZONE)++; |
475 |
|
} |
476 |
+ |
if (!vdef(EYESEP)) { |
477 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
478 |
+ |
&org[0], &lim[0], &org[1], &lim[1], |
479 |
+ |
&org[2], &lim[2]) != 6) |
480 |
+ |
badvalue(ZONE); |
481 |
+ |
sprintf(buf, "%f", |
482 |
+ |
0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); |
483 |
+ |
vval(EYESEP) = savqstr(buf); |
484 |
+ |
vdef(EYESEP)++; |
485 |
+ |
} |
486 |
|
if (!vdef(INDIRECT)) { |
487 |
|
vval(INDIRECT) = "0"; |
488 |
|
vdef(INDIRECT)++; |
499 |
|
vval(PICTURE) = radname; |
500 |
|
vdef(PICTURE)++; |
501 |
|
} |
502 |
< |
if (!vdef(VIEW)) { |
503 |
< |
vval(VIEW) = "X"; |
504 |
< |
vdef(VIEW)++; |
502 |
> |
if (!vdef(VIEWS)) { |
503 |
> |
vval(VIEWS) = "X"; |
504 |
> |
vdef(VIEWS)++; |
505 |
|
} |
506 |
|
if (!vdef(DETAIL)) { |
507 |
|
vval(DETAIL) = "M"; |
518 |
|
} |
519 |
|
|
520 |
|
|
521 |
< |
printvals() /* print variable values */ |
521 |
> |
static void |
522 |
> |
oconv(void) /* run oconv and mkillum if necessary */ |
523 |
|
{ |
659 |
– |
int i, j, clipline; |
660 |
– |
register char *cp; |
661 |
– |
register int k; |
662 |
– |
|
663 |
– |
for (i = 0; i < NVARS; i++) /* print each variable */ |
664 |
– |
for (j = 0; j < vdef(i); j++) { /* print each assignment */ |
665 |
– |
fputs(vnam(i), stdout); |
666 |
– |
fputs("= ", stdout); |
667 |
– |
k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 ) |
668 |
– |
- strlen(vnam(i)) ; |
669 |
– |
cp = nvalue(vv+i, j); |
670 |
– |
while (*cp) { |
671 |
– |
putchar(*cp++); |
672 |
– |
if (--k <= 0) { /* line too long */ |
673 |
– |
while (*cp && !isspace(*cp)) |
674 |
– |
putchar(*cp++); /* finish this word */ |
675 |
– |
if (*cp) { /* start new line */ |
676 |
– |
putchar('\n'); |
677 |
– |
fputs(vnam(i), stdout); |
678 |
– |
putchar('='); |
679 |
– |
k = clipline; |
680 |
– |
} |
681 |
– |
} |
682 |
– |
} |
683 |
– |
putchar('\n'); |
684 |
– |
} |
685 |
– |
fflush(stdout); |
686 |
– |
} |
687 |
– |
|
688 |
– |
|
689 |
– |
oconv() /* run oconv and mkillum if necessary */ |
690 |
– |
{ |
524 |
|
static char illumtmp[] = "ilXXXXXX"; |
525 |
< |
char combuf[1024], ocopts[64], mkopts[64]; |
525 |
> |
char combuf[PATH_MAX], ocopts[64], mkopts[1024]; |
526 |
|
|
527 |
|
oconvopts(ocopts); /* get options */ |
528 |
|
if (octreedate < scenedate) { /* check date on original octree */ |
530 |
|
touch(vval(OCTREE)); |
531 |
|
else { /* build command */ |
532 |
|
if (vdef(MATERIAL)) |
533 |
< |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
534 |
< |
vval(MATERIAL), vval(SCENE), |
535 |
< |
vval(OCTREE)); |
533 |
> |
sprintf(combuf, "%s%s %s %s > %s", c_oconv, |
534 |
> |
ocopts, vval(MATERIAL), |
535 |
> |
vval(SCENE), vval(OCTREE)); |
536 |
|
else |
537 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
537 |
> |
sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts, |
538 |
|
vval(SCENE), vval(OCTREE)); |
539 |
|
|
540 |
|
if (runcom(combuf)) { /* run it */ |
542 |
|
"%s: error generating octree\n\t%s removed\n", |
543 |
|
progname, vval(OCTREE)); |
544 |
|
unlink(vval(OCTREE)); |
545 |
< |
exit(1); |
545 |
> |
quit(1); |
546 |
|
} |
547 |
|
} |
548 |
|
octreedate = time((time_t *)NULL); |
551 |
|
} |
552 |
|
if (oct1name == vval(OCTREE)) /* no mkillum? */ |
553 |
|
oct1date = octreedate > matdate ? octreedate : matdate; |
554 |
< |
if (oct1date >= octreedate & oct1date >= matdate |
555 |
< |
& oct1date >= illumdate) /* all done */ |
554 |
> |
if ((oct1date >= octreedate) & (oct1date >= matdate) |
555 |
> |
& (oct1date >= illumdate)) /* all done */ |
556 |
|
return; |
557 |
|
/* make octree0 */ |
558 |
< |
if (oct0date < scenedate | oct0date < illumdate) { |
558 |
> |
if ((oct0date < scenedate) | (oct0date < illumdate)) { |
559 |
|
if (touchonly && oct0date) |
560 |
|
touch(oct0name); |
561 |
|
else { /* build command */ |
562 |
|
if (octreedate) |
563 |
< |
sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, |
564 |
< |
vval(OCTREE), vval(ILLUM), oct0name); |
563 |
> |
sprintf(combuf, "%s%s -i %s %s > %s", c_oconv, |
564 |
> |
ocopts, vval(OCTREE), |
565 |
> |
vval(ILLUM), oct0name); |
566 |
|
else if (vdef(MATERIAL)) |
567 |
< |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
568 |
< |
vval(MATERIAL), vval(ILLUM), oct0name); |
735 |
< |
else |
736 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
567 |
> |
sprintf(combuf, "%s%s %s %s > %s", c_oconv, |
568 |
> |
ocopts, vval(MATERIAL), |
569 |
|
vval(ILLUM), oct0name); |
570 |
+ |
else |
571 |
+ |
sprintf(combuf, "%s%s %s > %s", c_oconv, |
572 |
+ |
ocopts, vval(ILLUM), oct0name); |
573 |
|
if (runcom(combuf)) { /* run it */ |
574 |
|
fprintf(stderr, |
575 |
|
"%s: error generating octree\n\t%s removed\n", |
576 |
|
progname, oct0name); |
577 |
|
unlink(oct0name); |
578 |
< |
exit(1); |
578 |
> |
quit(1); |
579 |
|
} |
580 |
|
} |
581 |
|
oct0date = time((time_t *)NULL); |
589 |
|
else { |
590 |
|
mkillumopts(mkopts); /* build mkillum command */ |
591 |
|
mktemp(illumtmp); |
592 |
< |
sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, |
592 |
> |
sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts, |
593 |
|
oct0name, vval(ILLUM), illumtmp); |
594 |
|
if (runcom(combuf)) { /* run it */ |
595 |
< |
fprintf(stderr, "%s: error running mkillum\n", |
596 |
< |
progname); |
595 |
> |
fprintf(stderr, "%s: error running %s\n", |
596 |
> |
progname, c_mkillum); |
597 |
|
unlink(illumtmp); |
598 |
< |
exit(1); |
598 |
> |
quit(1); |
599 |
|
} |
600 |
+ |
rmfile(oct0name); |
601 |
|
/* make octree1 (frozen) */ |
602 |
|
if (octreedate) |
603 |
< |
sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, |
604 |
< |
vval(OCTREE), illumtmp, oct1name); |
603 |
> |
sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv, |
604 |
> |
ocopts, vval(OCTREE), illumtmp, oct1name); |
605 |
|
else if (vdef(MATERIAL)) |
606 |
< |
sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, |
607 |
< |
vval(MATERIAL), illumtmp, oct1name); |
606 |
> |
sprintf(combuf, "%s%s -f %s %s > %s", c_oconv, |
607 |
> |
ocopts, vval(MATERIAL), illumtmp, oct1name); |
608 |
|
else |
609 |
< |
sprintf(combuf, "oconv%s -f %s > %s", ocopts, |
609 |
> |
sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts, |
610 |
|
illumtmp, oct1name); |
611 |
|
if (runcom(combuf)) { /* run it */ |
612 |
|
fprintf(stderr, |
614 |
|
progname, oct1name); |
615 |
|
unlink(oct1name); |
616 |
|
unlink(illumtmp); |
617 |
< |
exit(1); |
617 |
> |
quit(1); |
618 |
|
} |
619 |
|
rmfile(illumtmp); |
620 |
|
} |
624 |
|
} |
625 |
|
|
626 |
|
|
627 |
< |
char * |
628 |
< |
addarg(op, arg) /* add argument and advance pointer */ |
793 |
< |
register char *op, *arg; |
627 |
> |
static void |
628 |
> |
mkpmap(void) /* run mkpmap if indicated */ |
629 |
|
{ |
630 |
+ |
char combuf[2048], *cp; |
631 |
+ |
time_t tnow; |
632 |
+ |
/* nothing to do? */ |
633 |
+ |
if ((pgmapname == NULL) | (pgmapdate >= oct1date) && |
634 |
+ |
(pcmapname == NULL) | (pcmapdate >= oct1date)) |
635 |
+ |
return; |
636 |
+ |
/* just update existing file dates? */ |
637 |
+ |
if (touchonly && (pgmapname == NULL) | (pgmapdate > 0) && |
638 |
+ |
(pcmapname == NULL) | (pcmapdate > 0)) { |
639 |
+ |
if (pgmapname != NULL) |
640 |
+ |
touch(pgmapname); |
641 |
+ |
if (pcmapname != NULL) |
642 |
+ |
touch(pcmapname); |
643 |
+ |
} else { /* else need to (re)run pkpmap */ |
644 |
+ |
strcpy(combuf, c_mkpmap); |
645 |
+ |
for (cp = combuf; *cp; cp++) |
646 |
+ |
; |
647 |
+ |
mkpmapopts(cp); |
648 |
+ |
/* force file overwrite */ |
649 |
+ |
cp = addarg(cp, "-fo+"); |
650 |
+ |
if (vdef(REPORT)) { |
651 |
+ |
char errfile[256]; |
652 |
+ |
int n; |
653 |
+ |
double minutes; |
654 |
+ |
n = sscanf(vval(REPORT), "%lf %s", &minutes, errfile); |
655 |
+ |
if (n == 2) |
656 |
+ |
sprintf(cp, " -t %d -e %s", (int)(minutes*60), errfile); |
657 |
+ |
else if (n == 1) |
658 |
+ |
sprintf(cp, " -t %d", (int)(minutes*60)); |
659 |
+ |
else |
660 |
+ |
badvalue(REPORT); |
661 |
+ |
} |
662 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) { |
663 |
+ |
cp = addarg(cp, "-apg"); |
664 |
+ |
addarg(cp, vval(PGMAP)); |
665 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
666 |
+ |
*cp = '\0'; |
667 |
+ |
} |
668 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) { |
669 |
+ |
cp = addarg(cp, "-apc"); |
670 |
+ |
addarg(cp, vval(PCMAP)); |
671 |
+ |
cp = sskip(sskip(cp)); /* remove any bandwidth */ |
672 |
+ |
*cp = '\0'; |
673 |
+ |
} |
674 |
+ |
cp = addarg(cp, oct1name); |
675 |
+ |
if (runcom(combuf)) { |
676 |
+ |
fprintf(stderr, "%s: error running %s\n", |
677 |
+ |
progname, c_mkpmap); |
678 |
+ |
if (pgmapname != NULL && pgmapdate < oct1date) |
679 |
+ |
unlink(pgmapname); |
680 |
+ |
if (pcmapname != NULL && pcmapdate < oct1date) |
681 |
+ |
unlink(pcmapname); |
682 |
+ |
quit(1); |
683 |
+ |
} |
684 |
+ |
} |
685 |
+ |
tnow = time((time_t *)NULL); |
686 |
+ |
if (pgmapname != NULL) |
687 |
+ |
pgmapdate = tnow; |
688 |
+ |
if (pcmapname != NULL) |
689 |
+ |
pcmapdate = tnow; |
690 |
+ |
oct1date = tnow; /* trigger ambient file removal if needed */ |
691 |
+ |
} |
692 |
+ |
|
693 |
+ |
|
694 |
+ |
static char * |
695 |
+ |
addarg( /* append argument and advance pointer */ |
696 |
+ |
char *op, |
697 |
+ |
char *arg |
698 |
+ |
) |
699 |
+ |
{ |
700 |
+ |
while (*op) |
701 |
+ |
op++; |
702 |
|
*op = ' '; |
703 |
< |
while (*++op = *arg++) |
703 |
> |
while ( (*++op = *arg++) ) |
704 |
|
; |
705 |
|
return(op); |
706 |
|
} |
707 |
|
|
708 |
|
|
709 |
< |
oconvopts(oo) /* get oconv options */ |
710 |
< |
register char *oo; |
709 |
> |
static void |
710 |
> |
oconvopts( /* get oconv options */ |
711 |
> |
char *oo |
712 |
> |
) |
713 |
|
{ |
714 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
715 |
|
|
716 |
|
*oo = '\0'; |
717 |
< |
if (vdef(OCONV)) |
718 |
< |
addarg(oo, vval(OCONV)); |
717 |
> |
if (!vdef(OCONV)) |
718 |
> |
return; |
719 |
> |
if (vval(OCONV)[0] != '-') { |
720 |
> |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
721 |
> |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
722 |
> |
} else |
723 |
> |
oo = addarg(oo, vval(OCONV)); |
724 |
|
} |
725 |
|
|
726 |
|
|
727 |
< |
mkillumopts(mo) /* get mkillum options */ |
728 |
< |
register char *mo; |
727 |
> |
static void |
728 |
> |
mkillumopts( /* get mkillum options */ |
729 |
> |
char *mo |
730 |
> |
) |
731 |
|
{ |
732 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
733 |
|
|
734 |
< |
*mo = '\0'; |
735 |
< |
if (vdef(MKILLUM)) |
736 |
< |
addarg(mo, vval(MKILLUM)); |
734 |
> |
if (nprocs > 1) |
735 |
> |
sprintf(mo, " -n %d", nprocs); |
736 |
> |
else |
737 |
> |
*mo = '\0'; |
738 |
> |
if (!vdef(MKILLUM)) |
739 |
> |
return; |
740 |
> |
if (vval(MKILLUM)[0] != '-') { |
741 |
> |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
742 |
> |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
743 |
> |
} else |
744 |
> |
mo = addarg(mo, vval(MKILLUM)); |
745 |
|
} |
746 |
|
|
747 |
|
|
748 |
< |
checkambfile() /* check date on ambient file */ |
748 |
> |
static void |
749 |
> |
mkpmapopts( /* get mkpmap options */ |
750 |
> |
char *mo |
751 |
> |
) |
752 |
|
{ |
753 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
754 |
+ |
|
755 |
+ |
if (nprocs > 1) |
756 |
+ |
sprintf(mo, " -n %d", nprocs); |
757 |
+ |
else |
758 |
+ |
*mo = '\0'; |
759 |
+ |
if (!vdef(MKPMAP)) |
760 |
+ |
return; |
761 |
+ |
if (vval(MKPMAP)[0] != '-') { |
762 |
+ |
atos(c_mkpmap, sizeof(c_mkpmap), vval(MKPMAP)); |
763 |
+ |
mo = addarg(mo, sskip2(vval(MKPMAP), 1)); |
764 |
+ |
} else |
765 |
+ |
mo = addarg(mo, vval(MKPMAP)); |
766 |
+ |
} |
767 |
+ |
|
768 |
+ |
|
769 |
+ |
static void |
770 |
+ |
checkambfile(void) /* check date on ambient file */ |
771 |
+ |
{ |
772 |
|
time_t afdate; |
773 |
|
|
774 |
|
if (!vdef(AMBFILE)) |
775 |
|
return; |
776 |
|
if (!(afdate = fdate(vval(AMBFILE)))) |
777 |
|
return; |
778 |
< |
if (oct1date > afdate) |
778 |
> |
if (oct1date > afdate) { |
779 |
|
if (touchonly) |
780 |
|
touch(vval(AMBFILE)); |
781 |
|
else |
782 |
|
rmfile(vval(AMBFILE)); |
783 |
+ |
} |
784 |
|
} |
785 |
|
|
786 |
|
|
787 |
< |
double |
788 |
< |
ambval() /* compute ambient value */ |
787 |
> |
static double |
788 |
> |
ambval(void) /* compute ambient value */ |
789 |
|
{ |
790 |
|
if (vdef(EXPOSURE)) { |
791 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
792 |
< |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
793 |
< |
return(.5/atof(vval(EXPOSURE))); |
792 |
> |
return(.5/pow(2.,vflt(EXPOSURE))); |
793 |
> |
return(.5/vflt(EXPOSURE)); |
794 |
|
} |
795 |
|
if (vlet(ZONE) == 'E') |
796 |
|
return(10.); |
797 |
|
if (vlet(ZONE) == 'I') |
798 |
|
return(.01); |
799 |
|
badvalue(ZONE); |
800 |
+ |
return 0; /* pro forma return */ |
801 |
|
} |
802 |
|
|
803 |
|
|
804 |
< |
renderopts(op, po) /* set rendering options */ |
805 |
< |
char *op, *po; |
804 |
> |
static void |
805 |
> |
renderopts( /* set rendering options */ |
806 |
> |
char *op, |
807 |
> |
char *po |
808 |
> |
) |
809 |
|
{ |
810 |
+ |
char pmapf[256], *bw; |
811 |
+ |
|
812 |
+ |
if (vdef(PGMAP)) { |
813 |
+ |
*op = '\0'; |
814 |
+ |
bw = sskip2(vval(PGMAP), 2); |
815 |
+ |
atos(pmapf, sizeof(pmapf), vval(PGMAP)); |
816 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
817 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
818 |
+ |
} |
819 |
|
switch(vscale(QUALITY)) { |
820 |
|
case LOW: |
821 |
|
lowqopts(op, po); |
827 |
|
hiqopts(op, po); |
828 |
|
break; |
829 |
|
} |
830 |
+ |
if (vdef(PCMAP)) { |
831 |
+ |
bw = sskip2(vval(PCMAP), 2); |
832 |
+ |
atos(pmapf, sizeof(pmapf), vval(PCMAP)); |
833 |
+ |
op = addarg(addarg(op, "-ap"), pmapf); |
834 |
+ |
if (atoi(bw) > 0) op = addarg(op, bw); |
835 |
+ |
} |
836 |
+ |
if (vdef(RENDER)) |
837 |
+ |
op = addarg(op, vval(RENDER)); |
838 |
+ |
if (rvdevice != NULL) { |
839 |
+ |
if (vdef(RVU)) { |
840 |
+ |
if (vval(RVU)[0] != '-') { |
841 |
+ |
atos(c_rvu, sizeof(c_rvu), vval(RVU)); |
842 |
+ |
po = addarg(po, sskip2(vval(RVU), 1)); |
843 |
+ |
} else |
844 |
+ |
po = addarg(po, vval(RVU)); |
845 |
+ |
} |
846 |
+ |
} else { |
847 |
+ |
if (vdef(RPICT)) { |
848 |
+ |
if (vval(RPICT)[0] != '-') { |
849 |
+ |
atos(c_rpict, sizeof(c_rpict), vval(RPICT)); |
850 |
+ |
po = addarg(po, sskip2(vval(RPICT), 1)); |
851 |
+ |
} else |
852 |
+ |
po = addarg(po, vval(RPICT)); |
853 |
+ |
} |
854 |
+ |
} |
855 |
|
} |
856 |
|
|
857 |
|
|
858 |
< |
lowqopts(op, po) /* low quality rendering options */ |
859 |
< |
register char *op; |
860 |
< |
char *po; |
858 |
> |
static void |
859 |
> |
lowqopts( /* low quality rendering options */ |
860 |
> |
char *op, |
861 |
> |
char *po |
862 |
> |
) |
863 |
|
{ |
864 |
|
double d, org[3], siz[3]; |
865 |
|
|
869 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
870 |
|
badvalue(ZONE); |
871 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
872 |
< |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
872 |
> |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
873 |
|
badvalue(ZONE); |
874 |
|
getoctcube(org, &d); |
875 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
877 |
|
case LOW: |
878 |
|
po = addarg(po, "-ps 16"); |
879 |
|
op = addarg(op, "-dp 64"); |
880 |
< |
sprintf(op, " -ar %d", (int)(4*d)); |
880 |
> |
sprintf(op, " -ar %d", (int)(8*d)); |
881 |
|
op += strlen(op); |
882 |
|
break; |
883 |
|
case MEDIUM: |
884 |
|
po = addarg(po, "-ps 8"); |
885 |
|
op = addarg(op, "-dp 128"); |
886 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
886 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
887 |
|
op += strlen(op); |
888 |
|
break; |
889 |
|
case HIGH: |
890 |
|
po = addarg(po, "-ps 4"); |
891 |
|
op = addarg(op, "-dp 256"); |
892 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
892 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
893 |
|
op += strlen(op); |
894 |
|
break; |
895 |
|
} |
898 |
|
op = addarg(op, "-ds .4"); |
899 |
|
else |
900 |
|
op = addarg(op, "-ds 0"); |
901 |
< |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); |
901 |
> |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5"); |
902 |
|
if (vdef(AMBFILE)) { |
903 |
|
sprintf(op, " -af %s", vval(AMBFILE)); |
904 |
|
op += strlen(op); |
906 |
|
overture = 0; |
907 |
|
switch (vscale(VARIABILITY)) { |
908 |
|
case LOW: |
909 |
< |
op = addarg(op, "-aa .4 -ad 64"); |
909 |
> |
op = addarg(op, "-aa .3 -ad 256"); |
910 |
|
break; |
911 |
|
case MEDIUM: |
912 |
< |
op = addarg(op, "-aa .3 -ad 128"); |
912 |
> |
op = addarg(op, "-aa .25 -ad 512"); |
913 |
|
break; |
914 |
|
case HIGH: |
915 |
< |
op = addarg(op, "-aa .25 -ad 256"); |
915 |
> |
op = addarg(op, "-aa .2 -ad 1024"); |
916 |
|
break; |
917 |
|
} |
918 |
|
op = addarg(op, "-as 0"); |
919 |
|
d = ambval(); |
920 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
921 |
|
op += strlen(op); |
922 |
< |
op = addarg(op, "-lr 3 -lw .02"); |
936 |
< |
if (vdef(RENDER)) |
937 |
< |
op = addarg(op, vval(RENDER)); |
922 |
> |
op = addarg(op, "-lr 6 -lw .003"); |
923 |
|
} |
924 |
|
|
925 |
|
|
926 |
< |
medqopts(op, po) /* medium quality rendering options */ |
927 |
< |
register char *op; |
928 |
< |
char *po; |
926 |
> |
static void |
927 |
> |
medqopts( /* medium quality rendering options */ |
928 |
> |
char *op, |
929 |
> |
char *po |
930 |
> |
) |
931 |
|
{ |
932 |
< |
double d, org[3], siz[3]; |
932 |
> |
double d, org[3], siz[3], asz; |
933 |
|
|
934 |
|
*op = '\0'; |
935 |
|
*po = '\0'; |
937 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
938 |
|
badvalue(ZONE); |
939 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
940 |
< |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
940 |
> |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
941 |
|
badvalue(ZONE); |
942 |
|
getoctcube(org, &d); |
943 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
943 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
944 |
> |
d /= asz; |
945 |
|
switch (vscale(DETAIL)) { |
946 |
|
case LOW: |
947 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
948 |
|
op = addarg(op, "-dp 256"); |
949 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
949 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
950 |
|
op += strlen(op); |
951 |
+ |
sprintf(op, " -ms %.2g", asz/20.); |
952 |
+ |
op += strlen(op); |
953 |
|
break; |
954 |
|
case MEDIUM: |
955 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
956 |
|
op = addarg(op, "-dp 512"); |
957 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
957 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
958 |
|
op += strlen(op); |
959 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
960 |
+ |
op += strlen(op); |
961 |
|
break; |
962 |
|
case HIGH: |
963 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
964 |
|
op = addarg(op, "-dp 1024"); |
965 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
965 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
966 |
|
op += strlen(op); |
967 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
968 |
+ |
op += strlen(op); |
969 |
|
break; |
970 |
|
} |
971 |
|
po = addarg(po, "-pt .08"); |
972 |
|
if (vbool(PENUMBRAS)) |
973 |
< |
op = addarg(op, "-ds .2 -dj .5"); |
973 |
> |
op = addarg(op, "-ds .2 -dj .9"); |
974 |
|
else |
975 |
|
op = addarg(op, "-ds .3"); |
976 |
< |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); |
977 |
< |
if (overture = vint(INDIRECT)) { |
976 |
> |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1"); |
977 |
> |
if ( (overture = vint(INDIRECT)) ) { |
978 |
|
sprintf(op, " -ab %d", overture); |
979 |
|
op += strlen(op); |
980 |
|
} |
985 |
|
overture = 0; |
986 |
|
switch (vscale(VARIABILITY)) { |
987 |
|
case LOW: |
988 |
< |
op = addarg(op, "-aa .25 -ad 196 -as 0"); |
988 |
> |
op = addarg(op, "-aa .2 -ad 329 -as 42"); |
989 |
|
break; |
990 |
|
case MEDIUM: |
991 |
< |
op = addarg(op, "-aa .2 -ad 400 -as 64"); |
991 |
> |
op = addarg(op, "-aa .15 -ad 800 -as 128"); |
992 |
|
break; |
993 |
|
case HIGH: |
994 |
< |
op = addarg(op, "-aa .15 -ad 768 -as 196"); |
994 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 392"); |
995 |
|
break; |
996 |
|
} |
997 |
|
d = ambval(); |
998 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
999 |
|
op += strlen(op); |
1000 |
< |
op = addarg(op, "-lr 6 -lw .002"); |
1007 |
< |
if (vdef(RENDER)) |
1008 |
< |
op = addarg(op, vval(RENDER)); |
1000 |
> |
op = addarg(op, "-lr 8 -lw 1e-4"); |
1001 |
|
} |
1002 |
|
|
1003 |
|
|
1004 |
< |
hiqopts(op, po) /* high quality rendering options */ |
1005 |
< |
register char *op; |
1006 |
< |
char *po; |
1004 |
> |
static void |
1005 |
> |
hiqopts( /* high quality rendering options */ |
1006 |
> |
char *op, |
1007 |
> |
char *po |
1008 |
> |
) |
1009 |
|
{ |
1010 |
< |
double d, org[3], siz[3]; |
1010 |
> |
double d, org[3], siz[3], asz; |
1011 |
|
|
1012 |
|
*op = '\0'; |
1013 |
|
*po = '\0'; |
1015 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
1016 |
|
badvalue(ZONE); |
1017 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
1018 |
< |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
1018 |
> |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
1019 |
|
badvalue(ZONE); |
1020 |
|
getoctcube(org, &d); |
1021 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
1021 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
1022 |
> |
d /= asz; |
1023 |
|
switch (vscale(DETAIL)) { |
1024 |
|
case LOW: |
1025 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
1026 |
|
op = addarg(op, "-dp 1024"); |
1027 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
1027 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
1028 |
|
op += strlen(op); |
1029 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
1030 |
+ |
op += strlen(op); |
1031 |
|
break; |
1032 |
|
case MEDIUM: |
1033 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
1034 |
|
op = addarg(op, "-dp 2048"); |
1035 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
1035 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
1036 |
|
op += strlen(op); |
1037 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
1038 |
+ |
op += strlen(op); |
1039 |
|
break; |
1040 |
|
case HIGH: |
1041 |
|
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
1042 |
|
op = addarg(op, "-dp 4096"); |
1043 |
< |
sprintf(op, " -ar %d", (int)(64*d)); |
1043 |
> |
sprintf(op, " -ar %d", (int)(128*d)); |
1044 |
|
op += strlen(op); |
1045 |
+ |
sprintf(op, " -ms %.2g", asz/160.); |
1046 |
+ |
op += strlen(op); |
1047 |
|
break; |
1048 |
|
} |
1049 |
|
po = addarg(po, "-pt .04"); |
1050 |
|
if (vbool(PENUMBRAS)) |
1051 |
< |
op = addarg(op, "-ds .1 -dj .65"); |
1051 |
> |
op = addarg(op, "-ds .1 -dj .9"); |
1052 |
|
else |
1053 |
|
op = addarg(op, "-ds .2"); |
1054 |
< |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); |
1054 |
> |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01"); |
1055 |
|
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
1056 |
|
op += strlen(op); |
1057 |
|
if (vdef(AMBFILE)) { |
1061 |
|
overture = 0; |
1062 |
|
switch (vscale(VARIABILITY)) { |
1063 |
|
case LOW: |
1064 |
< |
op = addarg(op, "-aa .15 -ad 256 -as 0"); |
1064 |
> |
op = addarg(op, "-aa .125 -ad 512 -as 64"); |
1065 |
|
break; |
1066 |
|
case MEDIUM: |
1067 |
< |
op = addarg(op, "-aa .125 -ad 512 -as 256"); |
1067 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 768"); |
1068 |
|
break; |
1069 |
|
case HIGH: |
1070 |
< |
op = addarg(op, "-aa .08 -ad 1024 -as 512"); |
1070 |
> |
op = addarg(op, "-aa .075 -ad 4096 -as 2048"); |
1071 |
|
break; |
1072 |
|
} |
1073 |
|
d = ambval(); |
1074 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
1075 |
|
op += strlen(op); |
1076 |
< |
op = addarg(op, "-lr 12 -lw .0005"); |
1076 |
< |
if (vdef(RENDER)) |
1077 |
< |
op = addarg(op, vval(RENDER)); |
1076 |
> |
op = addarg(op, "-lr 12 -lw 1e-5"); |
1077 |
|
} |
1078 |
|
|
1079 |
|
|
1080 |
< |
xferopts(ro) /* transfer options if indicated */ |
1081 |
< |
char *ro; |
1080 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1081 |
> |
static void |
1082 |
> |
setenv( /* set an environment variable */ |
1083 |
> |
char *vname, |
1084 |
> |
char *value |
1085 |
> |
) |
1086 |
|
{ |
1087 |
+ |
char *evp; |
1088 |
+ |
|
1089 |
+ |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1090 |
+ |
if (evp == NULL) |
1091 |
+ |
syserr(progname); |
1092 |
+ |
sprintf(evp, "%s=%s", vname, value); |
1093 |
+ |
if (putenv(evp) != 0) { |
1094 |
+ |
fprintf(stderr, "%s: out of environment space\n", progname); |
1095 |
+ |
quit(1); |
1096 |
+ |
} |
1097 |
+ |
if (!silent) |
1098 |
+ |
printf("set %s\n", evp); |
1099 |
+ |
} |
1100 |
+ |
#endif |
1101 |
+ |
|
1102 |
+ |
|
1103 |
+ |
static void |
1104 |
+ |
xferopts( /* transfer options if indicated */ |
1105 |
+ |
char *ro |
1106 |
+ |
) |
1107 |
+ |
{ |
1108 |
|
int fd, n; |
1109 |
< |
register char *cp; |
1109 |
> |
char *cp; |
1110 |
|
|
1111 |
|
n = strlen(ro); |
1112 |
|
if (n < 2) |
1113 |
|
return; |
1114 |
|
if (vdef(OPTFILE)) { |
1115 |
|
for (cp = ro; cp[1]; cp++) |
1116 |
< |
if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) |
1116 |
> |
if (isspace(cp[1]) && (cp[2] == '@' || |
1117 |
> |
(cp[2] == '-' && isalpha(cp[3])))) |
1118 |
|
*cp = '\n'; |
1119 |
|
else |
1120 |
|
*cp = cp[1]; |
1124 |
|
syserr(vval(OPTFILE)); |
1125 |
|
sprintf(ro, " @%s", vval(OPTFILE)); |
1126 |
|
} |
1127 |
< |
#ifdef MSDOS |
1127 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1128 |
|
else if (n > 50) { |
1129 |
|
setenv("ROPT", ro+1); |
1130 |
|
strcpy(ro, " $ROPT"); |
1133 |
|
} |
1134 |
|
|
1135 |
|
|
1136 |
< |
pfiltopts(po) /* get pfilt options */ |
1137 |
< |
register char *po; |
1136 |
> |
static void |
1137 |
> |
pfiltopts( /* get pfilt options */ |
1138 |
> |
char *po |
1139 |
> |
) |
1140 |
|
{ |
1141 |
|
*po = '\0'; |
1142 |
|
if (vdef(EXPOSURE)) { |
1145 |
|
} |
1146 |
|
switch (vscale(QUALITY)) { |
1147 |
|
case MEDIUM: |
1148 |
< |
po = addarg(po, "-r 1"); |
1148 |
> |
po = addarg(po, "-r .6"); |
1149 |
|
break; |
1150 |
|
case HIGH: |
1151 |
|
po = addarg(po, "-m .25"); |
1152 |
|
break; |
1153 |
|
} |
1154 |
< |
if (vdef(PFILT)) |
1155 |
< |
po = addarg(po, vval(PFILT)); |
1154 |
> |
if (vdef(PFILT)) { |
1155 |
> |
if (vval(PFILT)[0] != '-') { |
1156 |
> |
atos(c_pfilt, sizeof(c_pfilt), vval(PFILT)); |
1157 |
> |
po = addarg(po, sskip2(vval(PFILT), 1)); |
1158 |
> |
} else |
1159 |
> |
po = addarg(po, vval(PFILT)); |
1160 |
> |
} |
1161 |
|
} |
1162 |
|
|
1163 |
|
|
1164 |
< |
matchword(s1, s2) /* match white-delimited words */ |
1165 |
< |
register char *s1, *s2; |
1164 |
> |
static int |
1165 |
> |
matchword( /* match white-delimited words */ |
1166 |
> |
char *s1, |
1167 |
> |
char *s2 |
1168 |
> |
) |
1169 |
|
{ |
1170 |
|
while (isspace(*s1)) s1++; |
1171 |
|
while (isspace(*s2)) s2++; |
1176 |
|
} |
1177 |
|
|
1178 |
|
|
1179 |
< |
char * |
1180 |
< |
specview(vs) /* get proper view spec from vs */ |
1181 |
< |
register char *vs; |
1179 |
> |
static char * |
1180 |
> |
specview( /* get proper view spec from vs */ |
1181 |
> |
char *vs |
1182 |
> |
) |
1183 |
|
{ |
1184 |
|
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
1185 |
|
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
1186 |
|
static char viewopts[128]; |
1187 |
< |
register char *cp; |
1187 |
> |
char *cp; |
1188 |
|
int xpos, ypos, zpos, viewtype, upax; |
1189 |
< |
register int i; |
1189 |
> |
int i; |
1190 |
|
double cent[3], dim[3], mult, d; |
1191 |
|
|
1192 |
|
if (vs == NULL || *vs == '-') |
1197 |
|
upax = 1-'X'+UPPER(vval(UP)[1]); |
1198 |
|
else |
1199 |
|
upax = 1-'X'+vlet(UP); |
1200 |
< |
if (upax < 1 | upax > 3) |
1200 |
> |
if ((upax < 1) | (upax > 3)) |
1201 |
|
badvalue(UP); |
1202 |
|
if (vval(UP)[0] == '-') |
1203 |
|
upax = -upax; |
1219 |
|
} else if (*vs == 'z') { |
1220 |
|
zpos = -1; vs++; |
1221 |
|
} |
1222 |
< |
viewtype = 'v'; |
1223 |
< |
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c') |
1222 |
> |
switch (*vs) { |
1223 |
> |
case VT_PER: |
1224 |
> |
case VT_PAR: |
1225 |
> |
case VT_ANG: |
1226 |
> |
case VT_HEM: |
1227 |
> |
case VT_PLS: |
1228 |
> |
case VT_CYL: |
1229 |
|
viewtype = *vs++; |
1230 |
+ |
break; |
1231 |
+ |
default: |
1232 |
+ |
viewtype = VT_PER; |
1233 |
+ |
break; |
1234 |
+ |
} |
1235 |
|
cp = viewopts; |
1236 |
|
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
1237 |
|
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
1246 |
|
cent[i] += .5*dim[i]; |
1247 |
|
} |
1248 |
|
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
1249 |
< |
sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", |
1249 |
> |
sprintf(cp, " -vp %.3g %.3g %.3g -vd %.3g %.3g %.3g", |
1250 |
|
cent[0]+xpos*mult*dim[0], |
1251 |
|
cent[1]+ypos*mult*dim[1], |
1252 |
|
cent[2]+zpos*mult*dim[2], |
1273 |
|
} |
1274 |
|
cp = addarg(cp, vup[upax+3]); |
1275 |
|
switch (viewtype) { |
1276 |
< |
case 'v': |
1276 |
> |
case VT_PER: |
1277 |
|
cp = addarg(cp, "-vh 45 -vv 45"); |
1278 |
|
break; |
1279 |
< |
case 'l': |
1279 |
> |
case VT_PAR: |
1280 |
|
d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); |
1281 |
< |
sprintf(cp, " -vh %.2g -vv %.2g", d, d); |
1281 |
> |
sprintf(cp, " -vh %.3g -vv %.3g", d, d); |
1282 |
|
cp += strlen(cp); |
1283 |
|
break; |
1284 |
< |
case 'a': |
1285 |
< |
case 'h': |
1284 |
> |
case VT_ANG: |
1285 |
> |
case VT_HEM: |
1286 |
> |
case VT_PLS: |
1287 |
|
cp = addarg(cp, "-vh 180 -vv 180"); |
1288 |
|
break; |
1289 |
< |
case 'c': |
1289 |
> |
case VT_CYL: |
1290 |
|
cp = addarg(cp, "-vh 180 -vv 90"); |
1291 |
|
break; |
1292 |
|
} |
1294 |
|
while (!isspace(*vs)) /* else skip id */ |
1295 |
|
if (!*vs++) |
1296 |
|
return(NULL); |
1297 |
< |
if (upax) { /* specify up vector */ |
1297 |
> |
if (upax) { /* prepend up vector */ |
1298 |
|
strcpy(cp, vup[upax+3]); |
1299 |
|
cp += strlen(cp); |
1300 |
|
} |
1302 |
|
if (cp == viewopts) /* append any additional options */ |
1303 |
|
vs++; /* skip prefixed space if unneeded */ |
1304 |
|
strcpy(cp, vs); |
1305 |
< |
#ifdef MSDOS |
1305 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1306 |
|
if (strlen(viewopts) > 40) { |
1307 |
|
setenv("VIEW", viewopts); |
1308 |
|
return("$VIEW"); |
1312 |
|
} |
1313 |
|
|
1314 |
|
|
1315 |
< |
char * |
1316 |
< |
getview(n, vn) /* get view n, or NULL if none */ |
1317 |
< |
int n; |
1318 |
< |
char *vn; /* returned view name */ |
1315 |
> |
static char * |
1316 |
> |
getview( /* get view n, or NULL if none */ |
1317 |
> |
int n, |
1318 |
> |
char *vn /* returned view name */ |
1319 |
> |
) |
1320 |
|
{ |
1321 |
< |
register char *mv; |
1321 |
> |
char *mv; |
1322 |
|
|
1323 |
|
if (viewselect != NULL) { /* command-line selected */ |
1324 |
|
if (n) /* only do one */ |
1325 |
|
return(NULL); |
1326 |
+ |
|
1327 |
+ |
if (isint(viewselect)) { /* view number? */ |
1328 |
+ |
n = atoi(viewselect)-1; |
1329 |
+ |
goto numview; |
1330 |
+ |
} |
1331 |
|
if (viewselect[0] == '-') { /* already specified */ |
1332 |
< |
if (vn != NULL) *vn = '\0'; |
1332 |
> |
if (vn != NULL) |
1333 |
> |
strcpy(vn, "0"); |
1334 |
|
return(viewselect); |
1335 |
|
} |
1336 |
|
if (vn != NULL) { |
1339 |
|
; |
1340 |
|
*vn = '\0'; |
1341 |
|
} |
1288 |
– |
/* view number? */ |
1289 |
– |
if (isint(viewselect)) |
1290 |
– |
return(specview(nvalue(vv+VIEW, atoi(viewselect)-1))); |
1342 |
|
/* check list */ |
1343 |
< |
while ((mv = nvalue(vv+VIEW, n++)) != NULL) |
1343 |
> |
while ((mv = nvalue(VIEWS, n++)) != NULL) |
1344 |
|
if (matchword(viewselect, mv)) |
1345 |
|
return(specview(mv)); |
1346 |
+ |
|
1347 |
|
return(specview(viewselect)); /* standard view? */ |
1348 |
|
} |
1349 |
< |
mv = nvalue(vv+VIEW, n); /* use view n */ |
1350 |
< |
if (vn != NULL & mv != NULL) { |
1351 |
< |
register char *mv2 = mv; |
1352 |
< |
if (*mv2 != '-') |
1349 |
> |
numview: |
1350 |
> |
mv = nvalue(VIEWS, n); /* use view n */ |
1351 |
> |
if ((vn != NULL) & (mv != NULL)) { |
1352 |
> |
if (*mv != '-') { |
1353 |
> |
char *mv2 = mv; |
1354 |
|
while (*mv2 && !isspace(*mv2)) |
1355 |
|
*vn++ = *mv2++; |
1356 |
< |
*vn = '\0'; |
1356 |
> |
*vn = '\0'; |
1357 |
> |
} else |
1358 |
> |
sprintf(vn, "%d", n+1); |
1359 |
|
} |
1360 |
|
return(specview(mv)); |
1361 |
|
} |
1362 |
|
|
1363 |
|
|
1364 |
< |
printview(vopts) /* print out selected view */ |
1365 |
< |
register char *vopts; |
1364 |
> |
static int |
1365 |
> |
myprintview( /* print out selected view */ |
1366 |
> |
char *vopts, |
1367 |
> |
FILE *fp |
1368 |
> |
) |
1369 |
|
{ |
1370 |
< |
extern char *atos(), *getenv(); |
1371 |
< |
char buf[256]; |
1372 |
< |
FILE *fp; |
1373 |
< |
register char *cp; |
1374 |
< |
|
1370 |
> |
VIEW vwr; |
1371 |
> |
char buf[128]; |
1372 |
> |
char *cp; |
1373 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1374 |
> |
/* XXX Should we allow something like this for all platforms? */ |
1375 |
> |
/* XXX Or is it still required at all? */ |
1376 |
> |
again: |
1377 |
> |
#endif |
1378 |
|
if (vopts == NULL) |
1379 |
|
return(-1); |
1380 |
< |
fputs("VIEW=", stdout); |
1381 |
< |
do { |
1382 |
< |
if (matchword(vopts, "-vf")) { /* expand view file */ |
1383 |
< |
vopts = sskip(vopts); |
1384 |
< |
if (!*atos(buf, sizeof(buf), vopts)) |
1324 |
< |
return(-1); |
1325 |
< |
if ((fp = fopen(buf, "r")) == NULL) |
1326 |
< |
return(-1); |
1327 |
< |
for (buf[sizeof(buf)-2] = '\n'; |
1328 |
< |
fgets(buf, sizeof(buf), fp) != NULL && |
1329 |
< |
buf[0] != '\n'; |
1330 |
< |
buf[sizeof(buf)-2] = '\n') { |
1331 |
< |
if (buf[sizeof(buf)-2] != '\n') { |
1332 |
< |
ungetc(buf[sizeof(buf)-2], fp); |
1333 |
< |
buf[sizeof(buf)-2] = '\0'; |
1334 |
< |
} |
1335 |
< |
if (matchword(buf, "VIEW=") || |
1336 |
< |
matchword(buf, "rview")) { |
1337 |
< |
for (cp = sskip(buf); *cp && *cp != '\n'; cp++) |
1338 |
< |
putchar(*cp); |
1339 |
< |
} |
1340 |
< |
} |
1341 |
< |
fclose(fp); |
1342 |
< |
vopts = sskip(vopts); |
1343 |
< |
} else { |
1344 |
< |
while (isspace(*vopts)) |
1345 |
< |
vopts++; |
1346 |
< |
putchar(' '); |
1347 |
< |
#ifdef MSDOS |
1348 |
< |
if (*vopts == '$') { /* expand env. var. */ |
1349 |
< |
if (!*atos(buf, sizeof(buf), vopts+1)) |
1350 |
< |
return(-1); |
1351 |
< |
if ((cp = getenv(buf)) == NULL) |
1352 |
< |
return(-1); |
1353 |
< |
fputs(cp, stdout); |
1354 |
< |
vopts = sskip(vopts); |
1355 |
< |
} else |
1380 |
> |
#if defined(_WIN32) || defined(_WIN64) |
1381 |
> |
if (vopts[0] == '$') { |
1382 |
> |
vopts = getenv(vopts+1); |
1383 |
> |
goto again; |
1384 |
> |
} |
1385 |
|
#endif |
1386 |
< |
while (*vopts && !isspace(*vopts)) |
1387 |
< |
putchar(*vopts++); |
1388 |
< |
} |
1389 |
< |
} while (*vopts++); |
1390 |
< |
putchar('\n'); |
1386 |
> |
vwr = stdview; |
1387 |
> |
sscanview(&vwr, cp=vopts); /* set initial options */ |
1388 |
> |
while ((cp = strstr(cp, "-vf ")) != NULL && |
1389 |
> |
*atos(buf, sizeof(buf), cp += 4)) { |
1390 |
> |
viewfile(buf, &vwr, NULL); /* load -vf file */ |
1391 |
> |
sscanview(&vwr, cp); /* reset tail */ |
1392 |
> |
} |
1393 |
> |
fputs(VIEWSTR, fp); |
1394 |
> |
fprintview(&vwr, fp); /* print full spec. */ |
1395 |
> |
fputc('\n', fp); |
1396 |
|
return(0); |
1397 |
|
} |
1398 |
|
|
1399 |
|
|
1400 |
< |
rview(opts, po) /* run rview with first view */ |
1401 |
< |
char *opts, *po; |
1400 |
> |
static void |
1401 |
> |
rvu( /* run rvu with first view */ |
1402 |
> |
char *opts, |
1403 |
> |
char *po |
1404 |
> |
) |
1405 |
|
{ |
1406 |
|
char *vw; |
1407 |
< |
char combuf[512]; |
1407 |
> |
char combuf[PATH_MAX]; |
1408 |
|
/* build command */ |
1409 |
|
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1410 |
|
return; |
1411 |
|
if (sayview) |
1412 |
< |
printview(vw); |
1413 |
< |
sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname); |
1412 |
> |
myprintview(vw, stdout); |
1413 |
> |
sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname); |
1414 |
> |
if (nprocs > 1) |
1415 |
> |
sprintf(combuf+strlen(combuf), "-n %d ", nprocs); |
1416 |
|
if (rvdevice != NULL) |
1417 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1418 |
|
if (vdef(EXPOSURE)) |
1419 |
|
sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); |
1420 |
|
strcat(combuf, oct1name); |
1421 |
|
if (runcom(combuf)) { /* run it */ |
1422 |
< |
fprintf(stderr, "%s: error running rview\n", progname); |
1423 |
< |
exit(1); |
1422 |
> |
fprintf(stderr, "%s: error running %s\n", progname, c_rvu); |
1423 |
> |
quit(1); |
1424 |
|
} |
1425 |
|
} |
1426 |
|
|
1427 |
|
|
1428 |
< |
rpict(opts, po) /* run rpict and pfilt for each view */ |
1429 |
< |
char *opts, *po; |
1428 |
> |
static int |
1429 |
> |
syncf_done( /* check if an rpiece sync file is complete */ |
1430 |
> |
char *sfname |
1431 |
> |
) |
1432 |
|
{ |
1433 |
< |
char combuf[1024]; |
1434 |
< |
char rawfile[MAXPATH], picfile[MAXPATH]; |
1435 |
< |
char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; |
1433 |
> |
FILE *fp = fopen(sfname, "r"); |
1434 |
> |
int todo = 1; |
1435 |
> |
int x, y; |
1436 |
> |
|
1437 |
> |
if (fp == NULL) |
1438 |
> |
return(0); |
1439 |
> |
if (fscanf(fp, "%d %d", &x, &y) != 2) |
1440 |
> |
goto checked; |
1441 |
> |
todo = x*y; /* total number of tiles */ |
1442 |
> |
if (fscanf(fp, "%d %d", &x, &y) != 2 || (x != 0) | (y != 0)) |
1443 |
> |
goto checked; |
1444 |
> |
/* XXX assume no redundant tiles */ |
1445 |
> |
while (fscanf(fp, "%d %d", &x, &y) == 2) |
1446 |
> |
if (!--todo) |
1447 |
> |
break; |
1448 |
> |
checked: |
1449 |
> |
fclose(fp); |
1450 |
> |
return(!todo); |
1451 |
> |
} |
1452 |
> |
|
1453 |
> |
|
1454 |
> |
static void |
1455 |
> |
rpict( /* run rpict and pfilt for each view */ |
1456 |
> |
char *opts, |
1457 |
> |
char *po |
1458 |
> |
) |
1459 |
> |
{ |
1460 |
> |
#define do_rpiece (sfile[0]!='\0') |
1461 |
> |
char combuf[5*PATH_MAX+512]; |
1462 |
> |
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1463 |
> |
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1464 |
> |
char rppopt[32], sfile[PATH_MAX], *pfile = NULL; |
1465 |
|
char pfopts[128]; |
1466 |
|
char vs[32], *vw; |
1467 |
|
int vn, mult; |
1468 |
+ |
FILE *fp; |
1469 |
|
time_t rfdt, pfdt; |
1470 |
+ |
int xres, yres; |
1471 |
+ |
double aspect; |
1472 |
+ |
int n; |
1473 |
|
/* get pfilt options */ |
1474 |
|
pfiltopts(pfopts); |
1475 |
|
/* get resolution, reporting */ |
1484 |
|
mult = 3; |
1485 |
|
break; |
1486 |
|
} |
1487 |
< |
{ |
1488 |
< |
int xres, yres; |
1489 |
< |
double aspect; |
1490 |
< |
int n; |
1491 |
< |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1492 |
< |
if (n == 3) |
1493 |
< |
sprintf(res, "-x %d -y %d -pa %.3f", |
1494 |
< |
mult*xres, mult*yres, aspect); |
1495 |
< |
else if (n) { |
1496 |
< |
if (n == 1) yres = xres; |
1423 |
< |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1424 |
< |
} else |
1425 |
< |
badvalue(RESOLUTION); |
1426 |
< |
} |
1487 |
> |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1488 |
> |
if (n == 3) |
1489 |
> |
sprintf(res, "-x %d -y %d -pa %.3f", |
1490 |
> |
mult*xres, mult*yres, aspect); |
1491 |
> |
else if (n) { |
1492 |
> |
aspect = 1.; |
1493 |
> |
if (n == 1) yres = xres; |
1494 |
> |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1495 |
> |
} else |
1496 |
> |
badvalue(RESOLUTION); |
1497 |
|
rep[0] = '\0'; |
1498 |
|
if (vdef(REPORT)) { |
1499 |
|
double minutes; |
1430 |
– |
int n; |
1500 |
|
n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); |
1501 |
|
if (n == 2) |
1502 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1505 |
|
else |
1506 |
|
badvalue(REPORT); |
1507 |
|
} |
1508 |
< |
/* do each view */ |
1509 |
< |
vn = 0; |
1508 |
> |
/* set up parallel rendering */ |
1509 |
> |
sfile[0] = '\0'; |
1510 |
> |
if ((nprocs > 1) & !touchonly & !vdef(ZFILE) && |
1511 |
> |
getview(0, vs) != NULL) { |
1512 |
> |
if (!strcmp(c_rpict, DEF_RPICT_PATH) && |
1513 |
> |
getview(1, NULL) == NULL) { |
1514 |
> |
sprintf(sfile, "%s_%s_rpsync.txt", |
1515 |
> |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), |
1516 |
> |
vs); |
1517 |
> |
strcpy(rppopt, "-PP pfXXXXXX"); |
1518 |
> |
} else { |
1519 |
> |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
1520 |
> |
} |
1521 |
> |
pfile = rppopt + strlen(rppopt) - 8; |
1522 |
> |
if (mktemp(pfile) == NULL) { |
1523 |
> |
if (do_rpiece) { |
1524 |
> |
fprintf(stderr, "%s: cannot create\n", pfile); |
1525 |
> |
quit(1); |
1526 |
> |
} |
1527 |
> |
pfile[-5] = '\0'; |
1528 |
> |
pfile = NULL; |
1529 |
> |
} |
1530 |
> |
} |
1531 |
> |
vn = 0; /* do each view */ |
1532 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1533 |
|
if (sayview) |
1534 |
< |
printview(vw); |
1535 |
< |
if (!vs[0]) |
1445 |
< |
sprintf(vs, "%d", vn); |
1446 |
< |
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1534 |
> |
myprintview(vw, stdout); |
1535 |
> |
sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs); |
1536 |
|
if (vdef(ZFILE)) |
1537 |
|
sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); |
1538 |
|
else |
1553 |
|
touch(picfile); |
1554 |
|
continue; |
1555 |
|
} |
1556 |
+ |
/* parallel running? */ |
1557 |
+ |
if (do_rpiece) { |
1558 |
+ |
if (rfdt < oct1date || !fdate(sfile)) { |
1559 |
+ |
int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; |
1560 |
+ |
if (rfdt >= oct1date) { |
1561 |
+ |
fprintf(stderr, |
1562 |
+ |
"%s: partial output not created with %s\n", rawfile, c_rpiece); |
1563 |
+ |
quit(1); |
1564 |
+ |
} |
1565 |
+ |
if (rfdt) { /* start fresh */ |
1566 |
+ |
rmfile(rawfile); |
1567 |
+ |
rfdt = 0; |
1568 |
+ |
} |
1569 |
+ |
if (!silent) |
1570 |
+ |
printf("\techo %d %d > %s\n", |
1571 |
+ |
xdiv, ydiv, sfile); |
1572 |
+ |
if ((fp = fopen(sfile, "w")) == NULL) { |
1573 |
+ |
fprintf(stderr, "%s: cannot create\n", |
1574 |
+ |
sfile); |
1575 |
+ |
quit(1); |
1576 |
+ |
} |
1577 |
+ |
fprintf(fp, "%d %d\n", xdiv, ydiv); |
1578 |
+ |
fclose(fp); |
1579 |
+ |
} |
1580 |
+ |
} else if (next_process(0)) { |
1581 |
+ |
if (pfile != NULL) |
1582 |
+ |
sleep(10); |
1583 |
+ |
continue; |
1584 |
+ |
} else if (!inchild()) |
1585 |
+ |
pfile = NULL; |
1586 |
+ |
/* XXX Remember to call finish_process() */ |
1587 |
|
/* build rpict command */ |
1588 |
< |
if (rfdt >= oct1date) /* recover */ |
1589 |
< |
sprintf(combuf, "rpict%s%s%s%s -ro %s %s", |
1590 |
< |
rep, po, opts, zopt, rawfile, oct1name); |
1591 |
< |
else { |
1588 |
> |
if (rfdt >= oct1date) { /* already in progress */ |
1589 |
> |
if (do_rpiece) { |
1590 |
> |
sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s", |
1591 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
1592 |
> |
res, opts, po, rawfile, oct1name); |
1593 |
> |
while (next_process(1)) { |
1594 |
> |
sleep(10); |
1595 |
> |
combuf[strlen(c_rpiece)+2] = 'F'; |
1596 |
> |
} |
1597 |
> |
} else |
1598 |
> |
sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, |
1599 |
> |
rep, opts, po, zopt, rawfile, oct1name); |
1600 |
> |
if (runcom(combuf)) /* run rpict/rpiece */ |
1601 |
> |
goto rperror; |
1602 |
> |
} else { |
1603 |
|
if (overture) { /* run overture calculation */ |
1604 |
|
sprintf(combuf, |
1605 |
< |
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1606 |
< |
rep, vw, opts, |
1605 |
> |
"%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1606 |
> |
c_rpict, rep, vw, opts, |
1607 |
|
oct1name, overfile); |
1608 |
< |
if (runcom(combuf)) { |
1609 |
< |
fprintf(stderr, |
1608 |
> |
if (!do_rpiece || !next_process(0)) { |
1609 |
> |
if (runcom(combuf)) { |
1610 |
> |
fprintf(stderr, |
1611 |
|
"%s: error in overture for view %s\n", |
1612 |
< |
progname, vs); |
1613 |
< |
exit(1); |
1614 |
< |
} |
1615 |
< |
#ifdef NIX |
1616 |
< |
rmfile(overfile); |
1612 |
> |
progname, vs); |
1613 |
> |
quit(1); |
1614 |
> |
} |
1615 |
> |
#ifndef NULL_DEVICE |
1616 |
> |
rmfile(overfile); |
1617 |
|
#endif |
1618 |
+ |
} else if (do_rpiece) |
1619 |
+ |
sleep(20); |
1620 |
|
} |
1621 |
< |
sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", |
1622 |
< |
rep, vw, res, po, opts, zopt, |
1623 |
< |
oct1name, rawfile); |
1621 |
> |
if (do_rpiece) { |
1622 |
> |
sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", |
1623 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
1624 |
> |
res, opts, po, rawfile, oct1name); |
1625 |
> |
while (next_process(1)) |
1626 |
> |
sleep(10); |
1627 |
> |
} else { |
1628 |
> |
sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", |
1629 |
> |
c_rpict, rep, vw, res, opts, po, |
1630 |
> |
zopt, oct1name, rawfile); |
1631 |
> |
} |
1632 |
> |
if ((pfile != NULL) & !do_rpiece) { |
1633 |
> |
if (!silent) |
1634 |
> |
printf("\t%s\n", combuf); |
1635 |
> |
fflush(stdout); |
1636 |
> |
sprintf(combuf, "%s%s %s %s%s%s %s > %s", |
1637 |
> |
c_rpict, rep, rppopt, res, |
1638 |
> |
opts, po, oct1name, rawfile); |
1639 |
> |
fp = popen(combuf, "w"); |
1640 |
> |
if (fp == NULL) |
1641 |
> |
goto rperror; |
1642 |
> |
myprintview(vw, fp); |
1643 |
> |
if (pclose(fp)) |
1644 |
> |
goto rperror; |
1645 |
> |
} else if (runcom(combuf)) |
1646 |
> |
goto rperror; |
1647 |
|
} |
1648 |
< |
if (runcom(combuf)) { /* run rpict */ |
1649 |
< |
fprintf(stderr, "%s: error rendering view %s\n", |
1650 |
< |
progname, vs); |
1651 |
< |
exit(1); |
1648 |
> |
if (do_rpiece) { /* need to finish raw, first */ |
1649 |
> |
finish_process(); |
1650 |
> |
wait_process(1); |
1651 |
> |
if (!syncf_done(sfile)) { |
1652 |
> |
fprintf(stderr, |
1653 |
> |
"%s: %s did not complete rendering of view %s\n", |
1654 |
> |
progname, c_rpiece, vs); |
1655 |
> |
quit(1); |
1656 |
> |
} |
1657 |
|
} |
1658 |
|
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1659 |
|
/* build pfilt command */ |
1660 |
< |
if (mult > 1) |
1661 |
< |
sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", |
1662 |
< |
pfopts, mult, mult, rawfile, picfile); |
1660 |
> |
if (do_rpiece) |
1661 |
> |
sprintf(combuf, |
1662 |
> |
"%s%s -x %d -y %d -p %.3f %s > %s", |
1663 |
> |
c_pfilt, pfopts, xres, yres, aspect, |
1664 |
> |
rawfile, picfile); |
1665 |
> |
else if (mult > 1) |
1666 |
> |
sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", |
1667 |
> |
c_pfilt, pfopts, mult, mult, |
1668 |
> |
rawfile, picfile); |
1669 |
|
else |
1670 |
< |
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1671 |
< |
rawfile, picfile); |
1672 |
< |
if (runcom(combuf)) { /* run pfilt */ |
1670 |
> |
sprintf(combuf, "%s%s %s > %s", c_pfilt, |
1671 |
> |
pfopts, rawfile, picfile); |
1672 |
> |
if (runcom(combuf)) { /* run pfilt */ |
1673 |
|
fprintf(stderr, |
1674 |
|
"%s: error filtering view %s\n\t%s removed\n", |
1675 |
|
progname, vs, picfile); |
1676 |
|
unlink(picfile); |
1677 |
< |
exit(1); |
1677 |
> |
quit(1); |
1678 |
|
} |
1679 |
|
} |
1680 |
|
/* remove/rename raw file */ |
1681 |
|
if (vdef(RAWFILE)) { |
1682 |
< |
sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); |
1682 |
> |
sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs); |
1683 |
|
mvfile(rawfile, combuf); |
1684 |
|
} else |
1685 |
|
rmfile(rawfile); |
1686 |
+ |
if (do_rpiece) /* done with sync file */ |
1687 |
+ |
rmfile(sfile); |
1688 |
+ |
else |
1689 |
+ |
finish_process(); /* exit if child */ |
1690 |
|
} |
1691 |
+ |
wait_process(1); /* wait for children to finish */ |
1692 |
+ |
if (pfile != NULL) { /* clean up persistent rpict */ |
1693 |
+ |
RT_PID pid; |
1694 |
+ |
fp = fopen(pfile, "r"); |
1695 |
+ |
if (fp != NULL) { |
1696 |
+ |
if (fscanf(fp, "%*s %d", &pid) != 1 || |
1697 |
+ |
kill(pid, 1) < 0) |
1698 |
+ |
unlink(pfile); |
1699 |
+ |
fclose(fp); |
1700 |
+ |
} |
1701 |
+ |
} |
1702 |
+ |
return; |
1703 |
+ |
rperror: |
1704 |
+ |
fprintf(stderr, "%s: error rendering view %s\n", progname, vs); |
1705 |
+ |
quit(1); |
1706 |
+ |
#undef do_rpiece |
1707 |
|
} |
1708 |
|
|
1709 |
|
|
1710 |
< |
touch(fn) /* update a file */ |
1711 |
< |
char *fn; |
1710 |
> |
static int |
1711 |
> |
touch( /* update a file */ |
1712 |
> |
char *fn |
1713 |
> |
) |
1714 |
|
{ |
1715 |
|
if (!silent) |
1716 |
|
printf("\ttouch %s\n", fn); |
1717 |
< |
if (noaction) |
1717 |
> |
if (!nprocs) |
1718 |
|
return(0); |
1529 |
– |
#ifdef notused |
1530 |
– |
if (access(fn, F_OK) == -1) /* create it */ |
1531 |
– |
if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1) |
1532 |
– |
return(-1); |
1533 |
– |
#endif |
1719 |
|
return(setfdate(fn, time((time_t *)NULL))); |
1720 |
|
} |
1721 |
|
|
1722 |
|
|
1723 |
< |
runcom(cs) /* run command */ |
1724 |
< |
char *cs; |
1723 |
> |
static int |
1724 |
> |
runcom( /* run command */ |
1725 |
> |
char *cs |
1726 |
> |
) |
1727 |
|
{ |
1728 |
|
if (!silent) /* echo it */ |
1729 |
|
printf("\t%s\n", cs); |
1730 |
< |
if (noaction) |
1730 |
> |
if (!nprocs) |
1731 |
|
return(0); |
1732 |
< |
fflush(stdout); /* flush output and pass to shell */ |
1732 |
> |
fflush(NULL); /* flush output and pass to shell */ |
1733 |
|
return(system(cs)); |
1734 |
|
} |
1735 |
|
|
1736 |
|
|
1737 |
< |
rmfile(fn) /* remove a file */ |
1738 |
< |
char *fn; |
1737 |
> |
static int |
1738 |
> |
rmfile( /* remove a file */ |
1739 |
> |
char *fn |
1740 |
> |
) |
1741 |
|
{ |
1742 |
|
if (!silent) |
1743 |
< |
#ifdef MSDOS |
1744 |
< |
printf("\tdel %s\n", fn); |
1556 |
< |
#else |
1557 |
< |
printf("\trm -f %s\n", fn); |
1558 |
< |
#endif |
1559 |
< |
if (noaction) |
1743 |
> |
printf("\t%s %s\n", DELCMD, fn); |
1744 |
> |
if (!nprocs) |
1745 |
|
return(0); |
1746 |
|
return(unlink(fn)); |
1747 |
|
} |
1748 |
|
|
1749 |
|
|
1750 |
< |
mvfile(fold, fnew) /* move a file */ |
1751 |
< |
char *fold, *fnew; |
1750 |
> |
static int |
1751 |
> |
mvfile( /* move a file */ |
1752 |
> |
char *fold, |
1753 |
> |
char *fnew |
1754 |
> |
) |
1755 |
|
{ |
1756 |
|
if (!silent) |
1757 |
< |
#ifdef MSDOS |
1758 |
< |
printf("\trename %s %s\n", fold, fnew); |
1571 |
< |
#else |
1572 |
< |
printf("\tmv %s %s\n", fold, fnew); |
1573 |
< |
#endif |
1574 |
< |
if (noaction) |
1757 |
> |
printf("\t%s %s %s\n", RENAMECMD, fold, fnew); |
1758 |
> |
if (!nprocs) |
1759 |
|
return(0); |
1760 |
|
return(rename(fold, fnew)); |
1761 |
|
} |
1762 |
|
|
1763 |
|
|
1764 |
< |
#ifdef MSDOS |
1765 |
< |
setenv(vname, value) /* set an environment variable */ |
1766 |
< |
char *vname, *value; |
1764 |
> |
#ifdef RHAS_FORK_EXEC |
1765 |
> |
static int |
1766 |
> |
next_process(int reserve) /* fork the next process */ |
1767 |
|
{ |
1768 |
< |
register char *evp; |
1768 |
> |
RT_PID child_pid; |
1769 |
|
|
1770 |
< |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1771 |
< |
if (evp == NULL) |
1772 |
< |
syserr(progname); |
1773 |
< |
sprintf(evp, "%s=%s", vname, value); |
1774 |
< |
if (putenv(evp) != 0) { |
1775 |
< |
fprintf(stderr, "%s: out of environment space\n", progname); |
1592 |
< |
exit(1); |
1770 |
> |
if (nprocs <= 1) |
1771 |
> |
return(0); /* it's us or no one */ |
1772 |
> |
if (inchild()) { |
1773 |
> |
fprintf(stderr, "%s: internal error 1 in next_process()\n", |
1774 |
> |
progname); |
1775 |
> |
quit(1); |
1776 |
|
} |
1777 |
< |
if (!silent) |
1778 |
< |
printf("set %s\n", evp); |
1777 |
> |
if (reserve > 0 && children_running >= nprocs-reserve) |
1778 |
> |
return(0); /* caller holding back process(es) */ |
1779 |
> |
if (children_running >= nprocs) |
1780 |
> |
wait_process(0); /* wait for someone to finish */ |
1781 |
> |
fflush(NULL); /* flush output */ |
1782 |
> |
child_pid = fork(); /* split process */ |
1783 |
> |
if (child_pid == 0) { /* we're the child */ |
1784 |
> |
children_running = -1; |
1785 |
> |
nprocs = 1; |
1786 |
> |
return(0); |
1787 |
> |
} |
1788 |
> |
if (child_pid > 0) { /* we're the parent */ |
1789 |
> |
++children_running; |
1790 |
> |
return(1); |
1791 |
> |
} |
1792 |
> |
fprintf(stderr, "%s: warning -- fork() failed\n", progname); |
1793 |
> |
return(0); |
1794 |
|
} |
1597 |
– |
#endif |
1795 |
|
|
1796 |
+ |
static void |
1797 |
+ |
wait_process( /* wait for process(es) to finish */ |
1798 |
+ |
int all |
1799 |
+ |
) |
1800 |
+ |
{ |
1801 |
+ |
int ourstatus = 0, status; |
1802 |
+ |
RT_PID pid; |
1803 |
|
|
1804 |
< |
badvalue(vc) /* report bad variable value and exit */ |
1805 |
< |
int vc; |
1804 |
> |
if (all) |
1805 |
> |
all = children_running; |
1806 |
> |
else if (children_running > 0) |
1807 |
> |
all = 1; |
1808 |
> |
while (all-- > 0) { |
1809 |
> |
pid = wait(&status); |
1810 |
> |
if (pid < 0) |
1811 |
> |
syserr(progname); |
1812 |
> |
status = status>>8 & 0xff; |
1813 |
> |
--children_running; |
1814 |
> |
if (status != 0) { /* child's problem is our problem */ |
1815 |
> |
if ((ourstatus == 0) & (children_running > 0)) |
1816 |
> |
fprintf(stderr, "%s: waiting for remaining processes\n", |
1817 |
> |
progname); |
1818 |
> |
ourstatus = status; |
1819 |
> |
all = children_running; |
1820 |
> |
} |
1821 |
> |
} |
1822 |
> |
if (ourstatus != 0) |
1823 |
> |
quit(ourstatus); /* bad status from child */ |
1824 |
> |
} |
1825 |
> |
#else /* ! RHAS_FORK_EXEC */ |
1826 |
> |
static int |
1827 |
> |
next_process(int reserve) |
1828 |
|
{ |
1829 |
+ |
return(0); /* cannot start new process */ |
1830 |
+ |
} |
1831 |
+ |
static void |
1832 |
+ |
wait_process(all) |
1833 |
+ |
int all; |
1834 |
+ |
{ |
1835 |
+ |
(void)all; /* no one to wait for */ |
1836 |
+ |
} |
1837 |
+ |
int |
1838 |
+ |
kill(pid, sig) /* win|unix_process.c should also wait and kill */ |
1839 |
+ |
RT_PID pid; |
1840 |
+ |
int sig; |
1841 |
+ |
{ |
1842 |
+ |
return 0; |
1843 |
+ |
} |
1844 |
+ |
#endif /* ! RHAS_FORK_EXEC */ |
1845 |
+ |
|
1846 |
+ |
static void |
1847 |
+ |
finish_process(void) /* exit a child process */ |
1848 |
+ |
{ |
1849 |
+ |
if (!inchild()) |
1850 |
+ |
return; /* in parent -- noop */ |
1851 |
+ |
exit(0); |
1852 |
+ |
} |
1853 |
+ |
|
1854 |
+ |
|
1855 |
+ |
static void |
1856 |
+ |
badvalue( /* report bad variable value and exit */ |
1857 |
+ |
int vc |
1858 |
+ |
) |
1859 |
+ |
{ |
1860 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1861 |
|
progname, vnam(vc)); |
1862 |
< |
exit(1); |
1862 |
> |
quit(1); |
1863 |
|
} |
1864 |
|
|
1865 |
|
|
1866 |
< |
syserr(s) /* report a system error and exit */ |
1867 |
< |
char *s; |
1866 |
> |
static void |
1867 |
> |
syserr( /* report a system error and exit */ |
1868 |
> |
char *s |
1869 |
> |
) |
1870 |
|
{ |
1871 |
|
perror(s); |
1872 |
< |
exit(1); |
1872 |
> |
quit(1); |
1873 |
> |
} |
1874 |
> |
|
1875 |
> |
|
1876 |
> |
void |
1877 |
> |
quit(ec) /* exit program */ |
1878 |
> |
int ec; |
1879 |
> |
{ |
1880 |
> |
exit(ec); |
1881 |
|
} |