| 33 |
|
|
| 34 |
|
int lin1cnt=0, lin2cnt=0; /* file line position */ |
| 35 |
|
|
| 36 |
+ |
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
| 37 |
+ |
"th","st","nd","rd","th","th","th","th","th","th" |
| 38 |
+ |
}; |
| 39 |
+ |
#define num_sfx(n) nsuffix[(n)%10] |
| 40 |
+ |
|
| 41 |
|
/* file types */ |
| 42 |
|
const char *file_type[] = { |
| 43 |
|
"Unrecognized", |
| 53 |
|
"BINARY_unknown", |
| 54 |
|
NULL /* terminator */ |
| 55 |
|
}; |
| 56 |
< |
|
| 56 |
> |
/* keep consistent with above */ |
| 57 |
|
enum {TYP_UNKNOWN, TYP_TEXT, TYP_ASCII, TYP_RGBE, TYP_XYZE, TYP_FLOAT, |
| 58 |
|
TYP_DOUBLE, TYP_RBFMESH, TYP_OCTREE, TYP_TMESH, TYP_BINARY}; |
| 59 |
|
|
| 82 |
|
|
| 83 |
|
/* running real differences */ |
| 84 |
|
double diff2sum = 0; |
| 85 |
< |
int nsum = 0; |
| 85 |
> |
long nsum = 0; |
| 86 |
|
|
| 87 |
|
/* Report usage and exit */ |
| 88 |
|
static void |
| 92 |
|
fputs(progname, stderr); |
| 93 |
|
fputs(" [-h][-s|-w|-v][-rel min_test][-rms epsilon][-max epsilon] reference test\n", |
| 94 |
|
stderr); |
| 95 |
< |
exit(1); |
| 95 |
> |
exit(2); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
/* Get type ID from name (or 0 if not found) */ |
| 134 |
|
return(1); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
+ |
/* Compare two color values for equivalence */ |
| 138 |
+ |
static int |
| 139 |
+ |
color_check(COLOR c1, COLOR c2) |
| 140 |
+ |
{ |
| 141 |
+ |
int p; |
| 142 |
+ |
|
| 143 |
+ |
if (!real_check(colval(c1,RED)+colval(c1,GRN)+colval(c1,BLU)*(1./3.), |
| 144 |
+ |
colval(c2,RED)+colval(c2,GRN)+colval(c2,BLU))*(1./3.)) |
| 145 |
+ |
return(0); |
| 146 |
+ |
|
| 147 |
+ |
p = (colval(c1,GRN) > colval(c1,RED)) ? GRN : RED; |
| 148 |
+ |
if (colval(c1,BLU) > colval(c1,p)) p = BLU; |
| 149 |
+ |
|
| 150 |
+ |
return(real_check(colval(c1,p), colval(c2,p))); |
| 151 |
+ |
} |
| 152 |
+ |
|
| 153 |
|
/* Compare two strings for equivalence */ |
| 154 |
|
static int |
| 155 |
|
equiv_string(char *s1, char *s2) |
| 244 |
|
val++; |
| 245 |
|
if (!*val) /* nothing set? */ |
| 246 |
|
return(0); |
| 226 |
– |
vln = strlen(val); /* eliminate space and newline at end */ |
| 227 |
– |
while (--vln > 0 && isspace(val[vln])) |
| 228 |
– |
; |
| 229 |
– |
val[++vln] = '\0'; |
| 247 |
|
/* check if key to ignore */ |
| 248 |
|
for (n = 0; hdr_ignkey[n]; n++) |
| 249 |
|
if (!strcmp(key, hdr_ignkey[n])) |
| 250 |
|
return(0); |
| 251 |
+ |
vln = strlen(val); /* eliminate space and newline at end */ |
| 252 |
+ |
while (isspace(val[--vln])) |
| 253 |
+ |
; |
| 254 |
+ |
val[++vln] = '\0'; |
| 255 |
|
if (!(tep = lu_find(htp, key))) |
| 256 |
|
return(-1); /* memory allocation error */ |
| 257 |
|
if (!tep->key) |
| 291 |
|
|
| 292 |
|
/* Compare two sets of header variables */ |
| 293 |
|
static int |
| 294 |
< |
headers_match(LUTAB *hp1, LUTAB *hp2) |
| 294 |
> |
headers_match() |
| 295 |
|
{ |
| 296 |
< |
int ne = lu_doall(hp1, match_val, hp2); |
| 296 |
> |
int ne = lu_doall(&hdr1, match_val, &hdr2); |
| 297 |
|
if (ne < 0) |
| 298 |
|
return(0); /* something didn't match! */ |
| 299 |
|
/* non-fatal if second header has extra */ |
| 300 |
< |
if (report >= REP_WARN && (ne = lu_doall(hp2, NULL, NULL) - ne)) |
| 300 |
> |
if (report >= REP_WARN && (ne = lu_doall(&hdr2, NULL, NULL) - ne)) |
| 301 |
|
printf("%s: warning - '%s' has %d extra header setting(s)\n", |
| 302 |
|
progname, f2name, ne); |
| 303 |
|
return(1); /* good match */ |
| 352 |
|
} |
| 353 |
|
if (getheader(fin, setheadvar, htp) < 0) { |
| 354 |
|
fputs(name, stderr); |
| 355 |
< |
fputs(": Unknown error reading header\n", stderr); |
| 355 |
> |
fputs(": unknown error reading header\n", stderr); |
| 356 |
|
return(-1); |
| 357 |
|
} |
| 358 |
|
adv_linecnt(htp); /* for trailing emtpy line */ |
| 371 |
|
badeof: |
| 372 |
|
if (report != REP_QUIET) { |
| 373 |
|
fputs(name, stdout); |
| 374 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
| 374 |
> |
fputs(": unexpected end-of-file\n", stdout); |
| 375 |
|
} |
| 376 |
|
return(-1); |
| 377 |
|
} |
| 417 |
|
return(1); /* success! */ |
| 418 |
|
if (report != REP_QUIET) { |
| 419 |
|
fputs(f1name, stdout); |
| 420 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
| 420 |
> |
fputs(": unexpected end-of-file\n", stdout); |
| 421 |
|
} |
| 422 |
|
return(0); |
| 423 |
|
} |
| 424 |
|
if (c2 == EOF) { |
| 425 |
|
if (report != REP_QUIET) { |
| 426 |
|
fputs(f2name, stdout); |
| 427 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
| 427 |
> |
fputs(": unexpected end-of-file\n", stdout); |
| 428 |
|
} |
| 429 |
|
return(0); |
| 430 |
|
} |
| 441 |
|
return(0); |
| 442 |
|
} |
| 443 |
|
|
| 444 |
+ |
/* If line is continued (no newline), then back up to word boundary if one */ |
| 445 |
+ |
static int |
| 446 |
+ |
leftover(char *buf) |
| 447 |
+ |
{ |
| 448 |
+ |
int minlen = strlen(buf); |
| 449 |
+ |
char *bend = buf + minlen; |
| 450 |
+ |
char *cp = bend-1; |
| 451 |
+ |
|
| 452 |
+ |
if (*cp == '\r') *cp = '\n'; /* AARG Windoze! */ |
| 453 |
+ |
if (*cp == '\n') /* complete line? */ |
| 454 |
+ |
return(0); |
| 455 |
+ |
|
| 456 |
+ |
minlen >>= 2; /* back over partial word */ |
| 457 |
+ |
while (!isspace(*cp)) |
| 458 |
+ |
if (--cp <= buf+minlen) |
| 459 |
+ |
return(0); |
| 460 |
+ |
*cp++ = '\0'; /* break line here */ |
| 461 |
+ |
return(bend - cp); |
| 462 |
+ |
} |
| 463 |
+ |
|
| 464 |
|
/* Compare two inputs as generic text files */ |
| 465 |
|
static int |
| 466 |
|
compare_text() |
| 467 |
|
{ |
| 468 |
|
char l1buf[4096], l2buf[4096]; |
| 469 |
+ |
int l1over=0, l2over=0; |
| 470 |
|
|
| 471 |
|
if (report >= REP_VERBOSE) { |
| 472 |
|
fputs(progname, stdout); |
| 473 |
|
fputs(": comparing inputs as ASCII text\n", stdout); |
| 474 |
|
} |
| 475 |
|
/* compare a line at a time */ |
| 476 |
< |
while (fgets(l1buf, sizeof(l1buf), f1in)) { |
| 477 |
< |
lin1cnt++; |
| 478 |
< |
if (!*sskip2(l1buf,0)) |
| 476 |
> |
while (fgets(l1buf+l1over, sizeof(l1buf)-l1over, f1in)) { |
| 477 |
> |
lin1cnt += !(l1over = leftover(l1buf)); |
| 478 |
> |
if (!*sskip2(l1buf,0)) { |
| 479 |
> |
memmove(l1buf, l1buf+sizeof(l1buf)-l1over, l1over); |
| 480 |
|
continue; /* ignore empty lines */ |
| 481 |
< |
while (fgets(l2buf, sizeof(l2buf), f2in)) { |
| 482 |
< |
lin2cnt++; |
| 481 |
> |
} |
| 482 |
> |
while (fgets(l2buf+l2over, sizeof(l2buf)-l2over, f2in)) { |
| 483 |
> |
lin2cnt += !(l2over = leftover(l2buf)); |
| 484 |
|
if (*sskip2(l2buf,0)) |
| 485 |
|
break; /* found other non-empty line */ |
| 486 |
+ |
memmove(l2buf, l2buf+sizeof(l2buf)-l2over, l2over); |
| 487 |
|
} |
| 488 |
|
if (feof(f2in)) { |
| 489 |
|
if (report != REP_QUIET) { |
| 490 |
|
fputs(f2name, stdout); |
| 491 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
| 491 |
> |
fputs(": unexpected end-of-file\n", stdout); |
| 492 |
|
} |
| 493 |
|
return(0); |
| 494 |
|
} |
| 508 |
|
} |
| 509 |
|
return(0); |
| 510 |
|
} |
| 511 |
+ |
if (l1over) memmove(l1buf, l1buf+sizeof(l1buf)-l1over, l1over); |
| 512 |
+ |
if (l2over) memmove(l2buf, l2buf+sizeof(l2buf)-l2over, l2over); |
| 513 |
|
} |
| 514 |
|
/* check for EOF on input 2 */ |
| 515 |
|
while (fgets(l2buf, sizeof(l2buf), f2in)) { |
| 517 |
|
continue; |
| 518 |
|
if (report != REP_QUIET) { |
| 519 |
|
fputs(f1name, stdout); |
| 520 |
< |
fputs(": Unexpected end-of-file\n", stdout); |
| 520 |
> |
fputs(": unexpected end-of-file\n", stdout); |
| 521 |
|
} |
| 522 |
|
return(0); |
| 523 |
|
} |
| 532 |
|
COLOR *scan1, *scan2; |
| 533 |
|
int x, y; |
| 534 |
|
|
| 535 |
+ |
if (report >= REP_VERBOSE) { |
| 536 |
+ |
fputs(progname, stdout); |
| 537 |
+ |
fputs(": comparing inputs as HDR images\n", stdout); |
| 538 |
+ |
} |
| 539 |
|
fgetsresolu(&rs1, f1in); |
| 540 |
|
fgetsresolu(&rs2, f2in); |
| 541 |
|
if (rs1.rt != rs2.rt) { |
| 562 |
|
if ((freadscan(scan1, scanlen(&rs1), f1in) < 0) | |
| 563 |
|
(freadscan(scan2, scanlen(&rs2), f2in) < 0)) { |
| 564 |
|
if (report != REP_QUIET) |
| 565 |
< |
printf("%s: Unexpected end-of-file\n", |
| 565 |
> |
printf("%s: unexpected end-of-file\n", |
| 566 |
|
progname); |
| 567 |
|
free(scan1); |
| 568 |
|
free(scan2); |
| 569 |
|
return(0); |
| 570 |
|
} |
| 571 |
|
for (x = 0; x < scanlen(&rs1); x++) { |
| 572 |
< |
if (real_check(colval(scan1[x],RED), |
| 522 |
< |
colval(scan2[x],RED)) & |
| 523 |
< |
real_check(colval(scan1[x],GRN), |
| 524 |
< |
colval(scan2[x],GRN)) & |
| 525 |
< |
real_check(colval(scan1[x],BLU), |
| 526 |
< |
colval(scan2[x],BLU))) |
| 572 |
> |
if (color_check(scan1[x], scan2[x])) |
| 573 |
|
continue; |
| 574 |
|
if (report != REP_QUIET) { |
| 575 |
|
printf( |
| 596 |
|
return(good_RMS()); /* final check of RMS */ |
| 597 |
|
} |
| 598 |
|
|
| 553 |
– |
const char nsuffix[10][3] = { /* 1st, 2nd, 3rd, etc. */ |
| 554 |
– |
"th","st","nd","rd","th","th","th","th","th","th" |
| 555 |
– |
}; |
| 556 |
– |
|
| 599 |
|
/* Compare two inputs that are known to be 32-bit floating-point data */ |
| 600 |
|
static int |
| 601 |
|
compare_float() |
| 603 |
|
long nread = 0; |
| 604 |
|
float f1, f2; |
| 605 |
|
|
| 606 |
+ |
if (report >= REP_VERBOSE) { |
| 607 |
+ |
fputs(progname, stdout); |
| 608 |
+ |
fputs(": comparing inputs as 32-bit IEEE floats\n", stdout); |
| 609 |
+ |
} |
| 610 |
|
while (getbinary(&f1, sizeof(f1), 1, f1in)) { |
| 611 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 612 |
|
goto badeof; |
| 615 |
|
continue; |
| 616 |
|
if (report != REP_QUIET) |
| 617 |
|
printf("%s: %ld%s float values differ\n", |
| 618 |
< |
progname, nread, nsuffix[nread%10]); |
| 618 |
> |
progname, nread, num_sfx(nread)); |
| 619 |
|
return(0); |
| 620 |
|
} |
| 621 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 622 |
|
return(good_RMS()); /* final check of RMS */ |
| 623 |
|
badeof: |
| 624 |
|
if (report != REP_QUIET) |
| 625 |
< |
printf("%s: Unexpected end-of-file\n", progname); |
| 625 |
> |
printf("%s: unexpected end-of-file\n", progname); |
| 626 |
|
return(0); |
| 627 |
|
} |
| 628 |
|
|
| 633 |
|
long nread = 0; |
| 634 |
|
double f1, f2; |
| 635 |
|
|
| 636 |
+ |
if (report >= REP_VERBOSE) { |
| 637 |
+ |
fputs(progname, stdout); |
| 638 |
+ |
fputs(": comparing inputs as 64-bit IEEE doubles\n", stdout); |
| 639 |
+ |
} |
| 640 |
|
while (getbinary(&f1, sizeof(f1), 1, f1in)) { |
| 641 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 642 |
|
goto badeof; |
| 644 |
|
if (real_check(f1, f2)) |
| 645 |
|
continue; |
| 646 |
|
if (report != REP_QUIET) |
| 647 |
< |
printf("%s: %ld%s float values differ\n", |
| 648 |
< |
progname, nread, nsuffix[nread%10]); |
| 647 |
> |
printf("%s: %ld%s double values differ\n", |
| 648 |
> |
progname, nread, num_sfx(nread)); |
| 649 |
|
return(0); |
| 650 |
|
} |
| 651 |
|
if (!getbinary(&f2, sizeof(f2), 1, f2in)) |
| 652 |
|
return(good_RMS()); /* final check of RMS */ |
| 653 |
|
badeof: |
| 654 |
|
if (report != REP_QUIET) |
| 655 |
< |
printf("%s: Unexpected end-of-file\n", progname); |
| 655 |
> |
printf("%s: unexpected end-of-file\n", progname); |
| 656 |
|
return(0); |
| 657 |
|
} |
| 658 |
|
|
| 699 |
|
} |
| 700 |
|
break; |
| 701 |
|
} |
| 702 |
< |
if (a != argc-2) |
| 702 |
> |
if (a != argc-2) /* make sure of two inputs */ |
| 703 |
|
usage(); |
| 704 |
< |
if (!f1name) f1name = argv[a]; |
| 655 |
< |
if (!f2name) f2name = argv[a+1]; |
| 656 |
< |
|
| 657 |
< |
if (!strcmp(f1name, f2name)) { /* inputs are same? */ |
| 704 |
> |
if (!strcmp(argv[a], argv[a+1])) { /* inputs are same? */ |
| 705 |
|
if (report >= REP_WARN) |
| 706 |
|
printf("%s: warning - identical inputs given\n", |
| 707 |
|
progname); |
| 708 |
|
return(0); |
| 709 |
|
} |
| 710 |
+ |
if (!f1name) f1name = argv[a]; |
| 711 |
+ |
if (!f2name) f2name = argv[a+1]; |
| 712 |
|
/* open inputs */ |
| 713 |
|
SET_FILE_BINARY(stdin); /* in case we're using it */ |
| 714 |
|
if (!f1in && !(f1in = fopen(f1name, "rb"))) { |
| 715 |
|
fprintf(stderr, "%s: cannot open for reading\n", f1name); |
| 716 |
< |
return(1); |
| 716 |
> |
return(2); |
| 717 |
|
} |
| 718 |
|
if (!strcmp(f2name, "-")) { |
| 719 |
|
f2in = stdin; |
| 720 |
|
f2name = stdin_name; |
| 721 |
|
} else if (!(f2in = fopen(f2name, "rb"))) { |
| 722 |
|
fprintf(stderr, "%s: cannot open for reading\n", f2name); |
| 723 |
< |
return(1); |
| 723 |
> |
return(2); |
| 724 |
|
} |
| 725 |
|
/* load headers */ |
| 726 |
|
if ((typ1 = identify_type(f1name, f1in, &hdr1)) < 0) |
| 727 |
< |
return(1); |
| 727 |
> |
return(2); |
| 728 |
|
if ((typ2 = identify_type(f2name, f2in, &hdr2)) < 0) |
| 729 |
< |
return(1); |
| 729 |
> |
return(2); |
| 730 |
|
if (typ1 != typ2) { |
| 731 |
|
if (report != REP_QUIET) |
| 732 |
|
printf("%s: '%s' is %s and '%s' is %s\n", |
| 735 |
|
return(1); |
| 736 |
|
} |
| 737 |
|
ign_header |= !has_header(typ1); /* check headers if indicated */ |
| 738 |
< |
if (!ign_header && !headers_match(&hdr1, &hdr2)) |
| 738 |
> |
if (!ign_header && !headers_match()) |
| 739 |
|
return(1); |
| 740 |
|
lu_done(&hdr1); lu_done(&hdr2); |
| 741 |
|
if (!ign_header & (report >= REP_WARN)) { |