| 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"; |
| 10 |
|
|
| 11 |
|
#include "standard.h" |
| 12 |
|
#include <fcntl.h> |
| 13 |
+ |
|
| 14 |
+ |
#ifndef F_SETLKW |
| 15 |
+ |
|
| 16 |
+ |
main(argc, argv) |
| 17 |
+ |
int argc; |
| 18 |
+ |
char *argv[]; |
| 19 |
+ |
{ |
| 20 |
+ |
fprintf(stderr, "%s: no NFS lock manager on this machine\n", argv[0]); |
| 21 |
+ |
exit(1); |
| 22 |
+ |
} |
| 23 |
+ |
|
| 24 |
+ |
#else |
| 25 |
+ |
|
| 26 |
|
#include <signal.h> |
| 27 |
|
#include "color.h" |
| 28 |
|
#include "view.h" |
| 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; |
| 82 |
|
|
| 83 |
|
progname = argv[0]; |
| 84 |
|
for (i = 1; i < argc; i++) { |
| 85 |
+ |
/* expand arguments */ |
| 86 |
+ |
while (rval = expandarg(&argc, &argv, i)) |
| 87 |
+ |
if (rval < 0) { |
| 88 |
+ |
fprintf(stderr, "%s: cannot expand '%s'", |
| 89 |
+ |
argv[0], argv[i]); |
| 90 |
+ |
exit(1); |
| 91 |
+ |
} |
| 92 |
|
if (argv[i][0] == '-') |
| 93 |
|
switch (argv[i][1]) { |
| 94 |
|
case 'v': |
| 137 |
|
case 'F': /* syncronization file */ |
| 138 |
|
if (argv[i][2]) |
| 139 |
|
break; |
| 140 |
< |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
| 140 |
> |
if ((syncfd = open(argv[++i], |
| 141 |
> |
O_RDWR|O_CREAT, 0666)) < 0) { |
| 142 |
|
fprintf(stderr, "%s: cannot open\n", |
| 143 |
|
argv[i]); |
| 144 |
|
exit(1); |
| 145 |
|
} |
| 146 |
|
continue; |
| 147 |
+ |
case 'z': /* z-file ist verbotten */ |
| 148 |
+ |
fprintf(stderr, "%s: -z option not allowed\n", |
| 149 |
+ |
argv[0]); |
| 150 |
+ |
exit(1); |
| 151 |
|
case 'o': /* output file */ |
| 152 |
|
if (argv[i][2]) |
| 153 |
|
break; |
| 163 |
|
} |
| 164 |
|
init(argc, argv); |
| 165 |
|
rpiece(); |
| 166 |
< |
rval = cleanup(0); |
| 134 |
< |
exit(rval); |
| 166 |
> |
exit(cleanup(0)); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
|
| 203 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
| 204 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
| 205 |
|
goto filerr; |
| 206 |
< |
getheader(fp, NULL); /* skip header */ |
| 207 |
< |
if (fscnresolu(&hr, &vr, fp) < 0 || /* check resolution */ |
| 206 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
| 207 |
> |
if (!fscnresolu(&hr, &vr, fp) || /* check resolution */ |
| 208 |
|
hr != hres*hmult || vr != vres*vmult) { |
| 209 |
|
fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n", |
| 210 |
|
progname, outfile); |
| 248 |
|
nextpiece(xp, yp) /* get next piece assignment */ |
| 249 |
|
int *xp, *yp; |
| 250 |
|
{ |
| 219 |
– |
extern char *fgets(); |
| 251 |
|
struct flock fls; |
| 252 |
|
char buf[64]; |
| 253 |
|
|
| 272 |
|
return(0); |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
< |
sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); |
| 275 |
> |
sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp); |
| 276 |
|
lseek(syncfd, 0L, 0); /* write new position */ |
| 277 |
|
write(syncfd, buf, strlen(buf)); |
| 278 |
|
fls.l_type = F_UNLCK; /* release sync file */ |
| 342 |
|
putc('\n', torp); |
| 343 |
|
fflush(torp); /* assigns piece to rpict */ |
| 344 |
|
putpiece(xorg, yorg); /* place piece in output */ |
| 314 |
– |
if (verbose) { /* notify caller */ |
| 315 |
– |
printf("%d %d done\n", xorg, yorg); |
| 316 |
– |
fflush(stdout); |
| 317 |
– |
} |
| 345 |
|
} |
| 346 |
|
} |
| 347 |
|
|
| 361 |
|
exit(cleanup(1)); |
| 362 |
|
} |
| 363 |
|
/* check header from rpict */ |
| 364 |
< |
getheader(fromrp, NULL); |
| 365 |
< |
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres | vr != vres) { |
| 364 |
> |
guard_io(); |
| 365 |
> |
getheader(fromrp, NULL, NULL); |
| 366 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
| 367 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
| 368 |
|
progname, rpargv[0]); |
| 369 |
|
exit(cleanup(1)); |
| 370 |
|
} |
| 371 |
+ |
unguard(); |
| 372 |
|
/* load new piece into buffer */ |
| 373 |
< |
for (y = 0; y < vr; y++) |
| 373 |
> |
for (y = 0; y < vr; y++) { |
| 374 |
> |
guard_io(); |
| 375 |
|
if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) { |
| 376 |
|
fprintf(stderr, "%s: read error from %s\n", |
| 377 |
|
progname, rpargv[0]); |
| 378 |
|
exit(cleanup(1)); |
| 379 |
|
} |
| 380 |
+ |
unguard(); |
| 381 |
+ |
} |
| 382 |
|
#if MAXFORK |
| 383 |
|
/* fork so we don't slow rpict down */ |
| 384 |
|
if ((pid = fork()) > 0) { |
| 393 |
|
#else |
| 394 |
|
pid = -1; /* no forking */ |
| 395 |
|
#endif |
| 396 |
+ |
fls.l_start = scanorig + |
| 397 |
+ |
((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR); |
| 398 |
|
#if NFS |
| 399 |
+ |
fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR); |
| 400 |
|
/* lock file section so NFS doesn't mess up */ |
| 401 |
|
fls.l_whence = 0; |
| 367 |
– |
fls.l_len = (long)vres*hmult*hres*sizeof(COLR); |
| 368 |
– |
fls.l_start = scanorig + (vmult-1-ypos)*fls.l_len; |
| 402 |
|
fls.l_type = F_WRLCK; |
| 403 |
|
fcntl(outfd, F_SETLKW, &fls); |
| 404 |
|
#endif |
| 405 |
|
/* write new piece to file */ |
| 406 |
< |
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
| 406 |
> |
if (lseek(outfd, fls.l_start, 0) == -1) |
| 407 |
|
goto seekerr; |
| 408 |
|
if (hmult == 1) { |
| 409 |
|
if (writebuf(outfd, (char *)pbuf, |
| 419 |
|
1) == -1) |
| 420 |
|
goto seekerr; |
| 421 |
|
} |
| 422 |
< |
if (pid == -1) { /* fork failed */ |
| 422 |
> |
if (verbose) { /* notify caller */ |
| 423 |
> |
printf("%d %d done\n", xpos, ypos); |
| 424 |
> |
fflush(stdout); |
| 425 |
> |
} |
| 426 |
> |
if (pid == -1) { /* didn't fork or fork failed */ |
| 427 |
|
#if NFS |
| 428 |
|
fls.l_type = F_UNLCK; /* release lock */ |
| 429 |
|
fcntl(outfd, F_SETLKW, &fls); |
| 438 |
|
fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); |
| 439 |
|
_exit(1); |
| 440 |
|
} |
| 441 |
+ |
|
| 442 |
+ |
#endif |