--- ray/src/rt/rpict.c 1993/01/20 15:19:47 2.21 +++ ray/src/rt/rpict.c 1993/08/02 21:48:37 2.27 @@ -29,6 +29,10 @@ static char SCCSid[] = "$SunId$ LBL"; #define RFTEMPLATE "rfXXXXXX" +#ifndef SIGCONT +#define SIGCONT SIGIO +#endif + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx; /* sample index number */ @@ -78,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 */ @@ -90,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; { @@ -115,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); @@ -124,10 +143,10 @@ 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(SIGALRM, report); + signal(SIGCONT, report); } #endif @@ -149,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; @@ -193,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); @@ -246,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"); } @@ -292,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 @@ -317,14 +351,14 @@ 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(); #ifndef BSD else #endif - signal(SIGALRM, report); + signal(SIGCONT, report); ypos = vres-1 - i; fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); /* compute scanlines */ @@ -347,7 +381,7 @@ char *zfile, *oldfile; fillscanbar(scanbar, zbar, hres, ypos, ystep); /* write it out */ #ifndef BSD - signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ + signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ #endif for (i = ystep; i > 0; i--) { if (zfd != -1 && write(zfd, (char *)zbar[i], @@ -365,11 +399,11 @@ char *zfile, *oldfile; report(); #ifndef BSD else - signal(SIGALRM, report); + signal(SIGCONT, report); #endif } /* clean up */ - signal(SIGALRM, SIG_IGN); + signal(SIGCONT, SIG_IGN); if (zfd != -1) { if (write(zfd, (char *)zbar[0], hres*sizeof(float)) < hres*sizeof(float)) @@ -389,6 +423,7 @@ char *zfile, *oldfile; pctdone = 100.0; if (ralrm > 0) report(); + signal(SIGCONT, SIG_DFL); return; writerr: error(SYSTEM, "write error in render");