Ticket #9: DATVERGL.PAS

File DATVERGL.PAS, 3.3 KB (added by M. Seidel, 16 years ago)

source

Line 
1uses dos,crt;
2
3const size=32768;
4 digits:array[0..$F] of char =('0','1','2','3','4','5','6','7',
5 '8','9','A','B','C','D','E','F');
6
7type pdata=array[0..size] of byte;
8
9var d1,d2:^pdata;
10 f1,f2:file;
11 f3:text;
12 gel1,gel2,work:word;
13 focnt,todo,done,diffs,i:longint;
14 follo:boolean;
15
16
17function strx(wert:longint;len:byte):string;
18var s:string;
19begin
20
21 str(wert,s);
22
23 while s[0]<chr(len) do s:=' '+s;
24
25 strx:=s;
26
27end;
28
29
30function w2x(x:word):string;
31var i:word;
32 s:string[7];
33begin
34
35 i:=4;
36 s[0]:=chr(i);
37 repeat
38 s[i]:=digits[x and $000F];
39 x:=x shr 4;
40 dec(i);
41 until i=0;
42
43 w2x:=s;
44end;
45
46
47
48function d2x(x:longint):string;
49var i:word;
50 s:string[9];
51begin
52
53 i:=8;
54 s[0]:=chr(i);
55 repeat
56 s[i]:=digits[x and $000F];
57 x:=x shr 4;
58 dec(i);
59 until i=0;
60
61 d2x:=s;
62end;
63
64
65
66
67function b2x(x:word):string;
68var i:word;
69 s:string[7];
70begin
71
72 i:=2;
73 s[0]:=chr(i);
74 repeat
75 s[i]:=digits[x and $000F];
76 x:=x shr 4;
77 dec(i);
78 until i=0;
79
80 b2x:='0x'+s;
81end;
82
83
84begin
85 getmem(d1,size);
86 getmem(d2,size);
87
88
89 writeln('V1.0 by M.S. 12/08');
90
91 if paramcount<2 then
92 begin
93 writeln('komplette pfade der zu vergleichenden Dateien angeben');
94 halt;
95 end;
96
97
98 assign(f1,paramstr(1));
99 reset(f1,1);
100 if ioresult<>0 then
101 begin
102 writeln('kann "',paramstr(1),'" nicht ”ffnen');
103 halt;
104 end;
105
106
107 assign(f2,paramstr(2));
108 reset(f2,1);
109 if ioresult<>0 then
110 begin
111 close(f1);
112 writeln('kann "',paramstr(2),'" nicht ”ffnen');
113 halt;
114 end;
115
116
117 todo:=filesize(f1);
118
119 if todo<>filesize(f2) then
120 begin
121 close(f1);
122 close(f2);
123 writeln('"',paramstr(1),'" und "',paramstr(2),'" mssen gleich groá sein');
124 halt;
125 end;
126
127 if todo=0 then
128 begin
129 close(f1);
130 close(f2);
131 writeln('"',paramstr(1),'" und "',paramstr(2),'" sind 0 Bytes groá');
132 halt;
133 end;
134
135
136
137 assign(f3,'datvergl.txt');
138 rewrite(f3);
139
140 follo:=false;
141 focnt:=0;
142 done :=0;
143 diffs:=0;
144 repeat
145
146 if todo>size then work:=size else work:=todo;
147
148 if work>0 then
149 begin
150 blockread(f1,d1^,work,gel1);
151 blockread(f2,d2^,work,gel2);
152
153 if (gel1<>work) or (gel2<>work) then
154 begin
155 close(f1);
156 close(f2);
157 close(f3);
158 writeln('Fehler beim Lesen');
159 halt;
160 end;
161
162 i:=0;
163 repeat
164 if d1^[i]<>d2^[i] then
165 begin
166 inc(diffs);
167 inc(focnt);
168 if diffs=1 then writeln(f3,'Adresse Data1 Data2 Count Follow');
169 writeln(f3,d2x(done+i),' ',b2x(d1^[i]),' != ',b2x(d2^[i]),strx(diffs,11),strx(focnt,11));
170 end
171 else focnt:=0;
172
173 inc(i);
174 until i=work;
175
176 dec(todo,work);
177 inc(done,work)
178
179 end;
180
181 until todo=0;
182
183 if diffs>0 then
184 begin
185 writeln( diffs,' Unterschiede gefunden, siehe "datvergl.txt"');
186 writeln(f3,diffs,' Unterschiede gefunden');
187 end
188 else
189 begin
190 writeln('Dateien stimmen berein!')
191 end;
192
193 close(f1);
194 close(f2);
195 close(f3);
196
197end.