97 |
|
int y; |
98 |
|
/* check if fseek() useful */ |
99 |
|
if (skip_len > skip_thresh && |
100 |
< |
fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { |
100 |
> |
fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { |
101 |
> |
int fd; |
102 |
|
off_t curpos; |
103 |
|
buf = (char *)malloc(ncols*elsiz); |
104 |
|
if (!buf) |
116 |
|
} |
117 |
|
} |
118 |
|
#else |
119 |
+ |
fd = fileno(fp); |
120 |
|
curpos = ftello(fp); |
121 |
|
for (y = nrows; y-- > 0; curpos += width*elsiz) { |
122 |
< |
if (pread(fileno(fp), buf, ncols*elsiz, |
122 |
> |
if (pread(fd, buf, ncols*elsiz, |
123 |
|
curpos) != ncols*elsiz) |
124 |
|
goto readerr; |
125 |
|
if (putbinary(buf, elsiz, ncols, stdout) != ncols) |
136 |
|
goto memerr; |
137 |
|
/* skip rows as requested */ |
138 |
|
if (skip_len > skip_thresh || |
139 |
< |
(rmin && fseek(fp, rmin*width*elsiz, SEEK_CUR) < 0)) |
139 |
> |
(rmin && fseek(fp, (long)rmin*width*elsiz, SEEK_CUR) < 0)) |
140 |
|
for (y = 0; y < rmin; y++) |
141 |
|
if (getbinary(buf, elsiz, width, fp) != width) |
142 |
|
goto readerr; |
165 |
|
|
166 |
|
/* Read (and copy) specified number of white-space-separated words */ |
167 |
|
static int |
168 |
< |
readwords(FILE *finp, int nwords, FILE *fout) |
168 |
> |
readwords(FILE *finp, long nwords, FILE *fout) |
169 |
|
{ |
170 |
|
while (nwords-- > 0) { |
171 |
|
int c; |
194 |
|
SET_FILE_TEXT(fp); /* started as binary */ |
195 |
|
SET_FILE_TEXT(stdout); |
196 |
|
/* skip rows as requested */ |
197 |
< |
if (readwords(fp, rmin*width*ncomp, NULL) < 0) |
197 |
> |
if (readwords(fp, (long)rmin*width*ncomp, NULL) < 0) |
198 |
|
goto io_err; |
199 |
|
for (y = 0; y < nrows; y++) { /* copy part */ |
200 |
|
if (readwords(fp, cmin*ncomp, NULL) < 0) |
271 |
|
cmin = atoi(argv[2]); |
272 |
|
nrows = atoi(argv[3]); |
273 |
|
ncols = atoi(argv[4]); |
274 |
< |
if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0)) |
274 |
> |
if ((rmin < 0) | (cmin < 0)) |
275 |
|
goto usage; |
276 |
|
if (argc <= 5) |
277 |
|
SET_FILE_BINARY(fp); |
303 |
|
fputs(": missing input dimensions\n", stderr); |
304 |
|
return(1); |
305 |
|
} |
306 |
< |
if (!nrows) |
307 |
< |
nrows = numscans(&res) - rmin; |
308 |
< |
if (!ncols) |
309 |
< |
ncols = scanlen(&res) - cmin; |
306 |
> |
if (nrows <= 0 ) |
307 |
> |
nrows += numscans(&res) - rmin; |
308 |
> |
if (ncols <= 0) |
309 |
> |
ncols += scanlen(&res) - cmin; |
310 |
|
if ((nrows <= 0) | (ncols <= 0) | |
311 |
|
(rmin+nrows > numscans(&res)) | |
312 |
|
(cmin+ncols > scanlen(&res))) { |