mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* add enc/trans/make_transdb.rb, dmytranscode.c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ea24d298cf
commit
7a8c02cd47
2 changed files with 42 additions and 0 deletions
2
dmytranscode.c
Normal file
2
dmytranscode.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define NO_TRANSDB_H 1
|
||||
#include "transcode.c"
|
40
enc/trans/make_transdb.rb
Normal file
40
enc/trans/make_transdb.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
#
|
||||
# static const rb_transcoder
|
||||
# rb_from_US_ASCII = {
|
||||
# "US-ASCII", "UTF-8", &from_US_ASCII, 1, 0,
|
||||
# NULL, NULL,
|
||||
# };
|
||||
#
|
||||
|
||||
count = 0
|
||||
converters = {}
|
||||
transdir = ARGV[0]
|
||||
outhdr = ARGV[1] || 'transdb.h'
|
||||
Dir.open(transdir) {|d| d.grep(/.+\.[ch]\z/)}.sort.each do |fn|
|
||||
open(File.join(transdir,fn)) do |f|
|
||||
f.each_line do |line|
|
||||
if (/^static const rb_transcoder/ =~ line)..(/"(.*?)"\s*,\s*"(.*?)"/ =~ line)
|
||||
if $1 && $2
|
||||
from_to = "%s to %s" % [$1, $2]
|
||||
converters[from_to]
|
||||
if converters[from_to]
|
||||
raise ArgumentError, '%s:%d: transcode "%s" is already registered (%s:%d)' %
|
||||
[fn, $., from_to, *converters[from_to].values_at(2, 3)]
|
||||
else
|
||||
converters[from_to] = [$1, $2, fn[0..-3], $.]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
result = converters.map {|k, v| %[rb_declare_transcoder("%s", "%s", "%s");\n] % v}.join
|
||||
mode = IO::RDWR|IO::CREAT
|
||||
mode |= IO::BINARY if defined?(IO::BINARY)
|
||||
open(outhdr, mode) do |f|
|
||||
unless f.read == result
|
||||
f.rewind
|
||||
f.truncate(0)
|
||||
f.print result
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue