27 |
|
{ |
28 |
|
if (formatval(fmt, s)) |
29 |
|
return(0); |
30 |
< |
if (!strncmp(s, "NCOMP=", 6)) { |
31 |
< |
ncomp = atoi(s+6); |
30 |
> |
if (isncomp(s)) { |
31 |
> |
ncomp = ncompval(s); |
32 |
|
return(-(ncomp <= 0)); |
33 |
|
} |
34 |
|
if (!strncmp(s, "NROWS=", 6)) { |
98 |
|
/* check if fseek() useful */ |
99 |
|
if (skip_len > skip_thresh && |
100 |
|
fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { |
101 |
+ |
off_t curpos; |
102 |
|
buf = (char *)malloc(ncols*elsiz); |
103 |
|
if (!buf) |
104 |
|
goto memerr; |
105 |
+ |
#ifdef NON_POSIX |
106 |
|
for (y = nrows; y-- > 0; ) { |
107 |
|
if (getbinary(buf, elsiz, ncols, fp) != ncols) |
108 |
|
goto readerr; |
114 |
|
return(0); |
115 |
|
} |
116 |
|
} |
117 |
< |
free(buf); /* success! */ |
118 |
< |
return(1); |
117 |
> |
#else |
118 |
> |
curpos = ftello(fp); |
119 |
> |
for (y = nrows; y-- > 0; curpos += width*elsiz) { |
120 |
> |
if (pread(fileno(fp), buf, ncols*elsiz, |
121 |
> |
curpos) != ncols*elsiz) |
122 |
> |
goto readerr; |
123 |
> |
if (putbinary(buf, elsiz, ncols, stdout) != ncols) |
124 |
> |
goto writerr; |
125 |
> |
} |
126 |
> |
#endif |
127 |
> |
free(buf); |
128 |
> |
if (fflush(stdout) == EOF) |
129 |
> |
goto writerr; |
130 |
> |
return(1); /* success! */ |
131 |
|
} /* else need to read it all... */ |
132 |
|
buf = (char *)malloc(width*elsiz); |
133 |
|
if (!buf) |
321 |
|
if (gotdims) /* dimensions + format */ |
322 |
|
printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols); |
323 |
|
if (ncomp) |
324 |
< |
printf("NCOMP=%d\n", ncomp); |
324 |
> |
fputncomp(ncomp, stdout); |
325 |
|
fputformat(fmt, stdout); /* will align bytes if it can */ |
326 |
|
fputc('\n', stdout); /* end of new header */ |
327 |
|
if (!gotdims) { /* add resolution string? */ |
351 |
|
asiz = -1; |
352 |
|
if (!ncomp) ncomp = 3; |
353 |
|
else ncomp *= (ncomp == 3); |
354 |
+ |
} else if (!strcmp(fmt, SPECFMT)) { |
355 |
+ |
asiz = ncomp+1; |
356 |
+ |
ncomp = 1; /* XXX assumes uncompressed */ |
357 |
|
} else if (strcasecmp(fmt, "ascii")) { |
358 |
|
fputs(progname, stderr); |
359 |
|
fputs(": unsupported format - ", stderr); |