From 2b291d3806d85d6a87963dfcc88750e89e147b2c Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 8 Oct 2005 10:15:50 +0000 Subject: * ext/iconv/charset_alias.rb: parse config.charset_alias file directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 +++- ext/iconv/charset_alias.rb | 46 ++++++++++++++++++++++++++++++++++++---------- ext/iconv/extconf.rb | 4 ++-- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3fc242b88..b1eaaa8c33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -Sat Oct 8 18:57:52 2005 Nobuyoshi Nakada +Sat Oct 8 19:15:02 2005 Nobuyoshi Nakada * parse.y (rb_parser_malloc, rb_parser_free): manage parser stack on heap. [ruby-list:41199] @@ -7,6 +7,8 @@ Sat Oct 8 18:57:52 2005 Nobuyoshi Nakada * ext/ripper/depend (check): get rid of re-generating ripper.y always. + * ext/iconv/charset_alias.rb: parse config.charset_alias file directly. + Thu Oct 6 20:10:38 2005 Minero Aoki * ext/strscan/strscan.c (strscan_free): remove useless code. diff --git a/ext/iconv/charset_alias.rb b/ext/iconv/charset_alias.rb index f1563b0dff..f3a54b8ddc 100644 --- a/ext/iconv/charset_alias.rb +++ b/ext/iconv/charset_alias.rb @@ -1,10 +1,11 @@ #! /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' -OS = Config::CONFIG["target"] +OS = Config::CONFIG["target_os"] SHELL = Config::CONFIG['SHELL'] class Hash::Ordered < Hash @@ -26,12 +27,26 @@ end def charset_alias(config_charset, mapfile, target = OS) map = Hash::Ordered.new comments = [] - IO.foreach("|#{SHELL} #{config_charset} #{target}") do |list| - next comments << list if /^\#/ =~ list - next unless /^(\S+)\s+(\S+)$/ =~ list - sys, can = $1, $2 - can.downcase! - map[can] = sys + match = false + open(config_charset) do |input| + input.find {|line| /^case "\$os" in/ =~ line} or return + input.find {|line| + /^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/ =~ line and + $&.split('|').any? {|pattern| File.fnmatch?(pattern.strip, target)} + } or return + 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 end case target when /linux|-gnu/ @@ -53,7 +68,7 @@ def charset_alias(config_charset, mapfile, target = OS) st.delete_if {|sys, i| i == 1}.empty? st.keys.each {|sys| st[sys] = nil} st.default = nil - open(mapfile, "w") do |f| + writer = proc do |f| f.puts("require 'iconv.so'") f.puts f.puts(comments) @@ -71,7 +86,18 @@ def charset_alias(config_charset, mapfile, target = OS) end f.puts("end") end + if mapfile + open(mapfile, "w", &writer) + else + writer[STDOUT] + end end -(2..3) === ARGV.size or abort "usage: #$0 config.status map.rb [target]" -charset_alias(*ARGV) +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) diff --git a/ext/iconv/extconf.rb b/ext/iconv/extconf.rb index 1fe2d8a932..71221d60a1 100644 --- a/ext/iconv/extconf.rb +++ b/ext/iconv/extconf.rb @@ -33,7 +33,7 @@ if have_func("iconv", "iconv.h") or require 'uri' scheme = URI.parse(conf).scheme else - conf = prefix + "config.charset" + conf = "$(srcdir)/config.charset" end $cleanfiles << wrapper end @@ -42,7 +42,7 @@ if have_func("iconv", "iconv.h") or open("Makefile", "a") do |mf| 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") + mf.print("\n\t$(RUBY) $(srcdir)/charset_alias.rb #{conf} $@\n") end end end -- cgit v1.2.3