--- ray/src/rt/rpict.c 2003/02/25 02:47:23 2.53 +++ ray/src/rt/rpict.c 2003/07/21 22:30:19 2.61 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpict.c,v 2.53 2003/02/25 02:47:23 greg Exp $"; +static const char RCSid[] = "$Id"; #endif /* * rpict.c - routines and variables for picture generation. @@ -7,11 +7,12 @@ static const char RCSid[] = "$Id: rpict.c,v 2.53 2003/ #include "copyright.h" +#include "platform.h" #include "ray.h" #include -#ifndef NIX +#ifndef NON_POSIX #ifdef BSD #include #include @@ -21,21 +22,21 @@ static const char RCSid[] = "$Id: rpict.c,v 2.53 2003/ #endif #endif -extern time_t time(); - +#include #include #include "view.h" - #include "random.h" - #include "paths.h" + #define RFTEMPLATE "rfXXXXXX" #ifndef SIGCONT +#ifdef SIGIO /* XXX can we live without this? */ #define SIGCONT SIGIO #endif +#endif CUBE thescene; /* our scene */ OBJECT nsceneobjs; /* number of objects in our scene */ @@ -108,15 +109,13 @@ int hres, vres; /* resolution for this frame */ static VIEW lastview; /* the previous view input */ -extern char *mktemp(); +extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ void report(); double pixvalue(); -#ifdef NIX -#define file_exists(f) (access(f,F_OK)==0) -#else +#ifdef RHAS_STAT #include #include int @@ -127,6 +126,8 @@ char *fname; if (stat(fname, &sbuf) < 0) return(0); return((sbuf.st_mode & S_IFREG) != 0); } +#else +#define file_exists(f) (access(f,F_OK)==0) #endif @@ -136,7 +137,7 @@ int code; { if (code) /* report status */ report(); -#ifndef NIX +#ifndef NON_POSIX headclean(); /* delete header file */ pfclean(); /* clean up persist files */ #endif @@ -144,7 +145,7 @@ int code; } -#ifndef NIX +#ifndef NON_POSIX void report() /* report progress */ { @@ -181,7 +182,7 @@ report() /* report progress */ nrays, pctdone, u/3600., s/3600., (tlastrept-tstart)/3600., myhostname()); eputs(errmsg); -#ifndef BSD +#ifdef SIGCONT signal(SIGCONT, report); #endif } @@ -213,7 +214,6 @@ char *pout, *zout, *prvr; * sequenced file naming. */ { - extern char *rindex(), *strncpy(), *strcat(), *strcpy(); char fbuf[128], fbuf2[128]; int npicts; register char *cp; @@ -253,7 +253,7 @@ char *pout, *zout, *prvr; cp--; strcpy(cp, RFTEMPLATE); prvr = mktemp(fbuf2); - if (rename(fbuf, prvr) < 0) + if (rename(fbuf, prvr) < 0) { if (errno == ENOENT) { /* ghost file */ sprintf(errmsg, "new output file \"%s\"", @@ -266,6 +266,7 @@ char *pout, *zout, *prvr; fbuf, prvr); error(SYSTEM, errmsg); } + } } } npicts = 0; /* render sequence */ @@ -290,13 +291,11 @@ char *pout, *zout, *prvr; "cannot open output file \"%s\"", fbuf); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); -#endif + SET_FILE_BINARY(stdout); dupheader(); } hres = hresolu; vres = vresolu; pa = pixaspect; - if (prvr != NULL) + if (prvr != NULL) { if (viewfile(prvr, &ourview, &rs) <= 0 || rs.rt != PIXSTANDARD) { sprintf(errmsg, @@ -307,6 +306,7 @@ char *pout, *zout, *prvr; hres = scanlen(&rs); vres = numscans(&rs); } + } if ((cp = setview(&ourview)) != NULL) error(USER, cp); normaspect(viewaspect(&ourview), &pa, &hres, &vres); @@ -324,6 +324,7 @@ char *pout, *zout, *prvr; putchar('\n'); if (pa < .99 || pa > 1.01) fputaspect(pa, stdout); + fputnow(stdout); fputformat(COLRFMT, stdout); putchar('\n'); if (zout != NULL) @@ -345,7 +346,7 @@ FILE *fp; { char linebuf[256]; - copystruct(&lastview, &ourview); + lastview = ourview; while (fgets(linebuf, sizeof(linebuf), fp) != NULL) if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) return(0); @@ -394,9 +395,7 @@ char *zfile, *oldfile; sprintf(errmsg, "cannot open z-file \"%s\"", zfile); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(zfd, O_BINARY); -#endif + SET_FD_BINARY(zfd); for (i = 0; i <= psample; i++) { zbar[i] = (float *)malloc(hres*sizeof(float)); if (zbar[i] == NULL) @@ -419,10 +418,10 @@ char *zfile, *oldfile; pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ report(); -#ifndef BSD +#ifdef SIGCONT else -#endif signal(SIGCONT, report); +#endif ypos = vres-1 - i; /* initialize sampling */ if (directvis) init_drawsources(psample); @@ -448,7 +447,7 @@ char *zfile, *oldfile; if (directvis) /* add bitty sources */ drawsources(scanbar, zbar, 0, hres, ypos, ystep); /* write it out */ -#ifndef BSD +#ifdef SIGCONT signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ #endif for (i = ystep; i > 0; i--) { @@ -465,13 +464,15 @@ char *zfile, *oldfile; pctdone = 100.0*(vres-1-ypos)/vres; if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) report(); -#ifndef BSD +#ifdef SIGCONT else signal(SIGCONT, report); #endif } /* clean up */ +#ifdef SIGCONT signal(SIGCONT, SIG_IGN); +#endif if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float)) < hres*sizeof(float)) goto writerr; @@ -492,7 +493,9 @@ alldone: pctdone = 100.0; if (ralrm > 0) report(); +#ifdef SIGCONT signal(SIGCONT, SIG_DFL); +#endif return; writerr: error(SYSTEM, "write error in render"); @@ -678,9 +681,7 @@ char *oldfile; error(WARNING, errmsg); goto gotzip; } -#ifdef MSDOS - setmode(fileno(fp), O_BINARY); -#endif + SET_FILE_BINARY(fp); /* discard header */ getheader(fp, NULL, NULL); /* get picture size */