(* * 83pv SpChar to 90pv ver 0.1 * written by: Sasaki Atsushi * last modified: Sat, 23-Feb-2002 * * This script requires: * o Jedit3 ; * * Latest Version: *) -- -- HEX to DEC handler on hex2dec(theHEX) set theDEC to 0 repeat with i from 1 to (length of theHEX) set theChar to (character -i of theHEX) repeat with j from 0 to 15 if (character (j + 1) of "0123456789ABCDEF") = theChar then exit repeat end repeat set theDEC to theDEC + j * (16 ^ (i - 1)) end repeat return theDEC end hex2dec -- DEC to HEX handler on dec2Hex(theDEC) if theDEC = 0 then return "" return dec2Hex(theDEC div 16) & (character ((theDEC mod 16) + 1) of "0123456789ABCDEF") end dec2Hex set fl to {} -- finding character list set rl to {} -- replacing character list -- 丸付き数字の検索文字列 (ShiftJIS:0x8740-0x8753) と置換文字列をリストに格納 repeat with i from hex2dec("8740") to hex2dec("8753") set fl to fl & dec2Hex(i) set rl to rl & dec2Hex(i - 512) end repeat -- ローマ数字の検索文字列 (ShiftJIS:0x8754-0x875D) と置換文字列 (ShiftJIS:0x85A0-0x85AD) をリストに格納 repeat with i from hex2dec("8754") to hex2dec("875D") set fl to fl & dec2Hex(i) set rl to rl & dec2Hex(i - 437) end repeat -- 省略単位文字 (カナ) の検索文字列と置換文字列をリストに格納 -- ミリ set fl to fl & "875F" set rl to rl & "879F" -- キロ set fl to fl & "8760" set rl to rl & "87A2" -- センチ set fl to fl & "8761" set rl to rl & "87A0" -- メートル set fl to fl & "8762" set rl to rl & "87A1" -- グラム set fl to fl & "8763" set rl to rl & "87A9" -- トン set fl to fl & "8764" set rl to rl & "87AB" -- アール set fl to fl & "8765" set rl to rl & "87A7" -- ヘクタール set fl to fl & "8766" set rl to rl & "87A8" -- リットル set fl to fl & "8767" set rl to rl & "87AC" -- ワット set fl to fl & "8768" set rl to rl & "87AF" -- カロリー set fl to fl & "8769" set rl to rl & "87B0" -- ドル set fl to fl & "876A" set rl to rl & "87B3" -- セント set fl to fl & "876B" set rl to rl & "87B2" -- パーセント set fl to fl & "876C" set rl to rl & "87B5" -- ミリバール set fl to fl & "876D" set rl to rl & "87AD" -- ページ set fl to fl & "876E" set rl to rl & "87B4" -- 省略単位文字 (Roman) の検索文字列と置換文字列をリストに格納 -- mm set fl to fl & "876F" set rl to rl & "8640" -- cm set fl to fl & "8770" set rl to rl & "8642" -- km set fl to fl & "8771" set rl to rl & "8648" -- mg set fl to fl & "8772" set rl to rl & "864A" -- kg set fl to fl & "8773" set rl to rl & "864C" -- cc set fl to fl & "8774" set rl to rl & "864D" -- m^2 set fl to fl & "8775" set rl to rl & "8646" -- Quartation Signs の検索文字列と置換文字列をリストに格納 set fl to fl & {"8780", "8781"} set rl to rl & {"8854", "8855"} -- 「No.」「K.K.」「TEL」の検索文字列 (ShiftJIS:0x8782-0x8784) と置換文字列 (ShiftJIS:0x869B-0x869D) をリストに格納 repeat with i from hex2dec("8782") to hex2dec("8784") set fl to fl & dec2Hex(i) set rl to rl & dec2Hex(i - 231) end repeat -- 丸付き「上」「中」「下」「左」「右」の検索文字列(ShiftJIS:0x8785-0x8789)と置換文字列(ShiftJIS:0x8793-0x8797)をリストに格納 repeat with i from hex2dec("8785") to hex2dec("8789") set fl to fl & dec2Hex(i) set rl to rl & dec2Hex(i + 14) end repeat -- (株), (有), (代) の検索文字列と置換文字列をリストに格納 -- (株): ShiftJIS:0x878A -> ShiftJIS:0x874D set fl to fl & "878A" set rl to rl & "874D" -- (有): ShiftJIS:0x878B -> ShiftJIS:0x8750 set fl to fl & "878B" set rl to rl & "8750" -- (代): ShiftJIS:0x878C -> ShiftJIS:0x874B set fl to fl & "878C" set rl to rl & "874B" -- 元号の検索文字列 (ShiftJIS:0x878D-0x878F) と置換文字列 (ShiftJIS:0x87E5-0x87E7) をリストに格納 repeat with i from hex2dec("878D") to hex2dec("878F") set fl to fl & dec2Hex(i) set rl to rl & dec2Hex(i + 88) end repeat -- 学術記号の検索文字列と置換文字列をリストに格納 -- nearly equal (ほぼ等しい): ShiftJIS:0x8790 -> 0x81E0 set fl to fl & "8790" set rl to rl & "81E0" -- 合同: ShiftJIS:0x8791 -> 0x81DF set fl to fl & "8791" set rl to rl & "81DF" -- インテグラル: ShiftJIS:0x8792 -> 0x81E7 set fl to fl & "8792" set rl to rl & "81E7" -- (読み不明): ShiftJIS:0x8793 -> 0x8840 set fl to fl & "8793" set rl to rl & "8840" -- シグマ: ShiftJIS:0x8794 -> 0x83B0 set fl to fl & "8794" set rl to rl & "83B0" -- ルート: ShiftJIS:0x8795 -> 0x81E3 set fl to fl & "8795" set rl to rl & "81E3" -- 垂直: ShiftJIS:0x8796 -> 0x81DB set fl to fl & "8796" set rl to rl & "81DB" -- 角: ShiftJIS:0x8797 -> 0x81DA set fl to fl & "8797" set rl to rl & "81DA" -- (読み不明): ShiftJIS:0x8798 -> 0x8841 set fl to fl & "8798" set rl to rl & "8841" -- (読み不明): ShiftJIS:0x8799 -> 0x8842 set fl to fl & "8799" set rl to rl & "8842" -- なぜならば・なんとなれば: ShiftJIS:0x879A -> 0x879A set fl to fl & "879A" set rl to rl & "81E6" -- 交わり: ShiftJIS:0x879A -> 0x81BF set fl to fl & "879B" set rl to rl & "81BF" -- 結び: ShiftJIS:0x879C -> 0x81BE set fl to fl & "879C" set rl to rl & "81BE" -- 置換した文字数を初期化 set r to 0 -- 83pv -> 90pv tell application "Jedit3" if not (exists document 1) then display dialog "ファイルが一つも開かれていません。" & return & "このスクリプトは処理を終了します。" buttons "終了" default button "終了" with icon stop return else display dialog "処理方法を決めて下さい。" & return & "1 ステップごと:実行後に変換した文字を確認できます。" & return & "一括置換:高速処理" buttons {"キャンセル", "1 文字ごと", "一括置換"} default button "一括置換" with icon note if button returned of the result is "一括置換" then set mode to 0 else if button returned of the result is "1 文字ごと" then set mode to 1 else return end if tell document 1 inhibit redraw set i to 0 set iMax to length of fl repeat until i = iMax set i to i + 1 set fi to "¥¥h" & item i of reverse of fl as string set ri to "¥¥h" & item i of reverse of rl as string if mode = 0 then replace fi to ri in paragraphs 1 thru -1 with grep set r to r + result else repeat find fi in paragraphs 1 thru -1 with grep if result is false then exit repeat end if replace fi to ri in selection set r to r + 1 end repeat end if end repeat allow redraw display dialog (r as string) & " カ所置換しました。" with icon note buttons {"復帰", "完了"} default button "完了" if button returned of the result is "復帰" then inhibit redraw repeat (r as number) times undo end repeat allow redraw end if end tell end if end tell -- EOF