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; |
130 |
|
case 'F': /* syncronization file */ |
131 |
|
if (argv[i][2]) |
132 |
|
break; |
133 |
< |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
133 |
> |
if ((syncfd = open(argv[++i], |
134 |
> |
O_RDWR|O_CREAT, 0666)) < 0) { |
135 |
|
fprintf(stderr, "%s: cannot open\n", |
136 |
|
argv[i]); |
137 |
|
exit(1); |
138 |
|
} |
139 |
|
continue; |
140 |
+ |
case 'z': /* z-file ist verbotten */ |
141 |
+ |
fprintf(stderr, "%s: -z option not allowed\n", |
142 |
+ |
argv[0]); |
143 |
+ |
exit(1); |
144 |
|
case 'o': /* output file */ |
145 |
|
if (argv[i][2]) |
146 |
|
break; |
156 |
|
} |
157 |
|
init(argc, argv); |
158 |
|
rpiece(); |
159 |
< |
rval = cleanup(0); |
134 |
< |
exit(rval); |
159 |
> |
exit(cleanup(0)); |
160 |
|
} |
161 |
|
|
162 |
|
|
196 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
197 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
198 |
|
goto filerr; |
199 |
< |
getheader(fp, NULL); /* skip header */ |
200 |
< |
if (fscnresolu(&hr, &vr, fp) < 0 || /* check resolution */ |
199 |
> |
getheader(fp, NULL, NULL); /* skip header */ |
200 |
> |
if (!fscnresolu(&hr, &vr, fp) || /* check resolution */ |
201 |
|
hr != hres*hmult || vr != vres*vmult) { |
202 |
|
fprintf(stderr, "%s: resolution mismatch on file \"%s\"\n", |
203 |
|
progname, outfile); |
241 |
|
nextpiece(xp, yp) /* get next piece assignment */ |
242 |
|
int *xp, *yp; |
243 |
|
{ |
219 |
– |
extern char *fgets(); |
244 |
|
struct flock fls; |
245 |
|
char buf[64]; |
246 |
|
|
265 |
|
return(0); |
266 |
|
} |
267 |
|
} |
268 |
< |
sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); |
268 |
> |
sprintf(buf, "%4d %4d\n%4d %4d\n", hmult, vmult, *xp, *yp); |
269 |
|
lseek(syncfd, 0L, 0); /* write new position */ |
270 |
|
write(syncfd, buf, strlen(buf)); |
271 |
|
fls.l_type = F_UNLCK; /* release sync file */ |
335 |
|
putc('\n', torp); |
336 |
|
fflush(torp); /* assigns piece to rpict */ |
337 |
|
putpiece(xorg, yorg); /* place piece in output */ |
314 |
– |
if (verbose) { /* notify caller */ |
315 |
– |
printf("%d %d done\n", xorg, yorg); |
316 |
– |
fflush(stdout); |
317 |
– |
} |
338 |
|
} |
339 |
|
} |
340 |
|
|
354 |
|
exit(cleanup(1)); |
355 |
|
} |
356 |
|
/* check header from rpict */ |
357 |
< |
getheader(fromrp, NULL); |
358 |
< |
if (fscnresolu(&hr, &vr, fromrp) < 0 || hr != hres | vr != vres) { |
357 |
> |
guard_io(); |
358 |
> |
getheader(fromrp, NULL, NULL); |
359 |
> |
if (!fscnresolu(&hr, &vr, fromrp) || hr != hres | vr != vres) { |
360 |
|
fprintf(stderr, "%s: resolution mismatch from %s\n", |
361 |
|
progname, rpargv[0]); |
362 |
|
exit(cleanup(1)); |
363 |
|
} |
364 |
+ |
unguard(); |
365 |
|
/* load new piece into buffer */ |
366 |
< |
for (y = 0; y < vr; y++) |
366 |
> |
for (y = 0; y < vr; y++) { |
367 |
> |
guard_io(); |
368 |
|
if (freadcolrs(pbuf+y*hr, hr, fromrp) < 0) { |
369 |
|
fprintf(stderr, "%s: read error from %s\n", |
370 |
|
progname, rpargv[0]); |
371 |
|
exit(cleanup(1)); |
372 |
|
} |
373 |
+ |
unguard(); |
374 |
+ |
} |
375 |
|
#if MAXFORK |
376 |
|
/* fork so we don't slow rpict down */ |
377 |
|
if ((pid = fork()) > 0) { |
386 |
|
#else |
387 |
|
pid = -1; /* no forking */ |
388 |
|
#endif |
389 |
+ |
fls.l_start = scanorig + |
390 |
+ |
((long)(vmult-1-ypos)*vres*hmult+xpos)*hres*sizeof(COLR); |
391 |
|
#if NFS |
392 |
+ |
fls.l_len = ((long)(vres-1)*hmult+1)*hres*sizeof(COLR); |
393 |
|
/* lock file section so NFS doesn't mess up */ |
394 |
|
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; |
395 |
|
fls.l_type = F_WRLCK; |
396 |
|
fcntl(outfd, F_SETLKW, &fls); |
397 |
|
#endif |
398 |
|
/* write new piece to file */ |
399 |
< |
if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1) |
399 |
> |
if (lseek(outfd, fls.l_start, 0) == -1) |
400 |
|
goto seekerr; |
401 |
|
if (hmult == 1) { |
402 |
|
if (writebuf(outfd, (char *)pbuf, |
412 |
|
1) == -1) |
413 |
|
goto seekerr; |
414 |
|
} |
415 |
< |
if (pid == -1) { /* fork failed */ |
415 |
> |
if (verbose) { /* notify caller */ |
416 |
> |
printf("%d %d done\n", xpos, ypos); |
417 |
> |
fflush(stdout); |
418 |
> |
} |
419 |
> |
if (pid == -1) { /* didn't fork or fork failed */ |
420 |
|
#if NFS |
421 |
|
fls.l_type = F_UNLCK; /* release lock */ |
422 |
|
fcntl(outfd, F_SETLKW, &fls); |
431 |
|
fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile); |
432 |
|
_exit(1); |
433 |
|
} |
434 |
+ |
|
435 |
+ |
#endif |