--- ray/src/util/rpiece.c 1994/02/28 09:22:32 2.29 +++ ray/src/util/rpiece.c 2003/02/22 02:07:30 2.37 @@ -1,9 +1,6 @@ -/* Copyright (c) 1993 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rpiece.c,v 2.37 2003/02/22 02:07:30 greg Exp $"; #endif - /* * Generate sections of a picture. */ @@ -25,7 +22,6 @@ char *argv[]; #include #include "color.h" #include "view.h" -#include "resolu.h" #ifndef NFS #define NFS 1 @@ -47,6 +43,9 @@ char *argv[]; #define guard_io() 0 #define unguard() 0 #endif + +extern char *strerror(); + /* rpict command */ char *rpargv[128] = {"rpict", "-S", "1"}; int rpargc = 3; @@ -69,10 +68,9 @@ int nforked = 0; char *progname; int verbose = 0; +unsigned timelim = 0; int rvrlim = -1; -extern long lseek(), ftell(); - int gotalrm = 0; int onalrm() { gotalrm++; } @@ -86,12 +84,13 @@ char *argv[]; progname = argv[0]; for (i = 1; i < argc; i++) { /* expand arguments */ - while (rval = expandarg(&argc, &argv, i)) - if (rval < 0) { - fprintf(stderr, "%s: cannot expand '%s'", - argv[0], argv[i]); - exit(1); - } + while ((rval = expandarg(&argc, &argv, i)) > 0) + ; + if (rval < 0) { + fprintf(stderr, "%s: cannot expand '%s'", + argv[0], argv[i]); + exit(1); + } if (argv[i][0] == '-') switch (argv[i][1]) { case 'v': @@ -118,8 +117,13 @@ char *argv[]; case 'p': /* pixel aspect ratio? */ if (argv[i][2] != 'a' || argv[i][3]) break; - pixaspect = atof(argv[i+1]); + pixaspect = atof(argv[++i]); continue; + case 'T': /* time limit (hours) */ + if (argv[i][2]) + break; + timelim = atof(argv[++i])*3600. + .5; + break; case 'x': /* overall x resolution */ if (argv[i][2]) break; @@ -187,12 +191,11 @@ int fd; int ltyp; { static struct flock fls; /* static so initialized to zeroes */ - extern char *sys_errlist[]; fls.l_type = ltyp; if (fcntl(fd, F_SETLKW, &fls) < 0) { fprintf(stderr, "%s: cannot lock/unlock file: %s\n", - progname, sys_errlist[errno]); + progname, strerror(errno)); exit(1); } } @@ -280,6 +283,8 @@ char **av; exit(1); } signal(SIGALRM, onalrm); + if (timelim) + alarm(timelim); return; filerr: fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); @@ -345,6 +350,10 @@ register int *xp, *yp; return(0); /* only check if asked */ if (pdone == NULL) /* first call */ pdone = calloc(hmult*vmult, sizeof(char)); + if (pdone == NULL) { + fprintf(stderr, "%s: out of memory\n", progname); + exit(1); + } if (readpos != -1) /* mark what's been done */ fseek(syncfp, readpos, 0); while (fscanf(syncfp, "%d %d", xp, yp) == 2) @@ -403,6 +412,11 @@ rpiece() /* render picture piece by piece */ pview.horiz = ourview.horiz / hmult; pview.vert = ourview.vert / vmult; break; + case VT_CYL: + pview.horiz = ourview.horiz / hmult; + pview.vert = 2.*180./PI*atan( + tan(PI/180./2.*ourview.vert)/vmult ); + break; case VT_HEM: pview.horiz = 2.*180./PI*asin( sin(PI/180./2.*ourview.horiz)/hmult ); @@ -416,8 +430,8 @@ rpiece() /* render picture piece by piece */ } /* render each piece */ while (nextpiece(&xorg, &yorg)) { - pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); - pview.voff = ourview.voff + yorg - 0.5*(vmult-1); + pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); + pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); fputs(VIEWSTR, torp); fprintview(&pview, torp); putc('\n', torp); @@ -489,7 +503,7 @@ int xpos, ypos; filerr("lock"); #endif /* write new piece to file */ - if (lseek(outfd, fls.l_start, 0) == -1) + if (lseek(outfd, (off_t)fls.l_start, 0) < 0) filerr("seek"); if (hmult == 1) { if (writebuf(outfd, (char *)pbuf, @@ -501,8 +515,8 @@ int xpos, ypos; hr*sizeof(COLR)) != hr*sizeof(COLR)) filerr("write"); if (y < vr-1 && lseek(outfd, - (long)(hmult-1)*hr*sizeof(COLR), - 1) == -1) + (off_t)(hmult-1)*hr*sizeof(COLR), + 1) < 0) filerr("seek"); } #if NFS @@ -510,6 +524,10 @@ int xpos, ypos; if (fcntl(outfd, F_SETLKW, &fls) < 0) filerr("lock"); #endif + if (verbose) { /* notify caller */ + printf("%d %d done\n", xpos, ypos); + fflush(stdout); + } if (syncfp != NULL) { /* record what's been done */ sflock(F_WRLCK); fseek(syncfp, 0L, 2); /* append index */ @@ -518,10 +536,6 @@ int xpos, ypos; /*** Unlock not necessary, since sflock(F_UNLCK); _exit() or nextpiece() is next ***/ } - if (verbose) { /* notify caller */ - printf("%d %d done\n", xpos, ypos); - fflush(stdout); - } if (pid == -1) /* didn't fork or fork failed */ return(0); _exit(0); /* else exit child process (releasing locks) */ @@ -531,10 +545,8 @@ int xpos, ypos; filerr(t) /* report file error and exit */ char *t; { - extern char *sys_errlist[]; - fprintf(stderr, "%s: %s error on file \"%s\": %s\n", - progname, t, outfile, sys_errlist[errno]); + progname, t, outfile, strerror(errno)); _exit(1); }