| 119 |
|
Display *thedisplay; |
| 120 |
|
Atom closedownAtom, wmProtocolsAtom; |
| 121 |
|
|
| 122 |
< |
int noop() {} |
| 122 |
> |
int sigrecv; |
| 123 |
|
|
| 124 |
+ |
int onsig() { sigrecv++; } |
| 125 |
|
|
| 126 |
+ |
|
| 127 |
|
main(argc, argv) |
| 128 |
|
int argc; |
| 129 |
|
char *argv[]; |
| 181 |
|
if (i > argc) |
| 182 |
|
goto userr; |
| 183 |
|
while (i < argc-1) { |
| 184 |
+ |
sigrecv = 0; |
| 185 |
+ |
signal(SIGCONT, onsig); |
| 186 |
|
if ((pid=fork()) == 0) { /* a child for each picture */ |
| 187 |
|
parent = -1; |
| 188 |
|
break; |
| 190 |
|
if (pid < 0) |
| 191 |
|
quiterr("fork failed"); |
| 192 |
|
parent++; |
| 193 |
< |
signal(SIGCONT, noop); |
| 194 |
< |
pause(); /* wait for wake-up call */ |
| 193 |
> |
while (!sigrecv) |
| 194 |
> |
pause(); /* wait for wake-up call */ |
| 195 |
|
i++; |
| 196 |
|
} |
| 197 |
|
if (i < argc) { /* open picture file */ |
| 198 |
|
fname = argv[i]; |
| 199 |
|
fin = fopen(fname, "r"); |
| 200 |
< |
if (fin == NULL) { |
| 201 |
< |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
| 198 |
< |
quiterr(errmsg); |
| 199 |
< |
} |
| 200 |
> |
if (fin == NULL) |
| 201 |
> |
quiterr("cannot open picture file"); |
| 202 |
|
} |
| 203 |
|
/* get header */ |
| 204 |
|
getheader(fin, headline, NULL); |
| 215 |
|
|
| 216 |
|
init(argc, argv); /* get file and open window */ |
| 217 |
|
|
| 218 |
< |
if (parent < 0) |
| 218 |
> |
if (parent < 0) { |
| 219 |
|
kill(getppid(), SIGCONT); /* signal parent if child */ |
| 220 |
< |
|
| 220 |
> |
sigrecv--; |
| 221 |
> |
} |
| 222 |
|
for ( ; ; ) |
| 223 |
|
getevent(); /* main loop */ |
| 224 |
|
userr: |
| 314 |
|
quiterr("cannot create window"); |
| 315 |
|
width = xmax; |
| 316 |
|
height = ymax; |
| 317 |
< |
xgcv.foreground = ourblack; |
| 315 |
< |
xgcv.background = ourwhite; |
| 317 |
> |
/* prepare graphics drawing context */ |
| 318 |
|
if ((xgcv.font = XLoadFont(thedisplay, FONTNAME)) == 0) |
| 319 |
|
quiterr("cannot get font"); |
| 320 |
+ |
xgcv.foreground = ourblack; |
| 321 |
+ |
xgcv.background = ourwhite; |
| 322 |
|
ourgc = XCreateGC(thedisplay, wind, GCForeground|GCBackground| |
| 323 |
|
GCFont, &xgcv); |
| 324 |
|
xgcv.function = GXinvert; |
| 354 |
|
quiterr(err) /* print message and exit */ |
| 355 |
|
char *err; |
| 356 |
|
{ |
| 357 |
< |
if (err != NULL) |
| 357 |
> |
register int es; |
| 358 |
> |
int cs; |
| 359 |
> |
|
| 360 |
> |
if (es = err != NULL) |
| 361 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
| 362 |
|
fname==NULL?"<stdin>":fname, err); |
| 363 |
< |
if (wind) { |
| 363 |
> |
if (parent > 0 & wind != 0) { |
| 364 |
|
XDestroyWindow(thedisplay, wind); |
| 365 |
|
XFlush(thedisplay); |
| 366 |
< |
} |
| 367 |
< |
while (parent > 0 && wait(0) != -1) /* wait for any children */ |
| 366 |
> |
} else if (parent < 0 & sigrecv == 0) |
| 367 |
> |
kill(getppid(), SIGCONT); |
| 368 |
> |
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
| 369 |
> |
if (es == 0) |
| 370 |
> |
es = cs>>8 & 0xff; |
| 371 |
|
parent--; |
| 372 |
< |
exit(err != NULL); |
| 372 |
> |
} |
| 373 |
> |
exit(es); |
| 374 |
|
} |
| 375 |
|
|
| 376 |
|
|
| 981 |
|
getmapped() /* get color-mapped data */ |
| 982 |
|
{ |
| 983 |
|
int y; |
| 984 |
+ |
/* make sure we can do it first */ |
| 985 |
+ |
if (fname == NULL) |
| 986 |
+ |
quiterr("cannot map colors from standard input"); |
| 987 |
|
/* set gamma correction */ |
| 988 |
|
setcolrgam(gamcor); |
| 989 |
|
/* make histogram */ |
| 990 |
|
new_histo(); |
| 991 |
|
for (y = 0; y < ymax; y++) { |
| 992 |
|
if (getscan(y) < 0) |
| 993 |
< |
quiterr("seek error in getmapped"); |
| 993 |
> |
break; |
| 994 |
|
add2icon(y, scanline); |
| 995 |
|
if (scale) |
| 996 |
|
shiftcolrs(scanline, xmax, scale); |
| 1001 |
|
if (!new_clrtab(maxcolors)) |
| 1002 |
|
quiterr("cannot create color map"); |
| 1003 |
|
for (y = 0; y < ymax; y++) { |
| 1004 |
< |
if (getscan(y) < 0) |
| 991 |
< |
quiterr("seek error in getmapped"); |
| 1004 |
> |
getscan(y); |
| 1005 |
|
if (scale) |
| 1006 |
|
shiftcolrs(scanline, xmax, scale); |
| 1007 |
|
colrs_gambs(scanline, xmax); |
| 1044 |
|
getscan(y) |
| 1045 |
|
int y; |
| 1046 |
|
{ |
| 1047 |
+ |
static int trunced = -1; /* truncated file? */ |
| 1048 |
+ |
skipit: |
| 1049 |
+ |
if (trunced >= 0 && y >= trunced) { |
| 1050 |
+ |
bzero(scanline, xmax*sizeof(COLR)); |
| 1051 |
+ |
return(-1); |
| 1052 |
+ |
} |
| 1053 |
|
if (y != cury) { |
| 1054 |
|
if (scanpos == NULL || scanpos[y] == -1) |
| 1055 |
|
return(-1); |
| 1059 |
|
} else if (scanpos != NULL && scanpos[y] == -1) |
| 1060 |
|
scanpos[y] = ftell(fin); |
| 1061 |
|
|
| 1062 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) |
| 1063 |
< |
quiterr("read error"); |
| 1064 |
< |
|
| 1062 |
> |
if (freadcolrs(scanline, xmax, fin) < 0) { |
| 1063 |
> |
fprintf(stderr, "%s: %s: unfinished picture\n", |
| 1064 |
> |
progname, fname==NULL?"<stdin>":fname); |
| 1065 |
> |
trunced = y; |
| 1066 |
> |
goto skipit; |
| 1067 |
> |
} |
| 1068 |
|
cury++; |
| 1069 |
|
return(0); |
| 1070 |
|
} |