diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ftools.rb | 17 | ||||
-rw-r--r-- | lib/jcode.rb | 160 | ||||
-rw-r--r-- | lib/mkmf.rb | 158 |
3 files changed, 205 insertions, 130 deletions
diff --git a/lib/ftools.rb b/lib/ftools.rb index 301bff6cee..39d6ca9462 100644 --- a/lib/ftools.rb +++ b/lib/ftools.rb @@ -74,12 +74,16 @@ class << File begin rename from, to rescue - from_stat = stat(from) - syscopy from, to and unlink from - utime(from_stat.atime, from_stat.mtime, to) begin - chown(fstat.uid, fstat.gid, tpath) + symlink File.readlink(from), to and unlink from rescue + from_stat = stat(from) + syscopy from, to and unlink from + utime(from_stat.atime, from_stat.mtime, to) + begin + chown(fstat.uid, fstat.gid, tpath) + rescue + end end end end @@ -109,7 +113,8 @@ class << File if fr = from.read(fsize) tr = to.read(fr.size) else - ret = !to.read(fsize) + ret = to.read(fsize) + ret = !ret || ret.length == 0 break end end @@ -167,7 +172,7 @@ class << File def install(from, to, mode = nil, verbose = false) to = catname(from, to) unless FileTest.exist? to and cmp from, to - unlink to if FileTest.exist? to + safe_unlink to if FileTest.exist? to cp from, to, verbose chmod mode, to, verbose if mode end diff --git a/lib/jcode.rb b/lib/jcode.rb index 5b5b80d797..0bd63cf6f2 100644 --- a/lib/jcode.rb +++ b/lib/jcode.rb @@ -1,6 +1,6 @@ # jcode.rb - ruby code to handle japanese (EUC/SJIS) string -$vsave, $VERBOSE = $VERBOSE, false +$vsave, $VERBOSE = $VERBOSE, FALSE class String printf STDERR, "feel free for some warnings:\n" if $VERBOSE @@ -12,9 +12,10 @@ class String private :original_succ def mbchar? - if $KCODE =~ /^s/i + case $KCODE[0] + when ?s, ?S self =~ /[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]/n - elsif $KCODE =~ /^e/i + when ?e, ?E self =~ /[\xa1-\xfe][\xa1-\xfe]/n else false @@ -22,16 +23,15 @@ class String end def succ - if self[-2] && self[-2] & 0x80 != 0 + if self[-2] and self[-2, 2].mbchar? s = self.dup s[-1] += 1 - s[-1] += 1 if !s.mbchar? + s[-1] += 1 unless s[-2, 2].mbchar? return s else original_succ end end - alias next succ def upto(to) return if self > to @@ -58,12 +58,11 @@ class String return nil end - ExpandChCache = {} + private - def _expand_ch - return ExpandChCache[self] if ExpandChCache.key? self + def _expand_ch str a = [] - self.scan(/(.|\n)-(.|\n)|(.|\n)/) do |r| + str.scan(/(.|\n)-(.|\n)|(.|\n)/) do |r| if $3 a.push $3 elsif $1.length != $2.length @@ -74,36 +73,41 @@ class String $1.upto($2) { |c| a.push c } end end - ExpandChCache[self] = a a end + HashCache = {} + + def expand_ch_hash from, to = "" + key = from.intern.to_s + ":" + to.intern.to_s + return HashCache[key] if HashCache.key? key + afrom = _expand_ch(from) + h = {} + if to.length != 0 + ato = _expand_ch(to) + afrom.each_with_index do |x,i| h[x] = ato[i] || ato[-1] end + else + afrom.each do |x| h[x] = true end + end + HashCache[key] = h + end + + def bsquote(str) + str.gsub(/\\/, '\\\\\\\\') + end + + public + def tr!(from, to) return self.delete!(from) if to.length == 0 - if from =~ /^\^/ - comp=true - from = $' - end - afrom = from._expand_ch - ato = to._expand_ch - i = 0 - if comp - self.gsub!(/(.|\n)/) do |c| - unless afrom.include?(c) - ato[-1] - else - c - end - end + pattern = /[#{bsquote(from)}]/ + if from[0] == ?^ + last = /.$/.match(to)[0] + self.gsub!(pattern, last) else - self.gsub!(/(.|\n)/) do |c| - if i = afrom.index(c) - if i < ato.size then ato[i] else ato[-1] end - else - c - end - end + h = expand_ch_hash(from, to) + self.gsub!(pattern) do |c| h[c] end end end @@ -112,22 +116,8 @@ class String end def delete!(del) - if del =~ /^\^/ - comp=true - del = $' - end - adel = del._expand_ch - if comp - self.gsub!(/(.|\n)/) do |c| - next unless adel.include?(c) - c - end - else - self.gsub!(/(.|\n)/) do |c| - next if adel.include?(c) - c - end - end + pattern = /[#{bsquote(del)}]+/ + self.gsub!(pattern, '') end def delete(del) @@ -135,27 +125,13 @@ class String end def squeeze!(del=nil) - if del - if del =~ /^\^/ - comp=true - del = $' - end - adel = del._expand_ch - if comp - self.gsub!(/(.|\n)\1+/) do - next unless adel.include?($1) - $& - end + pattern = + if del + /([#{bsquote(del)}])\1+/ else - for c in adel - cq = Regexp.quote(c) - self.gsub!(/#{cq}(#{cq})+/, cq) - end + /(.|\n)\1+/ end - self - else - self.gsub!(/(.|\n)\1+/, '\1') - end + self.gsub!(pattern, '\1') end def squeeze(del=nil) @@ -164,33 +140,14 @@ class String def tr_s!(from, to) return self.delete!(from) if to.length == 0 - if from =~ /^\^/ - comp=true - from = $' - end - afrom = from._expand_ch - ato = to._expand_ch - i = 0 - c = nil - last = nil - self.gsub!(/(.|\n)/) do |c| - if comp - unless afrom.include?(c) - c = ato[-1] - next if c == last - last = c - else - last = nil - c - end - elsif i = afrom.index(c) - c = if i < ato.size then ato[i] else ato[-1] end - next if c == last - last = c - else - last = nil - c - end + + pattern = /([#{bsquote(from)}])\1+/ + if from[0] == ?^ + last = /.$/.match(to)[0] + self.gsub!(pattern, last) + else + h = expand_ch_hash(from, to) + self.gsub!(pattern) do h[$1] end end end @@ -198,18 +155,17 @@ class String (str = self.dup).tr_s!(from,to) or str end - alias original_chop! chop! - private :original_chop! - def chop! - if self =~ /(.)$/ and $1.size == 2 - original_chop! - end - original_chop! + self.gsub!(/(?:.|\n)\z/, '') end def chop (str = self.dup).chop! or str end + + def jcount(str) + self.delete("^#{str}").jlength + end + end $VERBOSE = $vsave diff --git a/lib/mkmf.rb b/lib/mkmf.rb index e35f17b772..a3f2a8e6fe 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -6,6 +6,8 @@ require 'find' include Config +SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"] + $cache_mod = false $lib_cache = {} $lib_found = {} @@ -42,6 +44,8 @@ else STDERR.print "can't find header files for ruby.\n" exit 1 end +$topdir = $hdrdir +$hdrdir.gsub!('/', '\\') if RUBY_PLATFORM =~ /mswin32/ CFLAGS = CONFIG["CFLAGS"] if RUBY_PLATFORM == "m68k-human" @@ -145,12 +149,20 @@ def install_rb(mfile, srcdir = nil) end end +def append_library(libs, lib) + if /mswin32/ =~ RUBY_PLATFORM + lib + ".lib " + libs + else + "-l" + lib + " " + libs + end +end + def have_library(lib, func="main") printf "checking for %s() in -l%s... ", func, lib STDOUT.flush if $lib_cache[lib] if $lib_cache[lib] == "yes" - $libs = "-l" + lib + " " + $libs + $libs = append_library($libs, lib) print "(cached) yes\n" return true else @@ -160,18 +172,36 @@ def have_library(lib, func="main") end if func && func != "" - libs = "-l" + lib + " " + $libs - unless try_link(<<"SRC", libs) + libs = append_library($libs, lib) + if /mswin32/ =~ RUBY_PLATFORM + r = try_link(<<"SRC", libs) +#include <windows.h> +#include <winsock.h> +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC + unless r + r = try_link(<<"SRC", libs) +#include <windows.h> +#include <winsock.h> +int main() { return 0; } +int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; } +SRC + end + else + r = try_link(<<"SRC", libs) int main() { return 0; } int t() { #{func}(); return 0; } SRC + end + unless r $lib_cache[lib] = 'no' $cache_mod = true print "no\n" return false end else - libs = "-l" + lib + " " + $libs + libs = append_library($libs, lib) end $libs = libs @@ -181,6 +211,28 @@ SRC return true end +def find_library(lib, func, *paths) + printf "checking for %s() in -l%s... ", func, lib + STDOUT.flush + + ldflags = $LDFLAGS + libs = "-l" + lib + " " + $libs + until try_link(<<"SRC", libs) +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC + if paths.size == 0 + $LDFLAGS = ldflags + print "no\n" + return false + end + $LDFLAGS = ldflags + " -L"+paths.shift + end + $libs = libs + print "yes\n" + return true +end + def have_func(func) printf "checking for %s()... ", func STDOUT.flush @@ -197,11 +249,28 @@ def have_func(func) libs = $libs - unless try_link(<<"SRC", libs) -char #{func}(); + if /mswin32/ =~ RUBY_PLATFORM + r = try_link(<<"SRC", libs) +#include <windows.h> +#include <winsock.h> +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC + unless r + r = try_link(<<"SRC", libs) +#include <windows.h> +#include <winsock.h> +int main() { return 0; } +int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; } +SRC + end + else + r = try_link(<<"SRC", libs) int main() { return 0; } int t() { #{func}(); return 0; } SRC + end + unless r $func_found[func] = 'no' $cache_mod = true print "no\n" @@ -246,7 +315,6 @@ SRC end def arg_config(config, default=nil) - return default if /mswin32/i =~ RUBY_PLATFORM unless defined? $configure_args $configure_args = {} for arg in CONFIG["configure_args"].split + ARGV @@ -291,11 +359,30 @@ def create_header() end end -def create_makefile(target, installpos = "") +def dir_config(target) + dir = with_config("%s-dir"%target) + if dir + idir = " -I"+dir+"/include" + ldir = " -L"+dir+"/lib" + end + unless idir + dir = with_config("%s-include"%target) + idir = " -I"+dir if dir + end + unless ldir + dir = with_config("%s-lib"%target) + ldir = " -L"+dir if dir + end + + $CFLAGS += idir if idir + $LDFLAGS += ldir if ldir +end + +def create_makefile(target) print "creating Makefile\n" system "rm -f conftest*" STDOUT.flush - if CONFIG["DLEXT"] == "o" + if CONFIG["DLEXT"] == $OBJEXT libs = $libs.split for lib in libs lib.sub!(/-l(.*)/, '"lib\1.a"') @@ -319,9 +406,11 @@ def create_makefile(target, installpos = "") end unless $objs then - $objs = Dir["*.{c,cc,m}"] - for f in $objs - f.sub!(/\.(c|cc|m)$/, ".o") + $objs = [] + for f in Dir["*.{#{SRC_EXT.join(%q{,})}}"] + f = File.basename(f) + f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT) + $objs.push f end end $objs = $objs.join(" ") @@ -333,7 +422,7 @@ SHELL = /bin/sh #### Start of system configuration section. #### srcdir = #{$srcdir} -topdir = #{$hdrdir} +topdir = #{$topdir} hdrdir = #{$hdrdir} CC = #{CONFIG["CC"]} @@ -350,7 +439,7 @@ archdir = #{$archdir} #### End of system configuration section. #### -LOCAL_LIBS = #{$LOCAL_LIBS} +LOCAL_LIBS = #{$LOCAL_LIBS} #{$local_flags} LIBS = #{$libs} OBJS = #{$objs} @@ -359,13 +448,14 @@ DLLIB = $(TARGET).#{CONFIG["DLEXT"]} RUBY = #{CONFIG["ruby_install_name"]} -binsuffix = #{CONFIG["binsuffix"]} +EXEEXT = #{CONFIG["EXEEXT"]} all: $(DLLIB) -clean:; @rm -f *.o *.so *.sl *.a $(DLLIB) +clean:; @rm -f *.#{$OBJEXT} *.so *.sl *.a $(DLLIB) + @rm -f $(TARGET).lib $(TARGET).exp @rm -f Makefile extconf.h conftest.* - @rm -f core ruby$(binsuffix) *~ + @rm -f core ruby$(EXEEXT) *~ realclean: clean @@ -378,7 +468,7 @@ EOMF install_rb(mfile) mfile.printf "\n" - if CONFIG["DLEXT"] != "o" + if CONFIG["DLEXT"] != $OBJEXT mfile.printf <<EOMF $(DLLIB): $(OBJS) $(LDSHARED) $(DLDFLAGS) -o $(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS) @@ -397,7 +487,7 @@ EOMF dfile = open("depend", "r") mfile.printf "###\n" while line = dfile.gets() - mfile.print line + mfile.printf "%s", line.gsub(/\.o/, ".#{$OBJEXT}") end dfile.close end @@ -443,9 +533,33 @@ EOMF end end -$libs = RUBY_PLATFORM =~ /cygwin|beos|openstep|nextstep|rhapsody/ ? "" : "-lc" +$OBJEXT = CONFIG["OBJEXT"] $objs = nil +$libs = "-lc" +$local_flags = "" +case RUBY_PLATFORM +when /cygwin|beos|openstep|nextstep|rhapsody/ + $libs = "" +when /mswin32/ + $libs = "" + $local_flags = "rubymw.lib -link /LIBPATH:$(topdir) /EXPORT:Init_$(TARGET)" +end $LOCAL_LIBS = "" -$CFLAGS = "" -$LDFLAGS = "" $defs = [] + +dir = with_config("opt-dir") +if dir + idir = "-I"+dir+"/include" + ldir = "-L"+dir+"/lib" +end +unless idir + dir = with_config("opt-include") + idir = "-I"+dir if dir +end +unless ldir + dir = with_config("opt-lib") + ldir = "-L"+dir if dir +end + +$CFLAGS = idir || "" +$LDFLAGS = ldir || "" |