1 |
– |
/* Copyright (c) 1993 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 <time.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" |
15 |
+ |
#include "view.h" |
16 |
+ |
#include "paths.h" |
17 |
+ |
#include "vars.h" |
18 |
|
|
19 |
< |
typedef struct { |
20 |
< |
char *name; /* variable name */ |
21 |
< |
short nick; /* # characters required for nickname */ |
22 |
< |
short nass; /* # assignments made */ |
23 |
< |
char *value; /* assigned value(s) */ |
24 |
< |
int (*fixval)(); /* assignment checking function */ |
25 |
< |
} VARIABLE; |
19 |
> |
#ifdef _WIN32 |
20 |
> |
#define DELCMD "del" |
21 |
> |
#define RENAMECMD "rename" |
22 |
> |
#else |
23 |
> |
#define DELCMD "rm -f" |
24 |
> |
#define RENAMECMD "mv" |
25 |
> |
#include <sys/types.h> |
26 |
> |
#include <sys/wait.h> |
27 |
> |
#endif |
28 |
|
|
29 |
< |
int onevalue(), catvalues(); |
30 |
< |
|
31 |
< |
/* variables */ |
32 |
< |
#define OBJECT 0 /* object files */ |
33 |
< |
#define SCENE 1 /* scene files */ |
34 |
< |
#define MATERIAL 2 /* material files */ |
35 |
< |
#define RENDER 3 /* rendering options */ |
36 |
< |
#define OCONV 4 /* oconv options */ |
37 |
< |
#define PFILT 5 /* pfilt options */ |
38 |
< |
#define VIEW 6 /* view(s) for picture(s) */ |
39 |
< |
#define ZONE 7 /* simulation zone */ |
40 |
< |
#define QUALITY 8 /* desired rendering quality */ |
41 |
< |
#define OCTREE 9 /* octree file name */ |
42 |
< |
#define PICTURE 10 /* picture file name */ |
43 |
< |
#define AMBFILE 11 /* ambient file name */ |
44 |
< |
#define OPTFILE 12 /* rendering options file */ |
45 |
< |
#define EXPOSURE 13 /* picture exposure setting */ |
46 |
< |
#define RESOLUTION 14 /* maximum picture resolution */ |
47 |
< |
#define UP 15 /* view up (X, Y or Z) */ |
48 |
< |
#define INDIRECT 16 /* indirection in lighting */ |
49 |
< |
#define DETAIL 17 /* level of scene detail */ |
50 |
< |
#define PENUMBRAS 18 /* shadow penumbras are desired */ |
51 |
< |
#define VARIABILITY 19 /* level of light variability */ |
52 |
< |
#define REPORT 20 /* report frequency and errfile */ |
29 |
> |
/* variables (alphabetical by name) */ |
30 |
> |
#define AMBFILE 0 /* ambient file name */ |
31 |
> |
#define DETAIL 1 /* level of scene detail */ |
32 |
> |
#define EXPOSURE 2 /* picture exposure setting */ |
33 |
> |
#define EYESEP 3 /* interocular distance */ |
34 |
> |
#define ILLUM 4 /* mkillum input files */ |
35 |
> |
#define INDIRECT 5 /* indirection in lighting */ |
36 |
> |
#define MATERIAL 6 /* material files */ |
37 |
> |
#define MKILLUM 7 /* mkillum options */ |
38 |
> |
#define OBJECT 8 /* object files */ |
39 |
> |
#define OCONV 9 /* oconv options */ |
40 |
> |
#define OCTREE 10 /* octree file name */ |
41 |
> |
#define OPTFILE 11 /* rendering options file */ |
42 |
> |
#define PENUMBRAS 12 /* shadow penumbras are desired */ |
43 |
> |
#define PFILT 13 /* pfilt options */ |
44 |
> |
#define PICTURE 14 /* picture file root name */ |
45 |
> |
#define QUALITY 15 /* desired rendering quality */ |
46 |
> |
#define RAWFILE 16 /* raw picture file root name */ |
47 |
> |
#define RENDER 17 /* rendering options */ |
48 |
> |
#define REPORT 18 /* report frequency and errfile */ |
49 |
> |
#define RESOLUTION 19 /* maximum picture resolution */ |
50 |
> |
#define RPICT 20 /* rpict parameters */ |
51 |
> |
#define RVU 21 /* rvu parameters */ |
52 |
> |
#define SCENE 22 /* scene files */ |
53 |
> |
#define UP 23 /* view up (X, Y or Z) */ |
54 |
> |
#define VARIABILITY 24 /* level of light variability */ |
55 |
> |
#define VIEWS 25 /* view(s) for picture(s) */ |
56 |
> |
#define ZFILE 26 /* distance file root name */ |
57 |
> |
#define ZONE 27 /* simulation zone */ |
58 |
|
/* total number of variables */ |
59 |
< |
#define NVARS 21 |
59 |
> |
int NVARS = 28; |
60 |
|
|
61 |
< |
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
62 |
< |
{"objects", 3, 0, NULL, catvalues}, |
63 |
< |
{"scene", 3, 0, NULL, catvalues}, |
61 |
> |
VARIABLE vv[] = { /* variable-value pairs */ |
62 |
> |
{"AMBFILE", 3, 0, NULL, onevalue}, |
63 |
> |
{"DETAIL", 3, 0, NULL, qualvalue}, |
64 |
> |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
65 |
> |
{"EYESEP", 3, 0, NULL, fltvalue}, |
66 |
> |
{"illum", 3, 0, NULL, catvalues}, |
67 |
> |
{"INDIRECT", 3, 0, NULL, intvalue}, |
68 |
|
{"materials", 3, 0, NULL, catvalues}, |
69 |
< |
{"render", 3, 0, NULL, catvalues}, |
69 |
> |
{"mkillum", 3, 0, NULL, catvalues}, |
70 |
> |
{"objects", 3, 0, NULL, catvalues}, |
71 |
|
{"oconv", 3, 0, NULL, catvalues}, |
57 |
– |
{"pfilt", 2, 0, NULL, catvalues}, |
58 |
– |
{"view", 2, 0, NULL, NULL}, |
59 |
– |
{"ZONE", 2, 0, NULL, onevalue}, |
60 |
– |
{"QUALITY", 3, 0, NULL, onevalue}, |
72 |
|
{"OCTREE", 3, 0, NULL, onevalue}, |
62 |
– |
{"PICTURE", 3, 0, NULL, onevalue}, |
63 |
– |
{"AMBFILE", 3, 0, NULL, onevalue}, |
73 |
|
{"OPTFILE", 3, 0, NULL, onevalue}, |
74 |
< |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
74 |
> |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
75 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
76 |
> |
{"PICTURE", 3, 0, NULL, onevalue}, |
77 |
> |
{"QUALITY", 3, 0, NULL, qualvalue}, |
78 |
> |
{"RAWFILE", 3, 0, NULL, onevalue}, |
79 |
> |
{"render", 3, 0, NULL, catvalues}, |
80 |
> |
{"REPORT", 3, 0, NULL, onevalue}, |
81 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
82 |
+ |
{"rpict", 3, 0, NULL, catvalues}, |
83 |
+ |
{"rvu", 3, 0, NULL, catvalues}, |
84 |
+ |
{"scene", 3, 0, NULL, catvalues}, |
85 |
|
{"UP", 2, 0, NULL, onevalue}, |
86 |
< |
{"INDIRECT", 3, 0, NULL, onevalue}, |
87 |
< |
{"DETAIL", 3, 0, NULL, onevalue}, |
88 |
< |
{"PENUMBRAS", 3, 0, NULL, onevalue}, |
89 |
< |
{"VARIABILITY", 3, 0, NULL, onevalue}, |
72 |
< |
{"REPORT", 3, 0, NULL, onevalue}, |
86 |
> |
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
87 |
> |
{"view", 2, 0, NULL, NULL}, |
88 |
> |
{"ZFILE", 2, 0, NULL, onevalue}, |
89 |
> |
{"ZONE", 2, 0, NULL, onevalue}, |
90 |
|
}; |
91 |
|
|
75 |
– |
VARIABLE *matchvar(); |
76 |
– |
char *nvalue(); |
77 |
– |
int vscale(); |
78 |
– |
|
79 |
– |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
80 |
– |
|
81 |
– |
#define vnam(vc) (vv[vc].name) |
82 |
– |
#define vdef(vc) (vv[vc].nass) |
83 |
– |
#define vval(vc) (vv[vc].value) |
84 |
– |
#define vint(vc) atoi(vval(vc)) |
85 |
– |
#define vlet(vc) UPPER(vval(vc)[0]) |
86 |
– |
#define vbool(vc) (vlet(vc)=='T') |
87 |
– |
|
88 |
– |
#define HIGH 2 |
89 |
– |
#define MEDIUM 1 |
90 |
– |
#define LOW 0 |
91 |
– |
|
92 |
– |
int lowqopts(), medqopts(), hiqopts(); |
93 |
– |
int (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; |
94 |
– |
|
95 |
– |
#define renderopts (*setqopts[vscale(QUALITY)]) |
96 |
– |
|
92 |
|
/* overture calculation file */ |
93 |
< |
#ifdef NIX |
94 |
< |
char overfile[] = "overture.raw"; |
93 |
> |
#ifdef NULL_DEVICE |
94 |
> |
char overfile[] = NULL_DEVICE; |
95 |
|
#else |
96 |
< |
char overfile[] = "/dev/null"; |
96 |
> |
char overfile[] = "overture.unf"; |
97 |
|
#endif |
98 |
|
|
104 |
– |
extern long fdate(), time(); |
99 |
|
|
100 |
< |
long scenedate; /* date of latest scene or object file */ |
101 |
< |
long octreedate; /* date of octree */ |
100 |
> |
time_t scenedate; /* date of latest scene or object file */ |
101 |
> |
time_t octreedate; /* date of octree */ |
102 |
> |
time_t matdate; /* date of latest material file */ |
103 |
> |
time_t illumdate; /* date of last illum file */ |
104 |
|
|
105 |
+ |
char *oct0name; /* name of pre-mkillum octree */ |
106 |
+ |
time_t oct0date; /* date of pre-mkillum octree */ |
107 |
+ |
char *oct1name; /* name of post-mkillum octree */ |
108 |
+ |
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
109 |
+ |
|
110 |
+ |
int nowarn = 0; /* no warnings */ |
111 |
|
int explicate = 0; /* explicate variables */ |
112 |
|
int silent = 0; /* do work silently */ |
113 |
< |
int noaction = 0; /* don't do anything */ |
114 |
< |
char *rvdevice = NULL; /* rview output device */ |
113 |
> |
int touchonly = 0; /* touch files only */ |
114 |
> |
int nprocs = 1; /* maximum executing processes */ |
115 |
> |
int sayview = 0; /* print view out */ |
116 |
> |
char *rvdevice = NULL; /* rvu output device */ |
117 |
|
char *viewselect = NULL; /* specific view only */ |
118 |
|
|
119 |
+ |
#define DEF_RPICT_PATH "rpict" /* default rpict path */ |
120 |
+ |
|
121 |
+ |
/* command paths */ |
122 |
+ |
char c_oconv[256] = "oconv"; |
123 |
+ |
char c_mkillum[256] = "mkillum"; |
124 |
+ |
char c_rvu[256] = "rvu"; |
125 |
+ |
char c_rpict[256] = DEF_RPICT_PATH; |
126 |
+ |
char c_rpiece[] = "rpiece"; |
127 |
+ |
char c_pfilt[256] = "pfilt"; |
128 |
+ |
|
129 |
|
int overture = 0; /* overture calculation needed */ |
130 |
|
|
131 |
+ |
int children_running = 0; /* set negative in children */ |
132 |
+ |
|
133 |
|
char *progname; /* global argv[0] */ |
134 |
+ |
char *rifname; /* global rad input file name */ |
135 |
|
|
136 |
< |
char radname[MAXPATH]; /* root Radiance file name */ |
136 |
> |
char radname[PATH_MAX]; /* root Radiance file name */ |
137 |
|
|
138 |
+ |
#define inchild() (children_running < 0) |
139 |
|
|
140 |
< |
main(argc, argv) |
141 |
< |
int argc; |
142 |
< |
char *argv[]; |
140 |
> |
static void rootname(char *rn, char *fn); |
141 |
> |
static time_t checklast(char *fnames); |
142 |
> |
static char * newfname(char *orig, int pred); |
143 |
> |
static void checkfiles(void); |
144 |
> |
static void getoctcube(double org[3], double *sizp); |
145 |
> |
static void setdefaults(void); |
146 |
> |
static void oconv(void); |
147 |
> |
static char * addarg(char *op, char *arg); |
148 |
> |
static void oconvopts(char *oo); |
149 |
> |
static void mkillumopts(char *mo); |
150 |
> |
static void checkambfile(void); |
151 |
> |
static double ambval(void); |
152 |
> |
static void renderopts(char *op, char *po); |
153 |
> |
static void lowqopts(char *op, char *po); |
154 |
> |
static void medqopts(char *op, char *po); |
155 |
> |
static void hiqopts(char *op, char *po); |
156 |
> |
static void xferopts(char *ro); |
157 |
> |
static void pfiltopts(char *po); |
158 |
> |
static int matchword(char *s1, char *s2); |
159 |
> |
static char * specview(char *vs); |
160 |
> |
static char * getview(int n, char *vn); |
161 |
> |
static int myprintview(char *vopts, FILE *fp); |
162 |
> |
static void rvu(char *opts, char *po); |
163 |
> |
static void rpict(char *opts, char *po); |
164 |
> |
static int touch(char *fn); |
165 |
> |
static int runcom(char *cs); |
166 |
> |
static int rmfile(char *fn); |
167 |
> |
static int mvfile(char *fold, char *fnew); |
168 |
> |
static int next_process(int reserve); |
169 |
> |
static void wait_process(int all); |
170 |
> |
static void finish_process(void); |
171 |
> |
static void badvalue(int vc); |
172 |
> |
static void syserr(char *s); |
173 |
> |
|
174 |
> |
|
175 |
> |
int |
176 |
> |
main( |
177 |
> |
int argc, |
178 |
> |
char *argv[] |
179 |
> |
) |
180 |
|
{ |
181 |
|
char ropts[512]; |
182 |
+ |
char popts[64]; |
183 |
|
int i; |
184 |
|
|
185 |
|
progname = argv[0]; |
190 |
|
silent++; |
191 |
|
break; |
192 |
|
case 'n': |
193 |
< |
noaction++; |
193 |
> |
nprocs = 0; |
194 |
|
break; |
195 |
+ |
case 'N': |
196 |
+ |
nprocs = atoi(argv[++i]); |
197 |
+ |
if (nprocs < 0) |
198 |
+ |
nprocs = 0; |
199 |
+ |
break; |
200 |
+ |
case 't': |
201 |
+ |
touchonly++; |
202 |
+ |
break; |
203 |
|
case 'e': |
204 |
|
explicate++; |
205 |
|
break; |
206 |
|
case 'o': |
207 |
|
rvdevice = argv[++i]; |
208 |
|
break; |
209 |
+ |
case 'V': |
210 |
+ |
sayview++; |
211 |
+ |
break; |
212 |
|
case 'v': |
213 |
|
viewselect = argv[++i]; |
214 |
|
break; |
215 |
+ |
case 'w': |
216 |
+ |
nowarn++; |
217 |
+ |
break; |
218 |
|
default: |
219 |
|
goto userr; |
220 |
|
} |
221 |
|
if (i >= argc) |
222 |
|
goto userr; |
223 |
+ |
rifname = argv[i]; |
224 |
|
/* assign Radiance root file name */ |
225 |
< |
rootname(radname, argv[i]); |
225 |
> |
rootname(radname, rifname); |
226 |
|
/* load variable values */ |
227 |
< |
load(argv[i]); |
227 |
> |
loadvars(rifname); |
228 |
|
/* get any additional assignments */ |
229 |
|
for (i++; i < argc; i++) |
230 |
< |
setvariable(argv[i]); |
230 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
231 |
> |
fprintf(stderr, "%s: unknown variable: %s\n", |
232 |
> |
progname, argv[i]); |
233 |
> |
quit(1); |
234 |
> |
} |
235 |
|
/* check assignments */ |
236 |
|
checkvalues(); |
237 |
|
/* check files and dates */ |
240 |
|
setdefaults(); |
241 |
|
/* print all values if requested */ |
242 |
|
if (explicate) |
243 |
< |
printvals(); |
244 |
< |
/* run simulation */ |
243 |
> |
printvars(stdout); |
244 |
> |
/* build octree (and run mkillum) */ |
245 |
|
oconv(); |
246 |
< |
renderopts(ropts); |
246 |
> |
/* check date on ambient file */ |
247 |
> |
checkambfile(); |
248 |
> |
/* run simulation */ |
249 |
> |
renderopts(ropts, popts); |
250 |
|
xferopts(ropts); |
251 |
|
if (rvdevice != NULL) |
252 |
< |
rview(ropts); |
252 |
> |
rvu(ropts, popts); |
253 |
|
else |
254 |
< |
rpict(ropts); |
255 |
< |
exit(0); |
254 |
> |
rpict(ropts, popts); |
255 |
> |
quit(0); |
256 |
|
userr: |
257 |
|
fprintf(stderr, |
258 |
< |
"Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n", |
258 |
> |
"Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
259 |
|
progname); |
260 |
< |
exit(1); |
260 |
> |
quit(1); |
261 |
> |
return 1; /* pro forma return */ |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
< |
rootname(rn, fn) /* remove tail from end of fn */ |
266 |
< |
register char *rn, *fn; |
265 |
> |
static void |
266 |
> |
rootname( /* remove tail from end of fn */ |
267 |
> |
register char *rn, |
268 |
> |
register char *fn |
269 |
> |
) |
270 |
|
{ |
271 |
|
char *tp, *dp; |
272 |
|
|
273 |
< |
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
273 |
> |
for (tp = NULL, dp = rn; (*rn = *fn++); rn++) |
274 |
|
if (ISDIRSEP(*rn)) |
275 |
|
dp = rn; |
276 |
|
else if (*rn == '.') |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
load(rfname) /* load Radiance simulation file */ |
284 |
< |
char *rfname; |
283 |
> |
static time_t |
284 |
> |
checklast( /* check files and find most recent */ |
285 |
> |
register char *fnames |
286 |
> |
) |
287 |
|
{ |
288 |
< |
FILE *fp; |
289 |
< |
char buf[512]; |
206 |
< |
register char *cp; |
288 |
> |
char thisfile[PATH_MAX]; |
289 |
> |
time_t thisdate, lastdate = 0; |
290 |
|
|
291 |
< |
if (rfname == NULL) |
292 |
< |
fp = stdin; |
293 |
< |
else if ((fp = fopen(rfname, "r")) == NULL) |
294 |
< |
syserr(rfname); |
295 |
< |
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
296 |
< |
for (cp = buf; *cp; cp++) { |
297 |
< |
switch (*cp) { |
298 |
< |
case '\\': |
216 |
< |
case '\n': |
217 |
< |
*cp = ' '; |
218 |
< |
continue; |
219 |
< |
case '#': |
220 |
< |
*cp = '\0'; |
221 |
< |
break; |
222 |
< |
default: |
223 |
< |
continue; |
224 |
< |
} |
225 |
< |
break; |
291 |
> |
if (fnames == NULL) |
292 |
> |
return(0); |
293 |
> |
while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { |
294 |
> |
if (thisfile[0] == '!' || |
295 |
> |
(thisfile[0] == '\\' && thisfile[1] == '!')) { |
296 |
> |
if (!lastdate) |
297 |
> |
lastdate = 1; |
298 |
> |
continue; |
299 |
|
} |
300 |
< |
setvariable(buf); |
300 |
> |
if (!(thisdate = fdate(thisfile))) |
301 |
> |
syserr(thisfile); |
302 |
> |
if (thisdate > lastdate) |
303 |
> |
lastdate = thisdate; |
304 |
|
} |
305 |
< |
fclose(fp); |
305 |
> |
return(lastdate); |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
< |
setvariable(ass) /* assign variable according to string */ |
310 |
< |
register char *ass; |
309 |
> |
static char * |
310 |
> |
newfname( /* create modified file name */ |
311 |
> |
char *orig, |
312 |
> |
int pred |
313 |
> |
) |
314 |
|
{ |
236 |
– |
char varname[32]; |
315 |
|
register char *cp; |
316 |
< |
register VARIABLE *vp; |
317 |
< |
register int i; |
240 |
< |
int n; |
316 |
> |
register int n; |
317 |
> |
int suffix; |
318 |
|
|
319 |
< |
while (isspace(*ass)) /* skip leading space */ |
320 |
< |
ass++; |
321 |
< |
cp = varname; /* extract name */ |
322 |
< |
while (cp < varname+sizeof(varname)-1 |
323 |
< |
&& *ass && !isspace(*ass) && *ass != '=') |
247 |
< |
*cp++ = *ass++; |
248 |
< |
*cp = '\0'; |
249 |
< |
if (!varname[0]) |
250 |
< |
return; /* no variable name! */ |
251 |
< |
/* trim value */ |
252 |
< |
while (isspace(*ass) || *ass == '=') |
253 |
< |
ass++; |
254 |
< |
cp = ass + strlen(ass); |
255 |
< |
do |
256 |
< |
*cp-- = '\0'; |
257 |
< |
while (cp >= ass && isspace(*cp)); |
258 |
< |
n = cp - ass + 1; |
259 |
< |
if (!n) { |
260 |
< |
fprintf(stderr, "%s: warning - missing value for variable '%s'\n", |
261 |
< |
progname, varname); |
262 |
< |
return; |
319 |
> |
n = 0; cp = orig; suffix = -1; /* suffix position, length */ |
320 |
> |
while (*cp) { |
321 |
> |
if (*cp == '.') suffix = n; |
322 |
> |
else if (ISDIRSEP(*cp)) suffix = -1; |
323 |
> |
cp++; n++; |
324 |
|
} |
325 |
< |
/* match variable from list */ |
326 |
< |
vp = matchvar(varname); |
266 |
< |
if (vp == NULL) { |
267 |
< |
fprintf(stderr, "%s: unknown variable '%s'\n", |
268 |
< |
progname, varname); |
269 |
< |
exit(1); |
270 |
< |
} |
271 |
< |
/* assign new value */ |
272 |
< |
if (i = vp->nass) { |
273 |
< |
cp = vp->value; |
274 |
< |
while (i--) |
275 |
< |
while (*cp++) |
276 |
< |
; |
277 |
< |
i = cp - vp->value; |
278 |
< |
vp->value = realloc(vp->value, i+n+1); |
279 |
< |
} else |
280 |
< |
vp->value = malloc(n+1); |
281 |
< |
if (vp->value == NULL) |
325 |
> |
if (suffix == -1) suffix = n; |
326 |
> |
if ((cp = bmalloc(n+2)) == NULL) |
327 |
|
syserr(progname); |
328 |
< |
strcpy(vp->value+i, ass); |
329 |
< |
vp->nass++; |
330 |
< |
} |
286 |
< |
|
287 |
< |
|
288 |
< |
VARIABLE * |
289 |
< |
matchvar(nam) /* match a variable by its name */ |
290 |
< |
char *nam; |
291 |
< |
{ |
292 |
< |
int n = strlen(nam); |
293 |
< |
register int i; |
294 |
< |
|
295 |
< |
for (i = 0; i < NVARS; i++) |
296 |
< |
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
297 |
< |
return(vv+i); |
298 |
< |
return(NULL); |
299 |
< |
} |
300 |
< |
|
301 |
< |
|
302 |
< |
char * |
303 |
< |
nvalue(vp, n) /* return nth variable value */ |
304 |
< |
VARIABLE *vp; |
305 |
< |
register int n; |
306 |
< |
{ |
307 |
< |
register char *cp; |
308 |
< |
|
309 |
< |
if (vp == NULL || n < 0 || n >= vp->nass) |
310 |
< |
return(NULL); |
311 |
< |
cp = vp->value; |
312 |
< |
while (n--) |
313 |
< |
while (*cp++) |
314 |
< |
; |
328 |
> |
strncpy(cp, orig, suffix); |
329 |
> |
cp[suffix] = pred; /* root name + pred + suffix */ |
330 |
> |
strcpy(cp+suffix+1, orig+suffix); |
331 |
|
return(cp); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
< |
int |
336 |
< |
vscale(vc) /* return scale for variable vc */ |
321 |
< |
int vc; |
335 |
> |
static void |
336 |
> |
checkfiles(void) /* check for existence and modified times */ |
337 |
|
{ |
338 |
< |
switch(vlet(vc)) { |
324 |
< |
case 'H': |
325 |
< |
return(HIGH); |
326 |
< |
case 'M': |
327 |
< |
return(MEDIUM); |
328 |
< |
case 'L': |
329 |
< |
return(LOW); |
330 |
< |
} |
331 |
< |
badvalue(vc); |
332 |
< |
} |
338 |
> |
time_t objdate; |
339 |
|
|
334 |
– |
|
335 |
– |
checkvalues() /* check assignments */ |
336 |
– |
{ |
337 |
– |
register int i; |
338 |
– |
|
339 |
– |
for (i = 0; i < NVARS; i++) |
340 |
– |
if (vv[i].fixval != NULL) |
341 |
– |
(*vv[i].fixval)(vv+i); |
342 |
– |
} |
343 |
– |
|
344 |
– |
|
345 |
– |
onevalue(vp) /* only one assignment for this variable */ |
346 |
– |
register VARIABLE *vp; |
347 |
– |
{ |
348 |
– |
if (vp->nass < 2) |
349 |
– |
return; |
350 |
– |
fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n", |
351 |
– |
progname, vp->name); |
352 |
– |
do |
353 |
– |
vp->value += strlen(vp->value)+1; |
354 |
– |
while (--vp->nass > 1); |
355 |
– |
} |
356 |
– |
|
357 |
– |
|
358 |
– |
catvalues(vp) /* concatenate variable values */ |
359 |
– |
register VARIABLE *vp; |
360 |
– |
{ |
361 |
– |
register char *cp; |
362 |
– |
|
363 |
– |
if (vp->nass < 2) |
364 |
– |
return; |
365 |
– |
for (cp = vp->value; vp->nass > 1; vp->nass--) { |
366 |
– |
while (*cp) |
367 |
– |
cp++; |
368 |
– |
*cp++ = ' '; |
369 |
– |
} |
370 |
– |
} |
371 |
– |
|
372 |
– |
|
373 |
– |
long |
374 |
– |
checklast(fnames) /* check files and find most recent */ |
375 |
– |
register char *fnames; |
376 |
– |
{ |
377 |
– |
char thisfile[MAXPATH]; |
378 |
– |
long thisdate, lastdate = -1; |
379 |
– |
register char *cp; |
380 |
– |
|
381 |
– |
while (*fnames) { |
382 |
– |
while (isspace(*fnames)) fnames++; |
383 |
– |
cp = thisfile; |
384 |
– |
while (*fnames && !isspace(*fnames)) |
385 |
– |
*cp++ = *fnames++; |
386 |
– |
*cp = '\0'; |
387 |
– |
if ((thisdate = fdate(thisfile)) < 0) |
388 |
– |
syserr(thisfile); |
389 |
– |
if (thisdate > lastdate) |
390 |
– |
lastdate = thisdate; |
391 |
– |
} |
392 |
– |
return(lastdate); |
393 |
– |
} |
394 |
– |
|
395 |
– |
|
396 |
– |
checkfiles() /* check for existence and modified times */ |
397 |
– |
{ |
398 |
– |
char *cp; |
399 |
– |
long objdate; |
400 |
– |
|
340 |
|
if (!vdef(OCTREE)) { |
341 |
< |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) |
341 |
> |
if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL) |
342 |
|
syserr(progname); |
343 |
< |
sprintf(cp, "%s.oct", radname); |
405 |
< |
vval(OCTREE) = cp; |
343 |
> |
sprintf(vval(OCTREE), "%s.oct", radname); |
344 |
|
vdef(OCTREE)++; |
345 |
+ |
} else if (vval(OCTREE)[0] == '!') { |
346 |
+ |
fprintf(stderr, "%s: illegal '%s' specification\n", |
347 |
+ |
progname, vnam(OCTREE)); |
348 |
+ |
quit(1); |
349 |
|
} |
350 |
|
octreedate = fdate(vval(OCTREE)); |
351 |
< |
scenedate = -1; |
352 |
< |
if (vdef(SCENE)) { |
353 |
< |
scenedate = checklast(vval(SCENE)); |
354 |
< |
if (vdef(OBJECT)) { |
355 |
< |
objdate = checklast(vval(OBJECT)); |
356 |
< |
if (objdate > scenedate) |
357 |
< |
scenedate = objdate; |
358 |
< |
} |
351 |
> |
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
352 |
> |
oct0name = newfname(vval(OCTREE), '0'); |
353 |
> |
oct1name = newfname(vval(OCTREE), '1'); |
354 |
> |
oct0date = fdate(oct0name); |
355 |
> |
oct1date = fdate(oct1name); |
356 |
> |
} else |
357 |
> |
oct0name = oct1name = vval(OCTREE); |
358 |
> |
if ((scenedate = checklast(vval(SCENE))) && |
359 |
> |
(objdate = checklast(vval(OBJECT))) > scenedate) |
360 |
> |
scenedate = objdate; |
361 |
> |
illumdate = checklast(vval(ILLUM)); |
362 |
> |
if (!octreedate & !scenedate & !illumdate) { |
363 |
> |
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
364 |
> |
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
365 |
> |
quit(1); |
366 |
|
} |
367 |
< |
if (octreedate < 0 & scenedate < 0) { |
419 |
< |
fprintf(stderr, "%s: need '%s' or '%s'\n", progname, |
420 |
< |
vnam(OCTREE), vnam(SCENE)); |
421 |
< |
exit(1); |
422 |
< |
} |
367 |
> |
matdate = checklast(vval(MATERIAL)); |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
< |
getoctcube(org, sizp) /* get octree bounding cube */ |
372 |
< |
double org[3], *sizp; |
371 |
> |
static void |
372 |
> |
getoctcube( /* get octree bounding cube */ |
373 |
> |
double org[3], |
374 |
> |
double *sizp |
375 |
> |
) |
376 |
|
{ |
429 |
– |
extern FILE *popen(); |
377 |
|
static double oorg[3], osiz = 0.; |
378 |
< |
char buf[MAXPATH+16]; |
378 |
> |
double min[3], max[3]; |
379 |
> |
char buf[1024]; |
380 |
|
FILE *fp; |
381 |
+ |
register int i; |
382 |
|
|
383 |
|
if (osiz <= FTINY) { |
384 |
< |
oconv(); /* does nothing if done already */ |
385 |
< |
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
386 |
< |
if ((fp = popen(buf, "r")) == NULL) |
387 |
< |
syserr("getinfo"); |
388 |
< |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
389 |
< |
&oorg[2], &osiz) != 4) { |
390 |
< |
fprintf(stderr, |
384 |
> |
if (!nprocs && fdate(oct1name) < |
385 |
> |
(scenedate>illumdate?scenedate:illumdate)) { |
386 |
> |
/* run getbbox */ |
387 |
> |
sprintf(buf, "getbbox -w -h %s", |
388 |
> |
vdef(SCENE) ? vval(SCENE) : vval(ILLUM)); |
389 |
> |
if ((fp = popen(buf, "r")) == NULL) |
390 |
> |
syserr("getbbox"); |
391 |
> |
if (fscanf(fp, "%lf %lf %lf %lf %lf %lf", |
392 |
> |
&min[0], &max[0], &min[1], &max[1], |
393 |
> |
&min[2], &max[2]) != 6) { |
394 |
> |
fprintf(stderr, |
395 |
> |
"%s: error reading bounding box from getbbox\n", |
396 |
> |
progname); |
397 |
> |
quit(1); |
398 |
> |
} |
399 |
> |
for (i = 0; i < 3; i++) |
400 |
> |
if (max[i] - min[i] > osiz) |
401 |
> |
osiz = max[i] - min[i]; |
402 |
> |
for (i = 0; i < 3; i++) |
403 |
> |
oorg[i] = (max[i]+min[i]-osiz)*.5; |
404 |
> |
pclose(fp); |
405 |
> |
} else { /* from octree */ |
406 |
> |
oconv(); /* does nothing if done already */ |
407 |
> |
sprintf(buf, "getinfo -d < %s", oct1name); |
408 |
> |
if ((fp = popen(buf, "r")) == NULL) |
409 |
> |
syserr("getinfo"); |
410 |
> |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
411 |
> |
&oorg[2], &osiz) != 4) { |
412 |
> |
fprintf(stderr, |
413 |
|
"%s: error reading bounding cube from getinfo\n", |
414 |
< |
progname); |
415 |
< |
exit(1); |
414 |
> |
progname); |
415 |
> |
quit(1); |
416 |
> |
} |
417 |
> |
pclose(fp); |
418 |
|
} |
446 |
– |
pclose(fp); |
419 |
|
} |
420 |
|
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
< |
setdefaults() /* set default values for unassigned var's */ |
424 |
> |
static void |
425 |
> |
setdefaults(void) /* set default values for unassigned var's */ |
426 |
|
{ |
427 |
< |
double org[3], size; |
427 |
> |
double org[3], lim[3], size; |
428 |
|
char buf[128]; |
429 |
|
|
430 |
|
if (!vdef(ZONE)) { |
434 |
|
vval(ZONE) = savqstr(buf); |
435 |
|
vdef(ZONE)++; |
436 |
|
} |
437 |
+ |
if (!vdef(EYESEP)) { |
438 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
439 |
+ |
&org[0], &lim[0], &org[1], &lim[1], |
440 |
+ |
&org[2], &lim[2]) != 6) |
441 |
+ |
badvalue(ZONE); |
442 |
+ |
sprintf(buf, "%f", |
443 |
+ |
0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); |
444 |
+ |
vval(EYESEP) = savqstr(buf); |
445 |
+ |
vdef(EYESEP)++; |
446 |
+ |
} |
447 |
|
if (!vdef(INDIRECT)) { |
448 |
|
vval(INDIRECT) = "0"; |
449 |
|
vdef(INDIRECT)++; |
460 |
|
vval(PICTURE) = radname; |
461 |
|
vdef(PICTURE)++; |
462 |
|
} |
463 |
< |
if (!vdef(VIEW)) { |
464 |
< |
vval(VIEW) = "X"; |
465 |
< |
vdef(VIEW)++; |
463 |
> |
if (!vdef(VIEWS)) { |
464 |
> |
vval(VIEWS) = "X"; |
465 |
> |
vdef(VIEWS)++; |
466 |
|
} |
467 |
|
if (!vdef(DETAIL)) { |
468 |
|
vval(DETAIL) = "M"; |
479 |
|
} |
480 |
|
|
481 |
|
|
482 |
< |
printvals() /* print variable values */ |
482 |
> |
static void |
483 |
> |
oconv(void) /* run oconv and mkillum if necessary */ |
484 |
|
{ |
485 |
< |
register int i, j; |
485 |
> |
static char illumtmp[] = "ilXXXXXX"; |
486 |
> |
char combuf[PATH_MAX], ocopts[64], mkopts[1024]; |
487 |
|
|
488 |
< |
for (i = 0; i < NVARS; i++) |
489 |
< |
for (j = 0; j < vdef(i); j++) |
490 |
< |
printf("%s= %s\n", vnam(i), nvalue(vv+i, j)); |
491 |
< |
fflush(stdout); |
492 |
< |
} |
493 |
< |
|
494 |
< |
|
495 |
< |
oconv() /* run oconv if necessary */ |
496 |
< |
{ |
497 |
< |
char combuf[512], ocopts[64]; |
498 |
< |
|
499 |
< |
if (octreedate >= scenedate) /* check dates */ |
488 |
> |
oconvopts(ocopts); /* get options */ |
489 |
> |
if (octreedate < scenedate) { /* check date on original octree */ |
490 |
> |
if (touchonly && octreedate) |
491 |
> |
touch(vval(OCTREE)); |
492 |
> |
else { /* build command */ |
493 |
> |
if (vdef(MATERIAL)) |
494 |
> |
sprintf(combuf, "%s%s %s %s > %s", c_oconv, |
495 |
> |
ocopts, vval(MATERIAL), |
496 |
> |
vval(SCENE), vval(OCTREE)); |
497 |
> |
else |
498 |
> |
sprintf(combuf, "%s%s %s > %s", c_oconv, ocopts, |
499 |
> |
vval(SCENE), vval(OCTREE)); |
500 |
> |
|
501 |
> |
if (runcom(combuf)) { /* run it */ |
502 |
> |
fprintf(stderr, |
503 |
> |
"%s: error generating octree\n\t%s removed\n", |
504 |
> |
progname, vval(OCTREE)); |
505 |
> |
unlink(vval(OCTREE)); |
506 |
> |
quit(1); |
507 |
> |
} |
508 |
> |
} |
509 |
> |
octreedate = time((time_t *)NULL); |
510 |
> |
if (octreedate < scenedate) /* in case clock is off */ |
511 |
> |
octreedate = scenedate; |
512 |
> |
} |
513 |
> |
if (oct1name == vval(OCTREE)) /* no mkillum? */ |
514 |
> |
oct1date = octreedate > matdate ? octreedate : matdate; |
515 |
> |
if ((oct1date >= octreedate) & (oct1date >= matdate) |
516 |
> |
& (oct1date >= illumdate)) /* all done */ |
517 |
|
return; |
518 |
< |
/* build command */ |
519 |
< |
oconvopts(ocopts); |
520 |
< |
if (vdef(MATERIAL)) |
521 |
< |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
522 |
< |
vval(MATERIAL), vval(SCENE), vval(OCTREE)); |
523 |
< |
else |
524 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
525 |
< |
vval(SCENE), vval(OCTREE)); |
526 |
< |
|
527 |
< |
if (runcom(combuf)) { /* run it */ |
528 |
< |
fprintf(stderr, "%s: error generating octree\n\t%s removed\n", |
529 |
< |
progname, vval(OCTREE)); |
530 |
< |
unlink(vval(OCTREE)); |
531 |
< |
exit(1); |
518 |
> |
/* make octree0 */ |
519 |
> |
if ((oct0date < scenedate) | (oct0date < illumdate)) { |
520 |
> |
if (touchonly && oct0date) |
521 |
> |
touch(oct0name); |
522 |
> |
else { /* build command */ |
523 |
> |
if (octreedate) |
524 |
> |
sprintf(combuf, "%s%s -i %s %s > %s", c_oconv, |
525 |
> |
ocopts, vval(OCTREE), |
526 |
> |
vval(ILLUM), oct0name); |
527 |
> |
else if (vdef(MATERIAL)) |
528 |
> |
sprintf(combuf, "%s%s %s %s > %s", c_oconv, |
529 |
> |
ocopts, vval(MATERIAL), |
530 |
> |
vval(ILLUM), oct0name); |
531 |
> |
else |
532 |
> |
sprintf(combuf, "%s%s %s > %s", c_oconv, |
533 |
> |
ocopts, vval(ILLUM), oct0name); |
534 |
> |
if (runcom(combuf)) { /* run it */ |
535 |
> |
fprintf(stderr, |
536 |
> |
"%s: error generating octree\n\t%s removed\n", |
537 |
> |
progname, oct0name); |
538 |
> |
unlink(oct0name); |
539 |
> |
quit(1); |
540 |
> |
} |
541 |
> |
} |
542 |
> |
oct0date = time((time_t *)NULL); |
543 |
> |
if (oct0date < octreedate) /* in case clock is off */ |
544 |
> |
oct0date = octreedate; |
545 |
> |
if (oct0date < illumdate) /* ditto */ |
546 |
> |
oct0date = illumdate; |
547 |
> |
} |
548 |
> |
if (touchonly && oct1date) |
549 |
> |
touch(oct1name); |
550 |
> |
else { |
551 |
> |
mkillumopts(mkopts); /* build mkillum command */ |
552 |
> |
mktemp(illumtmp); |
553 |
> |
sprintf(combuf, "%s%s %s \"<\" %s > %s", c_mkillum, mkopts, |
554 |
> |
oct0name, vval(ILLUM), illumtmp); |
555 |
> |
if (runcom(combuf)) { /* run it */ |
556 |
> |
fprintf(stderr, "%s: error running %s\n", |
557 |
> |
progname, c_mkillum); |
558 |
> |
unlink(illumtmp); |
559 |
> |
quit(1); |
560 |
> |
} |
561 |
> |
/* make octree1 (frozen) */ |
562 |
> |
if (octreedate) |
563 |
> |
sprintf(combuf, "%s%s -f -i %s %s > %s", c_oconv, |
564 |
> |
ocopts, vval(OCTREE), illumtmp, oct1name); |
565 |
> |
else if (vdef(MATERIAL)) |
566 |
> |
sprintf(combuf, "%s%s -f %s %s > %s", c_oconv, |
567 |
> |
ocopts, vval(MATERIAL), illumtmp, oct1name); |
568 |
> |
else |
569 |
> |
sprintf(combuf, "%s%s -f %s > %s", c_oconv, ocopts, |
570 |
> |
illumtmp, oct1name); |
571 |
> |
if (runcom(combuf)) { /* run it */ |
572 |
> |
fprintf(stderr, |
573 |
> |
"%s: error generating octree\n\t%s removed\n", |
574 |
> |
progname, oct1name); |
575 |
> |
unlink(oct1name); |
576 |
> |
unlink(illumtmp); |
577 |
> |
quit(1); |
578 |
> |
} |
579 |
> |
rmfile(illumtmp); |
580 |
|
} |
581 |
< |
octreedate = time(0); |
581 |
> |
oct1date = time((time_t *)NULL); |
582 |
> |
if (oct1date < oct0date) /* in case clock is off */ |
583 |
> |
oct1date = oct0date; |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
< |
char * |
588 |
< |
addarg(op, arg) /* add argument and advance pointer */ |
589 |
< |
register char *op, *arg; |
587 |
> |
static char * |
588 |
> |
addarg( /* append argument and advance pointer */ |
589 |
> |
register char *op, |
590 |
> |
register char *arg |
591 |
> |
) |
592 |
|
{ |
593 |
+ |
while (*op) |
594 |
+ |
op++; |
595 |
|
*op = ' '; |
596 |
< |
while (*++op = *arg++) |
596 |
> |
while ( (*++op = *arg++) ) |
597 |
|
; |
598 |
|
return(op); |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
< |
oconvopts(oo) /* get oconv options */ |
603 |
< |
register char *oo; |
602 |
> |
static void |
603 |
> |
oconvopts( /* get oconv options */ |
604 |
> |
register char *oo |
605 |
> |
) |
606 |
|
{ |
607 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
608 |
|
|
609 |
|
*oo = '\0'; |
610 |
|
if (vdef(OCONV)) |
611 |
< |
addarg(oo, vval(OCONV)); |
611 |
> |
if (vval(OCONV)[0] != '-') { |
612 |
> |
atos(c_oconv, sizeof(c_oconv), vval(OCONV)); |
613 |
> |
oo = addarg(oo, sskip2(vval(OCONV), 1)); |
614 |
> |
} else |
615 |
> |
oo = addarg(oo, vval(OCONV)); |
616 |
|
} |
617 |
|
|
618 |
|
|
619 |
< |
double |
620 |
< |
ambval() /* compute ambient value */ |
619 |
> |
static void |
620 |
> |
mkillumopts( /* get mkillum options */ |
621 |
> |
char *mo |
622 |
> |
) |
623 |
|
{ |
624 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
625 |
+ |
|
626 |
+ |
if (nprocs > 1) |
627 |
+ |
sprintf(mo, " -n %d", nprocs); |
628 |
+ |
else |
629 |
+ |
*mo = '\0'; |
630 |
+ |
if (vdef(MKILLUM)) |
631 |
+ |
if (vval(MKILLUM)[0] != '-') { |
632 |
+ |
atos(c_mkillum, sizeof(c_mkillum), vval(MKILLUM)); |
633 |
+ |
mo = addarg(mo, sskip2(vval(MKILLUM), 1)); |
634 |
+ |
} else |
635 |
+ |
mo = addarg(mo, vval(MKILLUM)); |
636 |
+ |
} |
637 |
+ |
|
638 |
+ |
|
639 |
+ |
static void |
640 |
+ |
checkambfile(void) /* check date on ambient file */ |
641 |
+ |
{ |
642 |
+ |
time_t afdate; |
643 |
+ |
|
644 |
+ |
if (!vdef(AMBFILE)) |
645 |
+ |
return; |
646 |
+ |
if (!(afdate = fdate(vval(AMBFILE)))) |
647 |
+ |
return; |
648 |
+ |
if (oct1date > afdate) { |
649 |
+ |
if (touchonly) |
650 |
+ |
touch(vval(AMBFILE)); |
651 |
+ |
else |
652 |
+ |
rmfile(vval(AMBFILE)); |
653 |
+ |
} |
654 |
+ |
} |
655 |
+ |
|
656 |
+ |
|
657 |
+ |
static double |
658 |
+ |
ambval(void) /* compute ambient value */ |
659 |
+ |
{ |
660 |
|
if (vdef(EXPOSURE)) { |
661 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
662 |
< |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
663 |
< |
if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') |
564 |
< |
return(.5/atof(vval(EXPOSURE))); |
565 |
< |
badvalue(EXPOSURE); |
662 |
> |
return(.5/pow(2.,vflt(EXPOSURE))); |
663 |
> |
return(.5/vflt(EXPOSURE)); |
664 |
|
} |
665 |
|
if (vlet(ZONE) == 'E') |
666 |
|
return(10.); |
667 |
|
if (vlet(ZONE) == 'I') |
668 |
|
return(.01); |
669 |
|
badvalue(ZONE); |
670 |
+ |
return 0; /* pro forma return */ |
671 |
|
} |
672 |
|
|
673 |
|
|
674 |
< |
lowqopts(op) /* low quality rendering options */ |
675 |
< |
register char *op; |
674 |
> |
static void |
675 |
> |
renderopts( /* set rendering options */ |
676 |
> |
char *op, |
677 |
> |
char *po |
678 |
> |
) |
679 |
|
{ |
680 |
+ |
switch(vscale(QUALITY)) { |
681 |
+ |
case LOW: |
682 |
+ |
lowqopts(op, po); |
683 |
+ |
break; |
684 |
+ |
case MEDIUM: |
685 |
+ |
medqopts(op, po); |
686 |
+ |
break; |
687 |
+ |
case HIGH: |
688 |
+ |
hiqopts(op, po); |
689 |
+ |
break; |
690 |
+ |
} |
691 |
+ |
if (vdef(RENDER)) |
692 |
+ |
op = addarg(op, vval(RENDER)); |
693 |
+ |
if (rvdevice != NULL) { |
694 |
+ |
if (vdef(RVU)) |
695 |
+ |
if (vval(RVU)[0] != '-') { |
696 |
+ |
atos(c_rvu, sizeof(c_rvu), vval(RVU)); |
697 |
+ |
po = addarg(po, sskip2(vval(RVU), 1)); |
698 |
+ |
} else |
699 |
+ |
po = addarg(po, vval(RVU)); |
700 |
+ |
} else { |
701 |
+ |
if (vdef(RPICT)) |
702 |
+ |
if (vval(RPICT)[0] != '-') { |
703 |
+ |
atos(c_rpict, sizeof(c_rpict), vval(RPICT)); |
704 |
+ |
po = addarg(po, sskip2(vval(RPICT), 1)); |
705 |
+ |
} else |
706 |
+ |
po = addarg(po, vval(RPICT)); |
707 |
+ |
} |
708 |
+ |
} |
709 |
+ |
|
710 |
+ |
|
711 |
+ |
static void |
712 |
+ |
lowqopts( /* low quality rendering options */ |
713 |
+ |
register char *op, |
714 |
+ |
char *po |
715 |
+ |
) |
716 |
+ |
{ |
717 |
|
double d, org[3], siz[3]; |
718 |
|
|
719 |
|
*op = '\0'; |
720 |
+ |
*po = '\0'; |
721 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
722 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
723 |
|
badvalue(ZONE); |
724 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
725 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
726 |
+ |
badvalue(ZONE); |
727 |
|
getoctcube(org, &d); |
728 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
729 |
|
switch (vscale(DETAIL)) { |
730 |
|
case LOW: |
731 |
< |
op = addarg(op, "-ps 16 -dp 16"); |
732 |
< |
sprintf(op, " -ar %d", (int)(4*d)); |
731 |
> |
po = addarg(po, "-ps 16"); |
732 |
> |
op = addarg(op, "-dp 64"); |
733 |
> |
sprintf(op, " -ar %d", (int)(8*d)); |
734 |
|
op += strlen(op); |
735 |
|
break; |
736 |
|
case MEDIUM: |
737 |
< |
op = addarg(op, "-ps 8 -dp 32"); |
738 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
737 |
> |
po = addarg(po, "-ps 8"); |
738 |
> |
op = addarg(op, "-dp 128"); |
739 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
740 |
|
op += strlen(op); |
741 |
|
break; |
742 |
|
case HIGH: |
743 |
< |
op = addarg(op, "-ps 4 -dp 64"); |
744 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
743 |
> |
po = addarg(po, "-ps 4"); |
744 |
> |
op = addarg(op, "-dp 256"); |
745 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
746 |
|
op += strlen(op); |
747 |
|
break; |
748 |
|
} |
749 |
< |
op = addarg(op, "-pt .16"); |
749 |
> |
po = addarg(po, "-pt .16"); |
750 |
|
if (vbool(PENUMBRAS)) |
751 |
|
op = addarg(op, "-ds .4"); |
752 |
|
else |
753 |
|
op = addarg(op, "-ds 0"); |
754 |
< |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7"); |
754 |
> |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -ss 0 -st .5"); |
755 |
|
if (vdef(AMBFILE)) { |
756 |
|
sprintf(op, " -af %s", vval(AMBFILE)); |
757 |
|
op += strlen(op); |
759 |
|
overture = 0; |
760 |
|
switch (vscale(VARIABILITY)) { |
761 |
|
case LOW: |
762 |
< |
op = addarg(op, "-aa .4 -ad 32"); |
762 |
> |
op = addarg(op, "-aa .3 -ad 256"); |
763 |
|
break; |
764 |
|
case MEDIUM: |
765 |
< |
op = addarg(op, "-aa .3 -ad 64"); |
765 |
> |
op = addarg(op, "-aa .25 -ad 512"); |
766 |
|
break; |
767 |
|
case HIGH: |
768 |
< |
op = addarg(op, "-aa .25 -ad 128"); |
768 |
> |
op = addarg(op, "-aa .2 -ad 1024"); |
769 |
|
break; |
770 |
|
} |
771 |
|
op = addarg(op, "-as 0"); |
772 |
|
d = ambval(); |
773 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
774 |
|
op += strlen(op); |
775 |
< |
op = addarg(op, "-lr 3 -lw .02"); |
631 |
< |
if (vdef(RENDER)) |
632 |
< |
op = addarg(op, vval(RENDER)); |
775 |
> |
op = addarg(op, "-lr 6 -lw .003"); |
776 |
|
} |
777 |
|
|
778 |
|
|
779 |
< |
medqopts(op) /* medium quality rendering options */ |
780 |
< |
register char *op; |
779 |
> |
static void |
780 |
> |
medqopts( /* medium quality rendering options */ |
781 |
> |
register char *op, |
782 |
> |
char *po |
783 |
> |
) |
784 |
|
{ |
785 |
< |
double d, org[3], siz[3]; |
785 |
> |
double d, org[3], siz[3], asz; |
786 |
|
|
787 |
|
*op = '\0'; |
788 |
+ |
*po = '\0'; |
789 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
790 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
791 |
|
badvalue(ZONE); |
792 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
793 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
794 |
+ |
badvalue(ZONE); |
795 |
|
getoctcube(org, &d); |
796 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
796 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
797 |
> |
d /= asz; |
798 |
|
switch (vscale(DETAIL)) { |
799 |
|
case LOW: |
800 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
801 |
< |
op = addarg(op, "-dp 64"); |
802 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
800 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
801 |
> |
op = addarg(op, "-dp 256"); |
802 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
803 |
|
op += strlen(op); |
804 |
+ |
sprintf(op, " -ms %.2g", asz/20.); |
805 |
+ |
op += strlen(op); |
806 |
|
break; |
807 |
|
case MEDIUM: |
808 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
809 |
< |
op = addarg(op, "-dp 128"); |
810 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
808 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
809 |
> |
op = addarg(op, "-dp 512"); |
810 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
811 |
|
op += strlen(op); |
812 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
813 |
+ |
op += strlen(op); |
814 |
|
break; |
815 |
|
case HIGH: |
816 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
817 |
< |
op = addarg(op, "-dp 256"); |
818 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
816 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
817 |
> |
op = addarg(op, "-dp 1024"); |
818 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
819 |
|
op += strlen(op); |
820 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
821 |
+ |
op += strlen(op); |
822 |
|
break; |
823 |
|
} |
824 |
< |
op = addarg(op, "-pt .08"); |
824 |
> |
po = addarg(po, "-pt .08"); |
825 |
|
if (vbool(PENUMBRAS)) |
826 |
< |
op = addarg(op, "-ds .2 -dj .35"); |
826 |
> |
op = addarg(op, "-ds .2 -dj .9"); |
827 |
|
else |
828 |
|
op = addarg(op, "-ds .3"); |
829 |
< |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); |
830 |
< |
if (overture = vint(INDIRECT)) { |
829 |
> |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -ss 1 -st .1"); |
830 |
> |
if ( (overture = vint(INDIRECT)) ) { |
831 |
|
sprintf(op, " -ab %d", overture); |
832 |
|
op += strlen(op); |
833 |
|
} |
838 |
|
overture = 0; |
839 |
|
switch (vscale(VARIABILITY)) { |
840 |
|
case LOW: |
841 |
< |
op = addarg(op, "-aa .25 -ad 128 -as 0"); |
841 |
> |
op = addarg(op, "-aa .2 -ad 329 -as 42"); |
842 |
|
break; |
843 |
|
case MEDIUM: |
844 |
< |
op = addarg(op, "-aa .2 -ad 300 -as 64"); |
844 |
> |
op = addarg(op, "-aa .15 -ad 800 -as 128"); |
845 |
|
break; |
846 |
|
case HIGH: |
847 |
< |
op = addarg(op, "-aa .15 -ad 500 -as 128"); |
847 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 392"); |
848 |
|
break; |
849 |
|
} |
850 |
|
d = ambval(); |
851 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
852 |
|
op += strlen(op); |
853 |
< |
op = addarg(op, "-lr 6 -lw .002"); |
698 |
< |
if (vdef(RENDER)) |
699 |
< |
op = addarg(op, vval(RENDER)); |
853 |
> |
op = addarg(op, "-lr 8 -lw 1e-4"); |
854 |
|
} |
855 |
|
|
856 |
|
|
857 |
< |
hiqopts(op) /* high quality rendering options */ |
858 |
< |
register char *op; |
857 |
> |
static void |
858 |
> |
hiqopts( /* high quality rendering options */ |
859 |
> |
register char *op, |
860 |
> |
char *po |
861 |
> |
) |
862 |
|
{ |
863 |
< |
double d, org[3], siz[3]; |
863 |
> |
double d, org[3], siz[3], asz; |
864 |
|
|
865 |
|
*op = '\0'; |
866 |
+ |
*po = '\0'; |
867 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
868 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
869 |
|
badvalue(ZONE); |
870 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
871 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
872 |
+ |
badvalue(ZONE); |
873 |
|
getoctcube(org, &d); |
874 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
874 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
875 |
> |
d /= asz; |
876 |
|
switch (vscale(DETAIL)) { |
877 |
|
case LOW: |
878 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
879 |
< |
op = addarg(op, "-dp 256"); |
880 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
878 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
879 |
> |
op = addarg(op, "-dp 1024"); |
880 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
881 |
|
op += strlen(op); |
882 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
883 |
+ |
op += strlen(op); |
884 |
|
break; |
885 |
|
case MEDIUM: |
886 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
887 |
< |
op = addarg(op, "-dp 512"); |
888 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
886 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
887 |
> |
op = addarg(op, "-dp 2048"); |
888 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
889 |
|
op += strlen(op); |
890 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
891 |
+ |
op += strlen(op); |
892 |
|
break; |
893 |
|
case HIGH: |
894 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
895 |
< |
op = addarg(op, "-dp 1024"); |
896 |
< |
sprintf(op, " -ar %d", (int)(64*d)); |
894 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
895 |
> |
op = addarg(op, "-dp 4096"); |
896 |
> |
sprintf(op, " -ar %d", (int)(128*d)); |
897 |
|
op += strlen(op); |
898 |
+ |
sprintf(op, " -ms %.2g", asz/160.); |
899 |
+ |
op += strlen(op); |
900 |
|
break; |
901 |
|
} |
902 |
< |
op = addarg(op, "-pt .04"); |
902 |
> |
po = addarg(po, "-pt .04"); |
903 |
|
if (vbool(PENUMBRAS)) |
904 |
< |
op = addarg(op, "-ds .1 -dj .7"); |
904 |
> |
op = addarg(op, "-ds .1 -dj .9"); |
905 |
|
else |
906 |
|
op = addarg(op, "-ds .2"); |
907 |
< |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03"); |
907 |
> |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -ss 16 -st .01"); |
908 |
|
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
909 |
|
op += strlen(op); |
910 |
|
if (vdef(AMBFILE)) { |
914 |
|
overture = 0; |
915 |
|
switch (vscale(VARIABILITY)) { |
916 |
|
case LOW: |
917 |
< |
op = addarg(op, "-aa .15 -ad 200 -as 0"); |
917 |
> |
op = addarg(op, "-aa .125 -ad 512 -as 64"); |
918 |
|
break; |
919 |
|
case MEDIUM: |
920 |
< |
op = addarg(op, "-aa .125 -ad 512 -as 128"); |
920 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 768"); |
921 |
|
break; |
922 |
|
case HIGH: |
923 |
< |
op = addarg(op, "-aa .08 -ad 850 -as 256"); |
923 |
> |
op = addarg(op, "-aa .075 -ad 4096 -as 2048"); |
924 |
|
break; |
925 |
|
} |
926 |
|
d = ambval(); |
927 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
928 |
|
op += strlen(op); |
929 |
< |
op = addarg(op, "-lr 12 -lw .0005"); |
763 |
< |
if (vdef(RENDER)) |
764 |
< |
op = addarg(op, vval(RENDER)); |
929 |
> |
op = addarg(op, "-lr 12 -lw 1e-5"); |
930 |
|
} |
931 |
|
|
932 |
|
|
933 |
< |
xferopts(ro) /* transfer options if indicated */ |
934 |
< |
char *ro; |
933 |
> |
static void |
934 |
> |
xferopts( /* transfer options if indicated */ |
935 |
> |
char *ro |
936 |
> |
) |
937 |
|
{ |
938 |
|
int fd, n; |
939 |
+ |
register char *cp; |
940 |
|
|
941 |
|
n = strlen(ro); |
942 |
|
if (n < 2) |
943 |
|
return; |
944 |
|
if (vdef(OPTFILE)) { |
945 |
< |
if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
945 |
> |
for (cp = ro; cp[1]; cp++) |
946 |
> |
if (isspace(cp[1]) && (cp[2] == '@' || |
947 |
> |
(cp[2] == '-' && isalpha(cp[3])))) |
948 |
> |
*cp = '\n'; |
949 |
> |
else |
950 |
> |
*cp = cp[1]; |
951 |
> |
*cp = '\n'; |
952 |
> |
fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); |
953 |
> |
if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) |
954 |
|
syserr(vval(OPTFILE)); |
955 |
< |
if (write(fd, ro+1, n-1) != n-1) |
780 |
< |
syserr(vval(OPTFILE)); |
781 |
< |
write(fd, "\n", 1); |
782 |
< |
close(fd); |
783 |
< |
sprintf(ro, " \"^%s\"", vval(OPTFILE)); |
955 |
> |
sprintf(ro, " @%s", vval(OPTFILE)); |
956 |
|
} |
957 |
< |
#ifdef MSDOS |
957 |
> |
#ifdef _WIN32 |
958 |
|
else if (n > 50) { |
959 |
< |
register char *evp = bmalloc(n+6); |
788 |
< |
if (evp == NULL) |
789 |
< |
syserr(progname); |
790 |
< |
strcpy(evp, "ROPT="); |
791 |
< |
strcat(evp, ro); |
792 |
< |
if (putenv(evp) != 0) { |
793 |
< |
fprintf(stderr, "%s: out of environment space\n", |
794 |
< |
progname); |
795 |
< |
exit(1); |
796 |
< |
} |
959 |
> |
setenv("ROPT", ro+1); |
960 |
|
strcpy(ro, " $ROPT"); |
961 |
|
} |
962 |
|
#endif |
963 |
|
} |
964 |
|
|
965 |
|
|
966 |
< |
pfiltopts(po) /* get pfilt options */ |
967 |
< |
register char *po; |
966 |
> |
static void |
967 |
> |
pfiltopts( /* get pfilt options */ |
968 |
> |
register char *po |
969 |
> |
) |
970 |
|
{ |
971 |
|
*po = '\0'; |
972 |
|
if (vdef(EXPOSURE)) { |
973 |
|
po = addarg(po, "-1 -e"); |
974 |
|
po = addarg(po, vval(EXPOSURE)); |
975 |
|
} |
976 |
< |
if (vscale(QUALITY) == HIGH) |
977 |
< |
po = addarg(po, "-r .65"); |
976 |
> |
switch (vscale(QUALITY)) { |
977 |
> |
case MEDIUM: |
978 |
> |
po = addarg(po, "-r .6"); |
979 |
> |
break; |
980 |
> |
case HIGH: |
981 |
> |
po = addarg(po, "-m .25"); |
982 |
> |
break; |
983 |
> |
} |
984 |
|
if (vdef(PFILT)) |
985 |
< |
po = addarg(po, vval(PFILT)); |
985 |
> |
if (vval(PFILT)[0] != '-') { |
986 |
> |
atos(c_pfilt, sizeof(c_pfilt), vval(PFILT)); |
987 |
> |
po = addarg(po, sskip2(vval(PFILT), 1)); |
988 |
> |
} else |
989 |
> |
po = addarg(po, vval(PFILT)); |
990 |
|
} |
991 |
|
|
992 |
|
|
993 |
< |
matchword(s1, s2) /* match white-delimited words */ |
994 |
< |
register char *s1, *s2; |
993 |
> |
static int |
994 |
> |
matchword( /* match white-delimited words */ |
995 |
> |
register char *s1, |
996 |
> |
register char *s2 |
997 |
> |
) |
998 |
|
{ |
999 |
|
while (isspace(*s1)) s1++; |
1000 |
|
while (isspace(*s2)) s2++; |
1005 |
|
} |
1006 |
|
|
1007 |
|
|
1008 |
< |
char * |
1009 |
< |
specview(vs) /* get proper view spec from vs */ |
1010 |
< |
register char *vs; |
1008 |
> |
static char * |
1009 |
> |
specview( /* get proper view spec from vs */ |
1010 |
> |
register char *vs |
1011 |
> |
) |
1012 |
|
{ |
1013 |
|
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
1014 |
|
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
1026 |
|
upax = 1-'X'+UPPER(vval(UP)[1]); |
1027 |
|
else |
1028 |
|
upax = 1-'X'+vlet(UP); |
1029 |
< |
if (upax < 1 | upax > 3) |
1029 |
> |
if ((upax < 1) | (upax > 3)) |
1030 |
|
badvalue(UP); |
1031 |
|
if (vval(UP)[0] == '-') |
1032 |
|
upax = -upax; |
1048 |
|
} else if (*vs == 'z') { |
1049 |
|
zpos = -1; vs++; |
1050 |
|
} |
1051 |
< |
viewtype = 'v'; |
1052 |
< |
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') |
1051 |
> |
switch (*vs) { |
1052 |
> |
case VT_PER: |
1053 |
> |
case VT_PAR: |
1054 |
> |
case VT_ANG: |
1055 |
> |
case VT_HEM: |
1056 |
> |
case VT_PLS: |
1057 |
> |
case VT_CYL: |
1058 |
|
viewtype = *vs++; |
1059 |
+ |
break; |
1060 |
+ |
default: |
1061 |
+ |
viewtype = VT_PER; |
1062 |
+ |
break; |
1063 |
+ |
} |
1064 |
|
cp = viewopts; |
1065 |
|
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
1066 |
|
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
1070 |
|
badvalue(ZONE); |
1071 |
|
for (i = 0; i < 3; i++) { |
1072 |
|
dim[i] -= cent[i]; |
1073 |
+ |
if (dim[i] <= FTINY) |
1074 |
+ |
badvalue(ZONE); |
1075 |
|
cent[i] += .5*dim[i]; |
1076 |
|
} |
1077 |
|
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
1102 |
|
} |
1103 |
|
cp = addarg(cp, vup[upax+3]); |
1104 |
|
switch (viewtype) { |
1105 |
< |
case 'v': |
1105 |
> |
case VT_PER: |
1106 |
|
cp = addarg(cp, "-vh 45 -vv 45"); |
1107 |
|
break; |
1108 |
< |
case 'l': |
1108 |
> |
case VT_PAR: |
1109 |
|
d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); |
1110 |
|
sprintf(cp, " -vh %.2g -vv %.2g", d, d); |
1111 |
|
cp += strlen(cp); |
1112 |
|
break; |
1113 |
< |
case 'a': |
1114 |
< |
case 'h': |
1113 |
> |
case VT_ANG: |
1114 |
> |
case VT_HEM: |
1115 |
> |
case VT_PLS: |
1116 |
|
cp = addarg(cp, "-vh 180 -vv 180"); |
1117 |
|
break; |
1118 |
+ |
case VT_CYL: |
1119 |
+ |
cp = addarg(cp, "-vh 180 -vv 90"); |
1120 |
+ |
break; |
1121 |
|
} |
1122 |
|
} else { |
1123 |
|
while (!isspace(*vs)) /* else skip id */ |
1124 |
|
if (!*vs++) |
1125 |
|
return(NULL); |
1126 |
< |
if (upax) { /* specify up vector */ |
1126 |
> |
if (upax) { /* prepend up vector */ |
1127 |
|
strcpy(cp, vup[upax+3]); |
1128 |
|
cp += strlen(cp); |
1129 |
|
} |
1130 |
|
} |
1131 |
< |
/* append any additional options */ |
1131 |
> |
if (cp == viewopts) /* append any additional options */ |
1132 |
> |
vs++; /* skip prefixed space if unneeded */ |
1133 |
|
strcpy(cp, vs); |
1134 |
+ |
#ifdef _WIN32 |
1135 |
+ |
if (strlen(viewopts) > 40) { |
1136 |
+ |
setenv("VIEW", viewopts); |
1137 |
+ |
return("$VIEW"); |
1138 |
+ |
} |
1139 |
+ |
#endif |
1140 |
|
return(viewopts); |
1141 |
|
} |
1142 |
|
|
1143 |
|
|
1144 |
< |
char * |
1145 |
< |
getview(n, vn) /* get view n, or NULL if none */ |
1146 |
< |
int n; |
1147 |
< |
char *vn; |
1144 |
> |
static char * |
1145 |
> |
getview( /* get view n, or NULL if none */ |
1146 |
> |
int n, |
1147 |
> |
char *vn /* returned view name */ |
1148 |
> |
) |
1149 |
|
{ |
1150 |
|
register char *mv; |
1151 |
|
|
1152 |
< |
if (viewselect != NULL) { |
1152 |
> |
if (viewselect != NULL) { /* command-line selected */ |
1153 |
|
if (n) /* only do one */ |
1154 |
|
return(NULL); |
1155 |
+ |
|
1156 |
+ |
if (isint(viewselect)) { /* view number? */ |
1157 |
+ |
n = atoi(viewselect)-1; |
1158 |
+ |
goto numview; |
1159 |
+ |
} |
1160 |
|
if (viewselect[0] == '-') { /* already specified */ |
1161 |
< |
if (vn != NULL) *vn = '\0'; |
1161 |
> |
if (vn != NULL) |
1162 |
> |
strcpy(vn, "0"); |
1163 |
|
return(viewselect); |
1164 |
|
} |
1165 |
|
if (vn != NULL) { |
1169 |
|
*vn = '\0'; |
1170 |
|
} |
1171 |
|
/* check list */ |
1172 |
< |
while ((mv = nvalue(vv+VIEW, n++)) != NULL) |
1172 |
> |
while ((mv = nvalue(VIEWS, n++)) != NULL) |
1173 |
|
if (matchword(viewselect, mv)) |
1174 |
|
return(specview(mv)); |
1175 |
+ |
|
1176 |
|
return(specview(viewselect)); /* standard view? */ |
1177 |
|
} |
1178 |
< |
if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) { |
1179 |
< |
if (*mv != '-') |
1180 |
< |
while (*mv && !isspace(*mv)) |
1181 |
< |
*vn++ = *mv++; |
1182 |
< |
*vn = '\0'; |
1178 |
> |
numview: |
1179 |
> |
mv = nvalue(VIEWS, n); /* use view n */ |
1180 |
> |
if ((vn != NULL) & (mv != NULL)) |
1181 |
> |
if (*mv != '-') { |
1182 |
> |
register char *mv2 = mv; |
1183 |
> |
while (*mv2 && !isspace(*mv2)) |
1184 |
> |
*vn++ = *mv2++; |
1185 |
> |
*vn = '\0'; |
1186 |
> |
} else |
1187 |
> |
sprintf(vn, "%d", n+1); |
1188 |
> |
|
1189 |
> |
return(specview(mv)); |
1190 |
> |
} |
1191 |
> |
|
1192 |
> |
|
1193 |
> |
static int |
1194 |
> |
myprintview( /* print out selected view */ |
1195 |
> |
register char *vopts, |
1196 |
> |
FILE *fp |
1197 |
> |
) |
1198 |
> |
{ |
1199 |
> |
VIEW vwr; |
1200 |
> |
char buf[128]; |
1201 |
> |
register char *cp; |
1202 |
> |
#ifdef _WIN32 |
1203 |
> |
/* XXX Should we allow something like this for all platforms? */ |
1204 |
> |
/* XXX Or is it still required at all? */ |
1205 |
> |
again: |
1206 |
> |
#endif |
1207 |
> |
if (vopts == NULL) |
1208 |
> |
return(-1); |
1209 |
> |
#ifdef _WIN32 |
1210 |
> |
if (vopts[0] == '$') { |
1211 |
> |
vopts = getenv(vopts+1); |
1212 |
> |
goto again; |
1213 |
|
} |
1214 |
< |
return(specview(nvalue(vv+VIEW, n))); /* use view n */ |
1214 |
> |
#endif |
1215 |
> |
vwr = stdview; |
1216 |
> |
sscanview(&vwr, cp=vopts); /* set initial options */ |
1217 |
> |
while ((cp = strstr(cp, "-vf ")) != NULL && |
1218 |
> |
*atos(buf, sizeof(buf), cp += 4)) { |
1219 |
> |
viewfile(buf, &vwr, NULL); /* load -vf file */ |
1220 |
> |
sscanview(&vwr, cp); /* reset tail */ |
1221 |
> |
} |
1222 |
> |
fputs(VIEWSTR, fp); |
1223 |
> |
fprintview(&vwr, fp); /* print full spec. */ |
1224 |
> |
fputc('\n', fp); |
1225 |
> |
return(0); |
1226 |
|
} |
1227 |
|
|
1228 |
|
|
1229 |
< |
rview(opts) /* run rview with first view */ |
1230 |
< |
char *opts; |
1229 |
> |
static void |
1230 |
> |
rvu( /* run rvu with first view */ |
1231 |
> |
char *opts, |
1232 |
> |
char *po |
1233 |
> |
) |
1234 |
|
{ |
1235 |
< |
char combuf[512]; |
1235 |
> |
char *vw; |
1236 |
> |
char combuf[PATH_MAX]; |
1237 |
|
/* build command */ |
1238 |
< |
sprintf(combuf, "rview %s%s ", getview(0, NULL), opts); |
1238 |
> |
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1239 |
> |
return; |
1240 |
> |
if (sayview) |
1241 |
> |
myprintview(vw, stdout); |
1242 |
> |
sprintf(combuf, "%s %s%s%s -R %s ", c_rvu, vw, opts, po, rifname); |
1243 |
> |
if (nprocs > 1) |
1244 |
> |
sprintf(combuf+strlen(combuf), "-n %d ", nprocs); |
1245 |
|
if (rvdevice != NULL) |
1246 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1247 |
< |
strcat(combuf, vval(OCTREE)); |
1247 |
> |
if (vdef(EXPOSURE)) |
1248 |
> |
sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); |
1249 |
> |
strcat(combuf, oct1name); |
1250 |
|
if (runcom(combuf)) { /* run it */ |
1251 |
< |
fprintf(stderr, "%s: error running rview\n", progname); |
1252 |
< |
exit(1); |
1251 |
> |
fprintf(stderr, "%s: error running %s\n", progname, c_rvu); |
1252 |
> |
quit(1); |
1253 |
|
} |
1254 |
|
} |
1255 |
|
|
1256 |
|
|
1257 |
< |
rpict(opts) /* run rpict and pfilt for each view */ |
1258 |
< |
char *opts; |
1257 |
> |
static void |
1258 |
> |
rpict( /* run rpict and pfilt for each view */ |
1259 |
> |
char *opts, |
1260 |
> |
char *po |
1261 |
> |
) |
1262 |
|
{ |
1263 |
< |
char combuf[1024]; |
1264 |
< |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; |
1263 |
> |
#define do_rpiece (sfile[0]!='\0') |
1264 |
> |
char combuf[5*PATH_MAX+512]; |
1265 |
> |
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1266 |
> |
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1267 |
> |
char rppopt[32], sfile[PATH_MAX], *pfile = NULL; |
1268 |
|
char pfopts[128]; |
1269 |
|
char vs[32], *vw; |
1270 |
|
int vn, mult; |
1271 |
+ |
FILE *fp; |
1272 |
+ |
time_t rfdt, pfdt; |
1273 |
+ |
int xres, yres; |
1274 |
+ |
double aspect; |
1275 |
+ |
int n; |
1276 |
|
/* get pfilt options */ |
1277 |
|
pfiltopts(pfopts); |
1278 |
|
/* get resolution, reporting */ |
1279 |
< |
mult = vscale(QUALITY)+1; |
1280 |
< |
{ |
1281 |
< |
int xres, yres; |
1282 |
< |
double aspect; |
1283 |
< |
int n; |
1284 |
< |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1285 |
< |
if (n == 3) |
1286 |
< |
sprintf(res, "-x %d -y %d -pa %.3f", |
1287 |
< |
mult*xres, mult*yres, aspect); |
1288 |
< |
else if (n) { |
1015 |
< |
if (n == 1) yres = xres; |
1016 |
< |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1017 |
< |
} else |
1018 |
< |
badvalue(RESOLUTION); |
1279 |
> |
switch (vscale(QUALITY)) { |
1280 |
> |
case LOW: |
1281 |
> |
mult = 1; |
1282 |
> |
break; |
1283 |
> |
case MEDIUM: |
1284 |
> |
mult = 2; |
1285 |
> |
break; |
1286 |
> |
case HIGH: |
1287 |
> |
mult = 3; |
1288 |
> |
break; |
1289 |
|
} |
1290 |
+ |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1291 |
+ |
if (n == 3) |
1292 |
+ |
sprintf(res, "-x %d -y %d -pa %.3f", |
1293 |
+ |
mult*xres, mult*yres, aspect); |
1294 |
+ |
else if (n) { |
1295 |
+ |
aspect = 1.; |
1296 |
+ |
if (n == 1) yres = xres; |
1297 |
+ |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1298 |
+ |
} else |
1299 |
+ |
badvalue(RESOLUTION); |
1300 |
|
rep[0] = '\0'; |
1301 |
|
if (vdef(REPORT)) { |
1302 |
|
double minutes; |
1023 |
– |
int n; |
1303 |
|
n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); |
1304 |
|
if (n == 2) |
1305 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1308 |
|
else |
1309 |
|
badvalue(REPORT); |
1310 |
|
} |
1311 |
< |
/* check date on ambient file */ |
1312 |
< |
if (vdef(AMBFILE)) { |
1313 |
< |
long afdate = fdate(vval(AMBFILE)); |
1314 |
< |
if (afdate >= 0 & octreedate > afdate) |
1315 |
< |
rmfile(vval(AMBFILE)); |
1311 |
> |
/* set up parallel rendering */ |
1312 |
> |
sfile[0] = '\0'; |
1313 |
> |
if ((nprocs > 1) & !touchonly & !vdef(ZFILE) && |
1314 |
> |
getview(0, vs) != NULL) { |
1315 |
> |
if (!strcmp(c_rpict, DEF_RPICT_PATH) && |
1316 |
> |
getview(1, NULL) == NULL) { |
1317 |
> |
sprintf(sfile, "%s_%s_rpsync.txt", |
1318 |
> |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), |
1319 |
> |
vs); |
1320 |
> |
strcpy(rppopt, "-PP pfXXXXXX"); |
1321 |
> |
} else { |
1322 |
> |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
1323 |
> |
} |
1324 |
> |
pfile = rppopt + strlen(rppopt) - 8; |
1325 |
> |
if (mktemp(pfile) == NULL) { |
1326 |
> |
if (do_rpiece) { |
1327 |
> |
fprintf(stderr, "%s: cannot create\n", pfile); |
1328 |
> |
quit(1); |
1329 |
> |
} |
1330 |
> |
pfile = NULL; |
1331 |
> |
} |
1332 |
|
} |
1333 |
< |
/* do each view */ |
1039 |
< |
vn = 0; |
1333 |
> |
vn = 0; /* do each view */ |
1334 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1335 |
< |
if (!vs[0]) |
1336 |
< |
sprintf(vs, "%d", vn); |
1337 |
< |
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1335 |
> |
if (sayview) |
1336 |
> |
myprintview(vw, stdout); |
1337 |
> |
sprintf(picfile, "%s_%s.hdr", vval(PICTURE), vs); |
1338 |
> |
if (vdef(ZFILE)) |
1339 |
> |
sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); |
1340 |
> |
else |
1341 |
> |
zopt[0] = '\0'; |
1342 |
|
/* check date on picture */ |
1343 |
< |
if (fdate(picfile) > octreedate) |
1343 |
> |
pfdt = fdate(picfile); |
1344 |
> |
if (pfdt >= oct1date) |
1345 |
|
continue; |
1346 |
+ |
/* get raw file name */ |
1347 |
+ |
sprintf(rawfile, "%s_%s.unf", |
1348 |
+ |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs); |
1349 |
+ |
rfdt = fdate(rawfile); |
1350 |
+ |
if (touchonly) { /* update times only */ |
1351 |
+ |
if (rfdt) { |
1352 |
+ |
if (rfdt < oct1date) |
1353 |
+ |
touch(rawfile); |
1354 |
+ |
} else if (pfdt && pfdt < oct1date) |
1355 |
+ |
touch(picfile); |
1356 |
+ |
continue; |
1357 |
+ |
} |
1358 |
+ |
/* parallel running? */ |
1359 |
+ |
if (do_rpiece) { |
1360 |
+ |
if (rfdt < oct1date || !fdate(sfile)) { |
1361 |
+ |
int xdiv = 8+nprocs/3, ydiv = 8+nprocs/3; |
1362 |
+ |
if (rfdt >= oct1date) { |
1363 |
+ |
fprintf(stderr, |
1364 |
+ |
"%s: partial output not created with rpiece\n", rawfile); |
1365 |
+ |
quit(1); |
1366 |
+ |
} |
1367 |
+ |
if (rfdt) { /* start fresh */ |
1368 |
+ |
rmfile(rawfile); |
1369 |
+ |
rfdt = 0; |
1370 |
+ |
} |
1371 |
+ |
if (!silent) |
1372 |
+ |
printf("\techo %d %d > %s\n", |
1373 |
+ |
xdiv, ydiv, sfile); |
1374 |
+ |
if ((fp = fopen(sfile, "w")) == NULL) { |
1375 |
+ |
fprintf(stderr, "%s: cannot create\n", |
1376 |
+ |
sfile); |
1377 |
+ |
quit(1); |
1378 |
+ |
} |
1379 |
+ |
fprintf(fp, "%d %d\n", xdiv, ydiv); |
1380 |
+ |
fclose(fp); |
1381 |
+ |
} |
1382 |
+ |
} else if (next_process(0)) { |
1383 |
+ |
if (pfile != NULL) |
1384 |
+ |
sleep(10); |
1385 |
+ |
continue; |
1386 |
+ |
} else if (!inchild()) |
1387 |
+ |
pfile = NULL; |
1388 |
+ |
/* XXX Remember to call finish_process() */ |
1389 |
|
/* build rpict command */ |
1390 |
< |
sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); |
1391 |
< |
if (fdate(rawfile) > octreedate) /* recover */ |
1392 |
< |
sprintf(combuf, "rpict%s%s -ro %s %s", |
1393 |
< |
rep, opts, rawfile, vval(OCTREE)); |
1394 |
< |
else { |
1390 |
> |
if (rfdt >= oct1date) { /* already in progress */ |
1391 |
> |
if (do_rpiece) { |
1392 |
> |
sprintf(combuf, "%s -R %s %s%s %s %s%s%s -o %s %s", |
1393 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
1394 |
> |
res, opts, po, rawfile, oct1name); |
1395 |
> |
while (next_process(1)) { |
1396 |
> |
sleep(10); |
1397 |
> |
combuf[strlen(c_rpiece)+2] = 'F'; |
1398 |
> |
} |
1399 |
> |
} else |
1400 |
> |
sprintf(combuf, "%s%s%s%s%s -ro %s %s", c_rpict, |
1401 |
> |
rep, opts, po, zopt, rawfile, oct1name); |
1402 |
> |
if (runcom(combuf)) /* run rpict/rpiece */ |
1403 |
> |
goto rperror; |
1404 |
> |
} else { |
1405 |
|
if (overture) { /* run overture calculation */ |
1406 |
|
sprintf(combuf, |
1407 |
< |
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1408 |
< |
rep, vw, opts, |
1409 |
< |
vval(OCTREE), overfile); |
1410 |
< |
if (runcom(combuf)) { |
1411 |
< |
fprintf(stderr, |
1407 |
> |
"%s%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1408 |
> |
c_rpict, rep, vw, opts, |
1409 |
> |
oct1name, overfile); |
1410 |
> |
if (!do_rpiece || !next_process(0)) { |
1411 |
> |
if (runcom(combuf)) { |
1412 |
> |
fprintf(stderr, |
1413 |
|
"%s: error in overture for view %s\n", |
1414 |
< |
progname, vs); |
1415 |
< |
exit(1); |
1416 |
< |
} |
1417 |
< |
#ifdef NIX |
1418 |
< |
rmfile(overfile); |
1414 |
> |
progname, vs); |
1415 |
> |
quit(1); |
1416 |
> |
} |
1417 |
> |
#ifndef NULL_DEVICE |
1418 |
> |
rmfile(overfile); |
1419 |
|
#endif |
1420 |
+ |
} else if (do_rpiece) |
1421 |
+ |
sleep(20); |
1422 |
|
} |
1423 |
< |
sprintf(combuf, "rpict%s %s %s%s %s > %s", |
1424 |
< |
rep, vw, res, opts, |
1425 |
< |
vval(OCTREE), rawfile); |
1423 |
> |
if (do_rpiece) { |
1424 |
> |
sprintf(combuf, "%s -F %s %s%s %s %s%s%s -o %s %s", |
1425 |
> |
c_rpiece, sfile, rppopt, rep, vw, |
1426 |
> |
res, opts, po, rawfile, oct1name); |
1427 |
> |
while (next_process(1)) |
1428 |
> |
sleep(10); |
1429 |
> |
} else { |
1430 |
> |
sprintf(combuf, "%s%s %s %s%s%s%s %s > %s", |
1431 |
> |
c_rpict, rep, vw, res, opts, po, |
1432 |
> |
zopt, oct1name, rawfile); |
1433 |
> |
} |
1434 |
> |
if ((pfile != NULL) & !do_rpiece) { |
1435 |
> |
if (!silent) |
1436 |
> |
printf("\t%s\n", combuf); |
1437 |
> |
fflush(stdout); |
1438 |
> |
sprintf(combuf, "%s%s %s %s%s%s %s > %s", |
1439 |
> |
c_rpict, rep, rppopt, res, |
1440 |
> |
opts, po, oct1name, rawfile); |
1441 |
> |
fp = popen(combuf, "w"); |
1442 |
> |
if (fp == NULL) |
1443 |
> |
goto rperror; |
1444 |
> |
myprintview(vw, fp); |
1445 |
> |
if (pclose(fp)) |
1446 |
> |
goto rperror; |
1447 |
> |
} else if (runcom(combuf)) |
1448 |
> |
goto rperror; |
1449 |
|
} |
1450 |
< |
if (runcom(combuf)) { /* run rpict */ |
1451 |
< |
fprintf(stderr, "%s: error rendering view %s\n", |
1452 |
< |
progname, vs); |
1453 |
< |
exit(1); |
1450 |
> |
if (do_rpiece) { /* need to finish raw, first */ |
1451 |
> |
finish_process(); |
1452 |
> |
wait_process(1); |
1453 |
> |
/* XXX should check sync file to see if really done? */ |
1454 |
|
} |
1455 |
+ |
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1456 |
|
/* build pfilt command */ |
1457 |
< |
if (mult > 1) |
1458 |
< |
sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", |
1459 |
< |
pfopts, mult, mult, rawfile, picfile); |
1460 |
< |
else |
1082 |
< |
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1457 |
> |
if (do_rpiece) |
1458 |
> |
sprintf(combuf, |
1459 |
> |
"%s%s -x %d -y %d -p %.3f %s > %s", |
1460 |
> |
c_pfilt, pfopts, xres, yres, aspect, |
1461 |
|
rawfile, picfile); |
1462 |
< |
if (runcom(combuf)) { /* run pfilt */ |
1463 |
< |
fprintf(stderr, |
1464 |
< |
"%s: error filtering view %s\n\t%s removed\n", |
1465 |
< |
progname, vs, picfile); |
1466 |
< |
unlink(picfile); |
1467 |
< |
exit(1); |
1462 |
> |
else if (mult > 1) |
1463 |
> |
sprintf(combuf, "%s%s -x /%d -y /%d %s > %s", |
1464 |
> |
c_pfilt, pfopts, mult, mult, |
1465 |
> |
rawfile, picfile); |
1466 |
> |
else |
1467 |
> |
sprintf(combuf, "%s%s %s > %s", c_pfilt, |
1468 |
> |
pfopts, rawfile, picfile); |
1469 |
> |
if (runcom(combuf)) { /* run pfilt */ |
1470 |
> |
fprintf(stderr, |
1471 |
> |
"%s: error filtering view %s\n\t%s removed\n", |
1472 |
> |
progname, vs, picfile); |
1473 |
> |
unlink(picfile); |
1474 |
> |
quit(1); |
1475 |
> |
} |
1476 |
|
} |
1477 |
< |
/* remove raw file */ |
1478 |
< |
rmfile(rawfile); |
1477 |
> |
/* remove/rename raw file */ |
1478 |
> |
if (vdef(RAWFILE)) { |
1479 |
> |
sprintf(combuf, "%s_%s.hdr", vval(RAWFILE), vs); |
1480 |
> |
mvfile(rawfile, combuf); |
1481 |
> |
} else |
1482 |
> |
rmfile(rawfile); |
1483 |
> |
if (do_rpiece) /* done with sync file */ |
1484 |
> |
rmfile(sfile); |
1485 |
> |
else |
1486 |
> |
finish_process(); /* exit if child */ |
1487 |
|
} |
1488 |
+ |
wait_process(1); /* wait for children to finish */ |
1489 |
+ |
if (pfile != NULL) { /* clean up persistent rpict */ |
1490 |
+ |
RT_PID pid; |
1491 |
+ |
fp = fopen(pfile, "r"); |
1492 |
+ |
if (fp != NULL) { |
1493 |
+ |
if (fscanf(fp, "%*s %d", &pid) != 1 || |
1494 |
+ |
kill(pid, 1) < 0) |
1495 |
+ |
unlink(pfile); |
1496 |
+ |
fclose(fp); |
1497 |
+ |
} |
1498 |
+ |
} |
1499 |
+ |
return; |
1500 |
+ |
rperror: |
1501 |
+ |
fprintf(stderr, "%s: error rendering view %s\n", progname, vs); |
1502 |
+ |
quit(1); |
1503 |
+ |
#undef do_rpiece |
1504 |
|
} |
1505 |
|
|
1506 |
|
|
1507 |
< |
runcom(cs) /* run command */ |
1508 |
< |
char *cs; |
1507 |
> |
static int |
1508 |
> |
touch( /* update a file */ |
1509 |
> |
char *fn |
1510 |
> |
) |
1511 |
|
{ |
1512 |
+ |
if (!silent) |
1513 |
+ |
printf("\ttouch %s\n", fn); |
1514 |
+ |
if (!nprocs) |
1515 |
+ |
return(0); |
1516 |
+ |
return(setfdate(fn, time((time_t *)NULL))); |
1517 |
+ |
} |
1518 |
+ |
|
1519 |
+ |
|
1520 |
+ |
static int |
1521 |
+ |
runcom( /* run command */ |
1522 |
+ |
char *cs |
1523 |
+ |
) |
1524 |
+ |
{ |
1525 |
|
if (!silent) /* echo it */ |
1526 |
|
printf("\t%s\n", cs); |
1527 |
< |
if (noaction) |
1527 |
> |
if (!nprocs) |
1528 |
|
return(0); |
1529 |
< |
fflush(stdout); /* flush output and pass to shell */ |
1529 |
> |
fflush(NULL); /* flush output and pass to shell */ |
1530 |
|
return(system(cs)); |
1531 |
|
} |
1532 |
|
|
1533 |
|
|
1534 |
< |
rmfile(fn) /* remove a file */ |
1535 |
< |
char *fn; |
1534 |
> |
static int |
1535 |
> |
rmfile( /* remove a file */ |
1536 |
> |
char *fn |
1537 |
> |
) |
1538 |
|
{ |
1539 |
|
if (!silent) |
1540 |
< |
#ifdef MSDOS |
1541 |
< |
printf("\tdel %s\n", fn); |
1115 |
< |
#else |
1116 |
< |
printf("\trm -f %s\n", fn); |
1117 |
< |
#endif |
1118 |
< |
if (noaction) |
1540 |
> |
printf("\t%s %s\n", DELCMD, fn); |
1541 |
> |
if (!nprocs) |
1542 |
|
return(0); |
1543 |
|
return(unlink(fn)); |
1544 |
|
} |
1545 |
|
|
1546 |
|
|
1547 |
< |
badvalue(vc) /* report bad variable value and exit */ |
1548 |
< |
int vc; |
1547 |
> |
static int |
1548 |
> |
mvfile( /* move a file */ |
1549 |
> |
char *fold, |
1550 |
> |
char *fnew |
1551 |
> |
) |
1552 |
|
{ |
1553 |
+ |
if (!silent) |
1554 |
+ |
printf("\t%s %s %s\n", RENAMECMD, fold, fnew); |
1555 |
+ |
if (!nprocs) |
1556 |
+ |
return(0); |
1557 |
+ |
return(rename(fold, fnew)); |
1558 |
+ |
} |
1559 |
+ |
|
1560 |
+ |
|
1561 |
+ |
#ifdef RHAS_FORK_EXEC |
1562 |
+ |
static int |
1563 |
+ |
next_process(int reserve) /* fork the next process */ |
1564 |
+ |
{ |
1565 |
+ |
RT_PID child_pid; |
1566 |
+ |
|
1567 |
+ |
if (nprocs <= 1) |
1568 |
+ |
return(0); /* it's us or no one */ |
1569 |
+ |
if (inchild()) { |
1570 |
+ |
fprintf(stderr, "%s: internal error 1 in next_process()\n", |
1571 |
+ |
progname); |
1572 |
+ |
quit(1); |
1573 |
+ |
} |
1574 |
+ |
if (reserve > 0 && children_running >= nprocs-reserve) |
1575 |
+ |
return(0); /* caller holding back process(es) */ |
1576 |
+ |
if (children_running >= nprocs) |
1577 |
+ |
wait_process(0); /* wait for someone to finish */ |
1578 |
+ |
fflush(NULL); /* flush output */ |
1579 |
+ |
child_pid = fork(); /* split process */ |
1580 |
+ |
if (child_pid == 0) { /* we're the child */ |
1581 |
+ |
children_running = -1; |
1582 |
+ |
nprocs = 1; |
1583 |
+ |
return(0); |
1584 |
+ |
} |
1585 |
+ |
if (child_pid > 0) { /* we're the parent */ |
1586 |
+ |
++children_running; |
1587 |
+ |
return(1); |
1588 |
+ |
} |
1589 |
+ |
fprintf(stderr, "%s: warning -- fork() failed\n", progname); |
1590 |
+ |
return(0); |
1591 |
+ |
} |
1592 |
+ |
|
1593 |
+ |
static void |
1594 |
+ |
wait_process( /* wait for process(es) to finish */ |
1595 |
+ |
int all |
1596 |
+ |
) |
1597 |
+ |
{ |
1598 |
+ |
int ourstatus = 0, status; |
1599 |
+ |
RT_PID pid; |
1600 |
+ |
|
1601 |
+ |
if (all) |
1602 |
+ |
all = children_running; |
1603 |
+ |
else if (children_running > 0) |
1604 |
+ |
all = 1; |
1605 |
+ |
while (all-- > 0) { |
1606 |
+ |
pid = wait(&status); |
1607 |
+ |
if (pid < 0) |
1608 |
+ |
syserr(progname); |
1609 |
+ |
status = status>>8 & 0xff; |
1610 |
+ |
--children_running; |
1611 |
+ |
if (status != 0) { /* child's problem is our problem */ |
1612 |
+ |
if ((ourstatus == 0) & (children_running > 0)) |
1613 |
+ |
fprintf(stderr, "%s: waiting for remaining processes\n", |
1614 |
+ |
progname); |
1615 |
+ |
ourstatus = status; |
1616 |
+ |
all = children_running; |
1617 |
+ |
} |
1618 |
+ |
} |
1619 |
+ |
if (ourstatus != 0) |
1620 |
+ |
quit(ourstatus); /* bad status from child */ |
1621 |
+ |
} |
1622 |
+ |
#else /* ! RHAS_FORK_EXEC */ |
1623 |
+ |
static int |
1624 |
+ |
next_process(int reserve) |
1625 |
+ |
{ |
1626 |
+ |
return(0); /* cannot start new process */ |
1627 |
+ |
} |
1628 |
+ |
static void |
1629 |
+ |
wait_process(all) |
1630 |
+ |
int all; |
1631 |
+ |
{ |
1632 |
+ |
(void)all; /* no one to wait for */ |
1633 |
+ |
} |
1634 |
+ |
int |
1635 |
+ |
kill(pid, sig) /* win|unix_process.c should also wait and kill */ |
1636 |
+ |
RT_PID pid; |
1637 |
+ |
int sig; |
1638 |
+ |
{ |
1639 |
+ |
return 0; |
1640 |
+ |
} |
1641 |
+ |
#endif /* ! RHAS_FORK_EXEC */ |
1642 |
+ |
|
1643 |
+ |
static void |
1644 |
+ |
finish_process(void) /* exit a child process */ |
1645 |
+ |
{ |
1646 |
+ |
if (!inchild()) |
1647 |
+ |
return; /* in parent -- noop */ |
1648 |
+ |
exit(0); |
1649 |
+ |
} |
1650 |
+ |
|
1651 |
+ |
#ifdef _WIN32 |
1652 |
+ |
setenv(vname, value) /* set an environment variable */ |
1653 |
+ |
char *vname, *value; |
1654 |
+ |
{ |
1655 |
+ |
register char *evp; |
1656 |
+ |
|
1657 |
+ |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1658 |
+ |
if (evp == NULL) |
1659 |
+ |
syserr(progname); |
1660 |
+ |
sprintf(evp, "%s=%s", vname, value); |
1661 |
+ |
if (putenv(evp) != 0) { |
1662 |
+ |
fprintf(stderr, "%s: out of environment space\n", progname); |
1663 |
+ |
quit(1); |
1664 |
+ |
} |
1665 |
+ |
if (!silent) |
1666 |
+ |
printf("set %s\n", evp); |
1667 |
+ |
} |
1668 |
+ |
#endif |
1669 |
+ |
|
1670 |
+ |
|
1671 |
+ |
static void |
1672 |
+ |
badvalue( /* report bad variable value and exit */ |
1673 |
+ |
int vc |
1674 |
+ |
) |
1675 |
+ |
{ |
1676 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1677 |
|
progname, vnam(vc)); |
1678 |
< |
exit(1); |
1678 |
> |
quit(1); |
1679 |
|
} |
1680 |
|
|
1681 |
|
|
1682 |
< |
syserr(s) /* report a system error and exit */ |
1683 |
< |
char *s; |
1682 |
> |
static void |
1683 |
> |
syserr( /* report a system error and exit */ |
1684 |
> |
char *s |
1685 |
> |
) |
1686 |
|
{ |
1687 |
|
perror(s); |
1688 |
< |
exit(1); |
1688 |
> |
quit(1); |
1689 |
> |
} |
1690 |
> |
|
1691 |
> |
|
1692 |
> |
void |
1693 |
> |
quit(ec) /* exit program */ |
1694 |
> |
int ec; |
1695 |
> |
{ |
1696 |
> |
exit(ec); |
1697 |
|
} |