{****************************************************************************** * * * File difference printout program * * * * Finds and prints the differences between two binary files. * * The difference is printed as: * * * * location (in hex): file1 / file2 * * * ******************************************************************************} program diff(file2, file1, output); type byte = 0..255; { byte } word = 0..65535; { word } var file1, file2: file of byte; l: word; b1, b2: byte; procedure prthex(f : byte; w : word); var i, j: byte; v: word; begin for i := 1 to f do begin { output digits } v := w; { save word } for j := 1 to f - i do v := v div 16; { extract digit } v := v mod 16; { mask } { convert ascii } if v >= 10 then v := v + (ord('A') - 10) else v := v + ord('0'); write(chr(v)) { output } end end; begin l := 0; { initalize location } reset(file1); { reset the files } reset(file2); while not eof(file1) and not eof(file2) do begin { compare } read(file1, b1); { read from files } read(file2, b2); if b1 <> b2 then begin { different, print } prthex(4, l); { print location } write(': '); { separate } prthex(2, b1); { print file data } write(' / '); prthex(2, b2); writeln { terminate line } end; l := l+1 { next location } end; if not eof(file1) then writeln('File 1 longer than file 2'); if not eof(file2) then writeln('File 2 longer than file 1'); writeln('Function complete') end.