| 75 |
|
lin2cnt += (htp == &hdr2)) |
| 76 |
|
|
| 77 |
|
typedef struct { /* dynamic line buffer */ |
| 78 |
< |
char *ptr; |
| 78 |
> |
char *str; |
| 79 |
|
int len; |
| 80 |
|
int siz; |
| 81 |
|
} LINEBUF; |
| 82 |
|
|
| 83 |
< |
#define init_line(bp) ((bp)->ptr = NULL, (bp)->siz = 0) |
| 83 |
> |
#define init_line(bp) ((bp)->str = NULL, (bp)->siz = 0) |
| 84 |
|
/* 100 MByte limit on line buffer */ |
| 85 |
|
#define MAXBUF (100L<<20) |
| 86 |
|
|
| 110 |
|
read_line(LINEBUF *bp, FILE *fp) |
| 111 |
|
{ |
| 112 |
|
bp->len = 0; |
| 113 |
< |
if (!bp->ptr) { |
| 114 |
< |
bp->ptr = (char *)malloc(bp->siz = 512); |
| 115 |
< |
if (!bp->ptr) |
| 113 |
> |
if (!bp->str) { |
| 114 |
> |
bp->str = (char *)malloc(bp->siz = 512); |
| 115 |
> |
if (!bp->str) |
| 116 |
|
goto memerr; |
| 117 |
|
} |
| 118 |
< |
while (fgets(bp->ptr + bp->len, bp->siz - bp->len, fp)) { |
| 119 |
< |
bp->len += strlen(bp->ptr + bp->len); |
| 120 |
< |
if (bp->ptr[bp->len-1] == '\n') |
| 118 |
> |
while (fgets(bp->str + bp->len, bp->siz - bp->len, fp)) { |
| 119 |
> |
bp->len += strlen(bp->str + bp->len); |
| 120 |
> |
if (bp->str[bp->len-1] == '\n') |
| 121 |
|
break; /* found EOL */ |
| 122 |
|
if (bp->len < bp->siz - 4) |
| 123 |
|
continue; /* at EOF? */ |
| 125 |
|
break; /* don't go to extremes */ |
| 126 |
|
if ((bp->siz += bp->siz/2) > MAXBUF) |
| 127 |
|
bp->siz = MAXBUF; |
| 128 |
< |
bp->ptr = (char *)realloc(bp->ptr, bp->siz); |
| 129 |
< |
if (!bp->ptr) |
| 128 |
> |
bp->str = (char *)realloc(bp->str, bp->siz); |
| 129 |
> |
if (!bp->str) |
| 130 |
|
goto memerr; |
| 131 |
|
} |
| 132 |
|
return(bp->len); |
| 141 |
|
static void |
| 142 |
|
free_line(LINEBUF *bp) |
| 143 |
|
{ |
| 144 |
< |
bp->len = 0; |
| 145 |
< |
if (!bp->ptr) return; |
| 146 |
< |
free(bp->ptr); |
| 147 |
< |
bp->ptr = NULL; |
| 144 |
> |
if (bp->str) free(bp->str); |
| 145 |
> |
init_line(bp); |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
/* Get type ID from name (or 0 if not found) */ |
| 504 |
|
init_line(&l1buf); init_line(&l2buf); /* compare a line at a time */ |
| 505 |
|
while (read_line(&l1buf, f1in)) { |
| 506 |
|
lin1cnt++; |
| 507 |
< |
if (!*sskip2(l1buf.ptr,0)) |
| 507 |
> |
if (!*sskip2(l1buf.str,0)) |
| 508 |
|
continue; /* ignore empty lines */ |
| 509 |
|
|
| 510 |
|
while (read_line(&l2buf, f2in)) { |
| 511 |
|
lin2cnt++; |
| 512 |
< |
if (*sskip2(l2buf.ptr,0)) |
| 512 |
> |
if (*sskip2(l2buf.str,0)) |
| 513 |
|
break; /* found other non-empty line */ |
| 514 |
|
} |
| 515 |
< |
if (feof(f2in)) { |
| 515 |
> |
if (!l2buf.len) { /* input 2 EOF? */ |
| 516 |
|
if (report != REP_QUIET) { |
| 517 |
|
fputs(f2name, stdout); |
| 518 |
|
fputs(": unexpected end-of-file\n", stdout); |
| 521 |
|
return(0); |
| 522 |
|
} |
| 523 |
|
/* compare non-empty lines */ |
| 524 |
< |
if (!equiv_string(l1buf.ptr, l2buf.ptr)) { |
| 524 |
> |
if (!equiv_string(l1buf.str, l2buf.str)) { |
| 525 |
|
if (report != REP_QUIET) { |
| 526 |
|
printf("%s: inputs '%s' and '%s' differ at line %d|%d\n", |
| 527 |
|
progname, f1name, f2name, |
| 531 |
|
(l2buf.len < 256) ) { |
| 532 |
|
fputs("------------- Mismatch -------------\n", stdout); |
| 533 |
|
printf("%s@%d:\t%s", f1name, |
| 534 |
< |
lin1cnt, l1buf.ptr); |
| 534 |
> |
lin1cnt, l1buf.str); |
| 535 |
|
printf("%s@%d:\t%s", f2name, |
| 536 |
< |
lin2cnt, l2buf.ptr); |
| 536 |
> |
lin2cnt, l2buf.str); |
| 537 |
|
} |
| 538 |
|
} |
| 539 |
|
free_line(&l1buf); free_line(&l2buf); |
| 540 |
|
return(0); |
| 541 |
|
} |
| 542 |
|
} |
| 543 |
< |
/* check for EOF on input 2 */ |
| 543 |
> |
free_line(&l1buf); /* check for EOF on input 2 */ |
| 544 |
|
while (read_line(&l2buf, f2in)) { |
| 545 |
< |
if (!*sskip2(l2buf.ptr,0)) |
| 545 |
> |
if (!*sskip2(l2buf.str,0)) |
| 546 |
|
continue; |
| 547 |
|
if (report != REP_QUIET) { |
| 548 |
|
fputs(f1name, stdout); |
| 549 |
|
fputs(": unexpected end-of-file\n", stdout); |
| 550 |
|
} |
| 551 |
< |
free_line(&l1buf); free_line(&l2buf); |
| 551 |
> |
free_line(&l2buf); |
| 552 |
|
return(0); |
| 553 |
|
} |
| 554 |
< |
free_line(&l1buf); free_line(&l2buf); |
| 554 |
> |
free_line(&l2buf); |
| 555 |
|
return(good_RMS()); /* final check for reals */ |
| 556 |
|
} |
| 557 |
|
|