Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Algorithm / diff.pl
1 #!/usr/bin/perl
2 #
3 # `Diff' program in Perl
4 # Copyright 1998 M-J. Dominus. (mjd-perl-diff@plover.com)
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
10 use Algorithm::Diff qw(diff);
11
12 bag("Usage: $0 oldfile newfile") unless @ARGV == 2;
13
14 my ($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
22 open (F1, $file1) or bag("Couldn't open $file1: $!");
23 open (F2, $file2) or bag("Couldn't open $file2: $!");
24 chomp(@f1 = <F1>);
25 close F1;
26 chomp(@f2 = <F2>);
27 close F2;
28
29 $diffs = diff(\@f1, \@f2);
30 exit 0 unless @$diffs;
31
32 foreach $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 }
40 exit 1;
41
42 sub bag {
43   my $msg = shift;
44   $msg .= "\n";
45   warn $msg;
46   exit 2;
47 }