25473
|
1 // File written by Michael Niedermayer and it is under GPL.
|
|
2 // Simple file compare program, it finds the number of rounding errors
|
|
3 // and dies if there is too large an error ( ABS(a-b)>1 ).
|
3510
|
4
|
|
5 #include <stdio.h>
|
25475
|
6 #include <stdlib.h>
|
3510
|
7
|
25473
|
8 // FIXME: No checks but it is just for debugging so who cares ;)
|
3510
|
9
|
|
10 int main(int argc, char **argv)
|
|
11 {
|
|
12 FILE *f0, *f1;
|
|
13 int dif=0;
|
25474
|
14
|
|
15 if(argc!=3)
|
3510
|
16 {
|
|
17 printf("compare <file1> <file2>\n");
|
|
18 exit(2);
|
|
19 }
|
25474
|
20
|
3510
|
21 f0= fopen(argv[1], "rb");
|
|
22 f1= fopen(argv[2], "rb");
|
25474
|
23
|
3510
|
24 for(;;)
|
|
25 {
|
3524
|
26 short c0;
|
|
27 short c1;
|
|
28 int d;
|
25474
|
29
|
3524
|
30 int e0= fread(&c0, 2, 1, f0);
|
|
31 int e1= fread(&c1, 2, 1, f1);
|
25474
|
32
|
3524
|
33 d=c0-c1;
|
|
34 if(e0==0 && e1==0) break;
|
|
35 if(e0==0 || e1==0)
|
3510
|
36 {
|
|
37 printf("FATAL error, files have different size!\n");
|
|
38 exit(1);
|
|
39 }
|
25474
|
40
|
3510
|
41 if(d<0) d=-d; // ABS
|
|
42 if(d>1)
|
|
43 {
|
25473
|
44 printf("FATAL error, too large a difference found (%d)!\n", d);
|
3510
|
45 exit(1);
|
|
46 }
|
25474
|
47
|
3510
|
48 if(d) dif++;
|
|
49 }
|
25474
|
50
|
3510
|
51 fclose(f0);
|
|
52 fclose(f1);
|
25474
|
53
|
3510
|
54 printf("%d (+/-1)differences found\n", dif);
|
|
55 exit(0);
|
25473
|
56 }
|
|
57
|