summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/htmldiff112
-rw-r--r--bin/ldiff45
2 files changed, 157 insertions, 0 deletions
diff --git a/bin/htmldiff b/bin/htmldiff
new file mode 100644
index 0000000..509860c
--- /dev/null
+++ b/bin/htmldiff
@@ -0,0 +1,112 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
+# adapted from:
+# Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
+# Smalltalk by Mario I. Wolczko <mario@wolczko.com>
+# 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$
+#++
+
+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|<pre class="match">#{event.old_element}</pre>\n|
+ end
+
+ # This will be called when there is a line in A that isn't in B
+ def discard_a(event)
+ @output << %Q|<pre class="only_a">#{event.old_element}</pre>\n|
+ end
+
+ # This will be called when there is a line in B that isn't in A
+ def discard_b(event)
+ @output << %Q|<pre class="only_b">#{event.new_element}</pre>\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
+<html>
+ <head>
+ <title>diff #{ARGV[0]} #{ARGV[1]}</title>
+ <style>
+ body { margin: 0; }
+ .diff
+ {
+ border: 1px solid black;
+ margin: 1em 2em;
+ }
+ pre
+ {
+ padding-left: 1em;
+ margin: 0;
+ font-family: Lucida, Courier, monospaced;
+ white-space: pre;
+ }
+ .match { }
+ .only_a
+ {
+ background-color: #fdd;
+ color: red;
+ text-decoration: line-through;
+ }
+ .only_b
+ {
+ background-color: #ddf;
+ color: blue;
+ border-left: 3px solid blue
+ }
+ h1 { margin-left: 2em; }
+ </style>
+ </head>
+ <body>
+ <h1>diff&nbsp;
+ <span class="only_a">#{ARGV[0]}</span>&nbsp;
+ <span class="only_b">#{ARGV[1]}</span>
+ </h1>
+ <div class="diff">
+START
+
+Diff::LCS.traverse_sequences(a, b, hd)
+
+$stdout.write <<-END
+ </div>
+ </body>
+</html>
+END
diff --git a/bin/ldiff b/bin/ldiff
new file mode 100644
index 0000000..ae2b245
--- /dev/null
+++ b/bin/ldiff
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
+# adapted from:
+# Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
+# Smalltalk by Mario I. Wolczko <mario@wolczko.com>
+# 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$
+#++
+
+ # 1) Try to load Ruwiki from the gem.
+ # 2) Try to load Ruwiki from $LOAD_PATH.
+ # 3) Modify $LOAD_PATH and try to load it from the modified $LOAD_PATH.
+ # 4) Fail hard.
+load_state = 1
+ begin
+ if 1 == load_state
+ require 'rubygems'
+ require_gem 'diff-lcs', '= 1.1.1'
+ else
+ require 'diff/lcs'
+ end
+ rescue LoadError
+ load_state += 1
+
+ case load_state
+ when 3
+ $LOAD_PATH.unshift "#{File.dirname($0)}/../lib"
+ when 4
+ $LOAD_PATH.shift
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+ when 5
+ raise
+ end
+ retry
+ end
+
+require 'diff/lcs/ldiff'
+
+exit Diff::LCS::Ldiff.run(ARGV)