# 何もしません class FilterBase attr_reader :path, :point def initialize @path = '' @point = 0 end def match(url) false end def search(url, string, cursor) false end end # 1ファイル→1URLの場合のフィルタ class PureFilter < FilterBase def initialize() # XXX @matcher = Regexp.compile("http:\/\/(localhost|zinnia.dyndns.org|risky-safety.org)[^\/]*\/~zinnia\/") end def match(url) @matcher.match(url) != nil end def search(url, string, cursor) if @matcher.match(url) then localname = $~.post_match; if $1 != 'localhost' then localname = 'labweb/' + localname end @path = "#{ENV['HOME']}/public_html/#{localname}" if localname =~ /\/$/ then @path = @path + "index.html" # XXX end @cursor = 0 return true end return false end end ISEARCH_BORDER=10 # 一致したとみなす文字数 # インクリメンタルサーチもどき # もっとうまい方法があったら教えてください _| ̄|○ def incremental_search(buf, expression) matched = false exp1 = '' Screen.debugprint("#{buf.jlength.to_s}\n") expression.each_char{|c| exp1 = exp1 + c if buf.include?(exp1) == false then break end if exp1.jlength >= ISEARCH_BORDER then matched = true break end if exp1.length == expression.length then matched = true end } return matched end # nファイル→1URLの場合のフィルタ。めんどいので日記のみ class DiaryFilter < FilterBase def initialize() @matcher = Regexp.compile("http:\/\/(localhost|zinnia.dyndns.org|risky-safety.org)[^\/]*\/~zinnia\/(labweb\/)?d\/") end def match(url) @matcher.match(url) != nil end def search(url, string, cursor) if @matcher.match(url) != nil then localname = 'labweb/d/' + $~.post_match; # Phase 1 日付決定 localpath = "#{ENV['HOME']}/public_html/#{localname}" if localpath =~ /\/$/ then localpath = localpath + "index.html" # XXX end lastd = '' d = '' matched = false nstring = normalize_for_search(string) Screen.debugprint("Search for '#{nstring}'...\n") line = File.readlines(localpath).join() line.gsub!(/[ \t]*<[^h][^>]*>[ \t]*/, '') line.gsub!(/\n/, '') while line != '' do if line =~ /

(\d\d\d\d\/\d\d\/\d\d)/ then line = $~.post_match lastd = d d = $1 Screen.debugprint("MATCHED #{d}.\n") else lastd = d break end if !incremental_search(line, nstring) then break end matched = true end if matched == false then Screen.put_to_errorbuf("No matched for '#{nstring}'\n") return false end lastd = d if lastd == '' # Phase 2 位置決定 @path = "#{ENV['HOME']}/diary/#{lastd}/text" Screen.debugprint("#{@path}\n"); @cursor = 0 return true end return false end end