| 21 |
|
|
| 22 |
|
#include "standard.h" |
| 23 |
|
|
| 24 |
+ |
#include <signal.h> |
| 25 |
|
#include <X11/Xlib.h> |
| 26 |
|
#include <X11/cursorfont.h> |
| 27 |
|
#include <X11/Xutil.h> |
| 72 |
|
int xoff = 0; /* x image offset */ |
| 73 |
|
int yoff = 0; /* y image offset */ |
| 74 |
|
|
| 75 |
+ |
int parent = 0; /* number of children, -1 if child */ |
| 76 |
+ |
|
| 77 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
| 78 |
|
int gotview = 0; /* got parameters from file */ |
| 79 |
|
|
| 119 |
|
Display *thedisplay; |
| 120 |
|
Atom closedownAtom, wmProtocolsAtom; |
| 121 |
|
|
| 122 |
+ |
int noop() {} |
| 123 |
|
|
| 124 |
+ |
|
| 125 |
|
main(argc, argv) |
| 126 |
|
int argc; |
| 127 |
|
char *argv[]; |
| 130 |
|
char *gv; |
| 131 |
|
int headline(); |
| 132 |
|
int i; |
| 133 |
+ |
int pid; |
| 134 |
|
|
| 135 |
|
progname = argv[0]; |
| 136 |
|
if ((gv = getenv("GAMMA")) != NULL) |
| 176 |
|
else |
| 177 |
|
break; |
| 178 |
|
|
| 179 |
< |
if (i == argc-1) { |
| 179 |
> |
if (i > argc) |
| 180 |
> |
goto userr; |
| 181 |
> |
while (i < argc-1) { |
| 182 |
> |
if ((pid=fork()) == 0) { /* a child for each picture */ |
| 183 |
> |
parent = -1; |
| 184 |
> |
break; |
| 185 |
> |
} |
| 186 |
> |
if (pid < 0) |
| 187 |
> |
quiterr("fork failed"); |
| 188 |
> |
parent++; |
| 189 |
> |
signal(SIGCONT, noop); |
| 190 |
> |
pause(); /* wait for wake-up call */ |
| 191 |
> |
i++; |
| 192 |
> |
} |
| 193 |
> |
if (i < argc) { /* open picture file */ |
| 194 |
|
fname = argv[i]; |
| 195 |
|
fin = fopen(fname, "r"); |
| 196 |
|
if (fin == NULL) { |
| 197 |
|
sprintf(errmsg, "cannot open file \"%s\"", fname); |
| 198 |
|
quiterr(errmsg); |
| 199 |
|
} |
| 200 |
< |
} else if (i != argc) |
| 181 |
< |
goto userr; |
| 200 |
> |
} |
| 201 |
|
/* get header */ |
| 202 |
|
getheader(fin, headline, NULL); |
| 203 |
|
/* get picture dimensions */ |
| 213 |
|
|
| 214 |
|
init(argc, argv); /* get file and open window */ |
| 215 |
|
|
| 216 |
+ |
if (parent < 0) |
| 217 |
+ |
kill(getppid(), SIGCONT); /* signal parent if child */ |
| 218 |
+ |
|
| 219 |
|
for ( ; ; ) |
| 220 |
|
getevent(); /* main loop */ |
| 221 |
|
userr: |
| 222 |
|
fprintf(stderr, |
| 223 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic\n", |
| 223 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops] pic ..\n", |
| 224 |
|
progname); |
| 225 |
|
exit(1); |
| 226 |
|
} |
| 350 |
|
quiterr(err) /* print message and exit */ |
| 351 |
|
char *err; |
| 352 |
|
{ |
| 353 |
< |
if (err != NULL) { |
| 354 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
| 355 |
< |
exit(1); |
| 353 |
> |
if (err != NULL) |
| 354 |
> |
fprintf(stderr, "%s: %s: %s\n", progname, |
| 355 |
> |
fname==NULL?"<stdin>":fname, err); |
| 356 |
> |
if (wind) { |
| 357 |
> |
XDestroyWindow(thedisplay, wind); |
| 358 |
> |
XFlush(thedisplay); |
| 359 |
|
} |
| 360 |
< |
exit(0); |
| 360 |
> |
while (parent > 0 && wait(0) != -1) /* wait for any children */ |
| 361 |
> |
parent--; |
| 362 |
> |
exit(err != NULL); |
| 363 |
|
} |
| 364 |
|
|
| 365 |
|
|
| 563 |
|
else |
| 564 |
|
getbox(&xev.xbutton); |
| 565 |
|
break; |
| 566 |
< |
case ClientMessage: |
| 566 |
> |
case ClientMessage: |
| 567 |
|
if ((xev.xclient.message_type == wmProtocolsAtom) && |
| 568 |
|
(xev.xclient.data.l[0] == closedownAtom)) |
| 569 |
|
quiterr(NULL); |
| 970 |
|
getmapped() /* get color-mapped data */ |
| 971 |
|
{ |
| 972 |
|
int y; |
| 973 |
+ |
/* make sure we can do it first */ |
| 974 |
+ |
if (fname == NULL) |
| 975 |
+ |
quiterr("cannot map colors from standard input"); |
| 976 |
|
/* set gamma correction */ |
| 977 |
|
setcolrgam(gamcor); |
| 978 |
|
/* make histogram */ |
| 979 |
|
new_histo(); |
| 980 |
|
for (y = 0; y < ymax; y++) { |
| 981 |
|
if (getscan(y) < 0) |
| 982 |
< |
quiterr("seek error in getmapped"); |
| 982 |
> |
break; |
| 983 |
|
add2icon(y, scanline); |
| 984 |
|
if (scale) |
| 985 |
|
shiftcolrs(scanline, xmax, scale); |
| 990 |
|
if (!new_clrtab(maxcolors)) |
| 991 |
|
quiterr("cannot create color map"); |
| 992 |
|
for (y = 0; y < ymax; y++) { |
| 993 |
< |
if (getscan(y) < 0) |
| 964 |
< |
quiterr("seek error in getmapped"); |
| 993 |
> |
getscan(y); |
| 994 |
|
if (scale) |
| 995 |
|
shiftcolrs(scanline, xmax, scale); |
| 996 |
|
colrs_gambs(scanline, xmax); |
| 1033 |
|
getscan(y) |
| 1034 |
|
int y; |
| 1035 |
|
{ |
| 1036 |
+ |
static int trunced = -1; /* truncated file? */ |
| 1037 |
+ |
skipit: |
| 1038 |
+ |
if (trunced >= 0 && y >= trunced) { |
| 1039 |
+ |
bzero(scanline, xmax*sizeof(COLR)); |
| 1040 |
+ |
return(-1); |
| 1041 |
+ |
} |
| 1042 |
|
if (y != cury) { |
| 1043 |
|
if (scanpos == NULL || scanpos[y] == -1) |
| 1044 |
|
return(-1); |
| 1048 |
|
} else if (scanpos != NULL && scanpos[y] == -1) |
| 1049 |
|
scanpos[y] = ftell(fin); |
| 1050 |
|
|
| 1051 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) |
| 1052 |
< |
quiterr("read error"); |
| 1053 |
< |
|
| 1051 |
> |
if (freadcolrs(scanline, xmax, fin) < 0) { |
| 1052 |
> |
fprintf(stderr, "%s: %s: unfinished picture\n", |
| 1053 |
> |
progname, fname==NULL?"<stdin>":fname); |
| 1054 |
> |
trunced = y; |
| 1055 |
> |
goto skipit; |
| 1056 |
> |
} |
| 1057 |
|
cury++; |
| 1058 |
|
return(0); |
| 1059 |
|
} |