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 >
Text File  |  2001-01-03  |  5KB  |  146 lines

  1. 書類比較マクロ
  2. programmed by Satoshi Matsumoto <satoshi@matsumoto.co.jp>
  3. Jedit4.0で開いている2つの書類のテキストを比較して、違うパラグラフは赤で表示します。フォントやスタイルが違いは無視します。
  4.  
  5. ーーーーーーーーーーーーーーーー
  6.  
  7. 違いのあるパラグラフを表示する色のRGB値
  8. property colorUnMatch : {65532, 0, 0}
  9. property diffFlag : false
  10.  
  11. tell application "Jedit4"
  12.     Jedit4を前面へ
  13.     activate
  14.     Jeditのバージョンチェック。Rev4.0.4より古いときは中止
  15.     if version < 404 then
  16.         preDialog
  17.         display dialog "Jedit4.0 Rev4.0.4 以降を使用してください" buttons {" 了解"}
  18.         postDialog
  19.         error number -128
  20.     end if
  21.     書類が2枚開いていないときは警告をだして終了
  22.     if (count document) < 2 then
  23.         preDialog
  24.         display dialog "比較する書類2つを先に開いてください。" buttons {" 了解"}
  25.         postDialog
  26.         error number -128
  27.     end if
  28.     各変数を初期化
  29.     set diffFlag to false
  30.     set paraDone1 to 1
  31.     set paraDone2 to 1
  32.     set maxPara1 to (count paragraphs of document 1)
  33.     set maxPara2 to (count paragraphs of document 2)
  34.     比較ループ開始
  35.     repeat
  36.         書類の最後に達したかどうかチェック
  37.         if paraDone1 > maxPara1 or paraDone2 > maxPara2 then
  38.             書類2が最後に達したときは、書類1の残りの部分を赤色に
  39.             if paraDone1 < maxPara1 + 1 then
  40.                 select paragraphs paraDone1 thru maxPara1 of document 1
  41.                 my showDifference(1)
  42.             end if
  43.             書類1が最後に達したときは、書類2の残りの部分を赤色に
  44.             if paraDone2 < maxPara2 + 1 then
  45.                 select paragraphs paraDone2 thru maxPara2 of document 2
  46.                 my showDifference(2)
  47.             end if
  48.             exit repeat
  49.         end if
  50.         それぞれのパラグラフの内容を変数 text1、text2へ保存
  51.         set text1 to contents of paragraph paraDone1 of document 1
  52.         set text2 to contents of paragraph paraDone2 of document 2
  53.         if text1 is text2 then
  54.             テキストの内容が同じときは次のパラグラフへ進む
  55.             set paraDone1 to paraDone1 + 1
  56.             set paraDone2 to paraDone2 + 1
  57.         else
  58.             テキストの内容が違うとき
  59.             text1と同じパラグラフが書類2にあるかどうかをチェック
  60.             set thePara2 to paraDone2
  61.             repeat
  62.                 if text1 is contents of paragraph thePara2 of document 2 then
  63.                     同じパラグラフがあった
  64.                     exit repeat
  65.                 end if
  66.                 set thePara2 to thePara2 + 1
  67.                 if thePara2 > maxPara2 then
  68.                     最後まで比較したが同じパラグラフがなかった
  69.                     exit repeat
  70.                 end if
  71.             end repeat
  72.             text2と同じパラグラフが書類1にあるかどうかをチェック
  73.             set thePara1 to paraDone1
  74.             repeat
  75.                 if text2 is contents of paragraph thePara1 of document 1 then
  76.                     同じパラグラフがあった
  77.                     exit repeat
  78.                 end if
  79.                 set thePara1 to thePara1 + 1
  80.                 if thePara1 > maxPara1 then
  81.                     最後まで比較したが同じパラグラフがなかった
  82.                     exit repeat
  83.                 end if
  84.             end repeat
  85.             if thePara1 > maxPara1 and thePara2 > maxPara2 then
  86.                 お互いにどちらのパラグラフも相手の書類に含まれないとき
  87.                 書類1のパラグラフを選択
  88.                 select paragraph paraDone1 of document 1
  89.                 選択流域を赤色に
  90.                 my showDifference(1)
  91.                 書類2のパラグラフを選択
  92.                 select paragraph paraDone2 of document 2
  93.                 選択流域を赤色に
  94.                 my showDifference(2)
  95.                 それぞれ次のパラグラフへ進む
  96.                 set paraDone1 to paraDone1 + 1
  97.                 set paraDone2 to paraDone2 + 1
  98.             else if thePara2 > maxPara2 then
  99.                 書類1のパラグラフが書類2には含まれない
  100.                 書類1のそのパラグラフを赤色へ
  101.                 select paragraphs paraDone1 thru (thePara1 - 1) of document 1
  102.                 my showDifference(1)
  103.                 set paraDone1 to thePara1
  104.             else if thePara1 > maxPara1 then
  105.                 書類2のパラグラフが書類1には含まれない
  106.                 書類2のそのパラグラフを赤色へ
  107.                 select paragraphs paraDone2 thru (thePara2 - 1) of document 2
  108.                 my showDifference(2)
  109.                 set paraDone2 to thePara2
  110.             else if (thePara1 - paraDone1) < (thePara2 - paraDone2) then
  111.                 書類1の違いのほうがパラグラフ数が少ない
  112.                 書類1のそのパラグラフを赤色へ
  113.                 select paragraphs paraDone1 thru (thePara1 - 1) of document 1
  114.                 my showDifference(1)
  115.                 set paraDone1 to thePara1
  116.             else
  117.                 書類2の違いのほうがパラグラフ数が少ない
  118.                 書類2のそのパラグラフを赤色へ
  119.                 select paragraphs paraDone2 thru (thePara2 - 1) of document 2
  120.                 my showDifference(2)
  121.                 set paraDone2 to thePara2
  122.             end if
  123.         end if
  124.     end repeat
  125.     if diffFlag then
  126.         違いのあったときはビープオンを鳴らす
  127.         beep
  128.         違いのあったときの終了メッセージをセット
  129.         set theResultString to "違いを検出しました"
  130.     else
  131.         違いのなかったときの終了メッセージをセット
  132.         set theResultString to "内容は全く同じです"
  133.     end if
  134.     終了ダイアログを表示
  135.     preDialog
  136.     display dialog theResultString buttons {" 了解"}
  137.     postDialog
  138. end tell
  139.  
  140. 指定ドキュメント番号の選択部分の表示色をcolorUnMatchに変更するサブルーチン
  141. on showDifference(docNum)
  142.     tell application "Jedit4"
  143.         set fore color of selection of document docNum to colorUnMatch
  144.     end tell
  145.     set diffFlag to true
  146. end showDifference