˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙//************************************************************* ********** //* //* Název makra: Porovnávání dvou souborů //* Autor: Software602 a.s. //* Datum vytvoření: 17.12.1996 //* //* Název souboru: //* Název programu: //* Tisk: //* //* Popis: Makro hledá první rozdíl ve dvou otevřených //* dokumentech //* //************************************************************* *****mt*** Program Porovnání; const MAXLEN = 200; MAXSTR = 15; ERR_NONE = 0; ERR_WND_CLOSED_1 = -1; ERR_WND_CLOSED_2 = -2; ERR_DOC_FREE = -3; var oldPos1, oldPos2 : integer; // pozice caretu při startu makra endPos : integer; // konec dokumentu title1, title2 : string[127]; // titulek dokumentů err : integer; difference, line : integer; wnd : short; // aktivní okno text1, text2 : array[1..MAXSTR] of string[MAXLEN]; countLn1,countLn2: short; other1,other2 : short; procedure PrepareMDI; var ePos1, ePos2 : integer; cursorPos : boolean; begin wnd := 1; WindowsTile; cursorPos := Yesno_box('Compare', 'Kontrolovat od pozice kurzoru?'); { první dokument : } oldPos1 := GetCaretPos; CaretEnd; ePos1 := GetCaretPos; if (cursorPos) then begin CaretHome; CharRight(oldPos1); LeftOfLine; end else CaretHome; title1 := GetDocWndTittle; { druhý dokument : } NextWindow; oldPos2 := GetCaretPos; CaretEnd; ePos2 := GetCaretPos; CaretHome; if (cursorPos) then begin CharRight(oldPos1); LeftOfLine; end; title2 := GetDocWndTittle; { zjištění konce dokumentu : } if (ePos2 < ePos1) then endPos := ePos2 else endPos := ePos1; end; function SetWindow(newWin:integer):boolean; var result : boolean; begin case (newWin) of 1: begin result := SwitchToWindow(title1, false); wnd := 1; end; 2: begin result := SwitchToWindow(title2, false); wnd := 2; end; else: result := false; end; SetWindow := result; end; procedure ChewError; var msg : string[MAXLEN]; begin msg := ''; case (err) of ERR_WND_CLOSED_1: msg := "Nepodařilo se aktivovat okno "+title1+"!"; ERR_WND_CLOSED_2: msg := "Nepodařilo se aktivovat okno "+title2+"!"; ERR_DOC_FREE: msg := "Dokument je prázdný!"; else: msg := "Neznámá chyba: " + int2str(err); end; { case } if (msg <> '') then Info_box('Chyba', msg); end; function GetString(window:short):short; var p,p2:integer; i:short; konec : boolean; begin i := 1; konec := false; while ((i <= MAXSTR) and not(konec)) do begin LeftOfLine; p := GetCaretPos; RightOfLine; p2 := GetCaretPos; konec := (p2 = endPos); case (window) of 1: text1[i] := GetText(p,p2); 2: text2[i] := GetText(p,p2); end; { case } inc(i); case (window) of 1: if (LineDown) then other1 := 1 else begin other1 := 0; konec := true; end; 2: if (LineDown) then other2 := 1 else begin other2 := 0; konec := true; end; end; end; { while } GetString := (i-1); end; function GetDifference(var ln:integer):integer; var i, j, result : integer; konec, diff : boolean; len : integer; s1, s2 : string[MAXLEN]; s : string[MAXLEN+MAXLEN]; begin j := 1; diff := false; result := 0; while (j <= MAXSTR) and not(diff) do begin i := 1; konec := false; s1 := text1[j]; s2 := text2[j]; if (StrLength(s1) < StrLength(s2)) then len := StrLength(s2) else len := StrLength(s1); if (s1 <> s2) and not((StrLength(s1) = 0) and (StrLength(s2) = 0)) then begin while not(konec) and (i <= len) do begin if (s1[i] <> s2[i]) then begin konec := true; diff := true; result := i; s := s1 + #13#10 + s2; info_box('Rozdílné řetězce', s); end else inc(i); end; { while } end; { if } if not(diff) then inc(j); end; { while } if (diff) then ln := j else ln := 0; GetDifference := result; end; procedure Compare; var konec : boolean; pos : integer; tmp : short; begin konec := false; err := ERR_NONE; difference := 0; pos := GetCaretPos; if (pos = endPos) then begin err := ERR_DOC_FREE; konec := true; end; while not(konec) and (pos < endPos) do begin { 1 } if not(SetWindow(1)) then begin konec := true; err := ERR_WND_CLOSED_1; end else countLn1 := GetString(wnd); { 2 } if not(SetWindow(2)) then begin konec := true; err := ERR_WND_CLOSED_2; end else countLn2 := GetString(wnd); { compare : } if not(konec) then begin difference := GetDifference(line); if (difference <> 0) then begin /* nalezen rozdíl : */ LeftOfLine; SetWindow(2); konec := true; end; end; { !konec } pos := GetCaretPos; end; { while } end; procedure SetPosInLine(p:integer); var pos1, pos2, len : integer; begin RightOfLine; pos1 := GetCaretPos; LeftOfLine; pos2 := GetCaretPos; len := pos1 - pos2; if (len > p) then CharRight(p) else RightOfLine; end; procedure SetPosDiff; var i : short; begin i := 1; { 2 } if not(wnd = 2) then SetWindow(2); LineUp(countLn2-line+other2); SetPosInLine(difference-1); { 1 } SetWindow(1); LineUp(countLn1-line+other1); SetPosInLine(difference-1); end; begin if (CountWindows <> 2) then Info_box('Zpráva', 'Počet otevřených dokumentů musí být roven 2 !') else begin PrepareMDI; Compare; if (difference <> 0) then begin SetPosDiff; //Info_box('Zpráva', 'Nalezen rozdíl.') end else begin SetWindow(2); CaretHome; CharRight(oldPos2); SetWindow(1); CaretHome; CharRight(oldPos1); if (err <> ERR_NONE) then ChewError else Info_box('Zpráva', 'Dokumenty jsou shodné.'); end; // DocMaximize; end; end.