| 14 |
|
|
| 15 |
|
#include "color.h" |
| 16 |
|
|
| 17 |
+ |
#include "resolu.h" |
| 18 |
|
|
| 19 |
< |
#define MAXFILE 32 |
| 19 |
> |
#define MAXFILE 64 |
| 20 |
|
|
| 20 |
– |
#define SIGNHT 24 |
| 21 |
– |
#define setpscom(b,n) sprintf(b, "psign -h %d '%.30s'|pfilt -1 -x /2 -y /2",\ |
| 22 |
– |
2*SIGNHT, n) |
| 23 |
– |
|
| 21 |
|
/* output picture size */ |
| 22 |
|
int xsiz = 0; |
| 23 |
|
int ysiz = 0; |
| 29 |
|
|
| 30 |
|
COLR bgcolr = BLKCOLR; /* background color */ |
| 31 |
|
|
| 32 |
+ |
int labelht = 24; /* label height */ |
| 33 |
+ |
|
| 34 |
|
int checkthresh = 0; /* check threshold value */ |
| 35 |
|
|
| 36 |
|
char *progname; |
| 48 |
|
|
| 49 |
|
int wrongformat = 0; |
| 50 |
|
|
| 51 |
< |
char tmpbuf[128]; |
| 51 |
> |
FILE *popen(), *lblopen(); |
| 52 |
|
|
| 54 |
– |
FILE *popen(); |
| 53 |
|
|
| 56 |
– |
|
| 54 |
|
tabputs(s) /* print line preceded by a tab */ |
| 55 |
|
char *s; |
| 56 |
|
{ |
| 70 |
|
int argc; |
| 71 |
|
char *argv[]; |
| 72 |
|
{ |
| 76 |
– |
double atof(); |
| 73 |
|
int ncolumns = 0; |
| 74 |
< |
int dolabels = 0; |
| 75 |
< |
int curcol = 0, curx = 0, cury = 0; |
| 74 |
> |
int autolabel = 0; |
| 75 |
> |
int curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0; |
| 76 |
> |
char *thislabel; |
| 77 |
|
int an; |
| 78 |
|
|
| 79 |
|
progname = argv[0]; |
| 81 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
| 82 |
|
switch (argv[an][1]) { |
| 83 |
|
case 'x': |
| 84 |
< |
xmax = xsiz = atoi(argv[++an]); |
| 84 |
> |
xsiz = atoi(argv[++an]); |
| 85 |
|
break; |
| 86 |
|
case 'y': |
| 87 |
< |
ymax = ysiz = atoi(argv[++an]); |
| 87 |
> |
ysiz = atoi(argv[++an]); |
| 88 |
|
break; |
| 89 |
|
case 'b': |
| 90 |
|
setcolr(bgcolr, atof(argv[an+1]), |
| 95 |
|
case 'a': |
| 96 |
|
ncolumns = atoi(argv[++an]); |
| 97 |
|
break; |
| 98 |
+ |
case 's': |
| 99 |
+ |
spacing = atoi(argv[++an]); |
| 100 |
+ |
break; |
| 101 |
+ |
case 'o': |
| 102 |
+ |
curx = x0 = atoi(argv[++an]); |
| 103 |
+ |
cury = atoi(argv[++an]); |
| 104 |
+ |
break; |
| 105 |
|
case 'l': |
| 106 |
< |
dolabels++; |
| 106 |
> |
switch (argv[an][2]) { |
| 107 |
> |
case 'a': |
| 108 |
> |
autolabel++; |
| 109 |
> |
break; |
| 110 |
> |
case 'h': |
| 111 |
> |
labelht = atoi(argv[++an]); |
| 112 |
> |
break; |
| 113 |
> |
case '\0': |
| 114 |
> |
goto dofiles; |
| 115 |
> |
default: |
| 116 |
> |
goto userr; |
| 117 |
> |
} |
| 118 |
|
break; |
| 119 |
|
case '\0': |
| 120 |
|
case 't': |
| 124 |
|
} |
| 125 |
|
dofiles: |
| 126 |
|
for (nfile = 0; an < argc; nfile++) { |
| 127 |
< |
if (dolabels) { |
| 128 |
< |
if (nfile >= MAXFILE-1) { |
| 129 |
< |
fprintf(stderr, |
| 115 |
< |
"%s: only %d files allowed with labels\n", |
| 116 |
< |
progname, MAXFILE/2); |
| 117 |
< |
} |
| 118 |
< |
} else { |
| 119 |
< |
if (nfile >= MAXFILE) { |
| 120 |
< |
fprintf(stderr, "%s: only %d files allowed\n", |
| 121 |
< |
progname, MAXFILE); |
| 122 |
< |
quit(1); |
| 123 |
< |
} |
| 124 |
< |
} |
| 125 |
< |
if (nfile >= (dolabels ? MAXFILE-1 : MAXFILE)) { |
| 126 |
< |
fprintf(stderr, "%s: too many files\n", progname); |
| 127 |
< |
quit(1); |
| 128 |
< |
} |
| 127 |
> |
if (nfile >= MAXFILE) |
| 128 |
> |
goto toomany; |
| 129 |
> |
thislabel = NULL; |
| 130 |
|
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 131 |
|
while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+')) |
| 132 |
|
switch (argv[an][1]) { |
| 147 |
|
} |
| 148 |
|
an += 2; |
| 149 |
|
break; |
| 150 |
+ |
case 'l': |
| 151 |
+ |
if (strcmp(argv[an], "-l")) |
| 152 |
+ |
goto userr; |
| 153 |
+ |
thislabel = argv[an+1]; |
| 154 |
+ |
an += 2; |
| 155 |
+ |
break; |
| 156 |
|
case '\0': |
| 157 |
|
if (argv[an][0] == '-') |
| 158 |
|
goto getfile; |
| 159 |
< |
/* fall through */ |
| 159 |
> |
goto userr; |
| 160 |
|
default: |
| 161 |
|
goto userr; |
| 162 |
|
} |
| 163 |
|
getfile: |
| 164 |
|
if (argc-an < (ncolumns ? 1 : 3)) |
| 165 |
|
goto userr; |
| 166 |
+ |
if (autolabel && thislabel == NULL) |
| 167 |
+ |
thislabel = argv[an]; |
| 168 |
|
if (!strcmp(argv[an], "-")) { |
| 169 |
|
input[nfile].name = "<stdin>"; |
| 170 |
|
input[nfile].fp = stdin; |
| 171 |
|
} else { |
| 172 |
< |
input[nfile].name = argv[an]; |
| 173 |
< |
if ((input[nfile].fp = argv[an][0] == '!' ? |
| 174 |
< |
popen(argv[an]+1, "r") : |
| 175 |
< |
fopen(argv[an], "r")) == NULL) { |
| 172 |
> |
if (argv[an][0] == '!') { |
| 173 |
> |
input[nfile].name = "<Command>"; |
| 174 |
> |
input[nfile].fp = popen(argv[an]+1, "r"); |
| 175 |
> |
} else { |
| 176 |
> |
input[nfile].name = argv[an]; |
| 177 |
> |
input[nfile].fp = fopen(argv[an], "r"); |
| 178 |
> |
} |
| 179 |
> |
if (input[nfile].fp == NULL) { |
| 180 |
|
perror(argv[an]); |
| 181 |
|
quit(1); |
| 182 |
|
} |
| 192 |
|
} |
| 193 |
|
/* get picture size */ |
| 194 |
|
if (fgetresolu(&input[nfile].xres, &input[nfile].yres, |
| 195 |
< |
input[nfile].fp) != (YMAJOR|YDECR)) { |
| 195 |
> |
input[nfile].fp) < 0) { |
| 196 |
|
fprintf(stderr, "%s: bad picture size\n", |
| 197 |
|
input[nfile].name); |
| 198 |
|
quit(1); |
| 199 |
|
} |
| 200 |
|
if (ncolumns > 0) { |
| 201 |
|
if (curcol >= ncolumns) { |
| 202 |
< |
cury = ymax; |
| 203 |
< |
curx = 0; |
| 202 |
> |
cury = ymax + spacing; |
| 203 |
> |
curx = x0; |
| 204 |
|
curcol = 0; |
| 205 |
|
} |
| 206 |
|
input[nfile].xloc = curx; |
| 207 |
|
input[nfile].yloc = cury; |
| 208 |
< |
curx += input[nfile].xres; |
| 208 |
> |
curx += input[nfile].xres + spacing; |
| 209 |
|
curcol++; |
| 210 |
|
} else { |
| 211 |
|
input[nfile].xloc = atoi(argv[an++]); |
| 219 |
|
xmax = input[nfile].xloc+input[nfile].xres; |
| 220 |
|
if (input[nfile].yloc+input[nfile].yres > ymax) |
| 221 |
|
ymax = input[nfile].yloc+input[nfile].yres; |
| 222 |
< |
if (dolabels) { |
| 223 |
< |
input[++nfile].name = "<Label>"; |
| 224 |
< |
setpscom(tmpbuf, input[nfile-1].name); |
| 225 |
< |
if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL) |
| 222 |
> |
if (thislabel != NULL) { |
| 223 |
> |
if (++nfile >= MAXFILE) |
| 224 |
> |
goto toomany; |
| 225 |
> |
input[nfile].name = "<Label>"; |
| 226 |
> |
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 227 |
> |
input[nfile].xres = input[nfile-1].xres; |
| 228 |
> |
input[nfile].yres = labelht; |
| 229 |
> |
if ((input[nfile].fp = lblopen(thislabel, |
| 230 |
> |
&input[nfile].xres, |
| 231 |
> |
&input[nfile].yres)) == NULL) |
| 232 |
|
goto labelerr; |
| 214 |
– |
if (checkheader(input[nfile].fp, COLRFMT, NULL) < 0) |
| 215 |
– |
goto labelerr; |
| 216 |
– |
if (fgetresolu(&input[nfile].xres, &input[nfile].yres, |
| 217 |
– |
input[nfile].fp) != (YMAJOR|YDECR)) |
| 218 |
– |
goto labelerr; |
| 233 |
|
input[nfile].xloc = input[nfile-1].xloc; |
| 234 |
|
input[nfile].yloc = input[nfile-1].yloc + |
| 235 |
< |
input[nfile-1].yres - SIGNHT; |
| 222 |
< |
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 235 |
> |
input[nfile-1].yres-input[nfile].yres; |
| 236 |
|
} |
| 237 |
|
} |
| 238 |
|
if (xsiz <= 0) |
| 239 |
|
xsiz = xmax; |
| 240 |
+ |
else if (xsiz > xmax) |
| 241 |
+ |
xmax = xsiz; |
| 242 |
|
if (ysiz <= 0) |
| 243 |
|
ysiz = ymax; |
| 244 |
+ |
else if (ysiz > ymax) |
| 245 |
+ |
ymax = ysiz; |
| 246 |
|
/* add new header info. */ |
| 247 |
|
printargs(argc, argv, stdout); |
| 248 |
|
fputformat(COLRFMT, stdout); |
| 249 |
< |
printf("\n-Y %d +X %d\n", ysiz, xsiz); |
| 249 |
> |
putchar('\n'); |
| 250 |
> |
fprtresolu(xsiz, ysiz, stdout); |
| 251 |
|
|
| 252 |
|
compos(); |
| 253 |
|
|
| 254 |
|
quit(0); |
| 255 |
|
userr: |
| 256 |
< |
fprintf(stderr, "Usage: %s [-x xres][-y yres][-b r g b] ", progname); |
| 257 |
< |
fprintf(stderr, "[-t min1][+t max1] file1 x1 y1 ..\n"); |
| 256 |
> |
fprintf(stderr, |
| 257 |
> |
"Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", |
| 258 |
> |
progname); |
| 259 |
> |
fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n"); |
| 260 |
|
quit(1); |
| 261 |
+ |
toomany: |
| 262 |
+ |
fprintf(stderr, "%s: only %d files and labels allowed\n", |
| 263 |
+ |
progname, MAXFILE); |
| 264 |
+ |
quit(1); |
| 265 |
|
labelerr: |
| 266 |
|
fprintf(stderr, "%s: error opening label\n", progname); |
| 267 |
|
quit(1); |
| 343 |
|
} |
| 344 |
|
|
| 345 |
|
|
| 346 |
+ |
FILE * |
| 347 |
+ |
lblopen(s, xp, yp) /* open pipe to label generator */ |
| 348 |
+ |
char *s; |
| 349 |
+ |
int *xp, *yp; |
| 350 |
+ |
{ |
| 351 |
+ |
char com[128]; |
| 352 |
+ |
FILE *fp; |
| 353 |
+ |
|
| 354 |
+ |
sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s); |
| 355 |
+ |
if ((fp = popen(com, "r")) == NULL) |
| 356 |
+ |
return(NULL); |
| 357 |
+ |
if (checkheader(fp, COLRFMT, NULL) < 0) |
| 358 |
+ |
goto err; |
| 359 |
+ |
if (fgetresolu(xp, yp, fp) < 0) |
| 360 |
+ |
goto err; |
| 361 |
+ |
return(fp); |
| 362 |
+ |
err: |
| 363 |
+ |
pclose(fp); |
| 364 |
+ |
return(NULL); |
| 365 |
+ |
} |
| 366 |
+ |
|
| 367 |
+ |
|
| 368 |
+ |
#ifdef NIX |
| 369 |
+ |
|
| 370 |
+ |
quit(code) |
| 371 |
+ |
int code; |
| 372 |
+ |
{ |
| 373 |
+ |
exit(code); |
| 374 |
+ |
} |
| 375 |
+ |
|
| 376 |
+ |
#else |
| 377 |
+ |
|
| 378 |
+ |
#include <signal.h> |
| 379 |
+ |
|
| 380 |
|
quit(code) /* exit gracefully */ |
| 381 |
|
int code; |
| 382 |
|
{ |
| 383 |
+ |
int status; |
| 384 |
+ |
|
| 385 |
+ |
if (code) { /* abnormal exit -- kill children */ |
| 386 |
+ |
signal(SIGPIPE, SIG_IGN); |
| 387 |
+ |
kill(0, SIGPIPE); |
| 388 |
+ |
} |
| 389 |
+ |
/* reap any children */ |
| 390 |
+ |
while (wait(&status) != -1) |
| 391 |
+ |
if (code == 0) |
| 392 |
+ |
code = status>>8 & 0xff; |
| 393 |
|
exit(code); |
| 394 |
|
} |
| 395 |
+ |
|
| 396 |
+ |
#endif |