diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-13 20:46:00 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-13 20:46:00 +0000 |
commit | 373539e9f175f3d892fc2ad2f46386a5b3911462 (patch) | |
tree | 7703aa64fb18ec9f329857ee7c023031711298b2 /enc/make_encdb.rb | |
parent | e210aeb24cc5c5d7bf36851543db34a32975ce7b (diff) | |
download | ruby-373539e9f175f3d892fc2ad2f46386a5b3911462.tar.gz ruby-373539e9f175f3d892fc2ad2f46386a5b3911462.tar.xz ruby-373539e9f175f3d892fc2ad2f46386a5b3911462.zip |
* enc/*.c: add replicas and aliases.
* enc/make_encdb.h: add duplicate and undefined check.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/make_encdb.rb')
-rwxr-xr-x | enc/make_encdb.rb | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/enc/make_encdb.rb b/enc/make_encdb.rb index f260a2caa..c140007f6 100755 --- a/enc/make_encdb.rb +++ b/enc/make_encdb.rb @@ -9,6 +9,12 @@ # 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] + end +end + encodings = [] replicas = {} aliases = {} @@ -17,20 +23,34 @@ Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.sort.each do |fn| open(File.join(encdir,fn)) do |f| orig = nil name = nil + encs = [] f.each_line do |line| break if /^OnigEncodingDefine/o =~ line end f.each_line do |line| break if /"(.*?)"/ =~ line end - encodings << $1 if $1 - f.each_line do |line| - if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line - encodings << $1 - replicas[$1] = $2 - elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line - encodings << $1 - aliases[$1] = $2 + if $1 + check_duplication(encs, $1, fn, $.) + encs << $1.upcase + encodings << $1 + f.each_line do |line| + if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line + raise ArgumentError, + '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' % + [fn, $., $2, $1] unless encs.include?($2.upcase) + check_duplication(encs, $1, fn, $.) + encs << $1.upcase + encodings << $1 + replicas[$1] = $2 + elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line + raise ArgumentError, + '%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' % + [fn, $., $2, $1] unless encs.include?($2.upcase) + check_duplication(encs, $1, fn, $.) + encodings << $1 + aliases[$1] = $2 + end end end end |