--- ray/src/util/radcompare.c 2019/08/24 02:22:02 2.22 +++ ray/src/util/radcompare.c 2023/03/08 19:59:48 2.32 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: radcompare.c,v 2.22 2019/08/24 02:22:02 greg Exp $"; +static const char RCSid[] = "$Id: radcompare.c,v 2.32 2023/03/08 19:59:48 greg Exp $"; #endif /* * Compare Radiance files for significant differences @@ -27,6 +27,8 @@ int report = REP_WARN; /* reporting level */ int ign_header = 0; /* ignore header differences? */ +int escape_newlines = 0; /* allow backslash to skip newlines */ + double rel_min = 1e-5; /* positive for relative comparisons */ double rms_lim = 0.01; /* RMS difference limit */ @@ -35,6 +37,8 @@ double max_lim = 0.25; /* difference limit if non-neg int lin1cnt=0, lin2cnt=0; /* file line position */ +int comment_c = '\0'; /* comment delimiter for text files */ + const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ "th","st","nd","rd","th","th","th","th","th","th" }; @@ -111,7 +115,7 @@ usage() { fputs("Usage: ", stderr); fputs(progname, stderr); - fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", + fputs(" [-h][-c#][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", stderr); exit(2); } @@ -130,8 +134,19 @@ read_line(LINEBUF *bp, FILE *fp) } 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') + if (bp->str[bp->len-1] == '\n') { + if (bp->len > 1 && bp->str[bp->len-2] == '\r') { + bp->str[--bp->len] = '\0'; + bp->str[bp->len-1] = '\n'; + } + if (escape_newlines && bp->len > 1 && + bp->str[bp->len-2] == '\\') { + bp->str[--bp->len] = '\0'; + bp->str[bp->len-1] = ' '; + continue; + } break; /* found EOL */ + } if (bp->len < bp->siz - 4) continue; /* at EOF? */ if (bp->siz >= MAXBUF) { @@ -149,6 +164,14 @@ read_line(LINEBUF *bp, FILE *fp) if (!bp->str) goto memerr; } + if (comment_c) { /* elide comment? */ + char *cp = sskip2(bp->str,0); + if (*cp == comment_c) { + *cp++ = '\n'; + *cp = '\0'; + bp->len = cp - bp->str; + } + } return(bp->len); memerr: fprintf(stderr, @@ -187,8 +210,9 @@ real_check(double r1, double r2) if (rel_min > 0) { /* doing relative differences? */ double av2 = .25*(r1*r1 + 2.*fabs(r1*r2) + r2*r2); - if (av2 > rel_min*rel_min) - diff2 /= av2; + if (av2 < rel_min*rel_min) + av2 = rel_min*rel_min; + diff2 /= av2; } if (max_lim >= 0 && diff2 > max_lim*max_lim) { if (report != REP_QUIET) @@ -317,6 +341,7 @@ equiv_string(char *s1, char *s2) static int setheadvar(char *val, void *p) { + char newval[128]; LUTAB *htp = (LUTAB *)p; LUENT *tep; char *key; @@ -359,8 +384,13 @@ setheadvar(char *val, void *p) return(-1); /* memory allocation error */ if (!tep->key) tep->key = strcpy(malloc(kln+1), key); - if (tep->data) + if (tep->data) { /* check for special cases */ + if (!strcmp(key, "EXPOSURE")) { + sprintf(newval, "%.6e", atof(tep->data)*atof(val)); + vln = strlen(val = newval); + } free(tep->data); + } tep->data = strcpy(malloc(vln+1), val); return(1); } @@ -469,7 +499,6 @@ identify_type(const char *name, FILE *fin, LUTAB *htp) } if (c) return(TYP_BINARY); - SET_FILE_TEXT(fin); /* originally set to binary */ return(TYP_TEXT); badeof: if (report != REP_QUIET) { @@ -552,8 +581,18 @@ compare_text() if (report >= REP_VERBOSE) { fputs(progname, stdout); - fputs(": comparing inputs as ASCII text\n", stdout); + fputs(": comparing inputs as ASCII text", stdout); + if (escape_newlines) + fputs(", allowing escaped newlines", stdout); + if (comment_c) { + fputs(", ignoring comments starting with '", stdout); + fputc(comment_c, stdout); + fputc('\'', stdout); + } + fputc('\n', stdout); } + SET_FILE_TEXT(f1in); /* originally set to binary */ + SET_FILE_TEXT(f2in); init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ while (read_line(&l1buf, f1in)) { lin1cnt++; @@ -576,9 +615,12 @@ compare_text() /* compare non-empty lines */ 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, - lin1cnt, lin2cnt); + printf("%s: inputs '%s' and '%s' differ at line %d", + progname, f1name, f2name, lin1cnt); + if (lin1cnt != lin2cnt) + printf("|%d\n", lin2cnt); + else + putchar('\n'); if ( report >= REP_VERBOSE && (l1buf.len < 256) & (l2buf.len < 256) ) { @@ -696,7 +738,7 @@ set_refdepth(DEPTHCODEC *dcp, LUTAB *htp) static char depthvar[] = DEPTHSTR; const char *drval; - depthvar[LDEPTHSTR] = '\0'; + depthvar[LDEPTHSTR-1] = '\0'; drval = (const char *)lu_find(htp, depthvar)->data; if (!drval) return(0); @@ -892,6 +934,12 @@ main(int argc, char *argv[]) switch (argv[a][1]) { case 'h': /* ignore header info. */ ign_header = !ign_header; + continue; + case 'n': /* allow newline escapes */ + escape_newlines = !escape_newlines; + continue; + case 'c': /* ignore comments */ + comment_c = argv[a][2]; continue; case 's': /* silent operation */ report = REP_QUIET;