--- ray/src/util/rcrop.c 2024/05/16 18:59:19 1.15 +++ ray/src/util/rcrop.c 2025/06/03 21:31:51 1.18 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcrop.c,v 1.15 2024/05/16 18:59:19 greg Exp $"; +static const char RCSid[] = "$Id: rcrop.c,v 1.18 2025/06/03 21:31:51 greg Exp $"; #endif /* * rcrop.c - crop a Radiance picture or matrix data @@ -12,8 +12,6 @@ static const char RCSid[] = "$Id: rcrop.c,v 1.15 2024/ #include "fvect.h" #include "view.h" -char *progname; /* global argv[0] */ - VIEW vw = STDVIEW; int gotvw = 0; char fmt[MAXFMTLEN] = "ascii"; /* assumed when unspecified */ @@ -98,6 +96,7 @@ binary_copyf(FILE *fp, int asize) /* check if fseek() useful */ if (skip_len > skip_thresh && fseek(fp, ((long)rmin*width + cmin)*elsiz, SEEK_CUR) == 0) { + int fd; off_t curpos; buf = (char *)malloc(ncols*elsiz); if (!buf) @@ -115,9 +114,10 @@ binary_copyf(FILE *fp, int asize) } } #else + fd = fileno(fp); curpos = ftello(fp); for (y = nrows; y-- > 0; curpos += width*elsiz) { - if (pread(fileno(fp), buf, ncols*elsiz, + if (pread(fd, buf, ncols*elsiz, curpos) != ncols*elsiz) goto readerr; if (putbinary(buf, elsiz, ncols, stdout) != ncols) @@ -257,8 +257,8 @@ main(int argc, char *argv[]) FILE *fp = stdin; int asiz = 0; int gotdims; - - progname = argv[0]; + /* set global progname */ + fixargv0(argv[0]); /* get input and output */ if ((argc < 5) | (argc > 7)) goto usage; @@ -269,7 +269,7 @@ main(int argc, char *argv[]) cmin = atoi(argv[2]); nrows = atoi(argv[3]); ncols = atoi(argv[4]); - if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0)) + if ((rmin < 0) | (cmin < 0)) goto usage; if (argc <= 5) SET_FILE_BINARY(fp); @@ -301,10 +301,10 @@ main(int argc, char *argv[]) fputs(": missing input dimensions\n", stderr); return(1); } - if (!nrows) - nrows = numscans(&res) - rmin; - if (!ncols) - ncols = scanlen(&res) - cmin; + if (nrows <= 0 ) + nrows += numscans(&res) - rmin; + if (ncols <= 0) + ncols += scanlen(&res) - cmin; if ((nrows <= 0) | (ncols <= 0) | (rmin+nrows > numscans(&res)) | (cmin+ncols > scanlen(&res))) {