home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacPeople 2003 February 1
/
MACPEOPLE-2003-02-01.ISO.7z
/
MACPEOPLE-2003-02-01.ISO
/
ぶらりオンラインウェアの旅
/
定番ソフト
/
Jedit(OS9)
/
MacroCollectionJ.sea
/
MacroCollection-J
/
書類比較
/
スクリプト解説
< prev
next >
Wrap
Text File
|
2001-01-03
|
5KB
|
146 lines
書類比較マクロ
programmed by Satoshi Matsumoto <satoshi@matsumoto.co.jp>
Jedit4.0で開いている2つの書類のテキストを比較して、違うパラグラフは赤で表示します。フォントやスタイルが違いは無視します。
ーーーーーーーーーーーーーーーー
違いのあるパラグラフを表示する色のRGB値
property colorUnMatch : {65532, 0, 0}
property diffFlag : false
tell application "Jedit4"
Jedit4を前面へ
activate
Jeditのバージョンチェック。Rev4.0.4より古いときは中止
if version < 404 then
preDialog
display dialog "Jedit4.0 Rev4.0.4 以降を使用してください" buttons {" 了解"}
postDialog
error number -128
end if
書類が2枚開いていないときは警告をだして終了
if (count document) < 2 then
preDialog
display dialog "比較する書類2つを先に開いてください。" buttons {" 了解"}
postDialog
error number -128
end if
各変数を初期化
set diffFlag to false
set paraDone1 to 1
set paraDone2 to 1
set maxPara1 to (count paragraphs of document 1)
set maxPara2 to (count paragraphs of document 2)
比較ループ開始
repeat
書類の最後に達したかどうかチェック
if paraDone1 > maxPara1 or paraDone2 > maxPara2 then
書類2が最後に達したときは、書類1の残りの部分を赤色に
if paraDone1 < maxPara1 + 1 then
select paragraphs paraDone1 thru maxPara1 of document 1
my showDifference(1)
end if
書類1が最後に達したときは、書類2の残りの部分を赤色に
if paraDone2 < maxPara2 + 1 then
select paragraphs paraDone2 thru maxPara2 of document 2
my showDifference(2)
end if
exit repeat
end if
それぞれのパラグラフの内容を変数 text1、text2へ保存
set text1 to contents of paragraph paraDone1 of document 1
set text2 to contents of paragraph paraDone2 of document 2
if text1 is text2 then
テキストの内容が同じときは次のパラグラフへ進む
set paraDone1 to paraDone1 + 1
set paraDone2 to paraDone2 + 1
else
テキストの内容が違うとき
text1と同じパラグラフが書類2にあるかどうかをチェック
set thePara2 to paraDone2
repeat
if text1 is contents of paragraph thePara2 of document 2 then
同じパラグラフがあった
exit repeat
end if
set thePara2 to thePara2 + 1
if thePara2 > maxPara2 then
最後まで比較したが同じパラグラフがなかった
exit repeat
end if
end repeat
text2と同じパラグラフが書類1にあるかどうかをチェック
set thePara1 to paraDone1
repeat
if text2 is contents of paragraph thePara1 of document 1 then
同じパラグラフがあった
exit repeat
end if
set thePara1 to thePara1 + 1
if thePara1 > maxPara1 then
最後まで比較したが同じパラグラフがなかった
exit repeat
end if
end repeat
if thePara1 > maxPara1 and thePara2 > maxPara2 then
お互いにどちらのパラグラフも相手の書類に含まれないとき
書類1のパラグラフを選択
select paragraph paraDone1 of document 1
選択流域を赤色に
my showDifference(1)
書類2のパラグラフを選択
select paragraph paraDone2 of document 2
選択流域を赤色に
my showDifference(2)
それぞれ次のパラグラフへ進む
set paraDone1 to paraDone1 + 1
set paraDone2 to paraDone2 + 1
else if thePara2 > maxPara2 then
書類1のパラグラフが書類2には含まれない
書類1のそのパラグラフを赤色へ
select paragraphs paraDone1 thru (thePara1 - 1) of document 1
my showDifference(1)
set paraDone1 to thePara1
else if thePara1 > maxPara1 then
書類2のパラグラフが書類1には含まれない
書類2のそのパラグラフを赤色へ
select paragraphs paraDone2 thru (thePara2 - 1) of document 2
my showDifference(2)
set paraDone2 to thePara2
else if (thePara1 - paraDone1) < (thePara2 - paraDone2) then
書類1の違いのほうがパラグラフ数が少ない
書類1のそのパラグラフを赤色へ
select paragraphs paraDone1 thru (thePara1 - 1) of document 1
my showDifference(1)
set paraDone1 to thePara1
else
書類2の違いのほうがパラグラフ数が少ない
書類2のそのパラグラフを赤色へ
select paragraphs paraDone2 thru (thePara2 - 1) of document 2
my showDifference(2)
set paraDone2 to thePara2
end if
end if
end repeat
if diffFlag then
違いのあったときはビープオンを鳴らす
beep
違いのあったときの終了メッセージをセット
set theResultString to "違いを検出しました"
else
違いのなかったときの終了メッセージをセット
set theResultString to "内容は全く同じです"
end if
終了ダイアログを表示
preDialog
display dialog theResultString buttons {" 了解"}
postDialog
end tell
指定ドキュメント番号の選択部分の表示色をcolorUnMatchに変更するサブルーチン
on showDifference(docNum)
tell application "Jedit4"
set fore color of selection of document docNum to colorUnMatch
end tell
set diffFlag to true
end showDifference