| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1993 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 39 |
|
#define MAXFORK 0 |
| 40 |
|
#endif |
| 41 |
|
#endif |
| 42 |
< |
|
| 42 |
> |
/* protection from SYSV signals(!) */ |
| 43 |
> |
#if defined(sgi) || defined(hpux) |
| 44 |
> |
#define guard_io() sighold(SIGALRM) |
| 45 |
> |
#define unguard() sigrelse(SIGALRM) |
| 46 |
> |
#endif |
| 47 |
> |
#ifndef guard_io |
| 48 |
> |
#define guard_io() 0 |
| 49 |
> |
#define unguard() 0 |
| 50 |
> |
#endif |
| 51 |
|
/* rpict command */ |
| 52 |
|
char *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"}; |
| 53 |
|
int rpargc = 9; |
| 266 |
|
return(0); |
| 267 |
|
} |
| 268 |
|
} |
| 269 |
< |
sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); |
| 269 |
> |
sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp); |
| 270 |
|
lseek(syncfd, 0L, 0); /* write new position */ |
| 271 |
|
write(syncfd, buf, strlen(buf)); |
| 272 |
|
fls.l_type = F_UNLCK; /* release sync file */ |
| 336 |
|
putc('\n', torp); |
| 337 |
|
fflush(torp); /* assigns piece to rpict */ |
| 338 |
|
putpiece(xorg, yorg); /* place piece in output */ |
| 331 |
– |
if (verbose) { /* notify caller */ |
| 332 |
– |
printf("%d %d done\n", xorg, yorg); |
| 333 |
– |
fflush(stdout); |
| 334 |
– |
} |
| 339 |
|
} |
| 340 |
|
} |
| 341 |
|
|
| 355 |
|
exit(cleanup(1)); |
| 356 |
|
} |
| 357 |
|
/* check header from rpict */ |
| 358 |
+ |
guard_io(); |
| 359 |
|
getheader(fromrp, NULL, NULL); |
| 360 |
|
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
| 361 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
| 362 |
|
progname, rpargv[0]); |
| 363 |
|
exit(cleanup(1)); |
| 364 |
|
} |
| 365 |
+ |
unguard(); |
| 366 |
|
/* load new piece into buffer */ |
| 367 |
< |
for (y = 0; y < vr; y++) |
| 367 |
> |
for (y = 0; y < vr; y++) { |
| 368 |
> |
guard_io(); |
| 369 |
|
if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) { |
| 370 |
|
fprintf(stderr, "%s: read error from %s\n", |
| 371 |
|
progname, rpargv[0]); |
| 372 |
|
exit(cleanup(1)); |
| 373 |
|
} |
| 374 |
+ |
unguard(); |
| 375 |
+ |
} |
| 376 |
|
#if MAXFORK |
| 377 |
|
/* fork so we don't slow rpict down */ |
| 378 |
|
if ((pid = fork()) > 0) { |
| 387 |
|
#else |
| 388 |
|
pid = -1; /* no forking */ |
| 389 |
|
#endif |
| 390 |
< |
fls.l_len = (long)vres*hmult*hres*sizeof(COLR); |
| 391 |
< |
fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len; |
| 390 |
> |
fls.l_start = scanorig + |
| 391 |
> |
((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR); |
| 392 |
|
#if NFS |
| 393 |
+ |
fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR); |
| 394 |
|
/* lock file section so NFS doesn't mess up */ |
| 395 |
|
fls.l_whence = 0; |
| 396 |
|
fls.l_type = F_WRLCK; |
| 397 |
|
fcntl(outfd, F_SETLKW, &fls); |
| 398 |
|
#endif |
| 399 |
|
/* write new piece to file */ |
| 400 |
< |
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
| 400 |
> |
if (lseek(outfd, fls.l_start, 0) == -1) |
| 401 |
|
goto seekerr; |
| 402 |
|
if (hmult == 1) { |
| 403 |
|
if (writebuf(outfd, (char *)pbuf, |
| 413 |
|
1) == -1) |
| 414 |
|
goto seekerr; |
| 415 |
|
} |
| 416 |
< |
if (pid == -1) { /* fork failed */ |
| 416 |
> |
if (verbose) { /* notify caller */ |
| 417 |
> |
printf("%d %d done\n", xpos, ypos); |
| 418 |
> |
fflush(stdout); |
| 419 |
> |
} |
| 420 |
> |
if (pid == -1) { /* didn't fork or fork failed */ |
| 421 |
|
#if NFS |
| 422 |
|
fls.l_type = F_UNLCK; /* release lock */ |
| 423 |
|
fcntl(outfd, F_SETLKW, &fls); |