Sha256: a9d7653209612b23acb024b10030e595ccac8f213232103cb45961de6152f32d

Contents?: true

Size: 1.2 KB

Versions: 38

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby
#
# gencatalog.rb
#
# Copyright (c) 2008 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the Ruby License.
#

require 'optparse'

def main
  catalog_path = nil
  parser = OptionParser.new
  parser.banner = "Usage: #{File.basename($0)} --merge=PATH [<file>...]"
  parser.on('--merge=PATH', 'Current catalog file.') {|path|
    catalog_path = path
  }
  parser.on('--help', 'Prints this message and quit.') {
    puts parser.help
    exit 0
  }
  begin
    parser.parse!
  rescue OptionParser::ParseError => err
    $stderr.puts err
    $stderr.puts parser.help
    exit 1
  end

  h = collect_messages(ARGF)
  h.update load_catalog(catalog_path) if catalog_path
  print_catalog h
end

def print_catalog(h)
  h.keys.sort.each do |key|
    puts key
    puts h[key]
  end
end

def collect_messages(f)
  h = {}
  f.each do |line|
    line.scan(/_\(
        (?: "( (?:[^"]+|\\.)* )"
          | '( (?:[^']+|\\.)* )'
          )
    /x) do
      text = ($1 || $2).strip
      h[text] = text unless text.empty?
    end
  end
  h
end

def load_catalog(path)
  h = {}
  File.open(path) {|f|
    f.each do |line|
      h[line.chomp] = f.gets.chomp
    end
  }
  h
end

main

Version data entries

38 entries across 31 versions & 2 rubygems

Version Path
bitclust-dev-1.3.0 tools/gencatalog.rb
bitclust-dev-1.2.6 tools/gencatalog.rb
bitclust-dev-1.2.5 tools/gencatalog.rb
bitclust-dev-1.2.4 tools/gencatalog.rb
bitclust-dev-1.2.3 tools/gencatalog.rb
bitclust-dev-1.2.2 tools/gencatalog.rb
bitclust-dev-1.2.1 tools/gencatalog.rb
bitclust-dev-1.2.0 tools/gencatalog.rb
bitclust-dev-1.1.1 tools/gencatalog.rb
bitclust-dev-1.1.0 tools/gencatalog.rb
bitclust-dev-1.0.0 tools/gencatalog.rb
bitclust-dev-0.9.6 tools/gencatalog.rb
bitclust-dev-0.9.5 tools/gencatalog.rb
bitclust-dev-0.9.4 tools/gencatalog.rb
bitclust-dev-0.9.3 tools/gencatalog.rb
bitclust-dev-0.9.2 tools/gencatalog.rb
bitclust-dev-0.9.1 tools/gencatalog.rb
bitclust-dev-0.9.0 tools/gencatalog.rb
bitclust-dev-0.8.0 tools/gencatalog.rb
bitclust-dev-0.7.0 tools/gencatalog.rb