| 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 | |
| 10 | use Algorithm::Diffscip-perl cpan Algorithm-Diff 1.201 Algorithm/Diff/ qw(diff); |
| 11 | |
| 12 | bagscip-perl cpan Algorithm-Diff 1.201 main/bag().("Usage: $0 oldfile newfile") unless @ARGVscip-perl cpan Algorithm-Diff 1.201 main/`@ARGV`. == 2; |
| 13 | |
| 14 | my ($file1, $file2) = @ARGVscip-perl cpan Algorithm-Diff 1.201 main/`@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 bagscip-perl cpan Algorithm-Diff 1.201 main/bag().("$file1: binary"); |
| 20 | -T $file2 or bagscip-perl cpan Algorithm-Diff 1.201 main/bag().("$file2: binary"); |
| 21 | |
| 22 | openscip-perl cpan Algorithm-Diff 1.201 main/open(). (F1, $file1) or bagscip-perl cpan Algorithm-Diff 1.201 main/bag().("Couldn't open $file1: $!"); |
| 23 | openscip-perl cpan Algorithm-Diff 1.201 main/open(). (F2, $file2) or bagscip-perl cpan Algorithm-Diff 1.201 main/bag().("Couldn't open $file2: $!"); |
| 24 | chompscip-perl cpan Algorithm-Diff 1.201 main/chomp().(@f1scip-perl cpan Algorithm-Diff 1.201 main/`@f1`. = <F1>); |
| 25 | close F1; |
| 26 | chompscip-perl cpan Algorithm-Diff 1.201 main/chomp().(@f2scip-perl cpan Algorithm-Diff 1.201 main/`@f2`. = <F2>); |
| 27 | close F2; |
| 28 | |
| 29 | $diffsscip-perl cpan Algorithm-Diff 1.201 main/$diffs. = diffscip-perl cpan Algorithm-Diff 1.201 Algorithm/Diff/diff().(\@f1scip-perl cpan Algorithm-Diff 1.201 main/`@f1`., \@f2scip-perl cpan Algorithm-Diff 1.201 main/`@f2`.); |
| 30 | exitscip-perl cpan Algorithm-Diff 1.201 main/exit(). 0 unless @$diffsscip-perl cpan Algorithm-Diff 1.201 main/$diffs.; |
| 31 | |
| 32 | foreach $chunkscip-perl cpan Algorithm-Diff 1.201 main/$chunk. (@$diffsscip-perl cpan Algorithm-Diff 1.201 main/$diffs.) { |
| 33 | |
| 34 | foreach $linescip-perl cpan Algorithm-Diff 1.201 main/$line. (@$chunkscip-perl cpan Algorithm-Diff 1.201 main/$chunk.) { |
| 35 | my ($sign, $lineno, $text) = @$linescip-perl cpan Algorithm-Diff 1.201 main/$line.; |
| 36 | printfscip-perl cpan Algorithm-Diff 1.201 main/printf(). "%4d$sign %s\n", $lineno+1, $text; |
| 37 | } |
| 38 | printscip-perl cpan Algorithm-Diff 1.201 main/print(). "--------\n"; |
| 39 | } |
| 40 | exitscip-perl cpan Algorithm-Diff 1.201 main/exit(). 1; |
| 41 | |
| 42 | sub bagscip-perl cpan Algorithm-Diff 1.201 main/bag(). { |
| 43 | my $msg = shiftscip-perl cpan Algorithm-Diff 1.201 main/shift().; |
| 44 | $msg .= "\n"; |
| 45 | warnscip-perl cpan Algorithm-Diff 1.201 main/warn(). $msg; |
| 46 | exitscip-perl cpan Algorithm-Diff 1.201 main/exit(). 2; |
| 47 | } |