hns - 日記自動生成システム - Version 2.19.9

先月 2008年06月 来月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Namazu for hns による簡易全文検索
詳しくは 詳細指定/ヘルプを参照して下さい
検索式:

2008年06月14日() 旧暦 [n年日記] [更新:"2008/06/15 02:19:28"]

#1 [Namazu] (File::MMagic) $magic->addMagicEntry の設定方法

恥ずかしながら、 実は namazu に filter を追加する時の addMagicEntry の意味が良く分っていなかった。
sub add_magic ($) {
    my ($magic) = @_;
   # See perldoc File::MMagic or man 5 magic for the syntax of following line.
   # If the first line starts with <HTML or <html, it will be recognaized as 
   #    text/html; x-type=hoge
    $magic->addMagicEntry("1\tstring/c\tHTML\ttext/html; x-type=hoge");
    return;
}
これは上の注に書いたように File::MMagic の説明を perldoc File::MMagic で見る か、更にその中に書いてある man 5 magic をすれば分る話で、
offset type (pattern) message
を" の場合には \t" か TAB で、また 'の場合なら TAB で' 区切って書く、というもの だということがやっと分った。もっともずうっと昔に mhonarch の例を見て、 見よう見真似で書いていたことはあるのだけれど。

上に示した例だと、<HTML あるいは <html と書いてあることを期待しているもので、 offset 1 なので二文字目から、 /c が付いているので大小文字の区別なく、 HTML という文字があれば(全て) text/html; x-type=hoge という文字を表示する(返す)、 という意味になる。実はこの場合には、全ての HTML 形式は x-type=hoge という形で 処理をしたい、ということ。追加した filter に、次のように書いておくと、 この magic 判定に合った場合には、ここに来るようになる。

sub mediatype() {
    return ('text/html; x-type=hoge');
}



最近の日記
2024年05月08日
comparison on ./buildsh tools
2024年05月06日
py-setuptools (python 3.11.9)
make release took 1 hours and 10 min
qemu invocation for 10.99.10
2024年05月05日
Windows 10 version
serial connection
bc bench
2024年05月04日
Trial on 10.99.10
another version (later trial) to succeed
2024年04月29日
dkim
以上、1 日分です。
タイトル一覧
カテゴリ分類
Powered by hns-2.19.9, HyperNikkiSystem Project

Count.cgi (since 2000/02/05)