libalgorithm-diff-ruby-0.4.orig/0040775000220700022070000000000007543070573016164 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/lib/0040775000220700022070000000000007543070573016732 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/lib/algorithm/0040775000220700022070000000000007543070573020720 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/lib/algorithm/diff.rb0100664000220700022070000001076207470547631022163 0ustar takakitakaki# # algorith/diff - a Ruby module to compute difference sets between two # objects. Copyright (c) 2001-2002 Lars Christensen. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # module Diff VERSION = 0.4 attr_reader :diffs def Diff.lcs(a, b) astart = 0 bstart = 0 afinish = a.length-1 bfinish = b.length-1 mvector = [] # First we prune off any common elements at the beginning while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart]) mvector[astart] = bstart astart += 1 bstart += 1 end # now the end while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish]) mvector[afinish] = bfinish afinish -= 1 bfinish -= 1 end bmatches = b.reverse_hash(bstart..bfinish) thresh = [] links = [] (astart..afinish).each { |aindex| aelem = a[aindex] next unless bmatches.has_key? aelem k = nil bmatches[aelem].reverse_each { |bindex| if k && (thresh[k] > bindex) && (thresh[k-1] < bindex) thresh[k] = bindex else k = thresh.replacenextlarger(bindex, k) end links[k] = [ k!=0 && links[k-1], aindex, bindex ] if k } } if !thresh.empty? link = links[thresh.length-1] while link mvector[link[1]] = link[2] link = link[0] end end return mvector end def Diff.makediff(a, b) mvector = Diff.lcs(a, b) ai = bi = 0 while ai < mvector.length bline = mvector[ai] if bline while bi < bline yield :+, bi, b[bi] bi += 1 end bi += 1 else yield :-, ai, a[ai] end ai += 1 end while ai < a.length yield :-, ai, a[ai] ai += 1 end while bi < b.length yield :+, bi, b[bi] bi += 1 end 1 end def Diff.diff(a, b, &block) isstring = b.kind_of? String diffs = [] block ||= proc { |action, index, element| prev = diffs[-1] if prev && prev[0] == action && prev[1] + prev[2].length == index prev[2] << element else diffs.push [ action, index, isstring ? element.chr : [element] ] end } Diff.makediff(a, b, &block) return diffs end end module Diffable def diff(b) Diff.diff(self, b) end # Create a hash that maps elements of the array to arrays of indices # where the elements are found. def reverse_hash(range = (0...self.length)) revmap = {} range.each { |i| elem = self[i] if revmap.has_key? elem revmap[elem].push i else revmap[elem] = [i] end } return revmap end # Replace the first element which is larger than value. Assumes that # the element indexed by high, if given is larger than value. def replacenextlarger(value, high = nil) high ||= length low = 0 index = found = nil while low < high index = (high+low) >> 1 found = self[index] if value > found # this first, most common case low = index + 1 elsif value == found return nil else high = index end end self[low] = value return low end # Patches self with the given set of differences. def patch(diffs) newary = nil kindofstring = kind_of? String if kindofstring newary = self.class.new('') else newary = self.class.new end ai = 0 bi = 0 diffs.each { |action,position,elements| case action when :- while ai < position newary << self[ai] ai += 1 bi += 1 end ai += elements.length when :+ while bi < position newary << self[ai] ai += 1 bi += 1 end if kindofstring newary << elements else newary.push *elements end bi += elements.length else raise "Unknown diff action" end } while ai < self.length newary << self[ai] ai += 1 bi += 1 end return newary end end class Array include Diffable end class String include Diffable end libalgorithm-diff-ruby-0.4.orig/test/0040775000220700022070000000000007543070573017143 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/test/stringdiff.rb0100764000220700022070000000037007470301363021616 0ustar takakitakaki#!/usr/bin/ruby require 'algorithm/diff' [ [ "Hello, World!", "Hello with you, World!" ], [ "foo bar baz", "foo rob baz", ], [ "foo bar baz", ">foo bar baz< "], ].each { |a,b| puts a,b d = a.diff(b) p d.diffs #p d.compact } libalgorithm-diff-ruby-0.4.orig/test/test_cases.rb0100664000220700022070000000425707354146027021630 0ustar takakitakakimodule DiffArrayTests def test_array_append difftest [1,2,3], [1,2,3,4] difftest [1,2,3], [1,2,3,4,5] end def test_array_prepend difftest [1,2,3], [0,1,2,3] difftest [1,2,3], [-1,0,1,2,3] end def test_array_insert difftest [1,2,3], [1,2,4,3] difftest [1,2,3], [1,2,4,5,3] end def test_array_remove difftest [1,2,3], [1,3] end def test_array_cutfront difftest [1,2,3], [2,3] difftest [1,2,3], [3] end def test_array_cutback difftest [1,2,3], [1,2] difftest [1,2,3], [1] end def test_array_empty difftest [1,2,3], [] end def test_array_fill difftest [], [1,2,3] end def test_array_change difftest [1,2,3], [1,4,3] difftest [1,2,3], [1,4,5] difftest [1,2,3,4], [1,5,4] end def test_array_noop difftest [1,2,3], [1,2,3] end def test_array_grow difftest [1,2,3], [4,1,5,2,6,3,7] end def test_array_shrink difftest [1,2,3,4,5,6,7], [2,4,6] end end module DiffStringTests def test_string_append difftest "abc", "abcd" difftest "abc", "abcde" end def test_string_preprend difftest "abc", "qabc" difftest "abc", "qrabc" end def test_string_insert difftest "abc", "abqc" difftest "abc", "abqrc" end def test_string_cutfront difftest "abc", "bc" difftest "abc", "c" end def test_string_cutback difftest "abc", "ab" difftest "abc", "a" end def test_string_empty difftest "abc", "" end def test_string_fill difftest "", "abc" end def test_string_change difftest "abc", "aqc" difftest "abc", "aqrc" difftest "abcd", "aqd" end def test_string_noop difftest "abc", "abc" end def test_string_grow difftest "abc", "qarbsct" end def test_string_shrink difftest "abcdefg", "bdf" end def test_string_remove difftest "abc", "ac" end end module DiffStressTest Elems = [1,2,3] def generate_array length = (16 + 16 * rand).to_i ary = [] length.times { ary << Elems[(rand * Elems.length).to_i] } return ary end def test_stress 256.times { a = generate_array b = generate_array difftest(a, b) } end end libalgorithm-diff-ruby-0.4.orig/test/test_diff.rb0100664000220700022070000000055007470510053021423 0ustar takakitakakirequire 'test/unit' require 'algorithm/diff' require 'test_cases' class DiffTest < Test::Unit::TestCase include DiffStringTests include DiffArrayTests include DiffStressTest def difftest(a, b) diff = Diff.diff(a, b) c = a.patch(diff) assert_equal(b, c) diff = Diff.diff(b, a) c = b.patch(diff) assert_equal(a, c) end end libalgorithm-diff-ruby-0.4.orig/test/test_unixdiff.rb0100600000220700022070000000132707451213243022320 0ustar takakitakakirequire 'runit/testcase' require 'runit/cui/testrunner' require 'runit/testsuite' require 'diff' require 'test_cases' class UnixDiffTest < RUNIT::TestCase include DiffArrayTests #include DiffStressTest def makefile(filename, ary) File.open(filename, "w") { |f| ary.each { |elem| f.puts elem.to_s } } end def rundiff(prog) res = [] IO.popen("#{prog} file1 file2") { |f| while ln = f.gets res << ln end } res end def difftest(a, b) makefile("file1", a) makefile("file2", b) result1 = rundiff("diff") result2 = rundiff("./unixdiff.rb"); assert_equal(result1, result2) end end RUNIT::CUI::TestRunner.run(UnixDiffTest.suite) libalgorithm-diff-ruby-0.4.orig/doc/0040775000220700022070000000000007543070573016731 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/doc/diff.rd0100664000220700022070000000474207470524364020175 0ustar takakitakaki= Diff (({diff.rb})) - computes the differences between two arrays or strings. Copyright (C) 2001-2002 Lars Christensen. == Synopsis diff = Diff.diff(a, b) a.diff(b) b = a.patch(diff) == Module Diff === Module Methods --- Diff.diff(a, b, &block) Creates a different set which represents the differences between ((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays with elements of any type, strings, or object of any class that include module ((|Diffable|)) If a block is not given, the default is to compact the difference set elements into an array of element of the type (({[action,position,elements]})). If action is :+, the array represent elements which is in b but not a which are inserted at ((|position|)). If action is :-, the array represents elements which are in a at ((|position|)) but has been removed from b. If the original data was arrays, ((|elements|)) will be an array of elements. If the original data was Strings, then ((|elements|)) will be a string.c If a block is given, it will be passed each of the element in the difference set. Each time it is called, three arguments are passed: action, position and element. Action is either :+ or :- for add or remove element, respectively. If the action is :+, position will denote the position to add element in the destination set, given all previous before this are changed. If the action is :-, position will denote the position to delete elements from the original set. == Module Diffable The ((|Diffable|)) module can be included into classes that you want to compute difference sets for Diffable is included into String and Array when (({diff.rb})) is (({require}))'d. Classes including Diffable should implement (({[]})) to get element at integer indices, (({<<})) and (({push})) to append elements to the object and (({ClassName#new})) should accept 0 arguments to create a new empty object. Finally, the class must implement the length method which should return the number of element in the array. === Instance Methods --- Diffable#diff(b, &block) Convinience method which calls Diff.diff(self, b, &block). --- Diffable#patch(diff) Applies the differences from ((|diff|)) to the object ((|obj|)) and return the result. ((|obj|)) is not changed. ((|obj|)) and can be either an array or a string, but must match the object from which the ((|diff|)) was created. libalgorithm-diff-ruby-0.4.orig/doc/diff.html0100664000220700022070000000706007471020025020512 0ustar takakitakaki doc/diff.rd

Diff

diff.rb - computes the differences between two arrays or strings. Copyright (C) 2001-2002 Lars Christensen.

Synopsis

diff = Diff.diff(a, b)
a.diff(b)
b = a.patch(diff)

Module Diff

Module Methods

Diff.diff(a, b, &block)

Creates a different set which represents the differences between a and b. a and b can be either be arrays with elements of any type, strings, or object of any class that include module Diffable

If a block is not given, the default is to compact the difference set elements into an array of element of the type [action,position,elements]. If action is :+, the array represent elements which is in b but not a which are inserted at position. If action is :-, the array represents elements which are in a at position but has been removed from b. If the original data was arrays, elements will be an array of elements. If the original data was Strings, then elements will be a string.c

If a block is given, it will be passed each of the element in the difference set. Each time it is called, three arguments are passed: action, position and element. Action is either :+ or :- for add or remove element, respectively. If the action is :+, position will denote the position to add element in the destination set, given all previous before this are changed. If the action is :-, position will denote the position to delete elements from the original set.

Module Diffable

The Diffable module can be included into classes that you want to compute difference sets for Diffable is included into String and Array when diff.rb is require'd.

Classes including Diffable should implement [] to get element at integer indices, << and push to append elements to the object and ClassName#new should accept 0 arguments to create a new empty object. Finally, the class must implement the length method which should return the number of element in the array.

Instance Methods

Diffable#diff(b, &block)

Convinience method which calls Diff.diff(self, b, &block).

Diffable#patch(diff)

Applies the differences from diff to the object obj and return the result. obj is not changed. obj and can be either an array or a string, but must match the object from which the diff was created.

libalgorithm-diff-ruby-0.4.orig/README0100600000220700022070000000514607471020013017015 0ustar takakitakaki diff.rb README Diff Algorithm Implementation, Copyright (C) 2001-2002 Lars Christensen, larsch@cs.auc.dk. LEGAL NOTICE This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ABOUT This implementation is basically a Ruby conversion of the Perl Algorithm::Diff module in CPAN. Diff is an algorithm which computes the differences between two lists a and b. The resulting set of differences can be applied to a (also called "patching") to get b. This is also what the Unix command line tools "diff" and "patch" are able to do. diff.rb generates a "minimal diff". This means that the set of changes that should be applied to a to get b can not be fewer than those generated by diff.rb. diff.rb does not generate contextual diffs. Therefor, the diff can only be succesfully applied to a list exactly equal to to original a. Documentation is in RD format in doc/diff.rd. HTML format of this is also provided in doc/diff.html. INSTALLATION To install the Diff ruby file in your local site_ruby directory, execute these three commands: ruby install.rb config ruby install.rb setup ruby install.rb install REVISION HISTORY Version 0.4 o New API o "Diff" is no longer a class, but a module. o Diffable#diff(b) now simply returns an array with the diff. o Diffs are now compacted by default. o :+ and :- are now used instead of "+" and "-" o You can now inject a block to receive diff elements. o Speed improvements Version 0.3 Added unixdiff.rb, an implementation of Unix Diff (simple format only) Version 0.2 Speed improvements and code clean up Version 0.1 Initial release. Diff algorithm works. CREDITS Thanks to authors of Perl's Algorithm::Diff (originally written by Mark-Jason Dominus, currently maintained by Ned Konz). This code is basically a rewrite of Algorithm::Diff in Ruby. libalgorithm-diff-ruby-0.4.orig/install.rb0100644000220700022070000005214007466240646020160 0ustar takakitakaki# # This file is automatically generated. DO NOT MODIFY! # # install.rb # # Copyright (c) 2000-2002 Minero Aoki # # This program is free software. # You can distribute/modify this program under the terms of # the GNU Lesser General Public License version 2. # ### begin compat.rb unless Enumerable.instance_methods.include? 'inject' then module Enumerable def inject( result ) each do |i| result = yield(result, i) end result end end end def File.read_all( fname ) File.open(fname, 'rb') {|f| return f.read } end def File.write( fname, str ) File.open(fname, 'wb') {|f| f.write str } end ### end compat.rb ### begin config.rb if i = ARGV.index(/\A--rbconfig=/) then file = $' ARGV.delete_at(i) require file else require 'rbconfig' end class ConfigTable c = ::Config::CONFIG rubypath = c['bindir'] + '/' + c['ruby_install_name'] major = c['MAJOR'].to_i minor = c['MINOR'].to_i teeny = c['TEENY'].to_i version = "#{major}.#{minor}" # ruby ver. >= 1.4.4? newpath_p = ((major >= 2) or ((major == 1) and ((minor >= 5) or ((minor == 4) and (teeny >= 4))))) re = Regexp.new('\A' + Regexp.quote(c['prefix'])) subprefix = lambda {|path| re === path and path.sub(re, '$prefix') } if c['rubylibdir'] then # 1.6.3 < V stdruby = subprefix.call(c['rubylibdir']) siteruby = subprefix.call(c['sitedir']) versite = subprefix.call(c['sitelibdir']) sodir = subprefix.call(c['sitearchdir']) elsif newpath_p then # 1.4.4 <= V <= 1.6.3 stdruby = "$prefix/lib/ruby/#{version}" siteruby = subprefix.call(c['sitedir']) versite = siteruby + '/' + version sodir = "$site-ruby/#{c['arch']}" else # V < 1.4.4 stdruby = "$prefix/lib/ruby/#{version}" siteruby = "$prefix/lib/ruby/#{version}/site_ruby" versite = siteruby sodir = "$site-ruby/#{c['arch']}" end DESCRIPTER = [ [ 'prefix', [ c['prefix'], 'path', 'path prefix of target environment' ] ], [ 'std-ruby', [ stdruby, 'path', 'the directory for standard ruby libraries' ] ], [ 'site-ruby-common', [ siteruby, 'path', 'the directory for version-independent non-standard ruby libraries' ] ], [ 'site-ruby', [ versite, 'path', 'the directory for non-standard ruby libraries' ] ], [ 'bin-dir', [ '$prefix/bin', 'path', 'the directory for commands' ] ], [ 'rb-dir', [ '$site-ruby', 'path', 'the directory for ruby scripts' ] ], [ 'so-dir', [ sodir, 'path', 'the directory for ruby extentions' ] ], [ 'data-dir', [ '$prefix/share', 'path', 'the directory for shared data' ] ], [ 'ruby-path', [ rubypath, 'path', 'path to set to #! line' ] ], [ 'ruby-prog', [ rubypath, 'name', 'the ruby program using for installation' ] ], [ 'make-prog', [ 'make', 'name', 'the make program to compile ruby extentions' ] ], [ 'without-ext', [ 'no', 'yes/no', 'does not compile/install ruby extentions' ] ] ] SAVE_FILE = 'config.save' def ConfigTable.each_name( &block ) keys().each( &block ) end def ConfigTable.keys DESCRIPTER.collect {|k,*dummy| k } end def ConfigTable.each_definition( &block ) DESCRIPTER.each( &block ) end def ConfigTable.get_entry( name ) name, ent = DESCRIPTER.assoc(name) ent end def ConfigTable.get_entry!( name ) get_entry(name) or raise ArgumentError, "no such config: #{name}" end def ConfigTable.add_entry( name, vals ) ConfigTable::DESCRIPTER.push [name,vals] end def ConfigTable.remove_entry( name ) get_entry name or raise ArgumentError, "no such config: #{name}" DESCRIPTER.delete_if {|n,arr| n == name } end def ConfigTable.config_key?( name ) get_entry(name) ? true : false end def ConfigTable.bool_config?( name ) ent = get_entry(name) or return false ent[1] == 'yes/no' end def ConfigTable.value_config?( name ) ent = get_entry(name) or return false ent[1] != 'yes/no' end def ConfigTable.path_config?( name ) ent = get_entry(name) or return false ent[1] == 'path' end class << self alias newobj new def new c = newobj() c.__send__ :init c end def load c = newobj() File.file? SAVE_FILE or raise InstallError, "#{File.basename $0} config first" File.foreach( SAVE_FILE ) do |line| k, v = line.split( '=', 2 ) c.instance_eval { @table[k] = v.strip } end c end end def initialize @table = {} end def init DESCRIPTER.each do |k, (default, vname, desc, default2)| @table[k] = default end end private :init def save File.open( SAVE_FILE, 'w' ) {|f| @table.each do |k, v| f.printf "%s=%s\n", k, v if v end } end def []=( k, v ) ConfigTable.config_key? k or raise InstallError, "unknown config option #{k}" if ConfigTable.path_config? k then @table[k] = (v[0,1] != '$') ? File.expand_path(v) : v else @table[k] = v end end def []( key ) @table[key] or return nil @table[key].gsub( %r<\$([^/]+)> ) { self[$1] } end def set_raw( key, val ) @table[key] = val end def get_raw( key ) @table[key] end end class MetaConfigEnvironment def self.eval_file( file ) return unless File.file? file new.instance_eval File.read_all(file), file, 1 end private def config_names ConfigTable.keys end def config?( name ) ConfigTable.config_key? name end def bool_config?( name ) ConfigTable.bool_config? name end def value_config?( name ) ConfigTable.value_config? name end def path_config?( name ) ConfigTable.path_config? name end def add_config( name, argname, default, desc ) ConfigTable.add_entry name,[default,argname,desc] end def add_path_config( name, default, desc ) add_config name, 'path', default, desc end def add_bool_config( name, default, desc ) add_config name, 'yes/no', default ? 'yes' : 'no', desc end def set_config_default( name, default ) if bool_config? name then ConfigTable.get_entry!(name)[0] = default ? 'yes' : 'no' else ConfigTable.get_entry!(name)[0] = default end end def remove_config( name ) ent = ConfigTable.get_entry(name) ConfigTable.remove_entry name ent end end ### end config.rb ### begin fileop.rb module FileOperations def mkdir_p( dname, prefix = nil ) dname = prefix + dname if prefix $stderr.puts "mkdir -p #{dname}" if verbose? return if no_harm? # does not check '/'... it's too abnormal case dirs = dname.split(%r_(?=/)_) if /\A[a-z]:\z/i === dirs[0] then disk = dirs.shift dirs[0] = disk + dirs[0] end dirs.each_index do |idx| path = dirs[0..idx].join('') Dir.mkdir path unless dir? path end end def rm_f( fname ) $stderr.puts "rm -f #{fname}" if verbose? return if no_harm? if File.exist? fname or File.symlink? fname then File.chmod 0777, fname File.unlink fname end end def rm_rf( dn ) $stderr.puts "rm -rf #{dn}" if verbose? return if no_harm? Dir.chdir dn Dir.foreach('.') do |fn| next if fn == '.' next if fn == '..' if dir? fn then verbose_off { rm_rf fn } else verbose_off { rm_f fn } end end Dir.chdir '..' Dir.rmdir dn end def mv( src, dest ) rm_f dest begin File.link src, dest rescue File.write dest, File.read_all(src) File.chmod File.stat(src).mode, dest end rm_f src end def install( from, dest, mode, prefix = nil ) $stderr.puts "install #{from} #{dest}" if verbose? return if no_harm? realdest = prefix + dest if prefix if dir? realdest then realdest += '/' + File.basename(from) end str = File.read_all(from) if diff? str, realdest then verbose_off { rm_f realdest if File.exist? realdest } File.write realdest, str File.chmod mode, realdest File.open( objdir + '/InstalledFiles', 'a' ) {|f| f.puts realdest } end end def diff?( orig, targ ) return true unless File.exist? targ orig != File.read_all(targ) end def command( str ) $stderr.puts str if verbose? system str or raise RuntimeError, "'system #{str}' failed" end def ruby( str ) command config('ruby-prog') + ' ' + str end def dir?( dname ) # for corrupted windows stat() File.directory?( (dname[-1,1] == '/') ? dname : dname + '/' ) end def all_files( dname ) Dir.open( dname ) {|d| return d.find_all {|n| File.file? "#{dname}/#{n}" } } end def all_dirs( dname ) Dir.open( dname ) {|d| return d.find_all {|n| dir? "#{dname}/#{n}" } - %w(. ..) } end end ### end fileop.rb ### begin base.rb class InstallError < StandardError; end class Installer Version = '3.1.2' Copyright = 'Copyright (c) 2000-2002 Minero Aoki' @toplevel = nil def self.declear_toplevel_installer( inst ) @toplevel and raise ArgumentError, 'more than one toplevel installer decleared' @toplevel = inst end def self.toplevel_installer @toplevel end FILETYPES = %w( bin lib ext data ) include FileOperations def initialize( config, opt, srcroot, objroot ) @config = config @options = opt @srcdir = File.expand_path(srcroot) @objdir = File.expand_path(objroot) @currdir = '.' end def inspect "#<#{type} #{__id__}>" end # # configs/options # def get_config( key ) @config[key] end alias config get_config def set_config( key, val ) @config[key] = val end def no_harm? @options['no-harm'] end def verbose? @options['verbose'] end def verbose_off save, @options['verbose'] = @options['verbose'], false yield @options['verbose'] = save end # # srcdir/objdir # attr_reader :srcdir alias srcdir_root srcdir alias package_root srcdir def curr_srcdir "#{@srcdir}/#{@currdir}" end attr_reader :objdir alias objdir_root objdir def curr_objdir "#{@objdir}/#{@currdir}" end def srcfile( path ) curr_srcdir + '/' + path end def srcexist?( path ) File.exist? srcfile(path) end def srcdirectory?( path ) dir? srcfile(path) end def srcfile?( path ) File.file? srcfile(path) end def srcentries( path = '.' ) Dir.open( curr_srcdir + '/' + path ) {|d| return d.to_a - %w(. ..) - hookfilenames } end def srcfiles( path = '.' ) srcentries(path).find_all {|fname| File.file? File.join(curr_srcdir, path, fname) } end def srcdirectories( path = '.' ) srcentries(path).find_all {|fname| dir? File.join(curr_srcdir, path, fname) } end def dive_into( rel ) return unless dir? "#{@srcdir}/#{rel}" dir = File.basename(rel) Dir.mkdir dir unless dir? dir save = Dir.pwd Dir.chdir dir $stderr.puts '---> ' + rel if verbose? @currdir = rel yield Dir.chdir save $stderr.puts '<--- ' + rel if verbose? @currdir = File.dirname(rel) end # # config # def exec_config exec_task_traverse 'config' end def config_dir_bin( rel ) end def config_dir_lib( rel ) end def config_dir_ext( rel ) extconf if extdir? curr_srcdir end def extconf opt = @options['config-opt'].join(' ') command "#{config('ruby-prog')} #{curr_srcdir}/extconf.rb #{opt}" end def config_dir_data( rel ) end # # setup # def exec_setup exec_task_traverse 'setup' end def setup_dir_bin( relpath ) all_files( curr_srcdir ).each do |fname| add_rubypath "#{curr_srcdir}/#{fname}" end end SHEBANG_RE = /\A\#!\s*\S*ruby\S*/ def add_rubypath( path ) $stderr.puts %Q if verbose? return if no_harm? tmpfile = File.basename(path) + '.tmp' begin File.open( path ) {|r| File.open( tmpfile, 'w' ) {|w| first = r.gets return unless SHEBANG_RE === first # reject '/usr/bin/env ruby' w.print first.sub( SHEBANG_RE, '#!' + config('ruby-path') ) w.write r.read } } mv tmpfile, File.basename(path) ensure rm_f tmpfile if File.exist? tmpfile end end def setup_dir_lib( relpath ) end def setup_dir_ext( relpath ) if extdir? curr_srcdir then make end end def make command config('make-prog') end def setup_dir_data( relpath ) end # # install # def exec_install exec_task_traverse 'install' end def install_dir_bin( rel ) install_files targfiles, config('bin-dir') + '/' + rel, 0755 end def install_dir_lib( rel ) install_files targfiles, config('rb-dir') + '/' + rel, 0644 end def install_dir_ext( rel ) if extdir? curr_srcdir then install_dir_ext_main File.dirname(rel) end end def install_dir_ext_main( rel ) install_files allext('.'), config('so-dir') + '/' + rel, 0555 end def install_dir_data( rel ) install_files targfiles, config('data-dir') + '/' + rel, 0644 end def install_files( list, dest, mode ) mkdir_p dest, @options['install-prefix'] list.each do |fname| install fname, dest, mode, @options['install-prefix'] end end def targfiles (targfilenames() - hookfilenames()).collect {|fname| File.exist?(fname) ? fname : File.join(curr_srcdir(), fname) } end def targfilenames [ curr_srcdir(), '.' ].inject([]) {|ret, dir| ret | all_files(dir) } end def hookfilenames %w( pre-%s post-%s pre-%s.rb post-%s.rb ).collect {|fmt| %w( config setup install clean ).collect {|t| sprintf fmt, t } }.flatten end def allext( dir ) _allext(dir) or raise InstallError, "no extention exists: Have you done 'ruby #{$0} setup' ?" end DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/ def _allext( dir ) Dir.open( dir ) {|d| return d.find_all {|fname| DLEXT === fname } } end # # clean # def exec_clean exec_task_traverse 'clean' rm_f 'config.save' rm_f 'InstalledFiles' end def clean_dir_bin( rel ) end def clean_dir_lib( rel ) end def clean_dir_ext( rel ) clean end def clean command config('make-prog') + ' clean' if File.file? 'Makefile' end def clean_dir_data( rel ) end # # lib # def exec_task_traverse( task ) run_hook 'pre-' + task FILETYPES.each do |type| if config('without-ext') == 'yes' and type == 'ext' then $stderr.puts 'skipping ext/* by user option' if verbose? next end traverse task, type, task + '_dir_' + type end run_hook 'post-' + task end def traverse( task, rel, mid ) dive_into( rel ) { run_hook 'pre-' + task __send__ mid, rel.sub( %r_\A.*?(?:/|\z)_, '' ) all_dirs( curr_srcdir ).each do |d| traverse task, rel + '/' + d, mid end run_hook 'post-' + task } end def run_hook( name ) try_run_hook curr_srcdir + '/' + name or try_run_hook curr_srcdir + '/' + name + '.rb' end def try_run_hook( fname ) return false unless File.file? fname env = self.dup begin env.instance_eval File.read_all(fname), fname, 1 rescue raise InstallError, "hook #{fname} failed:\n" + $!.message end true end def extdir?( dir ) File.exist? dir + '/MANIFEST' end end ### end base.rb ### begin toplevel.rb class ToplevelInstaller < Installer TASKS = [ [ 'config', 'saves your configurations' ], [ 'show', 'shows current configuration' ], [ 'setup', 'compiles extention or else' ], [ 'install', 'installs files' ], [ 'clean', "does `make clean' for each extention" ] ] def initialize( root ) super nil, {'verbose' => true}, root, '.' Installer.declear_toplevel_installer self end def execute run_metaconfigs case task = parsearg_global() when 'config' @config = ConfigTable.new else @config = ConfigTable.load end parsearg_TASK task exectask task end def run_metaconfigs MetaConfigEnvironment.eval_file "#{srcdir_root}/#{metaconfig}" end def metaconfig 'metaconfig' end def exectask( task ) if task == 'show' then exec_show else try task end end def try( task ) $stderr.printf "#{File.basename $0}: entering %s phase...\n", task if verbose? begin __send__ 'exec_' + task rescue $stderr.printf "%s failed\n", task raise end $stderr.printf "#{File.basename $0}: %s done.\n", task if verbose? end # # processing arguments # def parsearg_global task_re = /\A(?:#{TASKS.collect {|i| i[0] }.join '|'})\z/ while arg = ARGV.shift do case arg when /\A\w+\z/ task_re === arg or raise InstallError, "wrong task: #{arg}" return arg when '-q', '--quiet' @options['verbose'] = false when '--verbose' @options['verbose'] = true when '-h', '--help' print_usage $stdout exit 0 when '-v', '--version' puts "#{File.basename $0} version #{Version}" exit 0 when '--copyright' puts Copyright exit 0 else raise InstallError, "unknown global option '#{arg}'" end end raise InstallError, 'no task or global option given' end def parsearg_TASK( task ) mid = "parsearg_#{task}" if respond_to? mid, true then __send__ mid else ARGV.empty? or raise InstallError, "#{task}: unknown options: #{ARGV.join ' '}" end end def parsearg_config re = /\A--(#{ConfigTable.keys.join '|'})(?:=(.*))?\z/ @options['config-opt'] = [] while i = ARGV.shift do if /\A--?\z/ === i then @options['config-opt'] = ARGV.dup break end m = re.match(i) or raise InstallError, "config: unknown option #{i}" name, value = m.to_a[1,2] if value then if ConfigTable.bool_config?(name) then /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i === value or raise InstallError, "config: --#{name} allows only yes/no for argument" value = (/\Ay(es)?|\At(rue)/i === value) ? 'yes' : 'no' end else ConfigTable.bool_config?(name) or raise InstallError, "config: --#{name} requires argument" value = 'yes' end @config[name] = value end end def parsearg_install @options['no-harm'] = false @options['install-prefix'] = '' while a = ARGV.shift do case a when /\A--no-harm\z/ @options['no-harm'] = true when /\A--prefix=(.*)\z/ path = $1 path = File.expand_path(path) unless path[0,1] == '/' @options['install-prefix'] = path else raise InstallError, "install: unknown option #{a}" end end end def print_usage( out ) out.puts out.puts 'Usage:' out.puts " ruby #{File.basename $0} " out.puts " ruby #{File.basename $0} [] []" fmt = " %-20s %s\n" out.puts out.puts 'Global options:' out.printf fmt, '-q,--quiet', 'suppress message outputs' out.printf fmt, ' --verbose', 'output messages verbosely' out.printf fmt, '-h,--help', 'print this message' out.printf fmt, '-v,--version', 'print version and quit' out.printf fmt, '--copyright', 'print copyright and quit' out.puts out.puts 'Tasks:' TASKS.each do |name, desc| out.printf " %-10s %s\n", name, desc end out.puts out.puts 'Options for config:' ConfigTable.each_definition do |name, (default, arg, desc, default2)| out.printf " %-20s %s [%s]\n", '--'+ name + (ConfigTable.bool_config?(name) ? '' : '='+arg), desc, default2 || default end out.printf " %-20s %s [%s]\n", '--rbconfig=path', 'your rbconfig.rb to load', "running ruby's" out.puts out.puts 'Options for install:' out.printf " %-20s %s [%s]\n", '--no-harm', 'only display what to do if given', 'off' out.puts end # # config # def exec_config super @config.save end # # show # def exec_show ConfigTable.each_name do |k| v = @config.get_raw(k) if not v or v.empty? then v = '(not specified)' end printf "%-10s %s\n", k, v end end end ### end toplevel.rb if $0 == __FILE__ then begin installer = ToplevelInstaller.new( File.dirname($0) ) installer.execute rescue raise if $DEBUG $stderr.puts $!.message $stderr.puts "try 'ruby #{$0} --help' for usage" exit 1 end end libalgorithm-diff-ruby-0.4.orig/samples/0040775000220700022070000000000007543070573017630 5ustar takakitakakilibalgorithm-diff-ruby-0.4.orig/samples/bytediff.rb0100764000220700022070000000035007470304436021742 0ustar takakitakaki#!/usr/bin/ruby require 'algorithm/diff' if ARGV.length != 2 puts "Usage: #{$0} file1 file2" exit 1 end data = [] for i in 0..1 do File.open(ARGV[i], "r") { |f| data[i] = f.read } end diff = data[0].diff(data[1]) p diff libalgorithm-diff-ruby-0.4.orig/samples/unixdiff.rb0100775000220700022070000000261607470303544021772 0ustar takakitakaki#!/usr/bin/env ruby require 'algorithm/diff' # TODO: parameters def loadfile(filename) lines = nil File.open(filename, "r") { |f| lines = f.readlines } return lines end def diffrange(a, b) if (a == b) "#{a}" else "#{a},#{b}" end end class Diff def to_diff(io = $defout) offset = 0 return if @diffs.empty? #@diffs.each { |b| first = @diffs[0][1] length = @diffs.length action = @diffs[0][0] addcount = 0 remcount = 0 @diffs.each { |l| if l[0] == "+" addcount += 1 elsif l[0] == "-" remcount += 1 end } if addcount == 0 puts "#{diffrange(first+1, first+remcount)}d#{first+offset}" elsif remcount == 0 puts "#{first-offset}a#{diffrange(first+1, first+addcount)}" else puts "#{diffrange(first+1, first+remcount)}c#{diffrange(first+offset+1, first+offset+addcount)}" end lastdel = (@diffs[0][0] == "-") @diffs.each { |l| if l[0] == "-" offset -= 1 print "< " elsif l[0] == "+" offset += 1 if lastdel lastdel = false puts "---" end print "> " end print l[2] } #} end end if $0 == __FILE__ file1 = ARGV.shift file2 = ARGV.shift ary1 = loadfile file1 ary2 = loadfile file2 diff = Diff.new(ary1, ary2) diff.to_diff end libalgorithm-diff-ruby-0.4.orig/TODO0100664000220700022070000000047207351622706016652 0ustar takakitakaki= For 1.0: * Settle on a diff format, e.g. what should the first field look like: [ '+', 23, "foo" ] [ :add, 23, "foo" ] [ DiffAdd, 23, "foo" ] or should we have classed class DiffAdd attr_reader :position, :element end = Other Ideas: * Contextual diffs? * Unix diff/patch compatible wrapper