| 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 */ |
| 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) { |
| 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)) { |
| 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)) { |