From 62f8df2d3c95816028c006ecbe70bc51704eec4b Mon Sep 17 00:00:00 2001 From: muraken Date: Tue, 9 Mar 2010 09:15:42 +0000 Subject: * enc/trans/EMOJI/*.src, enc/trans/emoji*, enc/x-emoji.c, test/ruby/enc/test_emoji.rb, tool/enc-emoji-citrus-gen.rb, tool/enc-emoji4unicode.rb, tool/jisx0208.rb, tool/test/test_jisx0208.rb: new encodings to support emoji charsets, which are used by Japanese mobile phones [ruby-dev:40528]. Thanks Yoji Shidara for a lot of contribution. * tool/transcode-tblgen.rb: modified for enc-emoji4unicode.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/transcode-tblgen.rb | 176 +++++++++++++++++++++++++---------------------- 1 file changed, 92 insertions(+), 84 deletions(-) (limited to 'tool/transcode-tblgen.rb') diff --git a/tool/transcode-tblgen.rb b/tool/transcode-tblgen.rb index fa80ceacf7..227914b635 100755 --- a/tool/transcode-tblgen.rb +++ b/tool/transcode-tblgen.rb @@ -524,16 +524,22 @@ def citrus_euc_cstomb(csid, index) end.to_s(16) end +def citrus_stateless_iso_cstomb(csid, index) + (index | 0x8080 | (csid << 16)).to_s(16) +end + def citrus_cstomb(ces, csid, index) case ces when 'mskanji' citrus_mskanji_cstomb(csid, index) when 'euc' citrus_euc_cstomb(csid, index) + when 'stateless_iso' + citrus_stateless_iso_cstomb(csid, index) end end -SUBDIR = %w/APPLE AST BIG5 CNS CP EBCDIC GB GEORGIAN ISO646 ISO-8859 JIS KAZAKH KOI KS MISC TCVN/ +SUBDIR = %w/APPLE AST BIG5 CNS CP EBCDIC EMOJI GB GEORGIAN ISO646 ISO-8859 JIS KAZAKH KOI KS MISC TCVN/ def citrus_decode_mapsrc(ces, csid, mapsrcs) @@ -766,95 +772,97 @@ def make_signature(filename, src) "src=#{filename.dump}, len=#{src.length}, checksum=#{src.sum}" end -output_filename = nil -verbose_mode = false -force_mode = false - -op = OptionParser.new -op.def_option("--help", "show help message") { puts op; exit 0 } -op.def_option("--verbose", "verbose mode") { verbose_mode = true } -op.def_option("--force", "force table generation") { force_mode = true } -op.def_option("--output=FILE", "specify output file") {|arg| output_filename = arg } -op.parse! - -VERBOSE_MODE = verbose_mode - -OUTPUT_FILENAME = output_filename -OUTPUT_PREFIX = output_filename ? File.basename(output_filename)[/\A[A-Za-z0-9_]*/] : "" -OUTPUT_PREFIX.sub!(/\A_+/, '') -OUTPUT_PREFIX.sub!(/_*\z/, '_') - -TRANSCODE_GENERATED_BYTES_CODE = ArrayCode.new("unsigned char", "#{OUTPUT_PREFIX}byte_array") -TRANSCODE_GENERATED_WORDS_CODE = ArrayCode.new("unsigned int", "#{OUTPUT_PREFIX}word_array") - -arg = ARGV.shift -$srcdir = File.dirname(arg) -$:.unshift $srcdir unless $:.include? $srcdir -src = File.read(arg) -src.force_encoding("ascii-8bit") if src.respond_to? :force_encoding -this_script = File.read(__FILE__) -this_script.force_encoding("ascii-8bit") if this_script.respond_to? :force_encoding - -base_signature = "/* autogenerated. */\n" -base_signature << "/* #{make_signature(File.basename(__FILE__), this_script)} */\n" -base_signature << "/* #{make_signature(File.basename(arg), src)} */\n" - -if !force_mode && output_filename && File.readable?(output_filename) - old_signature = File.open(output_filename) {|f| f.gets("").chomp } - chk_signature = base_signature.dup - old_signature.each_line {|line| - if %r{/\* src="([0-9a-z_.-]+)",} =~ line - name = $1 - next if name == File.basename(arg) || name == File.basename(__FILE__) - path = File.join($srcdir, name) - if File.readable? path - chk_signature << "/* #{make_signature(name, File.read(path))} */\n" +if __FILE__ == $0 + output_filename = nil + verbose_mode = false + force_mode = false + + op = OptionParser.new + op.def_option("--help", "show help message") { puts op; exit 0 } + op.def_option("--verbose", "verbose mode") { verbose_mode = true } + op.def_option("--force", "force table generation") { force_mode = true } + op.def_option("--output=FILE", "specify output file") {|arg| output_filename = arg } + op.parse! + + VERBOSE_MODE = verbose_mode + + OUTPUT_FILENAME = output_filename + OUTPUT_PREFIX = output_filename ? File.basename(output_filename)[/\A[A-Za-z0-9_]*/] : "" + OUTPUT_PREFIX.sub!(/\A_+/, '') + OUTPUT_PREFIX.sub!(/_*\z/, '_') + + TRANSCODE_GENERATED_BYTES_CODE = ArrayCode.new("unsigned char", "#{OUTPUT_PREFIX}byte_array") + TRANSCODE_GENERATED_WORDS_CODE = ArrayCode.new("unsigned int", "#{OUTPUT_PREFIX}word_array") + + arg = ARGV.shift + $srcdir = File.dirname(arg) + $:.unshift $srcdir unless $:.include? $srcdir + src = File.read(arg) + src.force_encoding("ascii-8bit") if src.respond_to? :force_encoding + this_script = File.read(__FILE__) + this_script.force_encoding("ascii-8bit") if this_script.respond_to? :force_encoding + + base_signature = "/* autogenerated. */\n" + base_signature << "/* #{make_signature(File.basename(__FILE__), this_script)} */\n" + base_signature << "/* #{make_signature(File.basename(arg), src)} */\n" + + if !force_mode && output_filename && File.readable?(output_filename) + old_signature = File.open(output_filename) {|f| f.gets("").chomp } + chk_signature = base_signature.dup + old_signature.each_line {|line| + if %r{/\* src="([0-9a-z_.-]+)",} =~ line + name = $1 + next if name == File.basename(arg) || name == File.basename(__FILE__) + path = File.join($srcdir, name) + if File.readable? path + chk_signature << "/* #{make_signature(name, File.read(path))} */\n" + end end + } + if old_signature == chk_signature + now = Time.now + File.utime(now, now, output_filename) + STDERR.puts "already up-to-date: #{output_filename}" if VERBOSE_MODE + exit end - } - if old_signature == chk_signature - now = Time.now - File.utime(now, now, output_filename) - STDERR.puts "already up-to-date: #{output_filename}" if VERBOSE_MODE - exit end -end -if VERBOSE_MODE - if output_filename - STDERR.puts "generating #{output_filename} ..." + if VERBOSE_MODE + if output_filename + STDERR.puts "generating #{output_filename} ..." + end end -end -libs1 = $".dup -erb = ERB.new(src, nil, '%') -erb.filename = arg -erb_result = erb.result(binding) -libs2 = $".dup + libs1 = $".dup + erb = ERB.new(src, nil, '%') + erb.filename = arg + erb_result = erb.result(binding) + libs2 = $".dup -libs = libs2 - libs1 -lib_sigs = '' -libs.each {|lib| - lib = File.basename(lib) - path = File.join($srcdir, lib) - if File.readable? path - lib_sigs << "/* #{make_signature(lib, File.read(path))} */\n" - end -} + libs = libs2 - libs1 + lib_sigs = '' + libs.each {|lib| + lib = File.basename(lib) + path = File.join($srcdir, lib) + if File.readable? path + lib_sigs << "/* #{make_signature(lib, File.read(path))} */\n" + end + } -result = '' -result << base_signature -result << lib_sigs -result << "\n" -result << erb_result -result << "\n" - -if output_filename - new_filename = output_filename + ".new" - FileUtils.mkdir_p(File.dirname(output_filename)) - File.open(new_filename, "wb") {|f| f << result } - File.rename(new_filename, output_filename) - STDERR.puts "done." if VERBOSE_MODE -else - print result + result = '' + result << base_signature + result << lib_sigs + result << "\n" + result << erb_result + result << "\n" + + if output_filename + new_filename = output_filename + ".new" + FileUtils.mkdir_p(File.dirname(output_filename)) + File.open(new_filename, "wb") {|f| f << result } + File.rename(new_filename, output_filename) + STDERR.puts "done." if VERBOSE_MODE + else + print result + end end -- cgit v1.2.3