2003-07-18 23:51:42 +04:00
|
|
|
#! /usr/bin/ruby
|
2005-10-13 18:33:30 +04:00
|
|
|
# :stopdoc:
|
2003-07-18 23:51:42 +04:00
|
|
|
require 'rbconfig'
|
2005-10-08 14:15:50 +04:00
|
|
|
require 'optparse'
|
2003-07-18 23:51:42 +04:00
|
|
|
|
2003-09-01 19:41:31 +04:00
|
|
|
# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
|
2003-07-18 23:51:42 +04:00
|
|
|
# Fri, 30 May 2003 00:09:00 GMT'
|
|
|
|
|
* mkconfig.rb: generate RbConfig instead of Config.
* instruby.rb, rubytest.rb, runruby.rb, bcc32/Makefile.sub,
ext/extmk.rb, ext/dl/extconf.rb, ext/iconv/charset_alias.rb,
lib/mkmf.rb, lib/rdoc/ri/ri_paths.rb,
lib/webrick/httpservlet/cgihandler.rb,
test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb,
test/ruby/envutil.rb, test/soap/calc/test_calc_cgi.rb,
test/soap/header/test_authheader_cgi.rb, test/soap/ssl/test_ssl.rb,
win32/mkexports.rb, win32/resource.rb: Use RbConfig instead of
Config.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-02-20 11:34:53 +03:00
|
|
|
OS = RbConfig::CONFIG["target_os"]
|
|
|
|
SHELL = RbConfig::CONFIG['SHELL']
|
2003-07-18 23:51:42 +04:00
|
|
|
|
2003-12-13 12:55:21 +03:00
|
|
|
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
|
2004-01-18 17:59:49 +03:00
|
|
|
ary << val
|
2003-12-13 12:55:21 +03:00
|
|
|
end
|
2004-01-18 17:59:49 +03:00
|
|
|
def sort
|
|
|
|
values.sort.collect {|i, *rest| rest}
|
|
|
|
end
|
|
|
|
def each(&block)
|
|
|
|
sort.each(&block)
|
2003-12-13 12:55:21 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-09-01 19:41:31 +04:00
|
|
|
def charset_alias(config_charset, mapfile, target = OS)
|
2003-12-13 12:55:21 +03:00
|
|
|
map = Hash::Ordered.new
|
2003-07-18 23:51:42 +04:00
|
|
|
comments = []
|
2005-10-08 14:15:50 +04:00
|
|
|
open(config_charset) do |input|
|
2005-10-13 18:33:30 +04:00
|
|
|
input.find {|line| /^case "\$os" in/ =~ line} or break
|
2005-10-08 14:15:50 +04:00
|
|
|
input.find {|line|
|
|
|
|
/^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/ =~ line and
|
|
|
|
$&.split('|').any? {|pattern| File.fnmatch?(pattern.strip, target)}
|
2005-10-13 18:33:30 +04:00
|
|
|
} or break
|
2005-10-08 14:15:50 +04:00
|
|
|
input.find do |line|
|
|
|
|
case line
|
|
|
|
when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
|
|
|
|
sys, can = $1, $2
|
|
|
|
can.downcase!
|
|
|
|
map[can] = sys
|
|
|
|
false
|
|
|
|
when /^\s*;;/
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2003-07-18 23:51:42 +04:00
|
|
|
end
|
2003-09-01 19:41:31 +04:00
|
|
|
case target
|
2003-07-18 23:51:42 +04:00
|
|
|
when /linux|-gnu/
|
2005-10-13 18:33:30 +04:00
|
|
|
# map.delete('ascii')
|
2004-01-18 17:59:49 +03:00
|
|
|
when /cygwin|os2-emx/
|
2003-09-01 19:41:31 +04:00
|
|
|
# get rid of tilde/yen problem.
|
|
|
|
map['shift_jis'] = 'cp932'
|
2003-07-18 23:51:42 +04:00
|
|
|
end
|
2004-01-18 17:59:49 +03:00
|
|
|
st = Hash.new(0)
|
|
|
|
map = map.sort.collect do |can, *sys|
|
|
|
|
if sys.grep(/^en_us(?=.|$)/i) {break true} == true
|
2004-05-07 12:44:24 +04:00
|
|
|
noen = %r"^(?!en_us)\w+_\w+#{Regexp.new($')}$"i #"
|
2004-01-18 17:59:49 +03:00
|
|
|
sys.reject! {|s| noen =~ s}
|
|
|
|
end
|
|
|
|
sys = sys.first
|
|
|
|
st[sys] += 1
|
|
|
|
[can, sys]
|
|
|
|
end
|
|
|
|
st.delete_if {|sys, i| i == 1}.empty?
|
|
|
|
st.keys.each {|sys| st[sys] = nil}
|
|
|
|
st.default = nil
|
2005-10-08 14:15:50 +04:00
|
|
|
writer = proc do |f|
|
2003-07-18 23:51:42 +04:00
|
|
|
f.puts("require 'iconv.so'")
|
|
|
|
f.puts
|
|
|
|
f.puts(comments)
|
|
|
|
f.puts("class Iconv")
|
2004-01-18 17:59:49 +03:00
|
|
|
i = 0
|
|
|
|
map.each do |can, sys|
|
|
|
|
if s = st[sys]
|
|
|
|
sys = s
|
|
|
|
elsif st.key?(sys)
|
|
|
|
sys = (st[sys] = "sys#{i+=1}") + " = '#{sys}'.freeze"
|
|
|
|
else
|
|
|
|
sys = "'#{sys}'.freeze"
|
|
|
|
end
|
2004-05-07 12:44:24 +04:00
|
|
|
f.puts(" charset_map['#{can}'] = #{sys}")
|
2004-01-18 17:59:49 +03:00
|
|
|
end
|
2003-07-18 23:51:42 +04:00
|
|
|
f.puts("end")
|
|
|
|
end
|
2005-10-08 14:15:50 +04:00
|
|
|
if mapfile
|
|
|
|
open(mapfile, "w", &writer)
|
|
|
|
else
|
|
|
|
writer[STDOUT]
|
|
|
|
end
|
2003-07-18 23:51:42 +04:00
|
|
|
end
|
|
|
|
|
2005-10-08 14:15:50 +04:00
|
|
|
target = OS
|
|
|
|
opt = nil
|
|
|
|
ARGV.options do |opt|
|
|
|
|
opt.banner << " config.status map.rb"
|
|
|
|
opt.on("--target OS") {|t| target = t}
|
|
|
|
opt.parse! and (1..2) === ARGV.size
|
|
|
|
end or abort opt.to_s
|
|
|
|
charset_alias(ARGV[0], ARGV[1], target)
|