Skip to content

Commit

Permalink
* common.mk (encdb.h): give output file name to make_encdb.rb.
Browse files Browse the repository at this point in the history
* encoding.c (enc_table): simplified.

* encoding.c (enc_register_at): lazy loading.  [ruby-dev:33013]

* regenc.h (ENC_DUMMY): added.

* enc/make_encdb.rb: now emits macros only.

* enc/iso_2022_jp.h: split from encoding.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jan 17, 2008
1 parent a0029e3 commit 0052259
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 175 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
@@ -1,3 +1,17 @@
Thu Jan 17 23:56:20 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* common.mk (encdb.h): give output file name to make_encdb.rb.

* encoding.c (enc_table): simplified.

* encoding.c (enc_register_at): lazy loading. [ruby-dev:33013]

* regenc.h (ENC_DUMMY): added.

* enc/make_encdb.rb: now emits macros only.

* enc/iso_2022_jp.h: split from encoding.c.

Thu Jan 17 21:48:21 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* re.c (rb_char_to_option_kcode): fixed typo.
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Expand Up @@ -704,7 +704,7 @@ node_name.inc: {$(VPATH)}node.h
$(BASERUBY) -n $(srcdir)/tool/node_name.rb $? > $@

encdb.h: $(srcdir)/enc/make_encdb.rb
$(BASERUBY) $(srcdir)/enc/make_encdb.rb $(srcdir)/enc
$(BASERUBY) $(srcdir)/enc/make_encdb.rb $(srcdir)/enc $@

miniprelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
$(BASERUBY) -I$(srcdir) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@
Expand Down
6 changes: 6 additions & 0 deletions enc/iso_2022_jp.h
@@ -0,0 +1,6 @@
#include "regenc.h"
/* dummy for unsupported, statefull encoding */
ENC_DUMMY("ISO-2022-JP");
ENC_ALIAS("ISO2022-JP", "ISO-2022-JP");
ENC_REPLICATE("ISO-2022-JP-2", "ISO-2022-JP");
ENC_ALIAS("ISO2022-JP2", "ISO-2022-JP-2");
83 changes: 43 additions & 40 deletions enc/make_encdb.rb
Expand Up @@ -15,56 +15,59 @@ def check_duplication(encs, name, fn, line)
end
end

count = 0
lines = []
encodings = []
replicas = {}
aliases = {}
encdir = ARGV[0]
Dir.open(encdir) {|d| d.grep(/.+\.c\z/)}.sort.each do |fn|
outhdr = ARGV[1] || 'encdb.h'
Dir.open(encdir) {|d| d.grep(/.+\.[ch]\z/)}.sort.each do |fn|
open(File.join(encdir,fn)) do |f|
orig = nil
name = nil
encs = []
f.each_line do |line|
break if /^OnigEncodingDefine/o =~ line
end
f.each_line do |line|
break if /"(.*?)"/ =~ line
end
if $1
check_duplication(encs, $1, fn, $.)
encs << $1.upcase
encodings << $1
f.each_line do |line|
if /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
raise ArgumentError,
'%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
[fn, $., $2, $1] unless encs.include?($2.upcase)
check_duplication(encs, $1, fn, $.)
encs << $1.upcase
encodings << $1
replicas[$1] = $2
elsif /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/o =~ line
raise ArgumentError,
'%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
[fn, $., $2, $1] unless encs.include?($2.upcase)
check_duplication(encs, $1, fn, $.)
encodings << $1
aliases[$1] = $2
end
if (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
if $1
check_duplication(encs, $1, fn, $.)
encs << $1.upcase
encodings << $1
count += 1
end
else
case line
when /^\s*rb_enc_register\(\s*"([^"]+)"/
count += 1
line = nil
when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
raise ArgumentError,
'%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
[fn, $., $2, $1] unless encs.include?($2.upcase)
count += 1
when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
raise ArgumentError,
'%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
[fn, $., $2, $1] unless encs.include?($2.upcase)
when /^ENC_DUMMY\(\s*"([^"]+)"/
count += 1
else
next
end
check_duplication(encs, $1, fn, $.)
encs << $1.upcase
lines << line.sub(/;.*/m, ";\n") if line
end
end
end
end

open('encdb.h', 'wb') do |f|
f.puts 'static const char *const enc_name_list[] = {'
encodings.each {|name| f.puts' "%s",' % name}
f.puts('};', '', 'static void', 'enc_init_db(void)', '{')
replicas.each_pair {|name, orig|
f.puts ' ENC_REPLICATE("%s", "%s");' % [name, orig]
}
aliases.each_pair {|name, orig|
f.puts ' ENC_ALIAS("%s", "%s");' % [name, orig]
}
f.puts '}'
result = encodings.map {|e| %[ENC_DEFINE("#{e}");\n]}.join + lines.join +
"\n#define ENCODING_COUNT #{count}\n"
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

0 comments on commit 0052259

Please sign in to comment.