program FILECMPR ; Uses Dos ; const BufSiz = 16384 { 32 sectors } ; var Buf1, Buf2 : array [1..BufSiz] of byte ; File1, File2 : file ; Param1, Param2 : string ; Size1, Size2 : longint ; SRec : SearchRec ; K, ReadCount : word ; procedure QUIT(const N : word) ; const Elevs : array [0..9] of string[27] = ( '0 : Files identical', '1 : File content differs', '2 : File 2 unopenable', '3 : File 1 unopenable', '4 : File 2 is longer', '5 : File 1 is longer', '6 : File 2 not found', '7 : File 1 not found', '8 : Too many parameters', '9') ; begin Writeln('ErrorLevel ', Elevs[N]) ; HALT(N) end {Quit} ; procedure HELP ; begin Writeln( 'FILECMPR File1 File2 x ; returns ErrorLevels, see source "Elevs".'^M^J, ' File names non-wild; x not yet? used.'^M^J, ' (c) J R Stockton www.merlyn.demon.co.uk >= 2005-01-10') ; QUIT(9) end {HELP}; BEGIN ; if ParamCount < 2 then HELP ; if ParamCount > 3 then QUIT(8) ; Param1 := ParamStr(1) ; FindFirst(Param1, AnyFile, SRec) ; if DosError<>0 then QUIT(7) ; Size1 := SRec.Size ; Param2 := ParamStr(2) ; FindFirst(Param2, AnyFile, SRec) ; if DosError<>0 then QUIT(6) ; Size2 := SRec.Size ; if Size1 > Size2 then QUIT(5) ; if Size2 > Size1 then QUIT(4) ; FileMode := 0 ; Assign(File1, Param1) ; {$I-} Reset(File1, 1) {$I+} ; if IOResult <> 0 then QUIT(3) ; Assign(File2, Param2) ; {$I-} Reset(File2, 1) {$I+} ; if IOResult <> 0 then QUIT(2) ; repeat BlockRead(File1, Buf1, BufSiz, ReadCount) ; BlockRead(File2, Buf2, BufSiz, ReadCount) ; for K := 1 to ReadCount do if Buf1[K] <> Buf2[K] then QUIT(1) ; until ReadCount = 0 ; QUIT(0) ; END.