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-01  |  2KB  |  60 lines

  1. 分割保存マクロ
  2. programmed by Satoshi Matsumoto <satoshi@matsumoto.co.jp>
  3. Jedit4.0で開いている書類を分割保存します。分割境界は正規表現で指定します。
  4.  
  5. ーーーーーーーーーーーー
  6. 分割境界の正規表現、デフォルト値
  7. property borderString : "^-- cut here --"
  8.  
  9. tell application "Jedit4"
  10.     Jeditのバージョンが4.0.4以上かどうかをチェック。そうでない時は中止。
  11.     if version < 404 then
  12.         preDialog
  13.         display dialog "Jedit4.0 Rev4.0.4 以降を使用してください" buttons {" 了解"}
  14.         postDialog
  15.         error number -128
  16.     end if
  17.     Jeditの書類を前面へ
  18.     activate
  19.     書類はなにも開いていないときは警告をだして終了
  20.     if (count document) < 1 then
  21.         preDialog
  22.         display dialog "分割保存する書類を先に開いてください。" buttons {" 了解"}
  23.         postDialog
  24.         error number -128
  25.     end if
  26.     preDialog
  27.     try
  28.         ダイアログで、分割境界の正規表現を指定する
  29.         set borderString to text returned of (display dialog "分割境界の先頭パターンを正規表現で指定してください" default answer borderString)
  30.     on error
  31.         キャンセルボタンを押したときは終了
  32.         postDialog
  33.         error number -128
  34.     end try
  35.     postDialog
  36.     tell document 1
  37.         文字変数thePathにファイルのパス名を保存
  38.         set thePath to fileSpec as text
  39.         各変数を初期化
  40.         set theCount to 0
  41.         set theMatchLen to 0
  42.         set startOff to 1
  43.         set endOff to (count bytes)
  44.         分割境界文字列が見つかるまでrepeat文で繰り返す
  45.         repeat while (((startOff + theMatchLen) < endOff) and (find borderString in bytes (startOff + theMatchLen) thru endOff with grep without wrap around))
  46.             見つかったので、カウンタをインクレメント
  47.             set theCount to theCount + 1
  48.             set newOff to byteoffset of the selection
  49.             set theMatchLen to (length of the selection)
  50.             そのstartOffから(newOff - 1)までの部分を、ファイル名に連番をつけて保存
  51.             save (bytes startOff thru (newOff - 1)) in file (thePath & "_" & theCount)
  52.             set startOff to newOff
  53.         end repeat
  54.         if startOff < endOff then
  55.             まだ保存していない最後の部分を保存
  56.             set theCount to theCount + 1
  57.             save ( bytes startOff thru endOff ) in file (thePath & "_" & theCount)
  58.         end if
  59.     end tell
  60. end tell