1 |
< |
/* Copyright (c) 1993 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
39 |
|
#endif |
40 |
|
#endif |
41 |
|
/* protection from SYSV signals(!) */ |
42 |
< |
#if defined(sgi) || defined(hpux) |
42 |
> |
#if defined(sgi) |
43 |
|
#define guard_io() sighold(SIGALRM) |
44 |
|
#define unguard() sigrelse(SIGALRM) |
45 |
|
#endif |
69 |
|
|
70 |
|
char *progname; |
71 |
|
int verbose = 0; |
72 |
+ |
unsigned timelim = 0; |
73 |
|
int rvrlim = -1; |
74 |
|
|
75 |
|
extern long lseek(), ftell(); |
121 |
|
break; |
122 |
|
pixaspect = atof(argv[i+1]); |
123 |
|
continue; |
124 |
+ |
case 'T': /* time limit (hours) */ |
125 |
+ |
if (argv[i][2]) |
126 |
+ |
break; |
127 |
+ |
timelim = atof(argv[++i])*3600. + .5; |
128 |
+ |
break; |
129 |
|
case 'x': /* overall x resolution */ |
130 |
|
if (argv[i][2]) |
131 |
|
break; |
154 |
|
case 'F': /* syncronization file */ |
155 |
|
if (argv[i][2]) |
156 |
|
break; |
157 |
< |
if ((syncfp = fopen(argv[++i],"r+")) == NULL) { |
157 |
> |
if ((syncfp = |
158 |
> |
fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { |
159 |
|
fprintf(stderr, "%s: cannot open\n", |
160 |
|
argv[i]); |
161 |
|
exit(1); |
193 |
|
int ltyp; |
194 |
|
{ |
195 |
|
static struct flock fls; /* static so initialized to zeroes */ |
196 |
+ |
extern char *sys_errlist[]; |
197 |
|
|
198 |
|
fls.l_type = ltyp; |
199 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
200 |
< |
fprintf(stderr, "%s: cannot lock/unlock file\n", progname); |
200 |
> |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
201 |
> |
progname, sys_errlist[errno]); |
202 |
|
exit(1); |
203 |
|
} |
204 |
|
} |
239 |
|
dolock(outfd, F_WRLCK); |
240 |
|
if ((fp = fdopen(dup(outfd), "w")) == NULL) |
241 |
|
goto filerr; |
242 |
< |
printargs(ac, av, fp); /* write header */ |
242 |
> |
newheader("RADIANCE", fp); /* create header */ |
243 |
> |
printargs(ac, av, fp); |
244 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
245 |
|
fputs(VIEWSTR, fp); |
246 |
|
fprintview(&ourview, fp); |
286 |
|
exit(1); |
287 |
|
} |
288 |
|
signal(SIGALRM, onalrm); |
289 |
+ |
if (timelim) |
290 |
+ |
alarm(timelim); |
291 |
|
return; |
292 |
|
filerr: |
293 |
|
fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); |
333 |
|
sflock(F_UNLCK); /* release sync file */ |
334 |
|
return(1); |
335 |
|
} |
336 |
< |
if (scanf("%d %d", xp, yp) == 2) /* use stdin */ |
325 |
< |
return(1); |
326 |
< |
fprintf(stderr, "%s: input format error\n", progname); |
327 |
< |
exit(cleanup(1)); |
336 |
> |
return(scanf("%d %d", xp, yp) == 2); /* use stdin */ |
337 |
|
} |
338 |
|
|
339 |
|
|
353 |
|
return(0); /* only check if asked */ |
354 |
|
if (pdone == NULL) /* first call */ |
355 |
|
pdone = calloc(hmult*vmult, sizeof(char)); |
356 |
+ |
if (pdone == NULL) { |
357 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
358 |
+ |
exit(1); |
359 |
+ |
} |
360 |
|
if (readpos != -1) /* mark what's been done */ |
361 |
|
fseek(syncfp, readpos, 0); |
362 |
|
while (fscanf(syncfp, "%d %d", xp, yp) == 2) |
497 |
|
/* lock file section so NFS doesn't mess up */ |
498 |
|
fls.l_whence = 0; |
499 |
|
fls.l_type = F_WRLCK; |
500 |
< |
fcntl(outfd, F_SETLKW, &fls); |
500 |
> |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
501 |
> |
filerr("lock"); |
502 |
|
#endif |
503 |
|
/* write new piece to file */ |
504 |
|
if (lseek(outfd, fls.l_start, 0) == -1) |
505 |
< |
goto seekerr; |
505 |
> |
filerr("seek"); |
506 |
|
if (hmult == 1) { |
507 |
|
if (writebuf(outfd, (char *)pbuf, |
508 |
|
vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR)) |
509 |
< |
goto writerr; |
509 |
> |
filerr("write"); |
510 |
|
} else |
511 |
|
for (y = 0; y < vr; y++) { |
512 |
|
if (writebuf(outfd, (char *)(pbuf+y*hr), |
513 |
|
hr*sizeof(COLR)) != hr*sizeof(COLR)) |
514 |
< |
goto writerr; |
514 |
> |
filerr("write"); |
515 |
|
if (y < vr-1 && lseek(outfd, |
516 |
|
(long)(hmult-1)*hr*sizeof(COLR), |
517 |
|
1) == -1) |
518 |
< |
goto seekerr; |
518 |
> |
filerr("seek"); |
519 |
|
} |
520 |
|
#if NFS |
521 |
|
fls.l_type = F_UNLCK; /* release lock */ |
522 |
< |
fcntl(outfd, F_SETLKW, &fls); |
522 |
> |
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
523 |
> |
filerr("lock"); |
524 |
|
#endif |
525 |
|
if (syncfp != NULL) { /* record what's been done */ |
526 |
|
sflock(F_WRLCK); |
537 |
|
if (pid == -1) /* didn't fork or fork failed */ |
538 |
|
return(0); |
539 |
|
_exit(0); /* else exit child process (releasing locks) */ |
540 |
< |
seekerr: |
541 |
< |
fprintf(stderr, "%s: seek error on file \"%s\"\n", progname, outfile); |
542 |
< |
_exit(1); |
543 |
< |
writerr: |
544 |
< |
fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); |
540 |
> |
} |
541 |
> |
|
542 |
> |
|
543 |
> |
filerr(t) /* report file error and exit */ |
544 |
> |
char *t; |
545 |
> |
{ |
546 |
> |
extern char *sys_errlist[]; |
547 |
> |
|
548 |
> |
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
549 |
> |
progname, t, outfile, sys_errlist[errno]); |
550 |
|
_exit(1); |
551 |
|
} |
552 |
|
|