Imported Upstream version 4.6.0
[debian/atlc] / tools / src / locatediff.c
1 /*
2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers. 
4
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_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,
20 USA.
21
22 Dr. David Kirkby, e-mail drkirkby at ntlworld.com 
23
24 */
25 #include "config.h"
26
27 #ifdef HAVE_STDIO_H
28 #include <stdio.h>
29 #endif
30
31 #ifdef HAVE_STDLIB_H
32 #include <stdlib.h>
33 #endif
34
35 int main (int argc, char **argv)
36 {
37   FILE *fp1, *fp2;
38   unsigned char *mem1, *mem2;
39   long length1, length2, i;
40
41   if (argc != 3)
42   {
43     fprintf(stderr,"Usage file1 file2 - finds the difference between them\n");
44     exit(1);
45   }
46   if( (fp1=fopen(argv[1],"rb")) == NULL)
47   {
48     fprintf(stderr,"Unable to open %s\n", argv[1]);
49     exit(1);
50   }
51   if( (fp2=fopen(argv[2],"rb")) == NULL)
52   {
53     fprintf(stderr,"Unable to open %s\n", argv[2]);
54     exit(1);
55   }
56   if( fseek(fp1,0,SEEK_END) == -1) 
57   {
58     fprintf(stderr,"fseek failure on fp1 in locatediff.c\n");
59     exit(1);
60   }
61   if( fseek(fp2,0,SEEK_END) == -1) 
62   {
63     fprintf(stderr,"fseek failure on fp2 in locatediff.c\n");
64     exit(1);
65   }
66   if ((length1=ftell(fp1)) == -1)
67   {
68     fprintf(stderr,"Unable to determine file pointer position with ftelll on fp1\n");
69     exit(1);
70   }
71   if ((length2=ftell(fp2)) == -1)
72   {
73     fprintf(stderr,"Unable to determine file pointer position with ftelll on fp2\n");
74     exit(1);
75   }
76   if(length1 != length2)
77   {
78     fprintf(stderr,"file1 and file2 are not of the same length\n");
79     exit(2);
80   }
81   mem1=(unsigned char *) malloc((size_t)length1);
82   if(mem1 == NULL)
83   {
84     fprintf(stderr,"Failed to allocate memory in locatediff #mem1\n");
85     exit(1);
86   }
87   mem2=(unsigned char *) malloc((size_t)length2);
88   if(mem2 == NULL)
89   {
90     fprintf(stderr,"Failed to allocate memory in locatediff #mem2\n");
91     exit(1);
92   }
93   fseek(fp1,0,SEEK_SET);
94   fseek(fp2,0,SEEK_SET);
95   fread((void *) mem1,1,(size_t)length1, fp1);
96   fread((void *) mem2,1,(size_t)length2, fp2);
97   for(i=0; i<length1; ++i)
98   {
99     if(mem1[i] != mem2[i])
100       printf("At offset= %ld file1 = %d file2 = %d difference=%d\n",i,(int) mem1[i],(int) mem2[i],(int) (mem1[i]-mem2[i]));
101   }
102   return(0);
103 }