40 |
|
"ascii", |
41 |
|
COLRFMT, |
42 |
|
CIEFMT, |
43 |
< |
"BINARY_float", |
44 |
< |
"BINARY_double", |
43 |
> |
"float", |
44 |
> |
"double", |
45 |
|
"BSDF_RBFmesh", |
46 |
|
"Radiance_octree", |
47 |
|
"Radiance_tmesh", |
74 |
|
const char stdin_name[] = "<stdin>"; |
75 |
|
const char *f1name=NULL, *f2name=NULL; |
76 |
|
FILE *f1in=NULL, *f2in=NULL; |
77 |
+ |
|
78 |
|
/* running real differences */ |
79 |
|
double diff2sum = 0; |
80 |
|
int nsum = 0; |
85 |
|
{ |
86 |
|
fputs("Usage: ", stderr); |
87 |
|
fputs(progname, stderr); |
88 |
< |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] file1 file2\n", |
88 |
> |
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
89 |
|
stderr); |
90 |
|
exit(1); |
91 |
|
} |
117 |
|
} |
118 |
|
if (max_lim >= 0 && diff2 > max_lim*max_lim) { |
119 |
|
if (report != REP_QUIET) |
120 |
< |
fprintf(stderr, |
121 |
< |
"%s: %sdifference between %.8g and %.8g exceeds epsilon\n", |
120 |
> |
printf( |
121 |
> |
"%s: %sdifference between %.8g and %.8g exceeds epsilon of %.8g\n", |
122 |
|
progname, |
123 |
|
(rel_min > 0) ? "relative " : "", |
124 |
< |
r1, r2); |
124 |
> |
r1, r2, max_lim); |
125 |
|
return(0); |
126 |
|
} |
127 |
|
diff2sum += diff2; |
139 |
|
/* skip whitespace at beginning */ |
140 |
|
while (isspace(*s1)) s1++; |
141 |
|
while (isspace(*s2)) s2++; |
141 |
– |
if (!strcmp(s1, s2)) /* quick check */ |
142 |
– |
return(1); |
142 |
|
while (*s1) { /* check each word */ |
143 |
< |
int inquote = *s1; |
143 |
> |
int inquote; |
144 |
> |
if (!*s2) /* unexpected EOL in s2? */ |
145 |
> |
return(0); |
146 |
> |
inquote = *s1; |
147 |
|
if ((inquote != '\'') & (inquote != '"')) |
148 |
|
inquote = 0; |
149 |
|
if (inquote) { /* quoted text must match exactly */ |
207 |
|
int kln, vln; |
208 |
|
int n; |
209 |
|
|
210 |
+ |
adv_linecnt(htp); /* side-effect is to count lines */ |
211 |
|
if (!isalpha(*val)) /* key must start line */ |
212 |
|
return(0); |
213 |
|
key = val++; |
232 |
|
if (!strcmp(key, hdr_ignkey[n])) |
233 |
|
return(0); |
234 |
|
if (!(tep = lu_find(htp, key))) |
235 |
< |
return(-1); |
235 |
> |
return(-1); /* memory allocation error */ |
236 |
|
if (!tep->key) |
237 |
|
tep->key = strcpy(malloc(kln+1), key); |
238 |
|
if (tep->data) |
239 |
|
free(tep->data); |
240 |
|
tep->data = strcpy(malloc(vln+1), val); |
238 |
– |
adv_linecnt(htp); |
241 |
|
return(1); |
242 |
|
} |
243 |
|
|
248 |
|
const LUENT *ep2 = lu_find((LUTAB *)p2, ep1->key); |
249 |
|
if (!ep2 || !ep2->data) { |
250 |
|
if (report != REP_QUIET) |
251 |
< |
fprintf(stderr, "%s: Variable '%s' missing in '%s'\n", |
251 |
> |
printf("%s: variable '%s' missing in '%s'\n", |
252 |
|
progname, ep1->key, f2name); |
253 |
|
return(-1); |
254 |
|
} |
255 |
|
if (!equiv_string((char *)ep1->data, (char *)ep2->data)) { |
256 |
< |
if (report != REP_QUIET) |
257 |
< |
fprintf(stderr, "%s: Header variables '%s' have different values\n", |
256 |
> |
if (report != REP_QUIET) { |
257 |
> |
printf("%s: header variable '%s' has different values\n", |
258 |
|
progname, ep1->key); |
259 |
+ |
if (report >= REP_VERBOSE) { |
260 |
+ |
printf("%s: %s=%s\n", f1name, |
261 |
+ |
ep1->key, (char *)ep1->data); |
262 |
+ |
printf("%s: %s=%s\n", f2name, |
263 |
+ |
ep2->key, (char *)ep2->data); |
264 |
+ |
} |
265 |
+ |
} |
266 |
|
return(-1); |
267 |
|
} |
268 |
|
return(1); /* good match */ |
275 |
|
int ne = lu_doall(hp1, match_val, hp2); |
276 |
|
if (ne < 0) |
277 |
|
return(0); /* something didn't match! */ |
278 |
< |
ne = lu_doall(hp2, NULL, NULL) - ne; |
279 |
< |
if (ne) { |
280 |
< |
if (report != REP_QUIET) |
272 |
< |
fprintf(stderr, "%s: '%s' has %d extra header variable(s)\n", |
278 |
> |
/* non-fatal if second header has extra */ |
279 |
> |
if (report >= REP_WARN && (ne = lu_doall(hp2, NULL, NULL) - ne)) |
280 |
> |
printf("%s: warning - '%s' has %d extra header setting(s)\n", |
281 |
|
progname, f2name, ne); |
274 |
– |
return(0); |
275 |
– |
} |
282 |
|
return(1); /* good match */ |
283 |
|
} |
284 |
|
|
290 |
|
int c = 0; |
291 |
|
|
292 |
|
while ((c = getc(fin)) != EOF) { |
293 |
+ |
++n; |
294 |
|
if (!c | (c > 127)) |
295 |
|
break; /* non-ascii character */ |
296 |
< |
if (++n >= 10240) |
296 |
> |
if (n >= 10240) |
297 |
|
break; /* enough to be confident */ |
298 |
|
} |
299 |
|
if (!n) |
323 |
|
char sbuf[32]; |
324 |
|
if (!fgets(sbuf, sizeof(sbuf), fin)) |
325 |
|
goto badeof; |
326 |
+ |
adv_linecnt(htp); /* for #?ID string */ |
327 |
|
if (report >= REP_WARN && strncmp(sbuf, "RADIANCE", 8)) { |
328 |
< |
fputs(name, stderr); |
329 |
< |
fputs(": warning - unexpected header ID: ", stderr); |
330 |
< |
fputs(sbuf, stderr); |
328 |
> |
fputs(name, stdout); |
329 |
> |
fputs(": warning - unexpected header ID: ", stdout); |
330 |
> |
fputs(sbuf, stdout); |
331 |
|
} |
324 |
– |
adv_linecnt(htp); /* for #?ID string */ |
332 |
|
if (getheader(fin, setheadvar, htp) < 0) { |
333 |
|
fputs(name, stderr); |
334 |
|
fputs(": Unknown error reading header\n", stderr); |
349 |
|
return(TYP_TEXT); |
350 |
|
badeof: |
351 |
|
if (report != REP_QUIET) { |
352 |
< |
fputs(name, stderr); |
353 |
< |
fputs(": Unexpected end-of-file\n", stderr); |
352 |
> |
fputs(name, stdout); |
353 |
> |
fputs(": Unexpected end-of-file\n", stdout); |
354 |
|
} |
355 |
|
return(-1); |
356 |
|
} |
363 |
|
return(1); |
364 |
|
if (diff2sum/(double)nsum > rms_lim*rms_lim) { |
365 |
|
if (report != REP_QUIET) |
366 |
< |
fprintf(stderr, |
367 |
< |
"%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit\n", |
366 |
> |
printf( |
367 |
> |
"%s: %sRMS difference between '%s' and '%s' of %.5g exceeds limit of %.5g\n", |
368 |
|
progname, |
369 |
|
(rel_min > 0) ? "relative " : "", |
370 |
|
f1name, f2name, |
371 |
< |
sqrt(diff2sum/(double)nsum)); |
371 |
> |
sqrt(diff2sum/(double)nsum), rms_lim); |
372 |
|
return(0); |
373 |
|
} |
374 |
|
if (report >= REP_VERBOSE) |
375 |
< |
fprintf(stderr, |
369 |
< |
"%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n", |
375 |
> |
printf("%s: %sRMS difference of reals in '%s' and '%s' is %.5g\n", |
376 |
|
progname, (rel_min > 0) ? "relative " : "", |
377 |
|
f1name, f2name, sqrt(diff2sum/(double)nsum)); |
378 |
|
return(1); |
382 |
|
static int |
383 |
|
compare_binary() |
384 |
|
{ |
385 |
+ |
int c1=0, c2=0; |
386 |
+ |
|
387 |
|
if (report >= REP_VERBOSE) { |
388 |
< |
fputs(progname, stderr); |
389 |
< |
fputs(": comparing inputs as binary\n", stderr); |
388 |
> |
fputs(progname, stdout); |
389 |
> |
fputs(": comparing inputs as binary\n", stdout); |
390 |
|
} |
391 |
|
for ( ; ; ) { /* exact byte matching */ |
392 |
< |
int c1 = getc(f1in); |
393 |
< |
int c2 = getc(f2in); |
392 |
> |
c1 = getc(f1in); |
393 |
> |
c2 = getc(f2in); |
394 |
|
if (c1 == EOF) { |
395 |
|
if (c2 == EOF) |
396 |
|
return(1); /* success! */ |
397 |
|
if (report != REP_QUIET) { |
398 |
< |
fputs(f1name, stderr); |
399 |
< |
fputs(": Unexpected end-of-file\n", stderr); |
398 |
> |
fputs(f1name, stdout); |
399 |
> |
fputs(": Unexpected end-of-file\n", stdout); |
400 |
|
} |
401 |
|
return(0); |
402 |
|
} |
403 |
|
if (c2 == EOF) { |
404 |
|
if (report != REP_QUIET) { |
405 |
< |
fputs(f2name, stderr); |
406 |
< |
fputs(": Unexpected end-of-file\n", stderr); |
405 |
> |
fputs(f2name, stdout); |
406 |
> |
fputs(": Unexpected end-of-file\n", stdout); |
407 |
|
} |
408 |
|
return(0); |
409 |
|
} |
412 |
|
} |
413 |
|
if (report == REP_QUIET) |
414 |
|
return(0); |
415 |
< |
fprintf(stderr, "%s: binary files '%s' and '%s' differ at offset %ld|%ld\n", |
415 |
> |
printf("%s: binary files '%s' and '%s' differ at byte offset %ld|%ld\n", |
416 |
|
progname, f1name, f2name, ftell(f1in), ftell(f2in)); |
417 |
+ |
if (report >= REP_VERBOSE) |
418 |
+ |
printf("%s: byte in '%s' is 0x%X, byte in '%s' is 0x%X\n", |
419 |
+ |
progname, f1name, c1, f2name, c2); |
420 |
|
return(0); |
421 |
|
} |
422 |
|
|
427 |
|
char l1buf[4096], l2buf[4096]; |
428 |
|
|
429 |
|
if (report >= REP_VERBOSE) { |
430 |
< |
fputs(progname, stderr); |
431 |
< |
fputs(": comparing inputs as ASCII text\n", stderr); |
430 |
> |
fputs(progname, stdout); |
431 |
> |
fputs(": comparing inputs as ASCII text\n", stdout); |
432 |
|
} |
433 |
|
/* compare a line at a time */ |
434 |
|
while (fgets(l1buf, sizeof(l1buf), f1in)) { |
442 |
|
} |
443 |
|
if (feof(f2in)) { |
444 |
|
if (report != REP_QUIET) { |
445 |
< |
fputs(f2name, stderr); |
446 |
< |
fputs(": Unexpected end-of-file\n", stderr); |
445 |
> |
fputs(f2name, stdout); |
446 |
> |
fputs(": Unexpected end-of-file\n", stdout); |
447 |
|
} |
448 |
|
return(0); |
449 |
|
} |
450 |
|
/* compare non-empty lines */ |
451 |
|
if (!equiv_string(l1buf, l2buf)) { |
452 |
|
if (report != REP_QUIET) { |
453 |
< |
fprintf(stderr, "%s: inputs '%s' and '%s' differ at line %d|%d\n", |
453 |
> |
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
454 |
|
progname, f1name, f2name, |
455 |
|
lin1cnt, lin2cnt); |
456 |
|
if (report >= REP_VERBOSE) { |
457 |
< |
fputs("------------- Mismatch -------------\n", stderr); |
458 |
< |
fprintf(stderr, "%s(%d):\t%s", f1name, |
457 |
> |
fputs("------------- Mismatch -------------\n", stdout); |
458 |
> |
printf("%s@%d:\t%s", f1name, |
459 |
|
lin1cnt, l1buf); |
460 |
< |
fprintf(stderr, "%s(%d):\t%s", f2name, |
460 |
> |
printf("%s@%d:\t%s", f2name, |
461 |
|
lin2cnt, l2buf); |
462 |
|
} |
463 |
|
} |
469 |
|
if (!*sskip2(l2buf,0)) |
470 |
|
continue; |
471 |
|
if (report != REP_QUIET) { |
472 |
< |
fputs(f1name, stderr); |
473 |
< |
fputs(": Unexpected end-of-file\n", stderr); |
472 |
> |
fputs(f1name, stdout); |
473 |
> |
fputs(": Unexpected end-of-file\n", stdout); |
474 |
|
} |
475 |
|
return(0); |
476 |
|
} |
489 |
|
fgetsresolu(&rs2, f2in); |
490 |
|
if (rs1.rt != rs2.rt) { |
491 |
|
if (report != REP_QUIET) |
492 |
< |
fprintf(stderr, |
492 |
> |
printf( |
493 |
|
"%s: Images '%s' and '%s' have different pixel ordering\n", |
494 |
|
progname, f1name, f2name); |
495 |
|
return(0); |
496 |
|
} |
497 |
|
if ((rs1.xr != rs2.xr) | (rs1.yr != rs2.yr)) { |
498 |
|
if (report != REP_QUIET) |
499 |
< |
fprintf(stderr, |
499 |
> |
printf( |
500 |
|
"%s: Images '%s' and '%s' are different sizes\n", |
501 |
|
progname, f1name, f2name); |
502 |
|
return(0); |
511 |
|
if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) | |
512 |
|
(freadscan(scan2, scanlen(&rs2), f2in) < 0)) { |
513 |
|
if (report != REP_QUIET) |
514 |
< |
fprintf(stderr, "%s: Unexpected end-of-file\n", |
514 |
> |
printf("%s: Unexpected end-of-file\n", |
515 |
|
progname); |
516 |
|
free(scan1); |
517 |
|
free(scan2); |
518 |
|
return(0); |
519 |
|
} |
520 |
< |
for (x = scanlen(&rs1); x--; ) { |
520 |
> |
for (x = 0; x < scanlen(&rs1); x++) { |
521 |
|
if (real_check(colval(scan1[x],RED), |
522 |
|
colval(scan2[x],RED)) & |
523 |
|
real_check(colval(scan1[x],GRN), |
526 |
|
colval(scan2[x],BLU))) |
527 |
|
continue; |
528 |
|
if (report != REP_QUIET) { |
529 |
< |
fprintf(stderr, |
529 |
> |
printf( |
530 |
|
"%s: pixels at scanline %d offset %d differ\n", |
531 |
|
progname, y, x); |
532 |
|
if (report >= REP_VERBOSE) { |
533 |
< |
fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n", |
533 |
> |
printf("%s: (R,G,B)=(%g,%g,%g)\n", |
534 |
|
f1name, colval(scan1[x],RED), |
535 |
|
colval(scan1[x],GRN), |
536 |
|
colval(scan1[x],BLU)); |
537 |
< |
fprintf(stderr, "%s: (R,G,B)=(%g,%g,%g)\n", |
537 |
> |
printf("%s: (R,G,B)=(%g,%g,%g)\n", |
538 |
|
f2name, colval(scan2[x],RED), |
539 |
|
colval(scan2[x],GRN), |
540 |
|
colval(scan2[x],BLU)); |
568 |
|
if (real_check(f1, f2)) |
569 |
|
continue; |
570 |
|
if (report != REP_QUIET) |
571 |
< |
fprintf(stderr, "%s: %ld%s float values differ\n", |
571 |
> |
printf("%s: %ld%s float values differ\n", |
572 |
|
progname, nread, nsuffix[nread%10]); |
573 |
|
return(0); |
574 |
|
} |
576 |
|
return(good_RMS()); /* final check of RMS */ |
577 |
|
badeof: |
578 |
|
if (report != REP_QUIET) |
579 |
< |
fprintf(stderr, "%s: Unexpected end-of-file\n", progname); |
579 |
> |
printf("%s: Unexpected end-of-file\n", progname); |
580 |
|
return(0); |
581 |
|
} |
582 |
|
|
594 |
|
if (real_check(f1, f2)) |
595 |
|
continue; |
596 |
|
if (report != REP_QUIET) |
597 |
< |
fprintf(stderr, "%s: %ld%s float values differ\n", |
597 |
> |
printf("%s: %ld%s float values differ\n", |
598 |
|
progname, nread, nsuffix[nread%10]); |
599 |
|
return(0); |
600 |
|
} |
602 |
|
return(good_RMS()); /* final check of RMS */ |
603 |
|
badeof: |
604 |
|
if (report != REP_QUIET) |
605 |
< |
fprintf(stderr, "%s: Unexpected end-of-file\n", progname); |
605 |
> |
printf("%s: Unexpected end-of-file\n", progname); |
606 |
|
return(0); |
607 |
|
} |
608 |
|
|
656 |
|
|
657 |
|
if (!strcmp(f1name, f2name)) { /* inputs are same? */ |
658 |
|
if (report >= REP_WARN) |
659 |
< |
fprintf(stderr, "%s: warning - identical inputs given\n", |
659 |
> |
printf("%s: warning - identical inputs given\n", |
660 |
|
progname); |
661 |
|
return(0); |
662 |
|
} |
680 |
|
return(1); |
681 |
|
if (typ1 != typ2) { |
682 |
|
if (report != REP_QUIET) |
683 |
< |
fprintf(stderr, "%s: '%s' is %s and '%s' is %s\n", |
683 |
> |
printf("%s: '%s' is %s and '%s' is %s\n", |
684 |
|
progname, f1name, file_type[typ1], |
685 |
|
f2name, file_type[typ2]); |
686 |
|
return(1); |
691 |
|
lu_done(&hdr1); lu_done(&hdr2); |
692 |
|
if (!ign_header & (report >= REP_WARN)) { |
693 |
|
if (typ1 == TYP_UNKNOWN) |
694 |
< |
fprintf(stderr, "%s: warning - unrecognized format, comparing as binary\n", |
694 |
> |
printf("%s: warning - unrecognized format, comparing as binary\n", |
695 |
|
progname); |
696 |
|
if (lin1cnt != lin2cnt) |
697 |
< |
fprintf(stderr, "%s: warning - headers are different lengths\n", |
697 |
> |
printf("%s: warning - headers are different lengths\n", |
698 |
|
progname); |
699 |
|
} |
700 |
|
if (report >= REP_VERBOSE) |
701 |
< |
fprintf(stderr, "%s: input file type is %s\n", |
701 |
> |
printf("%s: input file type is %s\n", |
702 |
|
progname, file_type[typ1]); |
703 |
|
|
704 |
|
switch (typ1) { /* compare based on type */ |