scanhist.rb (1669B)
1 #!/usr/local/bin/ruby 2 3 # scan history 4 5 def usage 6 STDERR.print "usage: scanhist -h HISTORY ML-archive1 ML-archive2 ...\n" 7 exit 1 8 end 9 10 def html_quote(s) 11 s.gsub!(/&/,"&") 12 s.gsub!(/</,"<") 13 s.gsub!(/>/,">") 14 s 15 end 16 17 if ARGV.size == 0 then 18 usage 19 end 20 21 histfile = nil 22 23 while ARGV[0] =~ /^-/ 24 case ARGV.shift 25 when "-h" 26 histfile = ARGV.shift 27 else 28 usage 29 end 30 end 31 32 if histfile.nil? then 33 usage 34 end 35 36 patched = {} 37 histline = {} 38 f = open(histfile) 39 while f.gets 40 if /Subject: (\[w3m-dev.*\])/ then 41 patched[$1] = true 42 histline[$1] = $. 43 end 44 end 45 f.close 46 47 archive = {} 48 subject = nil 49 for fn in ARGV 50 f = open(fn) 51 while f.gets 52 if /^From / then 53 # beginning of a mail 54 subject = nil 55 elsif subject.nil? and /^Subject: / then 56 $_ =~ /Subject: (\[w3m-dev.*\])/ 57 subject = $1 58 archive[subject] = [$_.chop.sub(/^Subject:\s*/,""),false,fn+"#"+($.).to_s] 59 elsif /^\+\+\+/ or /\*\*\*/ or /filename=.*(patch|diff).*/ or /^begin \d\d\d/ 60 archive[subject][1] = true 61 end 62 end 63 f.close 64 end 65 66 print "<html><head><title>w3m patch configuration\n</title></head><body>\n" 67 print "<pre>\n" 68 for sub in archive.keys.sort 69 a = archive[sub] 70 if a[1] then 71 if patched[sub] then 72 print "[<a href=\"#{histfile}\##{histline[sub]}\">+</a>]" 73 else 74 print "[-]" 75 end 76 print "<a href=\"#{a[2]}\">" 77 print "<b>",html_quote(a[0]),"</b></a>\n" 78 else 79 if patched[sub] then 80 print "[<a href=\"#{histfile}\##{histline[sub]}\">o</a>]" 81 else 82 print " " 83 end 84 print "<a href=\"#{a[2]}\">" 85 print "<b>",html_quote(a[0]),"</b></a>\n" 86 end 87 end 88 print "</pre></body></html>\n"