summaryrefslogtreecommitdiff
path: root/ext/iconv
diff options
context:
space:
mode:
Diffstat (limited to 'ext/iconv')
-rw-r--r--ext/iconv/charset_alias.rb17
-rw-r--r--ext/iconv/extconf.rb4
2 files changed, 18 insertions, 3 deletions
diff --git a/ext/iconv/charset_alias.rb b/ext/iconv/charset_alias.rb
index 7947fd8127..be2c1412e7 100644
--- a/ext/iconv/charset_alias.rb
+++ b/ext/iconv/charset_alias.rb
@@ -7,8 +7,21 @@ require 'rbconfig'
OS = Config::CONFIG["target"]
SHELL = Config::CONFIG['SHELL']
+class Hash::Ordered < Hash
+ def [](key)
+ val = super and val.last
+ end
+ def []=(key, val)
+ ary = fetch(key) {return super(key, [self.size, key, val])} and
+ ary.last = val
+ end
+ def each
+ values.sort.each {|i, key, val| yield key, val}
+ end
+end
+
def charset_alias(config_charset, mapfile, target = OS)
- map = {}
+ map = Hash::Ordered.new
comments = []
IO.foreach("|#{SHELL} #{config_charset} #{target}") do |list|
next comments << list if /^\#/ =~ list
@@ -29,7 +42,7 @@ def charset_alias(config_charset, mapfile, target = OS)
f.puts
f.puts(comments)
f.puts("class Iconv")
- map.keys.sort.each {|can| f.puts(" charset_map['#{can}'.freeze] = '#{map[can]}'.freeze")}
+ map.each {|can, sys| f.puts(" charset_map['#{can}'.freeze] = '#{sys}'.freeze")}
f.puts("end")
end
end
diff --git a/ext/iconv/extconf.rb b/ext/iconv/extconf.rb
index 7176fa45e3..8dfd562a40 100644
--- a/ext/iconv/extconf.rb
+++ b/ext/iconv/extconf.rb
@@ -31,11 +31,13 @@ test(iconv_t cd, char **inptr, size_t *inlen, char **outptr, size_t *outlen)
else
conf = prefix + "config.charset"
end
+ wrapper = "iconv.rb"
+ $cleanfiles << wrapper
end
create_makefile("iconv")
if conf
open("Makefile", "a") do |mf|
- mf.print("\nall: iconv.rb\n\niconv.rb: ", prefix, "charset_alias.rb")
+ mf.print("\nall: #{wrapper}\n\n#{wrapper}: #{prefix}charset_alias.rb")
mf.print(" ", conf) unless scheme
mf.print("\n\t$(RUBY) ", prefix, "charset_alias.rb ", conf, " $@\n")
end