--- ray/src/util/rpiece.c 1993/10/18 13:17:47 2.27 +++ ray/src/util/rpiece.c 1995/11/30 09:26:20 2.31 @@ -1,4 +1,4 @@ -/* Copyright (c) 1993 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -69,6 +69,7 @@ int nforked = 0; char *progname; int verbose = 0; +unsigned timelim = 0; int rvrlim = -1; extern long lseek(), ftell(); @@ -120,6 +121,11 @@ char *argv[]; break; pixaspect = atof(argv[i+1]); 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; @@ -148,7 +154,8 @@ char *argv[]; case 'F': /* syncronization file */ if (argv[i][2]) break; - if ((syncfp = fopen(argv[++i],"r+")) == NULL) { + if ((syncfp = + fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { fprintf(stderr, "%s: cannot open\n", argv[i]); exit(1); @@ -186,10 +193,12 @@ 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\n", progname); + fprintf(stderr, "%s: cannot lock/unlock file: %s\n", + progname, sys_errlist[errno]); exit(1); } } @@ -230,7 +239,8 @@ char **av; dolock(outfd, F_WRLCK); if ((fp = fdopen(dup(outfd), "w")) == NULL) goto filerr; - printargs(ac, av, fp); /* write header */ + newheader("RADIANCE", fp); /* create header */ + printargs(ac, av, fp); fprintf(fp, "SOFTWARE= %s\n", VersionID); fputs(VIEWSTR, fp); fprintview(&ourview, fp); @@ -276,6 +286,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); @@ -341,6 +353,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)