28 |
|
char *outfile = NULL; |
29 |
|
int outfd; |
30 |
|
long scanorig; |
31 |
+ |
int syncfd = -1; /* lock file descriptor */ |
32 |
|
|
33 |
|
char *progname; |
34 |
|
int verbose = 0; |
89 |
|
break; |
90 |
|
vmult = atoi(argv[++i]); |
91 |
|
continue; |
92 |
+ |
case 'F': /* syncronization file */ |
93 |
+ |
if (argv[i][2]) |
94 |
+ |
break; |
95 |
+ |
if ((syncfd = open(argv[++i], O_RDWR)) < 0) { |
96 |
+ |
fprintf(stderr, "%s: cannot open\n", |
97 |
+ |
argv[i]); |
98 |
+ |
exit(1); |
99 |
+ |
} |
100 |
+ |
continue; |
101 |
|
case 'o': /* output file */ |
102 |
|
if (argv[i][2]) |
103 |
|
break; |
131 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
132 |
|
exit(1); |
133 |
|
} |
134 |
+ |
if (syncfd != -1) { |
135 |
+ |
char buf[32]; |
136 |
+ |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
137 |
+ |
sscanf(buf, "%d %d", &hmult, &vmult); |
138 |
+ |
} |
139 |
|
normaspect(viewaspect(&ourview)*hmult/vmult, &pixaspect, &hres, &vres); |
140 |
|
/* open output file */ |
141 |
|
if ((outfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0666)) >= 0) { |
152 |
|
putc('\n', fp); |
153 |
|
fprtresolu(hres*hmult, vres*vmult, fp); |
154 |
|
} else if ((outfd = open(outfile, O_RDWR)) >= 0) { |
140 |
– |
sleep(30); /* wait for header */ |
155 |
|
if ((fp = fdopen(dup(outfd), "r+")) == NULL) |
156 |
|
goto filerr; |
157 |
|
getheader(fp, NULL); /* skip header */ |
168 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
169 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
170 |
|
goto filerr; |
171 |
+ |
sync(); /* avoid NFS buffering */ |
172 |
|
/* start rpict process */ |
173 |
|
if (open_process(rpd, rpargv) <= 0) { |
174 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
192 |
|
|
193 |
|
|
194 |
|
int |
195 |
+ |
nextpiece(xp, yp) /* get next piece assignment */ |
196 |
+ |
int *xp, *yp; |
197 |
+ |
{ |
198 |
+ |
extern char *fgets(); |
199 |
+ |
struct flock fls; |
200 |
+ |
char buf[64]; |
201 |
+ |
|
202 |
+ |
if (syncfd != -1) { /* using sync file */ |
203 |
+ |
fls.l_type = F_WRLCK; /* gain exclusive access */ |
204 |
+ |
fls.l_whence = 0; |
205 |
+ |
fls.l_start = 0L; |
206 |
+ |
fls.l_len = 0L; |
207 |
+ |
fcntl(syncfd, F_SETLKW, &fls); |
208 |
+ |
lseek(syncfd, 0L, 0); |
209 |
+ |
buf[read(syncfd, buf, sizeof(buf)-1)] = '\0'; |
210 |
+ |
if (sscanf(buf, "%*d %*d %d %d", xp, yp) < 2) { |
211 |
+ |
*xp = hmult; |
212 |
+ |
*yp = vmult-1; |
213 |
+ |
} |
214 |
+ |
if (--(*xp) < 0) { /* decrement position */ |
215 |
+ |
*xp = hmult-1; |
216 |
+ |
if (--(*yp) < 0) { /* all done! */ |
217 |
+ |
close(syncfd); |
218 |
+ |
return(0); |
219 |
+ |
} |
220 |
+ |
} |
221 |
+ |
sprintf(buf, "%d %d\n%d %d\n", hmult, vmult, *xp, *yp); |
222 |
+ |
lseek(syncfd, 0L, 0); /* write new position */ |
223 |
+ |
write(syncfd, buf, strlen(buf)); |
224 |
+ |
fls.l_type = F_UNLCK; /* release sync file */ |
225 |
+ |
fcntl(syncfd, F_SETLKW, &fls); |
226 |
+ |
return(1); |
227 |
+ |
} |
228 |
+ |
if (fgets(buf, sizeof(buf), stdin) == NULL) /* using stdin */ |
229 |
+ |
return(0); |
230 |
+ |
if (sscanf(buf, "%d %d", xp, yp) == 2) |
231 |
+ |
return(1); |
232 |
+ |
fprintf(stderr, "%s: input format error\n", progname); |
233 |
+ |
exit(1); |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
|
237 |
+ |
int |
238 |
|
cleanup() /* close rpict process and clean up */ |
239 |
|
{ |
240 |
|
register int rpstat; |
251 |
|
|
252 |
|
rpiece() /* render picture piece by piece */ |
253 |
|
{ |
196 |
– |
extern char *gets(), *strcat(); |
254 |
|
VIEW pview; |
198 |
– |
char buf[48]; |
255 |
|
int xorg, yorg; |
256 |
|
|
257 |
< |
while (gets(buf) != NULL) { |
202 |
< |
if (sscanf(buf, "%d %d", &xorg, &yorg) != 2) { |
203 |
< |
fprintf(stderr, "%s: input format error\n", progname); |
204 |
< |
exit(1); |
205 |
< |
} |
257 |
> |
while (nextpiece(&xorg, &yorg)) { |
258 |
|
copystruct(&pview, &ourview); /* compute view for piece */ |
259 |
|
switch (ourview.type) { |
260 |
|
case VT_PER: |
287 |
|
fflush(torp); /* assign piece to rpict */ |
288 |
|
putpiece(xorg, yorg); /* place piece in output */ |
289 |
|
if (verbose) { /* notify caller */ |
290 |
< |
strcat(buf, " done\n"); |
291 |
< |
writebuf(fileno(stdout), buf, strlen(buf)); |
290 |
> |
printf("%d %d done\n", xorg, yorg); |
291 |
> |
fflush(stdout); |
292 |
|
} |
293 |
|
} |
294 |
|
} |
300 |
|
int hr, vr; |
301 |
|
int y; |
302 |
|
|
303 |
+ |
if (xpos < 0 | ypos < 0 | xpos >= hmult | ypos >= vmult) { |
304 |
+ |
fprintf(stderr, "%s: requested piece (%d,%d) out of range\n", |
305 |
+ |
progname, xpos, ypos); |
306 |
+ |
exit(1); |
307 |
+ |
} |
308 |
|
getheader(fromrp, NULL); /* discard header info. */ |
309 |
|
if (fscnresolu(&hr, &vr, fromrp) < 0 || /* check resolution */ |
310 |
|
hr != hres || vr != vres) { |