*preludes, outfile = *ARGV C_ESC = { "\\" => "\\\\", '"' => '\"', "\n" => '\n', } 0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\x%02x" % ch } 0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\x%02x" % ch } C_ESC_PAT = Regexp.union(*C_ESC.keys) def c_esc(str) '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"' end lines_list = preludes.map {|prelude| lines = [] File.readlines(prelude).each {|line| line.gsub!(/RbConfig::CONFIG\["(\w+)"\]/) { require 'rbconfig' if RbConfig::CONFIG.has_key? $1 c_esc(RbConfig::CONFIG[$1]) else $& end } lines << c_esc(line) } lines } open(outfile, 'w'){|f| f.puts <<'EOS__' #include "ruby/ruby.h" #include "vm_core.h" EOS__ preludes.zip(lines_list).each_with_index {|(prelude, lines), i| f.puts <