| 37 |
|
#ifndef NFS |
| 38 |
|
#define NFS 1 |
| 39 |
|
#endif |
| 40 |
< |
/* set the following to 0 to forgo forking */ |
| 40 |
> |
|
| 41 |
> |
#ifndef RHAS_FORK_EXEC |
| 42 |
> |
#undef MAXFORK |
| 43 |
> |
#define MAXFORK 0 |
| 44 |
> |
#endif |
| 45 |
|
#ifndef MAXFORK |
| 46 |
|
#if NFS |
| 47 |
|
#define MAXFORK 3 /* allotment of duped processes */ |
| 105 |
|
char *argv[] |
| 106 |
|
) |
| 107 |
|
{ |
| 108 |
< |
register int i, rval; |
| 108 |
> |
int i, rval; |
| 109 |
|
|
| 110 |
|
progname = argv[0]; |
| 111 |
|
for (i = 1; i < argc; i++) { |
| 155 |
|
++i; |
| 156 |
|
continue; |
| 157 |
|
} |
| 158 |
+ |
if (argv[i][2] == 'X') { |
| 159 |
+ |
fprintf(stderr, "%s: -pXYZ unsupported\n", |
| 160 |
+ |
argv[0]); |
| 161 |
+ |
++i; |
| 162 |
+ |
continue; |
| 163 |
+ |
} |
| 164 |
+ |
if (argv[i][2] == 'c') { |
| 165 |
+ |
fprintf(stderr, "%s: -pc unsupported\n", |
| 166 |
+ |
argv[0]); |
| 167 |
+ |
i += 9; |
| 168 |
+ |
continue; |
| 169 |
+ |
} |
| 170 |
|
if (argv[i][2] != 'a' || argv[i][3]) |
| 171 |
|
break; |
| 172 |
|
pixaspect = atof(argv[++i]); |
| 173 |
|
continue; |
| 174 |
+ |
case 'S': |
| 175 |
+ |
fprintf(stderr, "%s: -S unsupported\n", argv[0]); |
| 176 |
+ |
i++; |
| 177 |
+ |
continue; |
| 178 |
|
case 'T': /* time limit (hours) */ |
| 179 |
|
if (argv[i][2]) |
| 180 |
|
break; |
| 255 |
|
if (fcntl(fd, F_SETLKW, &fls) < 0) { |
| 256 |
|
fprintf(stderr, "%s: cannot lock/unlock file: %s\n", |
| 257 |
|
progname, strerror(errno)); |
| 258 |
< |
exit(1); |
| 258 |
> |
_exit(1); |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
|
|
| 295 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
| 296 |
|
if (!nowarn && (hr != hres*hmult) | (vr != vres*vmult)) |
| 297 |
|
fprintf(stderr, |
| 298 |
< |
"%s: warning - resolution changed from %dx%d to %dx%d\n", |
| 298 |
> |
"%s: warning - changed resolution from %dx%d to %dx%d\n", |
| 299 |
|
progname, hr, vr, hres*hmult, vres*vmult); |
| 300 |
|
sprintf(hrbuf, "%d", hres); |
| 301 |
|
rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; |
| 302 |
|
sprintf(vrbuf, "%d", vres); |
| 303 |
|
rpargv[rpargc++] = "-y"; rpargv[rpargc++] = vrbuf; |
| 304 |
|
rpargv[rpargc++] = "-pa"; rpargv[rpargc++] = "0"; |
| 305 |
+ |
rpargv[rpargc++] = "-pm"; rpargv[rpargc++] = "0"; |
| 306 |
|
rpargv[rpargc++] = av[ac-1]; |
| 307 |
|
rpargv[rpargc] = NULL; |
| 308 |
|
/* open output file */ |
| 315 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 316 |
|
fputs(VIEWSTR, fp); |
| 317 |
|
fprintview(&ourview, fp); |
| 318 |
< |
putc('\n', fp); |
| 318 |
> |
fputc('\n', fp); |
| 319 |
|
fputnow(fp); |
| 320 |
|
if (pixaspect < .99 || pixaspect > 1.01) |
| 321 |
|
fputaspect(pixaspect, fp); |
| 322 |
+ |
fputprims(stdprims, fp); |
| 323 |
|
fputformat(COLRFMT, fp); |
| 324 |
< |
putc('\n', fp); |
| 324 |
> |
fputc('\n', fp); |
| 325 |
|
fprtresolu(hres*hmult, vres*vmult, fp); |
| 326 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
| 327 |
|
dolock(outfd, F_RDLCK); |
| 344 |
|
goto filerr; |
| 345 |
|
dolock(outfd, F_UNLCK); |
| 346 |
|
/* start rpict process */ |
| 347 |
+ |
rpd = sp_inactive; |
| 348 |
|
if (open_process(&rpd, rpargv) <= 0) { |
| 349 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
| 350 |
|
exit(1); |
| 415 |
|
|
| 416 |
|
static int |
| 417 |
|
rvrpiece( /* check for recoverable pieces */ |
| 418 |
< |
register int *xp, |
| 419 |
< |
register int *yp |
| 418 |
> |
int *xp, |
| 419 |
> |
int *yp |
| 420 |
|
) |
| 421 |
|
{ |
| 422 |
|
static char *pdone = NULL; /* which pieces are done */ |
| 423 |
|
static long readpos = -1; /* how far we've read */ |
| 424 |
< |
register int i; |
| 424 |
> |
int px, py, i; |
| 425 |
|
/* |
| 426 |
|
* This routine is called by nextpiece() with an |
| 427 |
|
* exclusive lock on syncfp and the file pointer at the |
| 430 |
|
if (rvrlim < 0) |
| 431 |
|
return(0); /* only check if asked */ |
| 432 |
|
if (pdone == NULL) /* first call */ |
| 433 |
< |
pdone = calloc(hmult*vmult, sizeof(char)); |
| 433 |
> |
pdone = (char *)calloc(hmult*vmult, sizeof(char)); |
| 434 |
|
if (pdone == NULL) { |
| 435 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 436 |
|
exit(1); |
| 437 |
|
} |
| 438 |
|
if (readpos != -1) /* mark what's been done */ |
| 439 |
|
fseek(syncfp, readpos, 0); |
| 440 |
< |
while (fscanf(syncfp, "%d %d", xp, yp) == 2) |
| 441 |
< |
pdone[*xp*vmult+*yp] = 1; |
| 440 |
> |
while (fscanf(syncfp, "%d %d", &px, &py) == 2) |
| 441 |
> |
pdone[px*vmult+py] = 1; |
| 442 |
|
if (!feof(syncfp)) { |
| 443 |
|
fprintf(stderr, "%s: format error in sync file\n", progname); |
| 444 |
|
exit(1); |
| 479 |
|
static void |
| 480 |
|
rpiece(void) /* render picture piece by piece */ |
| 481 |
|
{ |
| 482 |
+ |
char *err; |
| 483 |
|
VIEW pview; |
| 484 |
|
int xorg, yorg; |
| 461 |
– |
/* compute view parameters */ |
| 462 |
– |
pview = ourview; |
| 463 |
– |
switch (ourview.type) { |
| 464 |
– |
case VT_PER: |
| 465 |
– |
pview.horiz = (2.*180./PI)*atan( |
| 466 |
– |
tan((PI/180./2.)*ourview.horiz)/hmult ); |
| 467 |
– |
pview.vert = (2.*180./PI)*atan( |
| 468 |
– |
tan((PI/180./2.)*ourview.vert)/vmult ); |
| 469 |
– |
break; |
| 470 |
– |
case VT_PAR: |
| 471 |
– |
case VT_ANG: |
| 472 |
– |
pview.horiz = ourview.horiz / hmult; |
| 473 |
– |
pview.vert = ourview.vert / vmult; |
| 474 |
– |
break; |
| 475 |
– |
case VT_CYL: |
| 476 |
– |
pview.horiz = ourview.horiz / hmult; |
| 477 |
– |
pview.vert = (2.*180./PI)*atan( |
| 478 |
– |
tan((PI/180./2.)*ourview.vert)/vmult ); |
| 479 |
– |
break; |
| 480 |
– |
case VT_HEM: |
| 481 |
– |
pview.horiz = (2.*180./PI)*asin( |
| 482 |
– |
sin((PI/180./2.)*ourview.horiz)/hmult ); |
| 483 |
– |
pview.vert = (2.*180./PI)*asin( |
| 484 |
– |
sin((PI/180./2.)*ourview.vert)/vmult ); |
| 485 |
– |
break; |
| 486 |
– |
case VT_PLS: |
| 487 |
– |
pview.horiz = sin((PI/180./2.)*ourview.horiz) / |
| 488 |
– |
(1.0 + cos((PI/180./2.)*ourview.horiz)) / hmult; |
| 489 |
– |
pview.horiz *= pview.horiz; |
| 490 |
– |
pview.horiz = (2.*180./PI)*acos((1. - pview.horiz) / |
| 491 |
– |
(1. + pview.horiz)); |
| 492 |
– |
pview.vert = sin((PI/180./2.)*ourview.vert) / |
| 493 |
– |
(1.0 + cos((PI/180./2.)*ourview.vert)) / vmult; |
| 494 |
– |
pview.vert *= pview.vert; |
| 495 |
– |
pview.vert = (2.*180./PI)*acos((1. - pview.vert) / |
| 496 |
– |
(1. + pview.vert)); |
| 497 |
– |
break; |
| 498 |
– |
default: |
| 499 |
– |
fprintf(stderr, "%s: unknown view type '-vt%c'\n", |
| 500 |
– |
progname, ourview.type); |
| 501 |
– |
exit(cleanup(1)); |
| 502 |
– |
} |
| 485 |
|
/* render each piece */ |
| 486 |
|
while (nextpiece(&xorg, &yorg)) { |
| 487 |
< |
pview.hoff = ourview.hoff*hmult + xorg - 0.5*(hmult-1); |
| 488 |
< |
pview.voff = ourview.voff*vmult + yorg - 0.5*(vmult-1); |
| 487 |
> |
pview = ourview; |
| 488 |
> |
err = cropview(&pview, (double)xorg/hmult, (double)yorg/vmult, |
| 489 |
> |
(xorg+1.)/hmult, (yorg+1.)/vmult); |
| 490 |
> |
if (err != NULL) { |
| 491 |
> |
fprintf(stderr, "%s: %s\n", progname, err); |
| 492 |
> |
exit(cleanup(1)); |
| 493 |
> |
} |
| 494 |
|
fputs(VIEWSTR, torp); |
| 495 |
|
fprintview(&pview, torp); |
| 496 |
< |
putc('\n', torp); |
| 496 |
> |
fputc('\n', torp); |
| 497 |
|
fflush(torp); /* assigns piece to rpict */ |
| 498 |
|
putpiece(xorg, yorg); /* place piece in output */ |
| 499 |
|
} |
| 509 |
|
struct flock fls; |
| 510 |
|
int pid, status; |
| 511 |
|
int hr, vr; |
| 512 |
< |
register int y; |
| 512 |
> |
int y; |
| 513 |
|
/* check bounds */ |
| 514 |
|
if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { |
| 515 |
|
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
| 560 |
|
/* lock file section so NFS doesn't mess up */ |
| 561 |
|
fls.l_whence = 0; |
| 562 |
|
fls.l_type = F_WRLCK; |
| 563 |
+ |
#if 0 |
| 564 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
| 565 |
|
filerr("lock"); |
| 566 |
+ |
#else |
| 567 |
+ |
dolock(outfd, F_WRLCK); |
| 568 |
|
#endif |
| 569 |
+ |
#endif |
| 570 |
|
/* write new piece to file */ |
| 571 |
|
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
| 572 |
|
filerr("seek"); |
| 573 |
|
if (hmult == 1) { |
| 574 |
< |
if (writebuf(outfd, (char *)pbuf, |
| 574 |
> |
if (writebuf(outfd, pbuf, |
| 575 |
|
vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR)) |
| 576 |
|
filerr("write"); |
| 577 |
|
} else |
| 578 |
|
for (y = 0; y < vr; y++) { |
| 579 |
< |
if (writebuf(outfd, (char *)(pbuf+y*hr), |
| 579 |
> |
if (writebuf(outfd, pbuf+y*hr, |
| 580 |
|
hr*sizeof(COLR)) != hr*sizeof(COLR)) |
| 581 |
|
filerr("write"); |
| 582 |
|
if (y < vr-1 && lseek(outfd, |
| 586 |
|
} |
| 587 |
|
#if NFS |
| 588 |
|
fls.l_type = F_UNLCK; /* release lock */ |
| 589 |
+ |
#if 0 |
| 590 |
|
if (fcntl(outfd, F_SETLKW, &fls) < 0) |
| 591 |
|
filerr("lock"); |
| 592 |
+ |
#else |
| 593 |
+ |
dolock(outfd, F_UNLCK); |
| 594 |
+ |
#endif |
| 595 |
|
#endif |
| 596 |
|
if (verbose) { /* notify caller */ |
| 597 |
|
printf("%d %d done\n", xpos, ypos); |