15 |
|
#include "view.h" |
16 |
|
#include "resolu.h" |
17 |
|
|
18 |
+ |
#ifndef NFS |
19 |
+ |
#define NFS 1 |
20 |
+ |
#endif |
21 |
|
/* set the following to 0 to forgo forking */ |
22 |
|
#ifndef MAXFORK |
23 |
+ |
#if NFS |
24 |
|
#define MAXFORK 3 /* allotment of duped processes */ |
25 |
+ |
#else |
26 |
+ |
#define MAXFORK 0 |
27 |
|
#endif |
28 |
+ |
#endif |
29 |
|
|
30 |
|
/* rpict command */ |
31 |
|
char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"}; |
109 |
|
case 'F': /* syncronization file */ |
110 |
|
if (argv[i][2]) |
111 |
|
break; |
112 |
< |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
112 |
> |
if ((syncfd = open(argv[++i], |
113 |
> |
O_RDWR|O_CREAT, 0666)) < 0) { |
114 |
|
fprintf(stderr, "%s: cannot open\n", |
115 |
|
argv[i]); |
116 |
|
exit(1); |
172 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
173 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
174 |
|
goto filerr; |
175 |
< |
getheader(fp, NULL); /* skip header */ |
175 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
176 |
|
if (fscnresolu(&hr, &vr, fp) < 0 || /* check resolution */ |
177 |
|
hr != hres*hmult || vr != vres*vmult) { |
178 |
|
fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n", |
187 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
188 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
189 |
|
goto filerr; |
190 |
+ |
#if NFS |
191 |
|
sync(); /* flush NFS buffers */ |
192 |
+ |
#endif |
193 |
|
/* start rpict process */ |
194 |
|
if (open_process(rpd, rpargv) <= 0) { |
195 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
278 |
|
{ |
279 |
|
VIEW pview; |
280 |
|
int xorg, yorg; |
281 |
< |
|
281 |
> |
/* compute view parameters */ |
282 |
> |
copystruct(&pview, &ourview); |
283 |
> |
switch (ourview.type) { |
284 |
> |
case VT_PER: |
285 |
> |
pview.horiz = 2.*180./PI*atan( |
286 |
> |
tan(PI/180./2.*ourview.horiz)/hmult ); |
287 |
> |
pview.vert = 2.*180./PI*atan( |
288 |
> |
tan(PI/180./2.*ourview.vert)/vmult ); |
289 |
> |
break; |
290 |
> |
case VT_PAR: |
291 |
> |
case VT_ANG: |
292 |
> |
pview.horiz = ourview.horiz / hmult; |
293 |
> |
pview.vert = ourview.vert / vmult; |
294 |
> |
break; |
295 |
> |
case VT_HEM: |
296 |
> |
pview.horiz = 2.*180./PI*asin( |
297 |
> |
sin(PI/180./2.*ourview.horiz)/hmult ); |
298 |
> |
pview.vert = 2.*180./PI*asin( |
299 |
> |
sin(PI/180./2.*ourview.vert)/vmult ); |
300 |
> |
break; |
301 |
> |
default: |
302 |
> |
fprintf(stderr, "%s: unknown view type '-vt%c'\n", |
303 |
> |
progname, ourview.type); |
304 |
> |
exit(cleanup(1)); |
305 |
> |
} |
306 |
> |
/* render each piece */ |
307 |
|
while (nextpiece(&xorg, &yorg)) { |
308 |
< |
copystruct(&pview, &ourview); /* compute view for piece */ |
309 |
< |
switch (ourview.type) { |
275 |
< |
case VT_PER: |
276 |
< |
pview.horiz = 2.*180./PI*atan( |
277 |
< |
tan(PI/180./2.*ourview.horiz)/hmult ); |
278 |
< |
pview.vert = 2.*180./PI*atan( |
279 |
< |
tan(PI/180./2.*ourview.vert)/vmult ); |
280 |
< |
break; |
281 |
< |
case VT_PAR: |
282 |
< |
case VT_ANG: |
283 |
< |
pview.horiz = ourview.horiz / hmult; |
284 |
< |
pview.vert = ourview.vert / vmult; |
285 |
< |
break; |
286 |
< |
case VT_HEM: |
287 |
< |
pview.horiz = 2.*180./PI*asin( |
288 |
< |
sin(PI/180./2.*ourview.horiz)/hmult ); |
289 |
< |
pview.vert = 2.*180./PI*asin( |
290 |
< |
sin(PI/180./2.*ourview.vert)/vmult ); |
291 |
< |
break; |
292 |
< |
default: |
293 |
< |
fprintf(stderr, "%s: unknown view type '-vt%c'\n", |
294 |
< |
progname, ourview.type); |
295 |
< |
exit(cleanup(1)); |
296 |
< |
} |
297 |
< |
pview.hoff += xorg - 0.5*(hmult-1); |
298 |
< |
pview.voff += yorg - 0.5*(vmult-1); |
308 |
> |
pview.hoff = ourview.hoff + xorg - 0.5*(hmult-1); |
309 |
> |
pview.voff = ourview.voff + yorg - 0.5*(vmult-1); |
310 |
|
fputs(VIEWSTR, torp); |
311 |
|
fprintview(&pview, torp); |
312 |
|
putc('\n', torp); |
313 |
< |
fflush(torp); /* assign piece to rpict */ |
313 |
> |
fflush(torp); /* assigns piece to rpict */ |
314 |
|
putpiece(xorg, yorg); /* place piece in output */ |
315 |
|
if (verbose) { /* notify caller */ |
316 |
|
printf("%d %d done\n", xorg, yorg); |
335 |
|
exit(cleanup(1)); |
336 |
|
} |
337 |
|
/* check header from rpict */ |
338 |
< |
getheader(fromrp, NULL); |
339 |
< |
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres || vr != vres) { |
338 |
> |
getheader(fromrp, NULL, NULL); |
339 |
> |
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres | vr != vres) { |
340 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
341 |
|
progname, rpargv[0]); |
342 |
|
exit(cleanup(1)); |
362 |
|
#else |
363 |
|
pid = -1; /* no forking */ |
364 |
|
#endif |
365 |
+ |
#if NFS |
366 |
|
/* lock file section so NFS doesn't mess up */ |
367 |
|
fls.l_whence = 0; |
368 |
|
fls.l_len = (long)vres*hmult*hres*sizeof(COLR); |
369 |
|
fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len; |
370 |
|
fls.l_type = F_WRLCK; |
371 |
|
fcntl(outfd, F_SETLKW, &fls); |
372 |
+ |
#endif |
373 |
|
/* write new piece to file */ |
374 |
|
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
375 |
|
goto seekerr; |
388 |
|
goto seekerr; |
389 |
|
} |
390 |
|
if (pid == -1) { /* fork failed */ |
391 |
+ |
#if NFS |
392 |
|
fls.l_type = F_UNLCK; /* release lock */ |
393 |
|
fcntl(outfd, F_SETLKW, &fls); |
394 |
+ |
#endif |
395 |
|
return(0); |
396 |
|
} |
397 |
|
_exit(0); /* else exit child process (releasing lock) */ |