134 |
|
|
135 |
|
|
136 |
|
|
137 |
– |
#ifdef RHAS_STAT |
138 |
– |
#include <sys/types.h> |
139 |
– |
#include <sys/stat.h> |
140 |
– |
int |
141 |
– |
file_exists(fname) /* ordinary file exists? */ |
142 |
– |
char *fname; |
143 |
– |
{ |
144 |
– |
struct stat sbuf; |
145 |
– |
if (stat(fname, &sbuf) < 0) return(0); |
146 |
– |
return((sbuf.st_mode & S_IFREG) != 0); |
147 |
– |
} |
148 |
– |
#else |
149 |
– |
#define file_exists(f) (access(f,F_OK)==0) |
150 |
– |
#endif |
151 |
– |
|
152 |
– |
|
137 |
|
void |
138 |
< |
quit(code) /* quit program */ |
155 |
< |
int code; |
138 |
> |
quit(int code) /* quit program */ |
139 |
|
{ |
140 |
|
if (code) /* report status */ |
141 |
|
report(0); |
287 |
|
break; |
288 |
|
pctdone = 0.0; |
289 |
|
if (pout != NULL) { |
290 |
+ |
int myfd; |
291 |
+ |
close(1); /* reassign stdout */ |
292 |
|
sprintf(fbuf, pout, seq); |
293 |
< |
if (file_exists(fbuf)) { |
294 |
< |
if (prvr != NULL || !strcmp(fbuf, pout)) { |
293 |
> |
tryagain: |
294 |
> |
errno = 0; /* exclusive open */ |
295 |
> |
if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) { |
296 |
> |
if ((errno != EEXIST) | (prvr != NULL) || |
297 |
> |
!strcmp(fbuf, pout)) { |
298 |
|
sprintf(errmsg, |
299 |
< |
"output file \"%s\" exists", |
299 |
> |
"cannot open output file \"%s\"", |
300 |
|
fbuf); |
301 |
< |
error(USER, errmsg); |
301 |
> |
error(SYSTEM, errmsg); |
302 |
|
} |
303 |
|
setview(&ourview); |
304 |
|
continue; /* don't clobber */ |
305 |
|
} |
306 |
< |
if (freopen(fbuf, "w", stdout) == NULL) { |
307 |
< |
sprintf(errmsg, |
308 |
< |
"cannot open output file \"%s\"", fbuf); |
321 |
< |
error(SYSTEM, errmsg); |
306 |
> |
if (myfd != 1) { |
307 |
> |
unlink(fbuf); |
308 |
> |
goto tryagain; /* leave it open */ |
309 |
|
} |
310 |
< |
SET_FILE_BINARY(stdout); |
310 |
> |
SET_FD_BINARY(1); |
311 |
|
dupheader(); |
312 |
|
} |
313 |
|
hres = hresolu; vres = vresolu; pa = pixaspect; |
340 |
|
if ((pa < .99) | (pa > 1.01)) |
341 |
|
fputaspect(pa, stdout); |
342 |
|
fputnow(stdout); |
343 |
+ |
fputprims(stdprims, stdout); |
344 |
|
fputformat(COLRFMT, stdout); |
345 |
|
putchar('\n'); |
346 |
|
if (zout != NULL) |
660 |
|
int y |
661 |
|
) |
662 |
|
{ |
675 |
– |
extern void SDsquare2disk(double ds[2], double seedx, double seedy); |
663 |
|
RAY thisray; |
664 |
|
FVECT lorg, ldir; |
665 |
|
double hpos, vpos, vdist, lmax; |