25562
|
1 /*
|
|
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 ).
|
|
4 *
|
|
5 * copyright (c) 2001 Michael Niedermayer
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License
|
|
18 * along with this program; if not, write to the Free Software
|
|
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
20 */
|
3510
|
21
|
|
22 #include <stdio.h>
|
25475
|
23 #include <stdlib.h>
|
3510
|
24
|
25473
|
25 // FIXME: No checks but it is just for debugging so who cares ;)
|
3510
|
26
|
|
27 int main(int argc, char **argv)
|
|
28 {
|
|
29 FILE *f0, *f1;
|
|
30 int dif=0;
|
25474
|
31
|
|
32 if(argc!=3)
|
3510
|
33 {
|
|
34 printf("compare <file1> <file2>\n");
|
|
35 exit(2);
|
|
36 }
|
25474
|
37
|
3510
|
38 f0= fopen(argv[1], "rb");
|
|
39 f1= fopen(argv[2], "rb");
|
25474
|
40
|
3510
|
41 for(;;)
|
|
42 {
|
3524
|
43 short c0;
|
|
44 short c1;
|
|
45 int d;
|
25474
|
46
|
3524
|
47 int e0= fread(&c0, 2, 1, f0);
|
|
48 int e1= fread(&c1, 2, 1, f1);
|
25474
|
49
|
3524
|
50 d=c0-c1;
|
|
51 if(e0==0 && e1==0) break;
|
|
52 if(e0==0 || e1==0)
|
3510
|
53 {
|
|
54 printf("FATAL error, files have different size!\n");
|
|
55 exit(1);
|
|
56 }
|
25474
|
57
|
3510
|
58 if(d<0) d=-d; // ABS
|
|
59 if(d>1)
|
|
60 {
|
25473
|
61 printf("FATAL error, too large a difference found (%d)!\n", d);
|
3510
|
62 exit(1);
|
|
63 }
|
25474
|
64
|
3510
|
65 if(d) dif++;
|
|
66 }
|
25474
|
67
|
3510
|
68 fclose(f0);
|
|
69 fclose(f1);
|
25474
|
70
|
3510
|
71 printf("%d (+/-1)differences found\n", dif);
|
|
72 exit(0);
|
25473
|
73 }
|
|
74
|