#!/usr/bin/env ruby #-- # Copyright 2004 Austin Ziegler # adapted from: # Algorithm::Diff (Perl) by Ned Konz # Smalltalk by Mario I. Wolczko # implements McIlroy-Hunt diff algorithm # # This program is free software. It may be redistributed and/or modified under # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the # Ruby licence. # # $Id: htmldiff,v 1.6 2004/10/17 19:33:21 austin Exp $ #++ begin require 'rubygems' require_gem 'diff-lcs', "1.1.1" require 'diff/lcs/string' rescue LoadError require 'diff/lcs' require 'diff/lcs/string' end require 'text/format' class HTMLDiff #:nodoc: attr_accessor :output def initialize(output) @output = output end # This will be called with both lines are the same def match(event) @output << %Q|
#{event.old_element}
\n| end # This will be called when there is a line in A that isn't in B def discard_a(event) @output << %Q|
#{event.old_element}
\n| end # This will be called when there is a line in B that isn't in A def discard_b(event) @output << %Q|
#{event.new_element}
\n| end end if ARGV.size != 2 puts "usage: #{File.basename($0)} old new > output.html" exit 255 end hd = HTMLDiff.new($stdout) tf = Text::Format.new tf.tabstop = 4 preprocess = lambda { |line| tf.expand(line.chomp) } a = IO.readlines(ARGV[0]).map(&preprocess) b = IO.readlines(ARGV[1]).map(&preprocess) $stdout.write <<-START diff #{ARGV[0]} #{ARGV[1]}

diff  #{ARGV[0]}  #{ARGV[1]}

START Diff::LCS.traverse_sequences(a, b, hd) $stdout.write <<-END
END