source: other-projects/diffcol/trunk/diffcol/Algorithm/diff.pl@ 21711

Last change on this file since 21711 was 21711, checked in by oranfry, 14 years ago

bringing across the diffcol project

File size: 977 bytes
Line 
1#!/usr/bin/perl
2#
3# `Diff' program in Perl
4# Copyright 1998 M-J. Dominus. ([email protected])
5#
6# This program is free software; you can redistribute it and/or modify it
7# under the same terms as Perl itself.
8#
9
10use Algorithm::Diff qw(diff);
11
12bag("Usage: $0 oldfile newfile") unless @ARGV == 2;
13
14my ($file1, $file2) = @ARGV;
15
16# -f $file1 or bag("$file1: not a regular file");
17# -f $file2 or bag("$file2: not a regular file");
18
19-T $file1 or bag("$file1: binary");
20-T $file2 or bag("$file2: binary");
21
22open (F1, $file1) or bag("Couldn't open $file1: $!");
23open (F2, $file2) or bag("Couldn't open $file2: $!");
24chomp(@f1 = <F1>);
25close F1;
26chomp(@f2 = <F2>);
27close F2;
28
29$diffs = diff(\@f1, \@f2);
30exit 0 unless @$diffs;
31
32foreach $chunk (@$diffs) {
33
34 foreach $line (@$chunk) {
35 my ($sign, $lineno, $text) = @$line;
36 printf "%4d$sign %s\n", $lineno+1, $text;
37 }
38 print "--------\n";
39}
40exit 1;
41
42sub bag {
43 my $msg = shift;
44 $msg .= "\n";
45 warn $msg;
46 exit 2;
47}
Note: See TracBrowser for help on using the repository browser.