From 9a1d7e4d01ca2f3a1a9d92e1539eca37d75aacb8 Mon Sep 17 00:00:00 2001 From: naruse Date: Sat, 19 Jan 2008 20:15:13 +0000 Subject: [PATCH] * enc/make_encdb.rb: fix duplication check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ enc/make_encdb.rb | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64744d001c..fd24c70e7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jan 20 05:12:44 2008 NARUSE, Yui + + * enc/make_encdb.rb: fix duplication check. + Sun Jan 20 05:03:46 2008 NARUSE, Yui * ascii.c: remove difinition of replica KOI8-U. diff --git a/enc/make_encdb.rb b/enc/make_encdb.rb index 15d5f3af3c..6eda76e5c4 100755 --- a/enc/make_encdb.rb +++ b/enc/make_encdb.rb @@ -9,27 +9,29 @@ # ENC_ALIAS("CP932", "Windows-31J") # -def check_duplication(encs, name, fn, line) - if encs.include?(name) - raise ArgumentError, "%s:%d: encoding %s is already registered" % [fn, line, name] +def check_duplication(defs, name, fn, line) + if defs[name] + raise ArgumentError, "%s:%d: encoding %s is already registered(%s:%d)" % + [fn, line, name, *defs[name]] + else + defs[name.upcase] = [fn,line] end end count = 0 lines = [] encodings = [] +defs = {} encdir = ARGV[0] outhdr = ARGV[1] || 'encdb.h' Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.sort.each do |fn| open(File.join(encdir,fn)) do |f| orig = nil name = nil - encs = [] f.each_line do |line| if (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line) if $1 - check_duplication(encs, $1, fn, $.) - encs << $1.upcase + check_duplication(defs, $1, fn, $.) encodings << $1 count += 1 end @@ -41,19 +43,18 @@ Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.sort.each do |fn| when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/ raise ArgumentError, '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' % - [fn, $., $2, $1] unless encs.include?($2.upcase) + [fn, $., $2, $1] unless defs[$2.upcase] count += 1 when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/ raise ArgumentError, '%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' % - [fn, $., $2, $1] unless encs.include?($2.upcase) + [fn, $., $2, $1] unless defs[$2.upcase] when /^ENC_DUMMY\(\s*"([^"]+)"/ count += 1 else next end - check_duplication(encs, $1, fn, $.) - encs << $1.upcase + check_duplication(defs, $1, fn, $.) lines << line.sub(/;.*/m, ";\n") if line end end