8 |
|
#include "standard.h" |
9 |
|
|
10 |
|
#include <ctype.h> |
11 |
+ |
#include <time.h> |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
|
#include "view.h" |
15 |
|
#include "paths.h" |
16 |
|
#include "vars.h" |
17 |
|
|
18 |
+ |
#ifdef _WIN32 |
19 |
+ |
#define DELCMD "del" |
20 |
+ |
#define RENAMECMD "rename" |
21 |
+ |
#else |
22 |
+ |
#define DELCMD "rm -f" |
23 |
+ |
#define RENAMECMD "mv" |
24 |
+ |
#endif |
25 |
+ |
|
26 |
|
/* variables (alphabetical by name) */ |
27 |
|
#define AMBFILE 0 /* ambient file name */ |
28 |
|
#define DETAIL 1 /* level of scene detail */ |
89 |
|
char overfile[] = "overture.unf"; |
90 |
|
#endif |
91 |
|
|
83 |
– |
extern time_t time(); |
92 |
|
|
93 |
|
time_t scenedate; /* date of latest scene or object file */ |
94 |
|
time_t octreedate; /* date of octree */ |
118 |
|
|
119 |
|
char radname[PATH_MAX]; /* root Radiance file name */ |
120 |
|
|
121 |
+ |
#define inchild() (children_running < 0) |
122 |
|
|
123 |
+ |
|
124 |
|
main(argc, argv) |
125 |
|
int argc; |
126 |
|
char *argv[]; |
168 |
|
if (i >= argc) |
169 |
|
goto userr; |
170 |
|
rifname = argv[i]; |
171 |
+ |
/* check command-line options */ |
172 |
+ |
if (nprocs > 1 & viewselect != NULL) |
173 |
+ |
nprocs = 1; |
174 |
|
/* assign Radiance root file name */ |
175 |
|
rootname(radname, rifname); |
176 |
|
/* load variable values */ |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
< |
printview(vopts) /* print out selected view */ |
1053 |
> |
int |
1054 |
> |
myprintview(vopts, fp) /* print out selected view */ |
1055 |
|
register char *vopts; |
1056 |
+ |
FILE *fp; |
1057 |
|
{ |
1058 |
|
VIEW vwr; |
1059 |
|
char buf[128]; |
1074 |
|
viewfile(buf, &vwr, NULL); /* load -vf file */ |
1075 |
|
sscanview(&vwr, cp); /* reset tail */ |
1076 |
|
} |
1077 |
< |
fputs(VIEWSTR, stdout); |
1078 |
< |
fprintview(&vwr, stdout); /* print full spec. */ |
1079 |
< |
fputc('\n', stdout); |
1077 |
> |
fputs(VIEWSTR, fp); |
1078 |
> |
fprintview(&vwr, fp); /* print full spec. */ |
1079 |
> |
fputc('\n', fp); |
1080 |
|
return(0); |
1081 |
|
} |
1082 |
|
|
1090 |
|
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1091 |
|
return; |
1092 |
|
if (sayview) |
1093 |
< |
printview(vw); |
1093 |
> |
myprintview(vw, stdout); |
1094 |
|
sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname); |
1095 |
|
if (rvdevice != NULL) |
1096 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1110 |
|
char combuf[PATH_MAX]; |
1111 |
|
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1112 |
|
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1113 |
+ |
char rppopt[128], *pfile = NULL; |
1114 |
|
char pfopts[128]; |
1115 |
|
char vs[32], *vw; |
1116 |
|
int vn, mult; |
1117 |
+ |
FILE *fp; |
1118 |
|
time_t rfdt, pfdt; |
1119 |
|
/* get pfilt options */ |
1120 |
|
pfiltopts(pfopts); |
1156 |
|
else |
1157 |
|
badvalue(REPORT); |
1158 |
|
} |
1159 |
+ |
/* set up parallel rendering */ |
1160 |
+ |
if (nprocs > 1 & !vdef(ZFILE)) { |
1161 |
+ |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
1162 |
+ |
pfile = rppopt+9; |
1163 |
+ |
if (mktemp(pfile) == NULL) |
1164 |
+ |
pfile = NULL; |
1165 |
+ |
} |
1166 |
|
vn = 0; /* do each view */ |
1167 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1168 |
|
if (sayview) |
1169 |
< |
printview(vw); |
1169 |
> |
myprintview(vw, stdout); |
1170 |
|
if (!vs[0]) |
1171 |
|
sprintf(vs, "%d", vn); |
1172 |
|
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1190 |
|
touch(picfile); |
1191 |
|
continue; |
1192 |
|
} |
1193 |
< |
if (next_process()) /* parallel running? */ |
1193 |
> |
if (next_process()) { /* parallel running? */ |
1194 |
> |
if (pfile != NULL) |
1195 |
> |
sleep(20); |
1196 |
|
continue; |
1197 |
+ |
} |
1198 |
|
/* XXX Remember to call finish_process() */ |
1199 |
|
/* build rpict command */ |
1200 |
< |
if (rfdt >= oct1date) /* recover */ |
1200 |
> |
if (rfdt >= oct1date) { /* recover */ |
1201 |
|
sprintf(combuf, "rpict%s%s%s%s -ro %s %s", |
1202 |
|
rep, po, opts, zopt, rawfile, oct1name); |
1203 |
< |
else { |
1203 |
> |
if (runcom(combuf)) /* run rpict */ |
1204 |
> |
goto rperror; |
1205 |
> |
} else { |
1206 |
|
if (overture) { /* run overture calculation */ |
1207 |
|
sprintf(combuf, |
1208 |
|
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1219 |
|
#endif |
1220 |
|
} |
1221 |
|
sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", |
1222 |
< |
rep, vw, res, po, opts, zopt, |
1223 |
< |
oct1name, rawfile); |
1222 |
> |
rep, vw, res, po, opts, |
1223 |
> |
zopt, oct1name, rawfile); |
1224 |
> |
if (pfile != NULL && inchild()) { |
1225 |
> |
/* rpict persistent mode */ |
1226 |
> |
if (!silent) |
1227 |
> |
printf("\t%s\n", combuf); |
1228 |
> |
sprintf(combuf, "rpict%s %s %s%s%s %s > %s", |
1229 |
> |
rep, rppopt, res, po, opts, |
1230 |
> |
oct1name, rawfile); |
1231 |
> |
fflush(stdout); |
1232 |
> |
fp = popen(combuf, "w"); |
1233 |
> |
if (fp == NULL) |
1234 |
> |
goto rperror; |
1235 |
> |
myprintview(vw, fp); |
1236 |
> |
if (pclose(fp)) |
1237 |
> |
goto rperror; |
1238 |
> |
} else { /* rpict normal mode */ |
1239 |
> |
if (runcom(combuf)) |
1240 |
> |
goto rperror; |
1241 |
> |
} |
1242 |
|
} |
1196 |
– |
if (runcom(combuf)) { /* run rpict */ |
1197 |
– |
fprintf(stderr, "%s: error rendering view %s\n", |
1198 |
– |
progname, vs); |
1199 |
– |
quit(1); |
1200 |
– |
} |
1243 |
|
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1244 |
|
/* build pfilt command */ |
1245 |
|
if (mult > 1) |
1248 |
|
else |
1249 |
|
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1250 |
|
rawfile, picfile); |
1251 |
< |
if (runcom(combuf)) { /* run pfilt */ |
1251 |
> |
if (runcom(combuf)) { /* run pfilt */ |
1252 |
|
fprintf(stderr, |
1253 |
|
"%s: error filtering view %s\n\t%s removed\n", |
1254 |
|
progname, vs, picfile); |
1265 |
|
finish_process(); /* leave if child */ |
1266 |
|
} |
1267 |
|
wait_process(1); /* wait for children to finish */ |
1268 |
+ |
if (pfile != NULL) { /* clean up rpict persistent mode */ |
1269 |
+ |
int pid; |
1270 |
+ |
fp = fopen(pfile, "r"); |
1271 |
+ |
if (fp != NULL) { |
1272 |
+ |
if (fscanf(fp, "%*s %d", &pid) != 1 || |
1273 |
+ |
kill(pid, 1) == -1) |
1274 |
+ |
unlink(pfile); |
1275 |
+ |
fclose(fp); |
1276 |
+ |
} |
1277 |
+ |
} |
1278 |
+ |
return; |
1279 |
+ |
rperror: |
1280 |
+ |
fprintf(stderr, "%s: error rendering view %s\n", progname, vs); |
1281 |
+ |
quit(1); |
1282 |
|
} |
1283 |
|
|
1284 |
|
|
1314 |
|
char *fn; |
1315 |
|
{ |
1316 |
|
if (!silent) |
1317 |
< |
#ifdef _WIN32 |
1262 |
< |
printf("\tdel %s\n", fn); |
1263 |
< |
#else |
1264 |
< |
printf("\trm -f %s\n", fn); |
1265 |
< |
#endif |
1317 |
> |
printf("\t%s %s\n", DELCMD, fn); |
1318 |
|
if (!nprocs) |
1319 |
|
return(0); |
1320 |
|
return(unlink(fn)); |
1325 |
|
char *fold, *fnew; |
1326 |
|
{ |
1327 |
|
if (!silent) |
1328 |
< |
#ifdef _WIN32 |
1277 |
< |
printf("\trename %s %s\n", fold, fnew); |
1278 |
< |
#else |
1279 |
< |
printf("\tmv %s %s\n", fold, fnew); |
1280 |
< |
#endif |
1328 |
> |
printf("\t%s %s %s\n", RENAMECMD, fold, fnew); |
1329 |
|
if (!nprocs) |
1330 |
|
return(0); |
1331 |
|
return(rename(fold, fnew)); |
1340 |
|
|
1341 |
|
if (nprocs <= 1) |
1342 |
|
return(0); /* it's us or no one */ |
1343 |
< |
if (children_running < 0) { |
1343 |
> |
if (inchild()) { |
1344 |
|
fprintf(stderr, "%s: internal error 1 in spawn_process()\n", |
1345 |
|
progname); |
1346 |
|
quit(1); |
1399 |
|
{ |
1400 |
|
(void)all; /* no one to wait for */ |
1401 |
|
} |
1402 |
+ |
int |
1403 |
+ |
kill(pid, sig) /* win|unix_process.c should also wait and kill */ |
1404 |
+ |
int pid, sig; |
1405 |
+ |
{ |
1406 |
+ |
return 0; |
1407 |
+ |
} |
1408 |
|
#endif /* ! RHAS_FORK_EXEC */ |
1409 |
|
|
1410 |
|
finish_process() /* exit a child process */ |
1411 |
|
{ |
1412 |
< |
if (children_running >= 0) |
1412 |
> |
if (!inchild()) |
1413 |
|
return; /* in parent -- noop */ |
1414 |
|
exit(0); |
1415 |
|
} |