1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
int line = 0;
char buffer1[1024];
char buffer2[1024];
void check(bool ok)
{
if (ok)
return;
// fprintf(stderr, "Error in testbench output compare (line=%d):\n-%s\n+%s\n", line, buffer1, buffer2);
exit(1);
}
int main(int argc, char **argv)
{
FILE *f1, *f2;
bool eof1, eof2;
int i;
check(argc == 3);
f1 = fopen(argv[1], "r");
f2 = fopen(argv[2], "r");
check(f1 && f2);
while (!feof(f1) && !feof(f2))
{
line++;
buffer1[0] = 0;
buffer2[0] = 0;
eof1 = fgets(buffer1, 1024, f1) == NULL;
eof2 = fgets(buffer2, 1024, f2) == NULL;
if (*buffer1 && buffer1[strlen(buffer1)-1] == '\n')
buffer1[strlen(buffer1)-1] = 0;
if (*buffer2 && buffer2[strlen(buffer2)-1] == '\n')
buffer2[strlen(buffer2)-1] = 0;
check(eof1 == eof2);
for (i = 0; buffer1[i] || buffer2[i]; i++)
{
check(buffer1[i] != 0 && buffer2[i] != 0);
// first argument is the reference. An 'z' or 'x'
// here means we don't care about the result.
if (buffer1[i] == 'z' || buffer1[i] == 'x')
continue;
check(buffer1[i] == buffer2[i]);
}
}
check(feof(f1) && feof(f2));
fclose(f1);
fclose(f2);
return 0;
}
|