--- ray/src/rt/rpict.c 1993/01/21 10:08:59 2.22 +++ ray/src/rt/rpict.c 1993/08/11 09:46:15 2.29 @@ -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; @@ -189,20 +205,37 @@ char *pout, *zout, *prvr; cp--; strcpy(cp, RFTEMPLATE); prvr = mktemp(fbuf2); - if (rename(fbuf, prvr) < 0 && errno != ENOENT) { - sprintf(errmsg, + if (rename(fbuf, prvr) < 0) + if (errno == ENOENT) { /* ghost file */ + sprintf(errmsg, + "new output file \"%s\"", + fbuf); + error(WARNING, errmsg); + prvr = NULL; + } else { /* serious error */ + sprintf(errmsg, "cannot rename \"%s\" to \"%s\"", fbuf, prvr); - error(SYSTEM, errmsg); - } + error(SYSTEM, errmsg); + } } } - /* 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 +283,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 +333,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 +358,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(); @@ -393,6 +430,7 @@ char *zfile, *oldfile; pctdone = 100.0; if (ralrm > 0) report(); + signal(SIGCONT, SIG_DFL); return; writerr: error(SYSTEM, "write error in render"); @@ -569,7 +607,8 @@ char *oldfile; getheader(fp, NULL, NULL); /* get picture size */ if (!fscnresolu(&x, &y, fp)) { - sprintf(errmsg, "bad recover file \"%s\"", oldfile); + sprintf(errmsg, "bad recover file \"%s\" - not removed", + oldfile); error(WARNING, errmsg); fclose(fp); return(0);