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 |
47 |
|
#define guard_io() 0 |
48 |
|
#define unguard() 0 |
49 |
|
#endif |
50 |
+ |
|
51 |
+ |
#ifndef linux |
52 |
+ |
extern char *sys_errlist[]; |
53 |
+ |
#endif |
54 |
+ |
|
55 |
|
/* rpict command */ |
56 |
|
char *rpargv[128] = {"rpict", "-S", "1"}; |
57 |
|
int rpargc = 3; |
74 |
|
|
75 |
|
char *progname; |
76 |
|
int verbose = 0; |
77 |
+ |
unsigned timelim = 0; |
78 |
|
int rvrlim = -1; |
79 |
|
|
80 |
|
extern long lseek(), ftell(); |
126 |
|
break; |
127 |
|
pixaspect = atof(argv[i+1]); |
128 |
|
continue; |
129 |
+ |
case 'T': /* time limit (hours) */ |
130 |
+ |
if (argv[i][2]) |
131 |
+ |
break; |
132 |
+ |
timelim = atof(argv[++i])*3600. + .5; |
133 |
+ |
break; |
134 |
|
case 'x': /* overall x resolution */ |
135 |
|
if (argv[i][2]) |
136 |
|
break; |
159 |
|
case 'F': /* syncronization file */ |
160 |
|
if (argv[i][2]) |
161 |
|
break; |
162 |
< |
if ((syncfp = fopen(argv[++i],"r+")) == NULL) { |
162 |
> |
if ((syncfp = |
163 |
> |
fdopen(open(argv[++i],O_RDWR|O_CREAT,0666),"r+")) == NULL) { |
164 |
|
fprintf(stderr, "%s: cannot open\n", |
165 |
|
argv[i]); |
166 |
|
exit(1); |
201 |
|
|
202 |
|
fls.l_type = ltyp; |
203 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
204 |
< |
fprintf(stderr, "%s: cannot lock/unlock file\n", progname); |
204 |
> |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
205 |
> |
progname, sys_errlist[errno]); |
206 |
|
exit(1); |
207 |
|
} |
208 |
|
} |
243 |
|
dolock(outfd, F_WRLCK); |
244 |
|
if ((fp = fdopen(dup(outfd), "w")) == NULL) |
245 |
|
goto filerr; |
246 |
< |
printargs(ac, av, fp); /* write header */ |
246 |
> |
newheader("RADIANCE", fp); /* create header */ |
247 |
> |
printargs(ac, av, fp); |
248 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
249 |
|
fputs(VIEWSTR, fp); |
250 |
|
fprintview(&ourview, fp); |
290 |
|
exit(1); |
291 |
|
} |
292 |
|
signal(SIGALRM, onalrm); |
293 |
+ |
if (timelim) |
294 |
+ |
alarm(timelim); |
295 |
|
return; |
296 |
|
filerr: |
297 |
|
fprintf(stderr, "%s: i/o error on file \"%s\"\n", progname, outfile); |
357 |
|
return(0); /* only check if asked */ |
358 |
|
if (pdone == NULL) /* first call */ |
359 |
|
pdone = calloc(hmult*vmult, sizeof(char)); |
360 |
+ |
if (pdone == NULL) { |
361 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
362 |
+ |
exit(1); |
363 |
+ |
} |
364 |
|
if (readpos != -1) /* mark what's been done */ |
365 |
|
fseek(syncfp, readpos, 0); |
366 |
|
while (fscanf(syncfp, "%d %d", xp, yp) == 2) |
419 |
|
pview.horiz = ourview.horiz / hmult; |
420 |
|
pview.vert = ourview.vert / vmult; |
421 |
|
break; |
422 |
+ |
case VT_CYL: |
423 |
+ |
pview.horiz = ourview.horiz / hmult; |
424 |
+ |
pview.vert = 2.*180./PI*atan( |
425 |
+ |
tan(PI/180./2.*ourview.vert)/vmult ); |
426 |
+ |
break; |
427 |
|
case VT_HEM: |
428 |
|
pview.horiz = 2.*180./PI*asin( |
429 |
|
sin(PI/180./2.*ourview.horiz)/hmult ); |
437 |
|
} |
438 |
|
/* render each piece */ |
439 |
|
while (nextpiece(&xorg, &yorg)) { |
440 |
< |
pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); |
441 |
< |
pview.voff = ourview.voff + yorg - 0.5*(vmult-1); |
440 |
> |
pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); |
441 |
> |
pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); |
442 |
|
fputs(VIEWSTR, torp); |
443 |
|
fprintview(&pview, torp); |
444 |
|
putc('\n', torp); |
531 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
532 |
|
filerr("lock"); |
533 |
|
#endif |
534 |
+ |
if (verbose) { /* notify caller */ |
535 |
+ |
printf("%d %d done\n", xpos, ypos); |
536 |
+ |
fflush(stdout); |
537 |
+ |
} |
538 |
|
if (syncfp != NULL) { /* record what's been done */ |
539 |
|
sflock(F_WRLCK); |
540 |
|
fseek(syncfp, 0L, 2); /* append index */ |
543 |
|
/*** Unlock not necessary, since |
544 |
|
sflock(F_UNLCK); _exit() or nextpiece() is next ***/ |
545 |
|
} |
517 |
– |
if (verbose) { /* notify caller */ |
518 |
– |
printf("%d %d done\n", xpos, ypos); |
519 |
– |
fflush(stdout); |
520 |
– |
} |
546 |
|
if (pid == -1) /* didn't fork or fork failed */ |
547 |
|
return(0); |
548 |
|
_exit(0); /* else exit child process (releasing locks) */ |
552 |
|
filerr(t) /* report file error and exit */ |
553 |
|
char *t; |
554 |
|
{ |
530 |
– |
extern char *sys_errlist[]; |
531 |
– |
|
555 |
|
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
556 |
|
progname, t, outfile, sys_errlist[errno]); |
557 |
|
_exit(1); |