<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://hetima.com/pblog/rss/style.css" type="text/css"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:content="http://purl.org/rss/1.0/modules/content/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xml:lang="ja">
<channel rdf:about="http://hetima.com/pblog/rss/1.0.php?id=87">
<title>ヘチマ_BLOG</title>
<link>http://hetima.com/pblog/index.php</link>
<dc:date>2005-07-25T06:12:14+09:00</dc:date>
<description>
ヘチマ_BLOG - RSS (RDF Site Summary).
</description>
<items>
<rdf:Seq>
<rdf:li rdf:resource="http://hetima.com/pblog/article.php?id=87" />
</rdf:Seq>
</items>
</channel>
<item>
<title>FileMerge.app でテキストエンコーディング自動判別</title>
<link>http://hetima.com/pblog/article.php?id=87</link>
<dc:date>2005-07-25T06:12:14+09:00</dc:date>
<description>Developer Tools に付属する FileMerge.app はテキストファイルの日本語対応が駄目で、Shift JIS しか扱えない。改善するぞ。

Preferences... で拡張子ごとに Filter を設定できるよ...</description>
<content:encoded>
<![CDATA[
<p>Developer Tools に付属する FileMerge.app はテキストファイルの日本語対応が駄目で、Shift JIS しか扱えない。改善するぞ。
</p>
<p>Preferences... で拡張子ごとに Filter を設定できるようになっている。エンコーディングを判別して変換するスクリプトを書いてテキストファイルの Filter に設定すれば良さそうだ。php で以下のようなスクリプトを書いた（うちは <a href="http://www.entropy.ch/software/macosx/php/">entropy のパッケージ</a> を入れているので、php のパスは「/usr/local/php5/bin/php」とした）。
</p>
<pre>#!/usr/bin/php
&lt;?php
    $body=file_get_contents($argv[1]);
    //改行コードもついでに変換
    $body = str_replace(&quot&yen;r&yen;n&quot, &quot&yen;n&quot, $body);
    $body = str_replace(&quot&yen;r&quot, &quot&yen;n&quot, $body);
    echo mb_convert_encoding($body,&quot;sjis&quot;,&quot;auto&quot;);
?&gt;
</pre>
<p>適当な場所に保存してパーミッションを 755 にしておく。FileMerge の Filter 設定を新規に追加し「Display」は「Filtered」、「Apply」はよく分からないので「No」に。「Filter」は「/path/to/script $(FILE)」という風にする。必要な拡張子の数だけ同じ設定を増やす。これで見事に自動判別されるようになる。ちなみに追加の仕方は、最後の1行が常に空白になっているのでそこに記入していく。</p>
<p>追記：<br />
nkf を入れている人ならわざわざスクリプトを書くまでもないなというわけで、入れてなかったので入れてみた。どこが本家なのかよく分からんがとりあえず <a href="http://sourceforge.jp/projects/nkf/">sourceforge.jp に nkf というプロジェクトがあった</a> のでここから 2.0.5 のソースを落とす。make 一発でビルド完了。「nkf --help」でヘルプを見ると UTF-8 も扱えるみたいだ。/usr 以下はあまりいじりたくないので ~/usr/bin にコピー。FileMerge の「Filter」は、<br />
/path/to/nkf -sLu $(FILE)<br />
とした。「s」は Shift JIS に変換、「Lu」は改行コードを LF に変換するという意味。結果これもばっちり成功。
</p>
]]>
</content:encoded>
</item>

</rdf:RDF>