aboutsummaryrefslogtreecommitdiffstats
path: root/ext/iconv/mkwrapper.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-07 11:55:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-07 11:55:48 +0000
commit1aa48a4ea943eb1d1c9b931fa735f2cf68eb4368 (patch)
tree437548b2bad8e0bbf14ee365005c7518ad1c47e3 /ext/iconv/mkwrapper.rb
parentf4413f14870550a7fb01200f4f41027b505ff96f (diff)
downloadruby-1aa48a4ea943eb1d1c9b931fa735f2cf68eb4368.tar.gz
* ext/iconv/iconv.c: iconvctl() support. [EXPERIMENTAL]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/iconv/mkwrapper.rb')
-rw-r--r--ext/iconv/mkwrapper.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/ext/iconv/mkwrapper.rb b/ext/iconv/mkwrapper.rb
new file mode 100644
index 0000000000..34718507d6
--- /dev/null
+++ b/ext/iconv/mkwrapper.rb
@@ -0,0 +1,53 @@
+#! /usr/bin/ruby
+require 'rbconfig'
+require 'optparse'
+
+# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
+# Fri, 30 May 2003 00:09:00 GMT'
+
+HEADER = <<SRC
+require 'iconv.so'
+
+class Iconv
+ case RUBY_PLATFORM
+SRC
+
+def charset_alias(config_charset, mapfile = nil)
+ found = nil
+ src = [HEADER]
+ open(config_charset) do |input|
+ input.find {|line| /^case "\$os" in/ =~ line} or return
+ input.each do |line|
+ case line
+ when /^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/
+ (s = " when ") << $&.split('|').collect {|targ|
+ targ.strip!
+ tail = targ.chomp!("*") ? '' : '\z'
+ head = targ.slice!(/\A\*/) ? '' : '\A'
+ targ.gsub!(/\*/, '.*')
+ "/#{head}#{targ}#{tail}/"
+ }.join(", ")
+ src << s
+ found = {}
+ when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
+ sys, can = $1, $2
+ can.downcase!
+ unless found[can] or (/\Aen_(?!US\z)/ =~ sys && /\ACP437\z/i =~ can)
+ found[can] = true
+ src << " charset_map['#{can}'] = '#{sys}'.freeze"
+ end
+ when /^\s*;;/
+ found = nil
+ end
+ end
+ end
+ src << " end" << "end"
+ if mapfile
+ open(mapfile, "wb") {|f| f.puts *src}
+ else
+ puts *src
+ end
+end
+
+(1..2) === ARGV.size or abort "usage: #{$0} config_charset [mapfile]"
+charset_alias(*ARGV)