1 |
– |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Generate sections of a picture. |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "platform.h" |
9 |
|
#include "standard.h" |
10 |
|
|
11 |
|
#ifndef F_SETLKW |
21 |
|
#else |
22 |
|
|
23 |
|
#include <signal.h> |
24 |
+ |
|
25 |
|
#include "color.h" |
26 |
|
#include "view.h" |
27 |
< |
#include "resolu.h" |
27 |
> |
#include "rtprocess.h" |
28 |
|
|
29 |
|
#ifndef NFS |
30 |
|
#define NFS 1 |
38 |
|
#endif |
39 |
|
#endif |
40 |
|
/* protection from SYSV signals(!) */ |
41 |
< |
#if defined(sgi) || defined(hpux) |
41 |
> |
#if defined(sgi) |
42 |
|
#define guard_io() sighold(SIGALRM) |
43 |
|
#define unguard() sigrelse(SIGALRM) |
44 |
|
#endif |
46 |
|
#define guard_io() 0 |
47 |
|
#define unguard() 0 |
48 |
|
#endif |
49 |
+ |
|
50 |
+ |
extern char *strerror(); |
51 |
+ |
|
52 |
|
/* rpict command */ |
53 |
|
char *rpargv[128] = {"rpict", "-S", "1"}; |
54 |
|
int rpargc = 3; |
53 |
– |
int rpd[3]; |
55 |
|
FILE *torp, *fromrp; |
56 |
|
COLR *pbuf; |
57 |
|
/* our view parameters */ |
70 |
|
|
71 |
|
char *progname; |
72 |
|
int verbose = 0; |
73 |
+ |
unsigned timelim = 0; |
74 |
|
int rvrlim = -1; |
75 |
|
|
74 |
– |
extern long lseek(), ftell(); |
75 |
– |
|
76 |
|
int gotalrm = 0; |
77 |
< |
int onalrm() { gotalrm++; } |
77 |
> |
void onalrm(int i) { gotalrm++; } |
78 |
|
|
79 |
|
|
80 |
|
main(argc, argv) |
86 |
|
progname = argv[0]; |
87 |
|
for (i = 1; i < argc; i++) { |
88 |
|
/* expand arguments */ |
89 |
< |
while (rval = expandarg(&argc, &argv, i)) |
90 |
< |
if (rval < 0) { |
91 |
< |
fprintf(stderr, "%s: cannot expand '%s'", |
92 |
< |
argv[0], argv[i]); |
93 |
< |
exit(1); |
94 |
< |
} |
89 |
> |
while ((rval = expandarg(&argc, &argv, i)) > 0) |
90 |
> |
; |
91 |
> |
if (rval < 0) { |
92 |
> |
fprintf(stderr, "%s: cannot expand '%s'", |
93 |
> |
argv[0], argv[i]); |
94 |
> |
exit(1); |
95 |
> |
} |
96 |
|
if (argv[i][0] == '-') |
97 |
|
switch (argv[i][1]) { |
98 |
|
case 'v': |
119 |
|
case 'p': /* pixel aspect ratio? */ |
120 |
|
if (argv[i][2] != 'a' || argv[i][3]) |
121 |
|
break; |
122 |
< |
pixaspect = atof(argv[i+1]); |
122 |
> |
pixaspect = atof(argv[++i]); |
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); |
196 |
|
|
197 |
|
fls.l_type = ltyp; |
198 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
199 |
< |
fprintf(stderr, "%s: cannot lock/unlock file\n", progname); |
199 |
> |
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
200 |
> |
progname, strerror(errno)); |
201 |
|
exit(1); |
202 |
|
} |
203 |
|
} |
212 |
|
char *err; |
213 |
|
FILE *fp; |
214 |
|
int hr, vr; |
215 |
+ |
SUBPROC rpd; /* since we don't close_process(), this can be local */ |
216 |
|
/* set up view */ |
217 |
|
if ((err = setview(&ourview)) != NULL) { |
218 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
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); |
271 |
|
goto filerr; |
272 |
|
dolock(outfd, F_UNLCK); |
273 |
|
/* start rpict process */ |
274 |
< |
if (open_process(rpd, rpargv) <= 0) { |
274 |
> |
if (open_process(&rpd, rpargv) <= 0) { |
275 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
276 |
|
exit(1); |
277 |
|
} |
278 |
< |
if ((fromrp = fdopen(rpd[0], "r")) == NULL || |
279 |
< |
(torp = fdopen(rpd[1], "w")) == NULL) { |
278 |
> |
if ((fromrp = fdopen(rpd.r, "r")) == NULL || |
279 |
> |
(torp = fdopen(rpd.w, "w")) == NULL) { |
280 |
|
fprintf(stderr, "%s: cannot open stream to %s\n", |
281 |
|
progname, rpargv[0]); |
282 |
|
exit(1); |
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); |
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) |
402 |
|
VIEW pview; |
403 |
|
int xorg, yorg; |
404 |
|
/* compute view parameters */ |
405 |
< |
copystruct(&pview, &ourview); |
405 |
> |
pview = ourview; |
406 |
|
switch (ourview.type) { |
407 |
|
case VT_PER: |
408 |
|
pview.horiz = 2.*180./PI*atan( |
415 |
|
pview.horiz = ourview.horiz / hmult; |
416 |
|
pview.vert = ourview.vert / vmult; |
417 |
|
break; |
418 |
+ |
case VT_CYL: |
419 |
+ |
pview.horiz = ourview.horiz / hmult; |
420 |
+ |
pview.vert = 2.*180./PI*atan( |
421 |
+ |
tan(PI/180./2.*ourview.vert)/vmult ); |
422 |
+ |
break; |
423 |
|
case VT_HEM: |
424 |
|
pview.horiz = 2.*180./PI*asin( |
425 |
|
sin(PI/180./2.*ourview.horiz)/hmult ); |
433 |
|
} |
434 |
|
/* render each piece */ |
435 |
|
while (nextpiece(&xorg, &yorg)) { |
436 |
< |
pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); |
437 |
< |
pview.voff = ourview.voff + yorg - 0.5*(vmult-1); |
436 |
> |
pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); |
437 |
> |
pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); |
438 |
|
fputs(VIEWSTR, torp); |
439 |
|
fprintview(&pview, torp); |
440 |
|
putc('\n', torp); |
453 |
|
int hr, vr; |
454 |
|
register int y; |
455 |
|
/* check bounds */ |
456 |
< |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
456 |
> |
if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { |
457 |
|
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
458 |
|
progname, xpos, ypos); |
459 |
|
exit(cleanup(1)); |
461 |
|
/* check header from rpict */ |
462 |
|
guard_io(); |
463 |
|
getheader(fromrp, NULL, NULL); |
464 |
< |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
464 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || (hr != hres) | (vr != vres)) { |
465 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
466 |
|
progname, rpargv[0]); |
467 |
|
exit(cleanup(1)); |
506 |
|
filerr("lock"); |
507 |
|
#endif |
508 |
|
/* write new piece to file */ |
509 |
< |
if (lseek(outfd, fls.l_start, 0) == -1) |
509 |
> |
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
510 |
|
filerr("seek"); |
511 |
|
if (hmult == 1) { |
512 |
|
if (writebuf(outfd, (char *)pbuf, |
518 |
|
hr*sizeof(COLR)) != hr*sizeof(COLR)) |
519 |
|
filerr("write"); |
520 |
|
if (y < vr-1 && lseek(outfd, |
521 |
< |
(long)(hmult-1)*hr*sizeof(COLR), |
522 |
< |
1) == -1) |
521 |
> |
(off_t)(hmult-1)*hr*sizeof(COLR), |
522 |
> |
SEEK_CUR) < 0) |
523 |
|
filerr("seek"); |
524 |
|
} |
525 |
|
#if NFS |
527 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
528 |
|
filerr("lock"); |
529 |
|
#endif |
530 |
+ |
if (verbose) { /* notify caller */ |
531 |
+ |
printf("%d %d done\n", xpos, ypos); |
532 |
+ |
fflush(stdout); |
533 |
+ |
} |
534 |
|
if (syncfp != NULL) { /* record what's been done */ |
535 |
|
sflock(F_WRLCK); |
536 |
|
fseek(syncfp, 0L, 2); /* append index */ |
539 |
|
/*** Unlock not necessary, since |
540 |
|
sflock(F_UNLCK); _exit() or nextpiece() is next ***/ |
541 |
|
} |
517 |
– |
if (verbose) { /* notify caller */ |
518 |
– |
printf("%d %d done\n", xpos, ypos); |
519 |
– |
fflush(stdout); |
520 |
– |
} |
542 |
|
if (pid == -1) /* didn't fork or fork failed */ |
543 |
|
return(0); |
544 |
|
_exit(0); /* else exit child process (releasing locks) */ |
548 |
|
filerr(t) /* report file error and exit */ |
549 |
|
char *t; |
550 |
|
{ |
530 |
– |
extern char *sys_errlist[]; |
531 |
– |
|
551 |
|
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
552 |
< |
progname, t, outfile, sys_errlist[errno]); |
552 |
> |
progname, t, outfile, strerror(errno)); |
553 |
|
_exit(1); |
554 |
|
} |
555 |
|
|