| 1 |
#!/usr/local/bin/ruby -Ks |
| 2 |
# $Id: cpruby18.rb,v 1.2 2008/06/13 21:07:26 arton Exp $ |
| 3 |
=begin |
| 4 |
-libruby18ӠÜ[ØôÀÃ˰͘Ж |
| 5 |
=end |
| 6 |
|
| 7 |
require 'fileutils' |
| 8 |
|
| 9 |
if ARGV.length == 0 |
| 10 |
STDERR.puts 'usage: ruby cpruby18.rb ruby-1.8.7-src-directory' |
| 11 |
exit 1 |
| 12 |
end |
| 13 |
|
| 14 |
unless File.exist?('./libruby18/src') |
| 15 |
STDERR.puts 'must change directory into exerb/src' |
| 16 |
exit 1 |
| 17 |
end |
| 18 |
|
| 19 |
def rm_and_cp(src, dst, excep = []) |
| 20 |
FileUtils.rm Dir.glob("#{dst}/*.c") |
| 21 |
FileUtils.rm Dir.glob("#{dst}/*.h") |
| 22 |
Dir.open(src).each do |x| |
| 23 |
next unless x =~ /\.c$/i || x =~ /\.h$/i |
| 24 |
next if excep.any? {|e| x =~ e } |
| 25 |
FileUtils.cp("#{src}/#{x}", "#{dst}") |
| 26 |
end |
| 27 |
end |
| 28 |
|
| 29 |
rm_and_cp(ARGV[0], 'libruby18/src', [/main.c/i]) |
| 30 |
rm_and_cp("#{ARGV[0]}/win32", 'libruby18/src/win32', [/winmain.c/i]) |
| 31 |
rm_and_cp("#{ARGV[0]}/missing", 'libruby18/src/missing') |
| 32 |
begin |
| 33 |
FileUtils.cp('libruby18/src/win32/config.h', 'libruby18/src') |
| 34 |
rescue Errno::ENOENT |
| 35 |
FileUtils.cp('libruby18/src/config.h', 'libruby18/src/win32') |
| 36 |
end |
| 37 |
|
| 38 |
File.open('libruby18/src/eval_exerb.c', 'w') do |dst| |
| 39 |
File.open('libruby18/src/eval.c', 'r').each_line do |i| |
| 40 |
# change require |
| 41 |
# return rb_require_safe(fname, ruby_safe_level); |
| 42 |
# return exerb_require(fname); |
| 43 |
|
| 44 |
m = /\A(\s*return\s*)(rb_require_safe)([^,]+).+\Z/.match(i) |
| 45 |
if m |
| 46 |
dst.puts "#{m[1]}exerb_require#{m[3]});" |
| 47 |
else |
| 48 |
dst.puts i |
| 49 |
end |
| 50 |
end |
| 51 |
end |