--- ray/src/util/radcompare.c 2018/10/19 23:50:32 2.13 +++ ray/src/util/radcompare.c 2018/11/17 20:22:17 2.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: radcompare.c,v 2.13 2018/10/19 23:50:32 greg Exp $"; +static const char RCSid[] = "$Id: radcompare.c,v 2.17 2018/11/17 20:22:17 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -75,12 +75,12 @@ LUTAB hdr2 = LU_SINIT(free,free); lin2cnt += (htp == &hdr2)) typedef struct { /* dynamic line buffer */ - char *ptr; + char *str; int len; int siz; } LINEBUF; -#define init_line(bp) ((bp)->ptr = NULL, (bp)->siz = 0) +#define init_line(bp) ((bp)->str = NULL, (bp)->siz = 0) /* 100 MByte limit on line buffer */ #define MAXBUF (100L<<20) @@ -109,24 +109,33 @@ usage() static int read_line(LINEBUF *bp, FILE *fp) { + static int doneWarn = 0; + bp->len = 0; - if (!bp->ptr) { - bp->ptr = (char *)malloc(bp->siz = 512); - if (!bp->ptr) + if (!bp->str) { + bp->str = (char *)malloc(bp->siz = 512); + if (!bp->str) goto memerr; } - while (fgets(bp->ptr + bp->len, bp->siz - bp->len, fp)) { - bp->len += strlen(bp->ptr + bp->len); - if (bp->ptr[bp->len-1] == '\n') + while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { + bp->len += strlen(bp->str + bp->len); + if (bp->str[bp->len-1] == '\n') break; /* found EOL */ if (bp->len < bp->siz - 4) continue; /* at EOF? */ - if (bp->siz >= MAXBUF) - break; /* don't go to extremes */ + if (bp->siz >= MAXBUF) { + if ((report >= REP_WARN) & !doneWarn) { + fprintf(stderr, + "%s: warning - input line(s) past %ld MByte limit\n", + progname, MAXBUF>>20); + doneWarn++; + } + break; /* return MAXBUF partial line */ + } if ((bp->siz += bp->siz/2) > MAXBUF) bp->siz = MAXBUF; - bp->ptr = (char *)realloc(bp->ptr, bp->siz); - if (!bp->ptr) + bp->str = (char *)realloc(bp->str, bp->siz); + if (!bp->str) goto memerr; } return(bp->len); @@ -141,7 +150,7 @@ memerr: static void free_line(LINEBUF *bp) { - if (bp->ptr) free(bp->ptr); + if (bp->str) free(bp->str); init_line(bp); } @@ -190,8 +199,8 @@ color_check(COLOR c1, COLOR c2) { int p; - if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.), - colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)) + if (!real_check((colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU))*(1./3.), + (colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.))) return(0); p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; @@ -504,12 +513,12 @@ compare_text() init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ while (read_line(&l1buf, f1in)) { lin1cnt++; - if (!*sskip2(l1buf.ptr,0)) + if (!*sskip2(l1buf.str,0)) continue; /* ignore empty lines */ while (read_line(&l2buf, f2in)) { lin2cnt++; - if (*sskip2(l2buf.ptr,0)) + if (*sskip2(l2buf.str,0)) break; /* found other non-empty line */ } if (!l2buf.len) { /* input 2 EOF? */ @@ -521,7 +530,7 @@ compare_text() return(0); } /* compare non-empty lines */ - if (!equiv_string(l1buf.ptr, l2buf.ptr)) { + if (!equiv_string(l1buf.str, l2buf.str)) { if (report != REP_QUIET) { printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", progname, f1name, f2name, @@ -531,9 +540,9 @@ compare_text() (l2buf.len < 256) ) { fputs("------------- Mismatch -------------\n", stdout); printf("%s@%d:\t%s", f1name, - lin1cnt, l1buf.ptr); + lin1cnt, l1buf.str); printf("%s@%d:\t%s", f2name, - lin2cnt, l2buf.ptr); + lin2cnt, l2buf.str); } } free_line(&l1buf); free_line(&l2buf); @@ -542,7 +551,7 @@ compare_text() } free_line(&l1buf); /* check for EOF on input 2 */ while (read_line(&l2buf, f2in)) { - if (!*sskip2(l2buf.ptr,0)) + if (!*sskip2(l2buf.str,0)) continue; if (report != REP_QUIET) { fputs(f1name, stdout); @@ -768,13 +777,13 @@ main(int argc, char *argv[]) ign_header |= !has_header(typ1); /* check headers if indicated */ if (!ign_header && !headers_match()) return(1); - lu_done(&hdr1); lu_done(&hdr2); + lu_done(&hdr1); lu_done(&hdr2); /* done with header info. */ if (!ign_header & (report >= REP_WARN)) { - if (typ1 == TYP_UNKNOWN) - printf("%s: warning - unrecognized format, comparing as binary\n", - progname); if (lin1cnt != lin2cnt) printf("%s: warning - headers are different lengths\n", + progname); + if (typ1 == TYP_UNKNOWN) + printf("%s: warning - unrecognized format\n", progname); } if (report >= REP_VERBOSE)