Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/woip/rb/index.rb
blob: dc376f93cbe89a70b313ee4d6e4447a1a53125ad (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require File.join(File.dirname(__FILE__), 'bzipreader')
require File.join(File.dirname(__FILE__), 'article')

$nblock = -1
$startblock = 0

def get_line  
  if $lines.empty?
    txt = $reader.decompressBlock($reader.readNextBlock)
    $nblock += 1
    
    $stderr.puts "#{$nblock}\t#{$reader.offset}\t#{txt.gsub(/\n/, "\\n")[0..30]}\t#{txt.size}"
    
    $lines = txt.split("\n").reverse
  end
  
  $lines.pop
end

def quote(str)
  str.gsub(/'/, "''")
end

def process_titles
  while true
    line = get_line
    block = $nblock
    if line.chomp == START_HEADING
      article = get_line.chomp
      puts "#{article}  #{block}" if $startblock <= $nblock
    end
  end
rescue EOF
  $stderr.puts "Done"
end

def main
  if ARGV[1]
    $startblock = ARGV[1].to_i
  end
  
  if ARGV.empty?
    $reader = BzipReader.new
  else
    $reader = BzipReader.new(ARGV.first)
  end
  
  $lines = []
  process_titles
end

if __FILE__ == $0
  main
end