| 5 |
|
* Generate sections of a picture. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
|
| 9 |
+ |
#include <stdio.h> |
| 10 |
+ |
#include <signal.h> |
| 11 |
+ |
#include <sys/types.h> |
| 12 |
+ |
#ifndef NON_POSIX /* XXX need abstraction for process management */ |
| 13 |
+ |
#include <sys/wait.h> |
| 14 |
+ |
#endif |
| 15 |
+ |
|
| 16 |
+ |
#include "platform.h" |
| 17 |
|
#include "standard.h" |
| 18 |
+ |
#include "color.h" |
| 19 |
+ |
#include "view.h" |
| 20 |
+ |
#include "rtprocess.h" |
| 21 |
|
|
| 22 |
|
#ifndef F_SETLKW |
| 23 |
|
|
| 24 |
< |
main(argc, argv) |
| 25 |
< |
int argc; |
| 26 |
< |
char *argv[]; |
| 24 |
> |
int |
| 25 |
> |
main( |
| 26 |
> |
int argc, |
| 27 |
> |
char *argv[] |
| 28 |
> |
) |
| 29 |
|
{ |
| 30 |
|
fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]); |
| 31 |
|
exit(1); |
| 33 |
|
|
| 34 |
|
#else |
| 35 |
|
|
| 22 |
– |
#include <signal.h> |
| 23 |
– |
#include "color.h" |
| 24 |
– |
#include "view.h" |
| 25 |
– |
|
| 36 |
|
#ifndef NFS |
| 37 |
|
#define NFS 1 |
| 38 |
|
#endif |
| 50 |
|
#define unguard() sigrelse(SIGALRM) |
| 51 |
|
#endif |
| 52 |
|
#ifndef guard_io |
| 53 |
< |
#define guard_io() 0 |
| 54 |
< |
#define unguard() 0 |
| 53 |
> |
#define guard_io() |
| 54 |
> |
#define unguard() |
| 55 |
|
#endif |
| 56 |
|
|
| 57 |
|
extern char *strerror(); |
| 59 |
|
/* rpict command */ |
| 60 |
|
char *rpargv[128] = {"rpict", "-S", "1"}; |
| 61 |
|
int rpargc = 3; |
| 52 |
– |
int rpd[3]; |
| 62 |
|
FILE *torp, *fromrp; |
| 63 |
|
COLR *pbuf; |
| 64 |
|
/* our view parameters */ |
| 81 |
|
int rvrlim = -1; |
| 82 |
|
|
| 83 |
|
int gotalrm = 0; |
| 84 |
< |
int onalrm() { gotalrm++; } |
| 84 |
> |
void onalrm(int i) { gotalrm++; } |
| 85 |
|
|
| 86 |
+ |
static void dolock(int fd, int ltyp); |
| 87 |
+ |
static void init(int ac, char **av); |
| 88 |
+ |
static int nextpiece(int *xp, int *yp); |
| 89 |
+ |
static int rvrpiece(int *xp, int *yp); |
| 90 |
+ |
static int cleanup(int rstat); |
| 91 |
+ |
static void rpiece(void); |
| 92 |
+ |
static int putpiece(int xpos, int ypos); |
| 93 |
+ |
static void filerr(char *t); |
| 94 |
|
|
| 95 |
< |
main(argc, argv) |
| 96 |
< |
int argc; |
| 97 |
< |
char *argv[]; |
| 95 |
> |
|
| 96 |
> |
int |
| 97 |
> |
main( |
| 98 |
> |
int argc, |
| 99 |
> |
char *argv[] |
| 100 |
> |
) |
| 101 |
|
{ |
| 102 |
|
register int i, rval; |
| 103 |
|
|
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
< |
dolock(fd, ltyp) /* lock or unlock a file */ |
| 210 |
< |
int fd; |
| 211 |
< |
int ltyp; |
| 209 |
> |
static void |
| 210 |
> |
dolock( /* lock or unlock a file */ |
| 211 |
> |
int fd, |
| 212 |
> |
int ltyp |
| 213 |
> |
) |
| 214 |
|
{ |
| 215 |
|
static struct flock fls; /* static so initialized to zeroes */ |
| 216 |
|
|
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
|
| 226 |
< |
init(ac, av) /* set up output file and start rpict */ |
| 227 |
< |
int ac; |
| 228 |
< |
char **av; |
| 226 |
> |
static void |
| 227 |
> |
init( /* set up output file and start rpict */ |
| 228 |
> |
int ac, |
| 229 |
> |
char **av |
| 230 |
> |
) |
| 231 |
|
{ |
| 232 |
|
static char hrbuf[16], vrbuf[16]; |
| 233 |
|
extern char VersionID[]; |
| 234 |
|
char *err; |
| 235 |
|
FILE *fp; |
| 236 |
|
int hr, vr; |
| 237 |
+ |
SUBPROC rpd; /* since we don't close_process(), this can be local */ |
| 238 |
|
/* set up view */ |
| 239 |
|
if ((err = setview(&ourview)) != NULL) { |
| 240 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
| 248 |
|
/* compute piece size */ |
| 249 |
|
hres /= hmult; |
| 250 |
|
vres /= vmult; |
| 251 |
+ |
if (hres <= 0 || vres <= 0) { |
| 252 |
+ |
fprintf(stderr, "%s: illegal resolution/subdivision\n"); |
| 253 |
+ |
exit(1); |
| 254 |
+ |
} |
| 255 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
| 256 |
|
sprintf(hrbuf, "%d", hres); |
| 257 |
|
rpargv[rpargc++] = "-x"; rpargv[rpargc++] = hrbuf; |
| 297 |
|
goto filerr; |
| 298 |
|
dolock(outfd, F_UNLCK); |
| 299 |
|
/* start rpict process */ |
| 300 |
< |
if (open_process(rpd, rpargv) <= 0) { |
| 300 |
> |
if (open_process(&rpd, rpargv) <= 0) { |
| 301 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
| 302 |
|
exit(1); |
| 303 |
|
} |
| 304 |
< |
if ((fromrp = fdopen(rpd[0], "r")) == NULL || |
| 305 |
< |
(torp = fdopen(rpd[1], "w")) == NULL) { |
| 304 |
> |
if ((fromrp = fdopen(rpd.r, "r")) == NULL || |
| 305 |
> |
(torp = fdopen(rpd.w, "w")) == NULL) { |
| 306 |
|
fprintf(stderr, "%s: cannot open stream to %s\n", |
| 307 |
|
progname, rpargv[0]); |
| 308 |
|
exit(1); |
| 321 |
|
} |
| 322 |
|
|
| 323 |
|
|
| 324 |
< |
int |
| 325 |
< |
nextpiece(xp, yp) /* get next piece assignment */ |
| 326 |
< |
int *xp, *yp; |
| 324 |
> |
static int |
| 325 |
> |
nextpiece( /* get next piece assignment */ |
| 326 |
> |
int *xp, |
| 327 |
> |
int *yp |
| 328 |
> |
) |
| 329 |
|
{ |
| 330 |
|
if (gotalrm) /* someone wants us to quit */ |
| 331 |
|
return(0); |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
|
| 368 |
< |
int |
| 369 |
< |
rvrpiece(xp, yp) /* check for recoverable pieces */ |
| 370 |
< |
register int *xp, *yp; |
| 368 |
> |
static int |
| 369 |
> |
rvrpiece( /* check for recoverable pieces */ |
| 370 |
> |
register int *xp, |
| 371 |
> |
register int *yp |
| 372 |
> |
) |
| 373 |
|
{ |
| 374 |
|
static char *pdone = NULL; /* which pieces are done */ |
| 375 |
|
static long readpos = -1; /* how far we've read */ |
| 411 |
|
} |
| 412 |
|
|
| 413 |
|
|
| 414 |
< |
int |
| 415 |
< |
cleanup(rstat) /* close rpict process and clean up */ |
| 416 |
< |
int rstat; |
| 414 |
> |
static int |
| 415 |
> |
cleanup( /* close rpict process and clean up */ |
| 416 |
> |
int rstat |
| 417 |
> |
) |
| 418 |
|
{ |
| 419 |
|
int status; |
| 420 |
|
|
| 428 |
|
} |
| 429 |
|
|
| 430 |
|
|
| 431 |
< |
rpiece() /* render picture piece by piece */ |
| 431 |
> |
static void |
| 432 |
> |
rpiece(void) /* render picture piece by piece */ |
| 433 |
|
{ |
| 434 |
|
VIEW pview; |
| 435 |
|
int xorg, yorg; |
| 436 |
|
/* compute view parameters */ |
| 437 |
< |
copystruct(&pview, &ourview); |
| 437 |
> |
pview = ourview; |
| 438 |
|
switch (ourview.type) { |
| 439 |
|
case VT_PER: |
| 440 |
|
pview.horiz = 2.*180./PI*atan( |
| 476 |
|
} |
| 477 |
|
|
| 478 |
|
|
| 479 |
< |
int |
| 480 |
< |
putpiece(xpos, ypos) /* get next piece from rpict */ |
| 481 |
< |
int xpos, ypos; |
| 479 |
> |
static int |
| 480 |
> |
putpiece( /* get next piece from rpict */ |
| 481 |
> |
int xpos, |
| 482 |
> |
int ypos |
| 483 |
> |
) |
| 484 |
|
{ |
| 485 |
|
struct flock fls; |
| 486 |
|
int pid, status; |
| 487 |
|
int hr, vr; |
| 488 |
|
register int y; |
| 489 |
|
/* check bounds */ |
| 490 |
< |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
| 490 |
> |
if ((xpos < 0) | (ypos < 0) | (xpos >= hmult) | (ypos >= vmult)) { |
| 491 |
|
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
| 492 |
|
progname, xpos, ypos); |
| 493 |
|
exit(cleanup(1)); |
| 495 |
|
/* check header from rpict */ |
| 496 |
|
guard_io(); |
| 497 |
|
getheader(fromrp, NULL, NULL); |
| 498 |
< |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
| 498 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || (hr != hres) | (vr != vres)) { |
| 499 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
| 500 |
|
progname, rpargv[0]); |
| 501 |
|
exit(cleanup(1)); |
| 540 |
|
filerr("lock"); |
| 541 |
|
#endif |
| 542 |
|
/* write new piece to file */ |
| 543 |
< |
if (lseek(outfd, (off_t)fls.l_start, 0) < 0) |
| 543 |
> |
if (lseek(outfd, (off_t)fls.l_start, SEEK_SET) < 0) |
| 544 |
|
filerr("seek"); |
| 545 |
|
if (hmult == 1) { |
| 546 |
|
if (writebuf(outfd, (char *)pbuf, |
| 553 |
|
filerr("write"); |
| 554 |
|
if (y < vr-1 && lseek(outfd, |
| 555 |
|
(off_t)(hmult-1)*hr*sizeof(COLR), |
| 556 |
< |
1) < 0) |
| 556 |
> |
SEEK_CUR) < 0) |
| 557 |
|
filerr("seek"); |
| 558 |
|
} |
| 559 |
|
#if NFS |
| 579 |
|
} |
| 580 |
|
|
| 581 |
|
|
| 582 |
< |
filerr(t) /* report file error and exit */ |
| 583 |
< |
char *t; |
| 582 |
> |
static void |
| 583 |
> |
filerr( /* report file error and exit */ |
| 584 |
> |
char *t |
| 585 |
> |
) |
| 586 |
|
{ |
| 587 |
|
fprintf(stderr, "%s: %s error on file \"%s\": %s\n", |
| 588 |
|
progname, t, outfile, strerror(errno)); |