--- ray/src/rt/rpict.c 1993/01/29 12:15:40 2.23 +++ ray/src/rt/rpict.c 1993/08/02 21:48:37 2.27 @@ -82,7 +82,7 @@ long tlastrept = 0L; /* time at last report */ extern long time(); extern long tstart; /* starting time */ -extern long nrays; /* number of rays traced */ +extern unsigned long nrays; /* number of rays traced */ #define MAXDIV 16 /* maximum sample size */ @@ -94,7 +94,22 @@ extern char *mktemp(); double pixvalue(); +#ifdef NIX +#define file_exists(f) (access(f,F_OK)==0) +#else +#include +#include +int +file_exists(fname) /* ordinary file exists? */ +char *fname; +{ + struct stat sbuf; + if (stat(fname, &sbuf) < 0) return(0); + return((sbuf.st_mode & S_IFREG) != 0); +} +#endif + quit(code) /* quit program */ int code; { @@ -119,7 +134,7 @@ report() /* report progress */ t += (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; t += rubuf.ru_utime.tv_sec + rubuf.ru_stime.tv_sec; - sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f CPU hours\n", + sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f CPU hours\n", nrays, pctdone, t/3600.0); eputs(errmsg); tlastrept = time((long *)0); @@ -128,7 +143,7 @@ report() /* report progress */ report() /* report progress */ { tlastrept = time((long *)0); - sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", + sprintf(errmsg, "%lu rays, %4.2f%% done after %5.4f hours\n", nrays, pctdone, (tlastrept-tstart)/3600.0); eputs(errmsg); signal(SIGCONT, report); @@ -153,6 +168,7 @@ char *pout, *zout, *prvr; { extern char *rindex(), *strncpy(), *strcat(), *strcpy(); char fbuf[128], fbuf2[128]; + int npicts; register char *cp; RESOLU rs; double pa; @@ -197,12 +213,22 @@ char *pout, *zout, *prvr; } } } - /* render sequence */ + npicts = 0; /* render sequence */ do { if (seq && nextview(stdin) == EOF) break; + pctdone = 0.0; if (pout != NULL) { sprintf(fbuf, pout, seq); + if (file_exists(fbuf)) { + if (prvr != NULL || !strcmp(fbuf, pout)) { + sprintf(errmsg, + "output file \"%s\" exists", + fbuf); + error(USER, errmsg); + } + continue; /* don't clobber */ + } if (freopen(fbuf, "w", stdout) == NULL) { sprintf(errmsg, "cannot open output file \"%s\"", fbuf); @@ -250,7 +276,11 @@ char *pout, *zout, *prvr; cp = NULL; render(cp, prvr); prvr = NULL; + npicts++; } while (seq++); + /* check that we did something */ + if (npicts == 0) + error(WARNING, "no output produced"); } @@ -296,10 +326,10 @@ char *zfile, *oldfile; sampdens[i] = hstep; } else sampdens = NULL; - /* open z file */ + /* open z-file */ if (zfile != NULL) { if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { - sprintf(errmsg, "cannot open z file \"%s\"", zfile); + sprintf(errmsg, "cannot open z-file \"%s\"", zfile); error(SYSTEM, errmsg); } #ifdef MSDOS @@ -321,7 +351,7 @@ char *zfile, *oldfile; i = salvage(oldfile); if (zfd != -1 && i > 0 && lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) - error(SYSTEM, "z file seek error in render"); + error(SYSTEM, "z-file seek error in render"); pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ report();