Line | |
---|
1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | my $oldfile = undef; |
---|
7 | my $newfile = undef; |
---|
8 | |
---|
9 | my $newpad = ''; |
---|
10 | my $oldpad = ''; |
---|
11 | |
---|
12 | my $correct = 0; # perform correction? |
---|
13 | my $corr = 0; # correct by number of lines |
---|
14 | |
---|
15 | sub set_padding_and_correction() { |
---|
16 | $correct = 1; |
---|
17 | $corr = 0; |
---|
18 | |
---|
19 | if (defined $oldfile and defined $newfile) { |
---|
20 | my $oldlen = length($oldfile); |
---|
21 | my $newlen = length($newfile); |
---|
22 | |
---|
23 | $newpad = ''; |
---|
24 | $oldpad = ''; |
---|
25 | |
---|
26 | while ($oldlen<$newlen) { $oldpad .= ' '; $oldlen++; } |
---|
27 | while ($newlen<$oldlen) { $newpad .= ' '; $newlen++; } |
---|
28 | |
---|
29 | if ($oldfile ne $newfile) { $correct = 0; } |
---|
30 | |
---|
31 | print "diff2grep.pl: oldfile='$oldfile'\n"; |
---|
32 | print "diff2grep.pl: newfile='$newfile'\n"; |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | my $pwd = `pwd`; chomp($pwd); |
---|
37 | |
---|
38 | print "diff2grep.pl: Entering directory `$pwd'\n"; |
---|
39 | |
---|
40 | my ($o1,$o2,$n1,$n2); |
---|
41 | |
---|
42 | while (defined ($_ = <>)) { |
---|
43 | chomp; |
---|
44 | if (/^--- ([^\t]+)\t/) { |
---|
45 | $oldfile = $1; |
---|
46 | set_padding_and_correction(); |
---|
47 | } |
---|
48 | elsif (/^\+\+\+ ([^\t]+)\t/) { |
---|
49 | $newfile = $1; |
---|
50 | set_padding_and_correction(); |
---|
51 | } |
---|
52 | elsif (/^-/) { |
---|
53 | print "$oldfile:".($o1+$corr*$correct).":$oldpad OLD: $'\n"; |
---|
54 | $o1++; |
---|
55 | $corr--; |
---|
56 | } |
---|
57 | elsif (/^\+/) { |
---|
58 | print "$newfile:".($n1).":$newpad NEW: $'\n"; |
---|
59 | $n1++; |
---|
60 | $corr++; |
---|
61 | } |
---|
62 | elsif (/^\@\@ -(.*),(.*) \+(.*),(.*) \@\@$/) { |
---|
63 | ($o1,$o2,$n1,$n2) = ($1,$2,$3,$4); |
---|
64 | print $_."\n"; |
---|
65 | } |
---|
66 | else { |
---|
67 | print $_."\n"; |
---|
68 | $o1++; |
---|
69 | $n1++; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | print "diff2grep.pl: Leaving directory `$pwd'\n"; |
---|
74 | |
---|
Note: See
TracBrowser
for help on using the repository browser.