| 14 |
|
|
| 15 |
|
#include "color.h" |
| 16 |
|
|
| 17 |
+ |
#include "resolu.h" |
| 18 |
|
|
| 19 |
|
#define MAXFILE 32 |
| 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 |
|
{ |
| 72 |
|
{ |
| 73 |
|
double atof(); |
| 74 |
|
int ncolumns = 0; |
| 75 |
< |
int dolabels = 0; |
| 75 |
> |
int autolabel = 0; |
| 76 |
|
int curcol = 0, curx = 0, cury = 0; |
| 77 |
+ |
char *thislabel; |
| 78 |
|
int an; |
| 79 |
|
|
| 80 |
|
progname = argv[0]; |
| 97 |
|
ncolumns = atoi(argv[++an]); |
| 98 |
|
break; |
| 99 |
|
case 'l': |
| 100 |
< |
dolabels++; |
| 100 |
> |
switch (argv[an][2]) { |
| 101 |
> |
case 'a': |
| 102 |
> |
autolabel++; |
| 103 |
> |
break; |
| 104 |
> |
case 'h': |
| 105 |
> |
labelht = atoi(argv[++an]); |
| 106 |
> |
break; |
| 107 |
> |
case '\0': |
| 108 |
> |
goto dofiles; |
| 109 |
> |
default: |
| 110 |
> |
goto userr; |
| 111 |
> |
} |
| 112 |
|
break; |
| 113 |
|
case '\0': |
| 114 |
|
case 't': |
| 118 |
|
} |
| 119 |
|
dofiles: |
| 120 |
|
for (nfile = 0; an < argc; nfile++) { |
| 121 |
< |
if (dolabels) { |
| 122 |
< |
if (nfile >= MAXFILE-1) { |
| 123 |
< |
fprintf(stderr, |
| 124 |
< |
"%s: only %d files allowed with labels\n", |
| 125 |
< |
progname, MAXFILE/2); |
| 126 |
< |
quit(1); |
| 118 |
< |
} |
| 119 |
< |
} else { |
| 120 |
< |
if (nfile >= MAXFILE) { |
| 121 |
< |
fprintf(stderr, "%s: only %d files allowed\n", |
| 122 |
< |
progname, MAXFILE); |
| 123 |
< |
quit(1); |
| 124 |
< |
} |
| 125 |
< |
} |
| 121 |
> |
if (nfile >= MAXFILE) |
| 122 |
> |
goto toomany; |
| 123 |
> |
if (autolabel) |
| 124 |
> |
thislabel = argv[an]; |
| 125 |
> |
else |
| 126 |
> |
thislabel = NULL; |
| 127 |
|
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 128 |
|
while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+')) |
| 129 |
|
switch (argv[an][1]) { |
| 144 |
|
} |
| 145 |
|
an += 2; |
| 146 |
|
break; |
| 147 |
+ |
case 'l': |
| 148 |
+ |
if (strcmp(argv[an], "-l")) |
| 149 |
+ |
goto userr; |
| 150 |
+ |
thislabel = argv[++an]; |
| 151 |
+ |
break; |
| 152 |
|
case '\0': |
| 153 |
|
if (argv[an][0] == '-') |
| 154 |
|
goto getfile; |
| 155 |
< |
/* fall through */ |
| 155 |
> |
goto userr; |
| 156 |
|
default: |
| 157 |
|
goto userr; |
| 158 |
|
} |
| 182 |
|
} |
| 183 |
|
/* get picture size */ |
| 184 |
|
if (fgetresolu(&input[nfile].xres, &input[nfile].yres, |
| 185 |
< |
input[nfile].fp) != (YMAJOR|YDECR)) { |
| 185 |
> |
input[nfile].fp) < 0) { |
| 186 |
|
fprintf(stderr, "%s: bad picture size\n", |
| 187 |
|
input[nfile].name); |
| 188 |
|
quit(1); |
| 209 |
|
xmax = input[nfile].xloc+input[nfile].xres; |
| 210 |
|
if (input[nfile].yloc+input[nfile].yres > ymax) |
| 211 |
|
ymax = input[nfile].yloc+input[nfile].yres; |
| 212 |
< |
if (dolabels) { |
| 213 |
< |
input[++nfile].name = "<Label>"; |
| 214 |
< |
setpscom(tmpbuf, input[nfile-1].name); |
| 215 |
< |
if ((input[nfile].fp = popen(tmpbuf, "r")) == NULL) |
| 212 |
> |
if (thislabel != NULL) { |
| 213 |
> |
if (++nfile >= MAXFILE) |
| 214 |
> |
goto toomany; |
| 215 |
> |
input[nfile].name = "<Label>"; |
| 216 |
> |
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 217 |
> |
if ((input[nfile].fp = lblopen(thislabel, |
| 218 |
> |
&input[nfile].xres, |
| 219 |
> |
&input[nfile].yres)) == NULL) |
| 220 |
|
goto labelerr; |
| 211 |
– |
if (checkheader(input[nfile].fp, COLRFMT, NULL) < 0) |
| 212 |
– |
goto labelerr; |
| 213 |
– |
if (fgetresolu(&input[nfile].xres, &input[nfile].yres, |
| 214 |
– |
input[nfile].fp) != (YMAJOR|YDECR)) |
| 215 |
– |
goto labelerr; |
| 221 |
|
input[nfile].xloc = input[nfile-1].xloc; |
| 222 |
|
input[nfile].yloc = input[nfile-1].yloc + |
| 223 |
< |
input[nfile-1].yres - SIGNHT; |
| 219 |
< |
input[nfile].hasmin = input[nfile].hasmax = 0; |
| 223 |
> |
input[nfile-1].yres-input[nfile].yres; |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
if (xsiz <= 0) |
| 230 |
|
/* add new header info. */ |
| 231 |
|
printargs(argc, argv, stdout); |
| 232 |
|
fputformat(COLRFMT, stdout); |
| 233 |
< |
printf("\n-Y %d +X %d\n", ysiz, xsiz); |
| 233 |
> |
putchar('\n'); |
| 234 |
> |
fprtresolu(xsiz, ysiz, stdout); |
| 235 |
|
|
| 236 |
|
compos(); |
| 237 |
|
|
| 238 |
|
quit(0); |
| 239 |
|
userr: |
| 240 |
< |
fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-l] ", |
| 240 |
> |
fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-la][-lh h] ", |
| 241 |
|
progname); |
| 242 |
< |
fprintf(stderr, "[-t min1][+t max1] pic1 x1 y1 ..\n"); |
| 242 |
> |
fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n"); |
| 243 |
|
quit(1); |
| 244 |
+ |
toomany: |
| 245 |
+ |
fprintf(stderr, "%s: only %d files and labels allowed\n", |
| 246 |
+ |
progname, MAXFILE); |
| 247 |
+ |
quit(1); |
| 248 |
|
labelerr: |
| 249 |
|
fprintf(stderr, "%s: error opening label\n", progname); |
| 250 |
|
quit(1); |
| 323 |
|
if (i = c1[j] - c2[j]) |
| 324 |
|
return(i); |
| 325 |
|
return(0); |
| 326 |
+ |
} |
| 327 |
+ |
|
| 328 |
+ |
|
| 329 |
+ |
FILE * |
| 330 |
+ |
lblopen(s, xp, yp) /* open pipe to label generator */ |
| 331 |
+ |
char *s; |
| 332 |
+ |
int *xp, *yp; |
| 333 |
+ |
{ |
| 334 |
+ |
char com[128]; |
| 335 |
+ |
FILE *fp; |
| 336 |
+ |
|
| 337 |
+ |
sprintf(com, "psign -h %d '%.30s' | pfilt -1 -x /2 -y /2", |
| 338 |
+ |
2*labelht, s); |
| 339 |
+ |
if ((fp = popen(com, "r")) == NULL) |
| 340 |
+ |
return(NULL); |
| 341 |
+ |
if (checkheader(fp, COLRFMT, NULL) < 0) |
| 342 |
+ |
goto err; |
| 343 |
+ |
if (fgetresolu(xp, yp, fp) < 0) |
| 344 |
+ |
goto err; |
| 345 |
+ |
return(fp); |
| 346 |
+ |
err: |
| 347 |
+ |
pclose(fp); |
| 348 |
+ |
return(NULL); |
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
|