12 |
|
#include "fvect.h" |
13 |
|
#include "view.h" |
14 |
|
|
15 |
– |
char *progname; /* global argv[0] */ |
16 |
– |
|
15 |
|
VIEW vw = STDVIEW; |
16 |
|
int gotvw = 0; |
17 |
|
char fmt[MAXFMTLEN] = "ascii"; /* assumed when unspecified */ |
96 |
|
/* check if fseek() useful */ |
97 |
|
if (skip_len > skip_thresh && |
98 |
|
fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { |
99 |
+ |
int fd; |
100 |
|
off_t curpos; |
101 |
|
buf = (char *)malloc(ncols*elsiz); |
102 |
|
if (!buf) |
114 |
|
} |
115 |
|
} |
116 |
|
#else |
117 |
+ |
fd = fileno(fp); |
118 |
|
curpos = ftello(fp); |
119 |
|
for (y = nrows; y-- > 0; curpos += width*elsiz) { |
120 |
< |
if (pread(fileno(fp), buf, ncols*elsiz, |
120 |
> |
if (pread(fd, buf, ncols*elsiz, |
121 |
|
curpos) != ncols*elsiz) |
122 |
|
goto readerr; |
123 |
|
if (putbinary(buf, elsiz, ncols, stdout) != ncols) |
257 |
|
FILE *fp = stdin; |
258 |
|
int asiz = 0; |
259 |
|
int gotdims; |
260 |
< |
|
261 |
< |
progname = argv[0]; |
260 |
> |
/* set global progname */ |
261 |
> |
fixargv0(argv[0]); |
262 |
|
/* get input and output */ |
263 |
|
if ((argc < 5) | (argc > 7)) |
264 |
|
goto usage; |
269 |
|
cmin = atoi(argv[2]); |
270 |
|
nrows = atoi(argv[3]); |
271 |
|
ncols = atoi(argv[4]); |
272 |
< |
if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0)) |
272 |
> |
if ((rmin < 0) | (cmin < 0)) |
273 |
|
goto usage; |
274 |
|
if (argc <= 5) |
275 |
|
SET_FILE_BINARY(fp); |
301 |
|
fputs(": missing input dimensions\n", stderr); |
302 |
|
return(1); |
303 |
|
} |
304 |
< |
if (!nrows) |
305 |
< |
nrows = numscans(&res) - rmin; |
306 |
< |
if (!ncols) |
307 |
< |
ncols = scanlen(&res) - cmin; |
304 |
> |
if (nrows <= 0 ) |
305 |
> |
nrows += numscans(&res) - rmin; |
306 |
> |
if (ncols <= 0) |
307 |
> |
ncols += scanlen(&res) - cmin; |
308 |
|
if ((nrows <= 0) | (ncols <= 0) | |
309 |
|
(rmin+nrows > numscans(&res)) | |
310 |
|
(cmin+ncols > scanlen(&res))) { |