17 |
|
#define MAXIDLEN 256 /* longest ID length supported */ |
18 |
|
#endif |
19 |
|
|
20 |
+ |
#define HF_TABLOUT 0x100 /* output ID table after header */ |
21 |
+ |
|
22 |
|
char *progname; /* global argv[0] */ |
23 |
|
|
24 |
|
static int unbuffered = 0; |
25 |
+ |
static int numeric = 0; |
26 |
|
static int sepc = '\n'; |
27 |
|
|
28 |
|
|
36 |
|
stderr); |
37 |
|
fputs(" Or: ", stderr); |
38 |
|
fputs(progname, stderr); |
39 |
< |
fputs(" -r [-i][-u][-h][-H][-tS] input.idx [output.txt]\n", stderr); |
39 |
> |
fputs(" -r [-i][-u][-h][-H][-l][-n][-tS] input.idx [output.txt]\n", |
40 |
> |
stderr); |
41 |
|
exit(code); |
42 |
|
} |
43 |
|
|
96 |
|
long n; |
97 |
|
int ndx; |
98 |
|
/* open file if not stdin */ |
99 |
< |
if (fname && !(fp = fopen(fname, "r"))) { |
99 |
> |
if (!fname) |
100 |
> |
fname = "<stdin>"; |
101 |
> |
else if (!(fp = fopen(fname, "r"))) { |
102 |
|
fputs(fname, stderr); |
103 |
|
fputs(": cannot open for input\n", stderr); |
104 |
|
return 0; |
194 |
|
stderr); |
195 |
|
break; |
196 |
|
} |
197 |
< |
fclose(fp); /* done with input */ |
197 |
> |
if (fp != stdin) /* done with input */ |
198 |
> |
fclose(fp); |
199 |
|
for (ndx = 0; ndx < nextID; ndx++) { /* append string table */ |
200 |
|
fputs(idmap[ndx], stdout); |
201 |
|
putchar('\0'); /* nul-terminated IDs */ |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
+ |
/* print out table IDs */ |
214 |
+ |
void |
215 |
+ |
print_IDs(IDMAP *idmp) |
216 |
+ |
{ |
217 |
+ |
int i; |
218 |
+ |
|
219 |
+ |
printf("============ %d IDs ============\n", idmp->nids); |
220 |
+ |
|
221 |
+ |
for (i = 0; i < idmp->nids; i++) |
222 |
+ |
puts(mapID(idmp, i)); |
223 |
+ |
|
224 |
+ |
puts("============= END ============="); |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
|
228 |
|
/* Load selected pixels from identifier index file */ |
229 |
|
int |
230 |
|
decode_select(const char *fname, int hdrflags) |
235 |
|
if (!idmp) |
236 |
|
return 0; |
237 |
|
|
238 |
+ |
if (hdrflags & HF_TABLOUT) |
239 |
+ |
print_IDs(idmp); |
240 |
+ |
|
241 |
|
if (idmp->res.rt != PIXSTANDARD) { |
242 |
|
fputs(progname, stderr); |
243 |
|
fputs(": can only handle standard pixel ordering\n", stderr); |
245 |
|
return 0; |
246 |
|
} |
247 |
|
while (scanf("%d %d", &x, &y) == 2) { |
248 |
< |
const char *id; |
249 |
< |
|
225 |
< |
if ((x < 0) | (y < 0) | |
226 |
< |
(x >= idmp->res.xr) | (y >= idmp->res.yr)) { |
248 |
> |
x = idmap_seek(idmp, x, idmp->res.yr-1 - y); |
249 |
> |
if (!x) { |
250 |
|
fputs(progname, stderr); |
251 |
|
fputs(": warning - pixel index is off map\n", stderr); |
252 |
|
continue; |
253 |
|
} |
254 |
< |
y = idmp->res.yr-1 - y; |
255 |
< |
|
256 |
< |
if (!(id = idmap_pix(idmp, x, y))) { |
254 |
> |
if (x > 0) |
255 |
> |
x = idmap_next_i(idmp); |
256 |
> |
if (x < 0) { |
257 |
> |
fputs(fname, stderr); |
258 |
> |
fputs(": read/seek error in decode_select()\n", stderr); |
259 |
|
idmap_close(idmp); |
260 |
|
return 0; |
261 |
|
} |
262 |
< |
fputs(id, stdout); |
262 |
> |
if (numeric) { |
263 |
> |
printf("%d", x); |
264 |
> |
} else { |
265 |
> |
const char *id = mapID(idmp, x); |
266 |
> |
if (!id) { |
267 |
> |
fputs(fname, stderr); |
268 |
> |
fputs(": bad ID index in file\n", stderr); |
269 |
> |
idmap_close(idmp); |
270 |
> |
return 0; |
271 |
> |
} |
272 |
> |
fputs(id, stdout); |
273 |
> |
} |
274 |
|
putchar(sepc); |
275 |
|
if (unbuffered && fflush(stdout) == EOF) { |
276 |
|
fputs(progname, stderr); |
300 |
|
if (!idmp) |
301 |
|
return 0; |
302 |
|
|
303 |
+ |
if (hdrflags & HF_TABLOUT) |
304 |
+ |
print_IDs(idmp); |
305 |
+ |
|
306 |
|
for (n = idmp->res.xr*idmp->res.yr; n-- > 0; ) { |
307 |
< |
const char *id = idmap_next(idmp); |
308 |
< |
if (!id) { |
307 |
> |
int ndx = idmap_next_i(idmp); |
308 |
> |
if (ndx < 0) { |
309 |
|
fputs(fname, stderr); |
310 |
|
fputs(": unexpected EOF\n", stderr); |
311 |
|
idmap_close(idmp); |
312 |
|
return 0; |
313 |
|
} |
314 |
< |
fputs(id, stdout); |
314 |
> |
if (numeric) { |
315 |
> |
printf("%d", ndx); |
316 |
> |
} else { |
317 |
> |
const char *id = mapID(idmp, ndx); |
318 |
> |
if (!id) { |
319 |
> |
fputs(fname, stderr); |
320 |
> |
fputs(": bad ID index in file\n", stderr); |
321 |
> |
idmap_close(idmp); |
322 |
> |
return 0; |
323 |
> |
} |
324 |
> |
fputs(id, stdout); |
325 |
> |
} |
326 |
|
putchar(sepc); |
327 |
|
} |
328 |
|
idmap_close(idmp); |
353 |
|
case 'u': |
354 |
|
unbuffered++; |
355 |
|
break; |
356 |
+ |
case 'n': |
357 |
+ |
numeric++; |
358 |
+ |
break; |
359 |
+ |
case 'l': |
360 |
+ |
hdrflags |= HF_TABLOUT; |
361 |
+ |
break; |
362 |
|
case 'h': |
363 |
|
hdrflags &= ~HF_HEADOUT; |
364 |
|
break; |
395 |
|
default: |
396 |
|
usage_exit(1); |
397 |
|
} |
398 |
+ |
if ((xres > 0) & (yres > 0)) /* user specified resolution? */ |
399 |
+ |
hdrflags &= ~HF_RESOUT; |
400 |
|
if (reverse && a >= argc) { |
401 |
|
fputs(progname, stderr); |
402 |
|
fputs(": -r option requires named input file\n", stderr); |