10 |
|
|
11 |
|
#include "standard.h" |
12 |
|
#include <fcntl.h> |
13 |
+ |
#include <signal.h> |
14 |
|
#include "color.h" |
15 |
|
#include "view.h" |
16 |
|
#include "resolu.h" |
36 |
|
|
37 |
|
extern long lseek(), ftell(); |
38 |
|
|
39 |
+ |
int gotalrm = 0; |
40 |
+ |
int onalrm() { gotalrm++; } |
41 |
|
|
42 |
+ |
|
43 |
|
main(argc, argv) |
44 |
|
int argc; |
45 |
|
char *argv[]; |
172 |
|
scanorig = ftell(fp); /* record position of first scanline */ |
173 |
|
if (fclose(fp) == -1) /* done with stream i/o */ |
174 |
|
goto filerr; |
171 |
– |
sync(); /* avoid NFS buffering */ |
175 |
|
/* start rpict process */ |
176 |
|
if (open_process(rpd, rpargv) <= 0) { |
177 |
|
fprintf(stderr, "%s: cannot start %s\n", progname, rpargv[0]); |
187 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
188 |
|
exit(1); |
189 |
|
} |
190 |
+ |
signal(SIGALRM, onalrm); |
191 |
|
return; |
192 |
|
filerr: |
193 |
|
fprintf(stderr, "%s: file i/o error\n", outfile); |
203 |
|
struct flock fls; |
204 |
|
char buf[64]; |
205 |
|
|
206 |
< |
if (syncfd != -1) { /* using sync file */ |
206 |
> |
if (gotalrm) /* someone wants us to quit */ |
207 |
> |
return(0); |
208 |
> |
if (syncfd != -1) { /* use sync file */ |
209 |
|
fls.l_type = F_WRLCK; /* gain exclusive access */ |
210 |
|
fls.l_whence = 0; |
211 |
|
fls.l_start = 0L; |
231 |
|
fcntl(syncfd, F_SETLKW, &fls); |
232 |
|
return(1); |
233 |
|
} |
234 |
< |
if (fgets(buf, sizeof(buf), stdin) == NULL) /* using stdin */ |
234 |
> |
if (fgets(buf, sizeof(buf), stdin) == NULL) /* use stdin */ |
235 |
|
return(0); |
236 |
|
if (sscanf(buf, "%d %d", xp, yp) == 2) |
237 |
|
return(1); |
303 |
|
putpiece(xpos, ypos) /* get next piece from rpict */ |
304 |
|
int xpos, ypos; |
305 |
|
{ |
306 |
+ |
struct flock fls; |
307 |
|
int hr, vr; |
308 |
|
int y; |
309 |
|
|
319 |
|
progname, rpargv[0]); |
320 |
|
exit(1); |
321 |
|
} |
322 |
+ |
fls.l_whence = 1; |
323 |
+ |
fls.l_start = 0L; |
324 |
+ |
fls.l_len = hr*sizeof(COLR); |
325 |
|
for (y = 0; y < vr; y++) { /* transfer scanlines */ |
326 |
|
if (freadcolrs(scanline, hr, fromrp) < 0) { |
327 |
|
fprintf(stderr, "%s: read error from %s\n", |
334 |
|
fprintf(stderr, "%s: seek error\n", outfile); |
335 |
|
exit(1); |
336 |
|
} |
337 |
+ |
fls.l_type = F_WRLCK; |
338 |
+ |
fcntl(outfd, F_SETLKW, &fls); |
339 |
|
if (writebuf(outfd, (char *)scanline, hr*sizeof(COLR)) != |
340 |
|
hr*sizeof(COLR)) { |
341 |
|
fprintf(stderr, "%s: write error\n", outfile); |
342 |
|
exit(1); |
343 |
|
} |
344 |
+ |
fls.l_type = F_UNLCK; |
345 |
+ |
fcntl(outfd, F_SETLKW, &fls); |
346 |
|
} |
347 |
|
} |